New file.
authortomo <tomo>
Thu, 24 Jun 2004 11:19:41 +0000 (11:19 +0000)
committertomo <tomo>
Thu, 24 Jun 2004 11:19:41 +0000 (11:19 +0000)
chise2otf/elisp/chise-tex.el [new file with mode: 0644]

diff --git a/chise2otf/elisp/chise-tex.el b/chise2otf/elisp/chise-tex.el
new file mode 100644 (file)
index 0000000..7178f6c
--- /dev/null
@@ -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 '(?\e$(O#@\e(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) ?\e$B!T\e(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"
+   ))