1 ;; iso-cvt.el -- translate to ISO 8859-1 from/to net/TeX conventions
2 ;; Copyright © 1993, 1994 Free Software Foundation, Inc.
3 ;; Was formerly called gm-lingo.el.
5 ;; Author: Michael Gschwind <mike@vlsivie.tuwien.ac.at>
6 ;; Keywords: tex, iso, latin, i18n
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
25 ;; This lisp code serves two purposes, both of which involve
26 ;; the translation of various conventions for representing European
27 ;; character sets to ISO 8859-1.
30 ; Various conventions exist in Newsgroups on how to represent national
31 ; characters. The functions provided here translate these net conventions
34 ; Calling `iso-german' will turn the net convention for umlauts ("a etc.)
35 ; into ISO latin1 umlaute for easy reading.
36 ; 'iso-spanish' will turn net conventions for representing spanish
37 ; to ISO latin1. (Note that accents are omitted in news posts most
38 ; of the time, only enye is escaped.)
41 ; This mode installs hooks which change TeX files to ISO Latin-1 for
42 ; simplified editing. When the TeX file is saved, ISO latin1 characters are
43 ; translated back to escape sequences.
45 ; An alternative is a TeX style that handles 8 bit ISO files
46 ; (available on ftp.vlsivie.tuwien.ac.at in /pub/8bit)
47 ; - but these files are difficult to transmit ... so while the net is
48 ; still @ 7 bit this may be useful
51 ; The net support should install hooks (like TeX support does)
52 ; which recognizes certains news groups and translates all articles from
55 ; Cover more cases for translation (There is an infinite number of ways to
56 ; represent accented characters in TeX)
59 ; If you are interested in questions related to using the ISO 8859-1
60 ; characters set (configuring emacs, Unix, etc. to use ISO), then you
61 ; can get the ISO 8859-1 FAQ via anonymous ftp from
62 ; ftp.vlsivie.tuwien.ac.at in /pub/bit/FAQ-ISO-8859-1
68 (defvar iso-spanish-trans-tab
71 ("\([a-zA-Z]\)#" "\\1ñ")
73 ("\\([-a-zA-Z\"`]\\)\"u" "\\1ü")
74 ("\\([-a-zA-Z\"`]\\)\"U" "\\1Ü")
75 ("\\([-a-zA-Z]\\)'o" "\\1ó")
76 ("\\([-a-zA-Z]\\)'O" "\\Ó")
77 ("\\([-a-zA-Z]\\)'e" "\\1é")
78 ("\\([-a-zA-Z]\\)'E" "\\1É")
79 ("\\([-a-zA-Z]\\)'a" "\\1á")
80 ("\\([-a-zA-Z]\\)'A" "\\1A")
81 ("\\([-a-zA-Z]\\)'i" "\\1í")
82 ("\\([-a-zA-Z]\\)'I" "\\1Í")
84 "Spanish translation table.")
86 (defun iso-translate-conventions (trans-tab)
87 "Use the translation table TRANS-TAB to translate the current buffer."
89 (goto-char (point-min))
90 (let ((work-tab trans-tab
)
91 (buffer-read-only nil
)
92 (case-fold-search nil
))
95 (let ((trans-this (car work-tab
)))
96 (while (re-search-forward (car trans-this
) nil t
)
97 (replace-match (car (cdr trans-this
)) t nil
)))
98 (setq work-tab
(cdr work-tab
)))))))
100 (defun iso-spanish ()
101 "Translate net conventions for Spanish to ISO 8859-1."
103 (iso-translate-conventions iso-spanish-trans-tab
))
105 (defvar iso-aggressive-german-trans-tab
116 "German translation table.
117 This table uses an aggressive translation approach and may erroneously
118 translate too much.")
120 (defvar iso-conservative-german-trans-tab
122 ("\\([-a-zA-Z\"`]\\)\"a" "\\1ä")
123 ("\\([-a-zA-Z\"`]\\)\"A" "\\1Ä")
124 ("\\([-a-zA-Z\"`]\\)\"o" "\\1ö")
125 ("\\([-a-zA-Z\"`]\\)\"O" "\\1Ö")
126 ("\\([-a-zA-Z\"`]\\)\"u" "\\1ü")
127 ("\\([-a-zA-Z\"`]\\)\"U" "\\1Ü")
128 ("\\([-a-zA-Z\"`]\\)\"s" "\\1ß")
129 ("\\([-a-zA-Z\"`]\\)\\\\3" "\\1ß")
131 "German translation table.
132 This table uses a conservative translation approach and may translate too
136 (defvar iso-german-trans-tab iso-aggressive-german-trans-tab
137 "Currently active translation table for German.")
140 "Translate net conventions for German to ISO 8859-1."
142 (iso-translate-conventions iso-german-trans-tab
))
144 (defvar iso-iso2tex-trans-tab
155 ("ï" "{\\\\\"\\\\i}")
199 ("\251" "{\\\\copyright}")
206 "Translation table for translating ISO 8859-1 characters to TeX sequences.")
211 (defun iso-iso2tex ()
212 "Translate ISO 8859-1 characters to TeX sequences."
214 (iso-translate-conventions iso-iso2tex-trans-tab
))
217 (defvar iso-tex2iso-trans-tab
228 ("{\\\\\"\\\\i}" "ï")
330 ("\\\\\"{\\\\i}" "ï")
378 ("{\\\\copyright}" "\251")
379 ("\\\\copyright{}" "\251")
380 ("{\\\\pounds}" "£" )
383 ("\\\\pounds{}" "£" )
391 "Translation table for translating TeX sequences to ISO 8859-1 characters.
392 This table is not exhaustive (and due to TeX's power can never be). It only
393 contains commonly used sequences.")
395 (defun iso-tex2iso ()
396 "Translate TeX sequences to ISO 8859-1 characters."
398 (iso-translate-conventions iso-tex2iso-trans-tab
))
400 (defvar iso-gtex2iso-trans-tab
411 ("{\\\\\"\\\\i}" "ï")
513 ("\\\\\"{\\\\i}" "ï")
561 ("{\\\\copyright}" "\251")
562 ("\\\\copyright{}" "\251")
563 ("{\\\\pounds}" "£" )
566 ("\\\\pounds{}" "£" )
582 "Translation table for translating German TeX sequences to ISO 8859-1.
583 This table is not exhaustive (and due to TeX's power can never be). It only
584 contains commonly used sequences.")
586 (defvar iso-iso2gtex-trans-tab
597 ("ï" "{\\\\\"\\\\i}")
641 ("\251" "{\\\\copyright}")
648 "Translation table for translating ISO 8859-1 characters to German TeX.")
650 (defun iso-gtex2iso ()
651 "Translate German TeX sequences to ISO 8859-1 characters."
653 (iso-translate-conventions iso-gtex2iso-trans-tab
))
656 (defun iso-iso2gtex ()
657 "Translate ISO 8859-1 characters to German TeX sequences."
659 (iso-translate-conventions iso-iso2gtex-trans-tab
))
662 (defun iso-german-tex-p ()
663 "Check if tex buffer is German LaTeX."
667 (goto-char (point-min))
668 (re-search-forward "\\\\documentstyle\\[.*german.*\\]" nil t
))))
670 (defun iso-fix-iso2tex ()
671 "Turn ISO 8859-1 (aka. ISO Latin-1) buffer into TeX sequences.
672 If German TeX is used, German TeX sequences are generated."
673 (if (or (equal major-mode
'latex-mode
)
674 (equal major-mode
'LaTeX-mode
)) ; AucTeX wants this
675 (if (iso-german-tex-p)
678 (if (or (equal major-mode
'tex-mode
)
679 (equal major-mode
'TeX-mode
) ; AucTeX wants this
680 (equal major-mode
'plain-tex-mode
))
683 (defun iso-fix-tex2iso ()
684 "Turn TeX sequences into ISO 8859-1 (aka. ISO Latin-1) characters.
685 This function recognices German TeX buffers."
686 (if (or (equal major-mode
'latex-mode
)
687 (equal major-mode
'Latex-mode
)) ; AucTeX wants this
688 (if (iso-german-tex-p)
691 (if (or (equal major-mode
'tex-mode
)
692 (equal major-mode
'TeX-mode
) ; AucTeX wants this
693 (equal major-mode
'plain-tex-mode
))
696 (defun iso-cvt-ffh ()
697 "find-file-hook for iso-cvt.el."
699 (set-buffer-modified-p nil
))
701 (defun iso-cvt-wfh ()
702 "write file hook for iso-cvt.el."
705 (defun iso-cvt-ash ()
706 "after save hook for iso-cvt.el."
708 (set-buffer-modified-p nil
))
710 (add-hook 'find-file-hooks
'iso-cvt-ffh
)
711 (add-hook 'write-file-hooks
'iso-cvt-wfh
)
712 (add-hook 'after-save-hook
'iso-cvt-ash
)
714 ;;; iso-cvt.el ends here