1 ;;; iso-cvt.-el -- translate to ISO 8859-1 from/to net/TeX conventions
2 ;; This file was formerly called gm-lingo.el.
4 ;; Copyright (C) 1993, 1994 Free Software Foundation, Inc.
6 ;; Author: Michael Gschwind <mike@vlsivie.tuwien.ac.at>
7 ;; Keywords: tex, iso, latin, i18n
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to
23 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
26 ;; This lisp code serves two purposes, both of which involve
27 ;; the translation of various conventions for representing European
28 ;; character sets to ISO 8859-1.
31 ; Various conventions exist in Newsgroups on how to represent national
32 ; characters. The functions provided here translate these net conventions
35 ; Calling `iso-german' will turn the net convention for umlauts ("a etc.)
36 ; into ISO latin1 umlaute for easy reading.
37 ; 'iso-spanish' will turn net conventions for representing spanish
38 ; to ISO latin1. (Note that accents are omitted in news posts most
39 ; of the time, only enye is escaped.)
42 ; This mode installs hooks which change TeX files to ISO Latin-1 for
43 ; simplified editing. When the TeX file is saved, ISO latin1 characters are
44 ; translated back to escape sequences.
46 ; An alternative is a TeX style that handles 8 bit ISO files
47 ; (available on ftp.vlsivie.tuwien.ac.at in /pub/8bit)
48 ; - but these files are difficult to transmit ... so while the net is
49 ; still @ 7 bit this may be useful
52 ; The net support should install hooks (like TeX support does)
53 ; which recognizes certains news groups and translates all articles from
56 ; Cover more cases for translation (There is an infinite number of ways to
57 ; represent accented characters in TeX)
60 ; If you are interested in questions related to using the ISO 8859-1
61 ; characters set (configuring emacs, Unix, etc. to use ISO), then you
62 ; can get the ISO 8859-1 FAQ via anonymous ftp from
63 ; ftp.vlsivie.tuwien.ac.at in /pub/bit/FAQ-ISO-8859-1
69 (defvar iso-spanish-trans-tab
72 ("\([a-zA-Z]\)#" "\\1ñ")
74 ("\\([-a-zA-Z\"`]\\)\"u" "\\1ü")
75 ("\\([-a-zA-Z\"`]\\)\"U" "\\1Ü")
76 ("\\([-a-zA-Z]\\)'o" "\\1ó")
77 ("\\([-a-zA-Z]\\)'O" "\\Ó")
78 ("\\([-a-zA-Z]\\)'e" "\\1é")
79 ("\\([-a-zA-Z]\\)'E" "\\1É")
80 ("\\([-a-zA-Z]\\)'a" "\\1á")
81 ("\\([-a-zA-Z]\\)'A" "\\1A")
82 ("\\([-a-zA-Z]\\)'i" "\\1í")
83 ("\\([-a-zA-Z]\\)'I" "\\1Í")
85 "Spanish translation table.")
87 (defun iso-translate-conventions (trans-tab)
88 "Use the translation table TRANS-TAB to translate the current buffer."
90 (goto-char (point-min))
91 (let ((work-tab trans-tab
)
92 (buffer-read-only nil
)
93 (case-fold-search nil
))
96 (let ((trans-this (car work-tab
)))
97 (while (re-search-forward (car trans-this
) nil t
)
98 (replace-match (car (cdr trans-this
)) t nil
)))
99 (setq work-tab
(cdr work-tab
)))))))
101 (defun iso-spanish ()
102 "Translate net conventions for Spanish to ISO 8859-1."
104 (iso-translate-conventions iso-spanish-trans-tab
))
106 (defvar iso-aggressive-german-trans-tab
117 "German translation table.
118 This table uses an aggressive translation approach and may erroneously
119 translate too much.")
121 (defvar iso-conservative-german-trans-tab
123 ("\\([-a-zA-Z\"`]\\)\"a" "\\1ä")
124 ("\\([-a-zA-Z\"`]\\)\"A" "\\1Ä")
125 ("\\([-a-zA-Z\"`]\\)\"o" "\\1ö")
126 ("\\([-a-zA-Z\"`]\\)\"O" "\\1Ö")
127 ("\\([-a-zA-Z\"`]\\)\"u" "\\1ü")
128 ("\\([-a-zA-Z\"`]\\)\"U" "\\1Ü")
129 ("\\([-a-zA-Z\"`]\\)\"s" "\\1ß")
130 ("\\([-a-zA-Z\"`]\\)\\\\3" "\\1ß")
132 "German translation table.
133 This table uses a conservative translation approach and may translate too
137 (defvar iso-german-trans-tab iso-aggressive-german-trans-tab
138 "Currently active translation table for German.")
141 "Translate net conventions for German to ISO 8859-1."
143 (iso-translate-conventions iso-german-trans-tab
))
145 (defvar iso-iso2tex-trans-tab
156 ("ï" "{\\\\\"\\\\i}")
200 ("\251" "{\\\\copyright}")
207 "Translation table for translating ISO 8859-1 characters to TeX sequences.")
212 (defun iso-iso2tex ()
213 "Translate ISO 8859-1 characters to TeX sequences."
215 (iso-translate-conventions iso-iso2tex-trans-tab
))
218 (defvar iso-tex2iso-trans-tab
229 ("{\\\\\"\\\\i}" "ï")
331 ("\\\\\"{\\\\i}" "ï")
379 ("{\\\\copyright}" "\251")
380 ("\\\\copyright{}" "\251")
381 ("{\\\\pounds}" "£" )
384 ("\\\\pounds{}" "£" )
392 "Translation table for translating TeX sequences to ISO 8859-1 characters.
393 This table is not exhaustive (and due to TeX's power can never be). It only
394 contains commonly used sequences.")
396 (defun iso-tex2iso ()
397 "Translate TeX sequences to ISO 8859-1 characters."
399 (iso-translate-conventions iso-tex2iso-trans-tab
))
401 (defvar iso-gtex2iso-trans-tab
412 ("{\\\\\"\\\\i}" "ï")
514 ("\\\\\"{\\\\i}" "ï")
562 ("{\\\\copyright}" "\251")
563 ("\\\\copyright{}" "\251")
564 ("{\\\\pounds}" "£" )
567 ("\\\\pounds{}" "£" )
583 "Translation table for translating German TeX sequences to ISO 8859-1.
584 This table is not exhaustive (and due to TeX's power can never be). It only
585 contains commonly used sequences.")
587 (defvar iso-iso2gtex-trans-tab
598 ("ï" "{\\\\\"\\\\i}")
642 ("\251" "{\\\\copyright}")
649 "Translation table for translating ISO 8859-1 characters to German TeX.")
651 (defun iso-gtex2iso ()
652 "Translate German TeX sequences to ISO 8859-1 characters."
654 (iso-translate-conventions iso-gtex2iso-trans-tab
))
657 (defun iso-iso2gtex ()
658 "Translate ISO 8859-1 characters to German TeX sequences."
660 (iso-translate-conventions iso-iso2gtex-trans-tab
))
663 (defun iso-german-tex-p ()
664 "Check if tex buffer is German LaTeX."
668 (goto-char (point-min))
669 (re-search-forward "\\\\documentstyle\\[.*german.*\\]" nil t
))))
671 (defun iso-fix-iso2tex ()
672 "Turn ISO 8859-1 (aka. ISO Latin-1) buffer into TeX sequences.
673 If German TeX is used, German TeX sequences are generated."
674 (if (or (equal major-mode
'latex-mode
)
675 (equal major-mode
'LaTeX-mode
)) ; AucTeX wants this
676 (if (iso-german-tex-p)
679 (if (or (equal major-mode
'tex-mode
)
680 (equal major-mode
'TeX-mode
) ; AucTeX wants this
681 (equal major-mode
'plain-tex-mode
))
684 (defun iso-fix-tex2iso ()
685 "Turn TeX sequences into ISO 8859-1 (aka. ISO Latin-1) characters.
686 This function recognices German TeX buffers."
687 (if (or (equal major-mode
'latex-mode
)
688 (equal major-mode
'Latex-mode
)) ; AucTeX wants this
689 (if (iso-german-tex-p)
692 (if (or (equal major-mode
'tex-mode
)
693 (equal major-mode
'TeX-mode
) ; AucTeX wants this
694 (equal major-mode
'plain-tex-mode
))
697 (defun iso-cvt-ffh ()
698 "find-file-hook for iso-cvt.el."
700 (set-buffer-modified-p nil
))
702 (defun iso-cvt-wfh ()
703 "write file hook for iso-cvt.el."
706 (defun iso-cvt-ash ()
707 "after save hook for iso-cvt.el."
709 (set-buffer-modified-p nil
))
711 (add-hook 'find-file-hooks
'iso-cvt-ffh
)
712 (add-hook 'write-file-hooks
'iso-cvt-wfh
)
713 (add-hook 'after-save-hook
'iso-cvt-ash
)
715 ;;; iso-cvt.el ends here