1 ;;; chise-tex.el --- Coding-system based chise2otf like tool
3 ;; Copyright (C) 2004,2005,2006 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-bmp@gb "UCSgb" 4 X)
29 (=ucs-bmp@jis "UCSjis" 4 X)
30 (=ucs-bmp@ks "UCSks" 4 X)
31 (=gt-pj-1 "GTpjA" 4 X)
32 (=gt-pj-2 "GTpjB" 4 X)
33 (=gt-pj-3 "GTpjC" 4 X)
34 (=gt-pj-4 "GTpjD" 4 X)
35 (=gt-pj-5 "GTpjE" 4 X)
36 (=gt-pj-6 "GTpjF" 4 X)
37 (=gt-pj-7 "GTpjG" 4 X)
38 (=gt-pj-8 "GTpjH" 4 X)
39 (=gt-pj-9 "GTpjI" 4 X)
40 (=gt-pj-10 "GTpjJ" 4 X)
41 (=gt-pj-11 "GTpjK" 4 X)
42 (=ruimoku-v6 "Ruimoku" 4 X)
43 (=ucs-bmp@cns "UCScns" 4 X)))
45 (defun chise-tex-encode-region-for-gb (start end)
49 (narrow-to-region start end)
51 (let (chr ret rest spec)
52 (while (and (skip-chars-forward "\x00-\xFF")
54 (setq chr (char-after))
55 (cond ((memq chr '(?
\e$(O#@
\e(B))
57 (insert (format "\\UCSjis{%04X}"
58 (encode-char chr '=ucs@jis)))
60 ((and (setq ret (encode-char chr '=jis-x0208-1983))
63 ;; ((setq ret (encode-char chr '=jis-x0208-1990))
65 ;; (insert (decode-char '=jis-x0208-1983 ret)))
66 ((and (encode-char chr '=ks-x1001)
67 (setq ret (or (encode-char chr '=ucs@ks)
70 ;; (if (eq (char-before) ?
\e$B!T
\e(B)
72 (insert (format "\\UCSks{%04X}" ret)))
74 (setq rest chise-tex-coded-charset-expression-alist)
75 (while (setq spec (car rest))
76 (if (setq ret (encode-char chr (car spec)))
78 (setq rest (cdr rest))))
80 ;; (if (eq (char-before) ?
\e$B!T
\e(B)
82 (insert (format (format "\\%s{%%0%d%s}"
90 (defun chise-tex-encode-region-for-jis (start end)
94 (narrow-to-region start end)
96 (let (chr ret rest spec modifier base modifier-1)
97 (while (and (skip-chars-forward "\x00-\x7F")
99 (setq chr (char-after))
100 (cond ((encode-char chr '=jis-x0208-1983)
102 ;; ((setq ret (encode-char chr '=jis-x0208-1990))
104 ;; (insert (decode-char '=jis-x0208-1983 ret)))
105 ((and (not (eq (char-ucs chr) #x0439))
106 (not (eq (char-ucs chr) #x0451))
107 (setq ret (char-feature chr '=decomposition))
108 (setq modifier (assq (nth 1 ret)
123 (setq base (car ret))
124 (if (and (setq ret (char-feature base '=decomposition))
130 (?\u0301 . "CircAcute")
131 (?\u0303 . "CircTilde")
132 (?\u0309 . "CircHook")
135 (?\u0302 . "Circudot")
137 (insert (format "\\%s{%c}" (cdr modifier-1) (car ret)))
138 (insert (format "\\%s{%c}" (cdr modifier) base))))
139 ((and (or (encode-char chr '=jis-x0213-1-2000)
140 (encode-char chr '=jis-x0213-2-2000))
141 (setq ret (or (encode-char chr '=ucs@jis/2000)
142 (encode-char chr '=ucs@jis/fw))))
144 ;; (if (eq (char-before) ?
\e$B!T
\e(B)
146 (insert (format "\\UCSjis{%04X}" ret)))
147 ((and (encode-char chr '=ks-x1001)
148 (setq ret (or (encode-char chr '=ucs@ks)
151 ;; (if (eq (char-before) ?
\e$B!T
\e(B)
153 (insert (format "\\UCSks{%04X}" ret)))
154 ((setq ret (encode-char chr '=ucs-hangul))
156 ;; (if (eq (char-before) ?
\e$B!T
\e(B)
158 (insert (format "\\UCSks{%04X}" ret)))
167 (insert "{\\usefont{T1}{pxr}{m}{n}\\dj}"))
170 (insert "{\\usefont{T1}{pxr}{m}{n}\\ng}"))
173 (insert "{\\usefont{T1}{pxr}{m}{n}\\k{s}}"))
176 (insert "\\textbullet{}"))
185 (insert "\\UCSjis{0294}"))
186 ((and (encode-char chr '=ucs@jp)
187 (setq ret (char-representative-of-domain chr 'gb))
188 (setq ret (encode-char ret '=ucs@gb)))
190 ;; (if (eq (char-before) ?
\e$B!T
\e(B)
192 (insert (format "\\UCSgb{%04X}" ret)))
194 (setq rest chise-tex-coded-charset-expression-alist)
195 (while (setq spec (car rest))
196 (if (setq ret (encode-char chr (car spec)))
198 (setq rest (cdr rest))))
200 ;; (if (eq (char-before) ?
\e$B!T
\e(B)
202 (insert (format (format "\\%s{%%0%d%s}"
208 (forward-char))))))))
210 (defun chise-tex-decode-region (start end)
214 (narrow-to-region start end)
216 (let (macro code ret me rest spec)
217 (while (re-search-forward "\\\\\\([a-zA-Z0-9]+\\){\\([0-9A-Fa-f]+\\)}"
219 (setq macro (match-string 1)
220 code (match-string 2)
223 (setq rest chise-tex-coded-charset-expression-alist)
224 (while (setq spec (car rest))
225 (if (string= (nth 1 spec) macro)
227 (setq rest (cdr rest))))
228 (setq ret (decode-char (car spec)
231 (if (eq (nth 3 spec) 'X)
234 (delete-region (match-beginning 0)(match-end 0))
239 'iso-2022-jp-tex-gb 'iso2022
240 "ISO-2022-JP with TeX representation for GB fonts."
244 input-charset-conversion ((latin-jisx0201 ascii)
245 (japanese-jisx0208-1978 japanese-jisx0208))
246 pre-write-conversion chise-tex-encode-region-for-gb
247 post-read-conversion chise-tex-decode-region
248 mnemonic "pTeX(GB)/7bit"
252 'iso-2022-jp-tex-jis 'iso2022
253 "ISO-2022-JP with TeX representation for JIS fonts."
257 ccs-priority-list (ascii
258 =jis-x0208@1983 =jis-x0208@1978
260 pre-write-conversion chise-tex-encode-region-for-jis
261 post-read-conversion chise-tex-decode-region
262 mnemonic "pTeX(JIS)/7bit"
271 ;;; chise-tex.el ends here