From: tomo Date: Thu, 24 Jun 2004 11:19:41 +0000 (+0000) Subject: New file. X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2a397921ac9d771d44d2bb6a063e20c68a2f7528;p=chise%2Fomega.git New file. --- diff --git a/chise2otf/elisp/chise-tex.el b/chise2otf/elisp/chise-tex.el new file mode 100644 index 0000000..7178f6c --- /dev/null +++ b/chise2otf/elisp/chise-tex.el @@ -0,0 +1,96 @@ +(defvar chise-tex-coded-charset-expression-alist + '((=ucs@gb "UCSgb" 4 X) + (=ucs@jis "UCSjis" 4 X) + (=gt-pj-1 "GTpj1" 4 X) + (=gt-pj-2 "GTpj2" 4 X) + (=gt-pj-3 "GTpj3" 4 X) + (=gt-pj-4 "GTpj4" 4 X) + (=gt-pj-5 "GTpj5" 4 X) + (=gt-pj-6 "GTpj6" 4 X) + (=gt-pj-7 "GTpj7" 4 X) + (=gt-pj-8 "GTpj8" 4 X) + (=gt-pj-9 "GTpj9" 4 X) + (=gt-pj-10 "GTpj10" 4 X) + (=gt-pj-11 "GTpj11" 4 X) + (=ucs@ks "UCSks" 4 X) + (=ucs@cns "UCScns" 4 X))) + +(defun chise-tex-encode-region (start end) + (interactive "r") + (save-excursion + (save-restriction + (narrow-to-region start end) + (goto-char start) + (let (chr ret rest spec) + (while (and (skip-chars-forward "\x00-\xFF") + (not (eobp))) + (setq chr (char-after)) + (cond ((memq chr '(?$(O#@(B)) + (delete-char) + (insert (format "\\UCSjis{%04X}" + (encode-char chr '=ucs@jis))) + ) + ((and (setq ret (encode-char chr '=jis-x0208-1983)) + (< ret #x3021)) + (forward-char)) + ;; ((setq ret (encode-char chr '=jis-x0208-1990)) + ;; (delete-char) + ;; (insert (decode-char '=jis-x0208-1983 ret))) + ((catch 'tag + (setq rest chise-tex-coded-charset-expression-alist) + (while (setq spec (car rest)) + (if (setq ret (encode-char chr (car spec))) + (throw 'tag ret)) + (setq rest (cdr rest)))) + (delete-char) + ;; (if (eq (char-before) ?$B!T(B) + ;; (insert " ")) + (insert (format (format "\\%s{%%0%d%s}" + (nth 1 spec) + (nth 2 spec) + (nth 3 spec)) + ret))) + (t + (forward-char)))))))) + +(defun chise-tex-decode-region (start end) + (interactive "r") + (save-excursion + (save-restriction + (narrow-to-region start end) + (goto-char start) + (let (macro code ret ms me) + (while (re-search-forward "\\\\\\([a-zA-Z0-9]+\\){\\([0-9A-Fa-f]+\\)}" + nil t) + (setq macro (match-string 1) + code (match-string 2) + ms (match-beginning 0) + me (match-end 0)) + (if (and (catch 'tag + (setq rest chise-tex-coded-charset-expression-alist) + (while (setq spec (car rest)) + (if (string= (nth 1 spec) macro) + (throw 'tag spec)) + (setq rest (cdr rest)))) + (setq ret (decode-char (car spec) + (string-to-int + code + (if (eq (nth 3 spec) 'X) + 16))))) + (progn + (delete-region (match-beginning 0)(match-end 0)) + (insert ret)) + (goto-char me))))))) + +(make-coding-system + 'iso-2022-jp-tex 'iso2022 + "ISO-2022-JP with TeX representation." + '(charset-g0 ascii + short t + seven t + input-charset-conversion ((latin-jisx0201 ascii) + (japanese-jisx0208-1978 japanese-jisx0208)) + pre-write-conversion chise-tex-encode-region + post-read-conversion chise-tex-decode-region + mnemonic "pTeX/7bit" + ))