;;; chise-tex.el --- Coding-system based chise2otf like tool ;; Copyright (C) 2004 MORIOKA Tomohiko ;; Author: MORIOKA Tomohiko ;; Keywords: OTF package, pTeX, CHISE, Multiscript, Multilingual ;; This file is a part of Omega/CHISE. ;; This program is free software; you can redistribute it and/or ;; modify it under the terms of the GNU General Public License as ;; published by the Free Software Foundation; either version 2, or (at ;; your option) any later version. ;; This program is distributed in the hope that it will be useful, but ;; WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program; see the file COPYING. If not, write to ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. ;;; Code: (defvar chise-tex-coded-charset-expression-alist '((=ucs-hangul "UCShang" 4 X) (=ucs@gb "UCSgb" 4 X) (=ucs@jis "UCSjis" 4 X) (=ucs@jis/2000 "UCSjis" 4 X) (=ucs@ks "UCSks" 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@cns "UCScns" 4 X))) (defun chise-tex-encode-region-for-gb (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-encode-region-for-jis (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 ((encode-char chr '=jis-x0208-1983) (forward-char)) ;; ((setq ret (encode-char chr '=jis-x0208-1990)) ;; (delete-char) ;; (insert (decode-char '=jis-x0208-1983 ret))) ((and (or (encode-char chr '=jis-x0213-1-2000) (encode-char chr '=jis-x0213-2-2000)) (setq ret (or (encode-char chr '=ucs@jis/2000) (encode-char chr '=ucs@jis/fw)))) (delete-char) ;; (if (eq (char-before) ?$B!T(B) ;; (insert " ")) (insert (format "\\UCSjis{%04X}" ret))) ((setq ret (encode-char chr '=ucs-hangul)) (delete-char) ;; (if (eq (char-before) ?$B!T(B) ;; (insert " ")) (insert (format "\\UCSks{%04X}" ret))) ((eq chr ?\u2022) (delete-char) (insert "\\textbullet{}")) ((eq chr ?\u0294) (delete-char) (insert "\\UCSjis{0294}")) ((and (encode-char chr '=ucs@jp) (setq ret (char-representative-of-domain chr 'gb)) (setq ret (encode-char ret '=ucs@gb))) (delete-char) ;; (if (eq (char-before) ?$B!T(B) ;; (insert " ")) (insert (format "\\UCSgb{%04X}" 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 me rest spec) (while (re-search-forward "\\\\\\([a-zA-Z0-9]+\\){\\([0-9A-Fa-f]+\\)}" nil t) (setq macro (match-string 1) code (match-string 2) 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-gb 'iso2022 "ISO-2022-JP with TeX representation for GB fonts." '(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-for-gb post-read-conversion chise-tex-decode-region mnemonic "pTeX(GB)/7bit" )) (make-coding-system 'iso-2022-jp-tex-jis 'iso2022 "ISO-2022-JP with TeX representation for JIS fonts." '(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-for-jis post-read-conversion chise-tex-decode-region mnemonic "pTeX(JIS)/7bit" )) ;;; @ End. ;;; (provide 'chise-tex) ;;; chise-tex.el ends here