1 ;;; chise-tex.el --- Coding-system based chise2otf like tool
3 ;; Copyright (C) 2004,2005 MORIOKA Tomohiko
5 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
6 ;; Keywords: OTF package, pTeX, CHISE, Multiscript, Multilingual
8 ;; This file is a part of Omega/CHISE.
10 ;; This program is free software; you can redistribute it and/or
11 ;; modify it under the terms of the GNU General Public License as
12 ;; published by the Free Software Foundation; either version 2, or (at
13 ;; your option) any later version.
15 ;; This program is distributed in the hope that it will be useful, but
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ;; General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with this program; see the file COPYING. If not, write to
22 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 (defvar chise-tex-coded-charset-expression-alist
28 '((=ucs-hangul "UCShang" 4 X)
30 (=ucs@jis "UCSjis" 4 X)
31 (=ucs@jis/2000 "UCSjis" 4 X)
33 (=gt-pj-1 "GTpj1" 4 X)
34 (=gt-pj-2 "GTpj2" 4 X)
35 (=gt-pj-3 "GTpj3" 4 X)
36 (=gt-pj-4 "GTpj4" 4 X)
37 (=gt-pj-5 "GTpj5" 4 X)
38 (=gt-pj-6 "GTpj6" 4 X)
39 (=gt-pj-7 "GTpj7" 4 X)
40 (=gt-pj-8 "GTpj8" 4 X)
41 (=gt-pj-9 "GTpj9" 4 X)
42 (=gt-pj-10 "GTpj10" 4 X)
43 (=gt-pj-11 "GTpj11" 4 X)
44 (=ucs@cns "UCScns" 4 X)))
46 (defun chise-tex-encode-region-for-gb (start end)
50 (narrow-to-region start end)
52 (let (chr ret rest spec)
53 (while (and (skip-chars-forward "\x00-\xFF")
55 (setq chr (char-after))
56 (cond ((memq chr '(?
\e$(O#@
\e(B))
58 (insert (format "\\UCSjis{%04X}"
59 (encode-char chr '=ucs@jis)))
61 ((and (setq ret (encode-char chr '=jis-x0208-1983))
64 ;; ((setq ret (encode-char chr '=jis-x0208-1990))
66 ;; (insert (decode-char '=jis-x0208-1983 ret)))
67 ((and (encode-char chr '=ks-x1001)
68 (setq ret (or (encode-char chr '=ucs@ks)
71 ;; (if (eq (char-before) ?
\e$B!T
\e(B)
73 (insert (format "\\UCSks{%04X}" ret)))
75 (setq rest chise-tex-coded-charset-expression-alist)
76 (while (setq spec (car rest))
77 (if (setq ret (encode-char chr (car spec)))
79 (setq rest (cdr rest))))
81 ;; (if (eq (char-before) ?
\e$B!T
\e(B)
83 (insert (format (format "\\%s{%%0%d%s}"
91 (defun chise-tex-encode-region-for-jis (start end)
95 (narrow-to-region start end)
97 (let (chr ret rest spec)
98 (while (and (skip-chars-forward "\x00-\xFF")
100 (setq chr (char-after))
101 (cond ((encode-char chr '=jis-x0208-1983)
103 ;; ((setq ret (encode-char chr '=jis-x0208-1990))
105 ;; (insert (decode-char '=jis-x0208-1983 ret)))
106 ((and (or (encode-char chr '=jis-x0213-1-2000)
107 (encode-char chr '=jis-x0213-2-2000))
108 (setq ret (or (encode-char chr '=ucs@jis/2000)
109 (encode-char chr '=ucs@jis/fw))))
111 ;; (if (eq (char-before) ?
\e$B!T
\e(B)
113 (insert (format "\\UCSjis{%04X}" ret)))
114 ((and (encode-char chr '=ks-x1001)
115 (setq ret (or (encode-char chr '=ucs@ks)
118 ;; (if (eq (char-before) ?
\e$B!T
\e(B)
120 (insert (format "\\UCSks{%04X}" ret)))
121 ((setq ret (encode-char chr '=ucs-hangul))
123 ;; (if (eq (char-before) ?
\e$B!T
\e(B)
125 (insert (format "\\UCSks{%04X}" ret)))
128 (insert "\\textbullet{}"))
131 (insert "\\UCSjis{0294}"))
132 ((and (encode-char chr '=ucs@jp)
133 (setq ret (char-representative-of-domain chr 'gb))
134 (setq ret (encode-char ret '=ucs@gb)))
136 ;; (if (eq (char-before) ?
\e$B!T
\e(B)
138 (insert (format "\\UCSgb{%04X}" ret)))
140 (setq rest chise-tex-coded-charset-expression-alist)
141 (while (setq spec (car rest))
142 (if (setq ret (encode-char chr (car spec)))
144 (setq rest (cdr rest))))
146 ;; (if (eq (char-before) ?
\e$B!T
\e(B)
148 (insert (format (format "\\%s{%%0%d%s}"
154 (forward-char))))))))
156 (defun chise-tex-decode-region (start end)
160 (narrow-to-region start end)
162 (let (macro code ret me rest spec)
163 (while (re-search-forward "\\\\\\([a-zA-Z0-9]+\\){\\([0-9A-Fa-f]+\\)}"
165 (setq macro (match-string 1)
166 code (match-string 2)
169 (setq rest chise-tex-coded-charset-expression-alist)
170 (while (setq spec (car rest))
171 (if (string= (nth 1 spec) macro)
173 (setq rest (cdr rest))))
174 (setq ret (decode-char (car spec)
177 (if (eq (nth 3 spec) 'X)
180 (delete-region (match-beginning 0)(match-end 0))
185 'iso-2022-jp-tex-gb 'iso2022
186 "ISO-2022-JP with TeX representation for GB fonts."
190 input-charset-conversion ((latin-jisx0201 ascii)
191 (japanese-jisx0208-1978 japanese-jisx0208))
192 pre-write-conversion chise-tex-encode-region-for-gb
193 post-read-conversion chise-tex-decode-region
194 mnemonic "pTeX(GB)/7bit"
198 'iso-2022-jp-tex-jis 'iso2022
199 "ISO-2022-JP with TeX representation for JIS fonts."
203 input-charset-conversion ((latin-jisx0201 ascii)
204 (japanese-jisx0208-1978 japanese-jisx0208))
205 pre-write-conversion chise-tex-encode-region-for-jis
206 post-read-conversion chise-tex-decode-region
207 mnemonic "pTeX(JIS)/7bit"
216 ;;; chise-tex.el ends here