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 the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
28 ;; This lisp code serves two purposes, both of which involve
29 ;; the translation of various conventions for representing European
30 ;; character sets to ISO 8859-1.
33 ;; Various conventions exist in Newsgroups on how to represent national
34 ;; characters. The functions provided here translate these net conventions
37 ;; Calling `iso-german' will turn the net convention for umlauts ("a etc.)
38 ;; into ISO latin1 umlauts for easy reading.
39 ;; 'iso-spanish' will turn net conventions for representing spanish
40 ;; to ISO latin1. (Note that accents are omitted in news posts most
41 ;; of the time, only enye is escaped.)
44 ;; This mode installs hooks which change TeX files to ISO Latin-1 for
45 ;; simplified editing. When the TeX file is saved, ISO latin1 characters are
46 ;; translated back to escape sequences.
48 ;; An alternative is a TeX style that handles 8 bit ISO files
49 ;; (available on ftp.vlsivie.tuwien.ac.at in /pub/8bit)
50 ;; - but these files are difficult to transmit ... so while the net is
51 ;; still @ 7 bit this may be useful
54 ;; The net support should install hooks (like TeX support does)
55 ;; which recognizes certain news groups and translates all articles from
58 ;; Cover more cases for translation (There is an infinite number of ways to
59 ;; represent accented characters in TeX)
62 ;; If you are interested in questions related to using the ISO 8859-1
63 ;; characters set (configuring emacs, Unix, etc. to use ISO), then you
64 ;; can get the ISO 8859-1 FAQ via anonymous ftp from
65 ;; ftp.vlsivie.tuwien.ac.at in /pub/bit/FAQ-ISO-8859-1
71 (defvar iso-spanish-trans-tab
74 ("\([a-zA-Z]\)#" "\\1ñ")
76 ("\\([-a-zA-Z\"`]\\)\"u" "\\1ü")
77 ("\\([-a-zA-Z\"`]\\)\"U" "\\1Ü")
78 ("\\([-a-zA-Z]\\)'o" "\\1ó")
79 ("\\([-a-zA-Z]\\)'O" "\\Ó")
80 ("\\([-a-zA-Z]\\)'e" "\\1é")
81 ("\\([-a-zA-Z]\\)'E" "\\1É")
82 ("\\([-a-zA-Z]\\)'a" "\\1á")
83 ("\\([-a-zA-Z]\\)'A" "\\1A")
84 ("\\([-a-zA-Z]\\)'i" "\\1í")
85 ("\\([-a-zA-Z]\\)'I" "\\1Í")
87 "Spanish translation table.")
89 (defun iso-translate-conventions (trans-tab)
90 "Use the translation table TRANS-TAB to translate the current buffer."
92 (goto-char (point-min))
93 (let ((work-tab trans-tab
)
94 (buffer-read-only nil
)
95 (case-fold-search nil
))
98 (let ((trans-this (car work-tab
)))
99 (while (re-search-forward (car trans-this
) nil t
)
100 (replace-match (car (cdr trans-this
)) t nil
)))
101 (setq work-tab
(cdr work-tab
)))))))
103 (defun iso-spanish ()
104 "Translate net conventions for Spanish to ISO 8859-1."
106 (iso-translate-conventions iso-spanish-trans-tab
))
108 (defvar iso-aggressive-german-trans-tab
119 "German translation table.
120 This table uses an aggressive translation approach and may erroneously
121 translate too much.")
123 (defvar iso-conservative-german-trans-tab
125 ("\\([-a-zA-Z\"`]\\)\"a" "\\1ä")
126 ("\\([-a-zA-Z\"`]\\)\"A" "\\1Ä")
127 ("\\([-a-zA-Z\"`]\\)\"o" "\\1ö")
128 ("\\([-a-zA-Z\"`]\\)\"O" "\\1Ö")
129 ("\\([-a-zA-Z\"`]\\)\"u" "\\1ü")
130 ("\\([-a-zA-Z\"`]\\)\"U" "\\1Ü")
131 ("\\([-a-zA-Z\"`]\\)\"s" "\\1ß")
132 ("\\([-a-zA-Z\"`]\\)\\\\3" "\\1ß")
134 "German translation table.
135 This table uses a conservative translation approach and may translate too
139 (defvar iso-german-trans-tab iso-aggressive-german-trans-tab
140 "Currently active translation table for German.")
143 "Translate net conventions for German to ISO 8859-1."
145 (iso-translate-conventions iso-german-trans-tab
))
147 (defvar iso-iso2tex-trans-tab
158 ("ï" "{\\\\\"\\\\i}")
202 ("\251" "{\\\\copyright}")
209 "Translation table for translating ISO 8859-1 characters to TeX sequences.")
214 (defun iso-iso2tex ()
215 "Translate ISO 8859-1 characters to TeX sequences."
217 (iso-translate-conventions iso-iso2tex-trans-tab
))
220 (defvar iso-tex2iso-trans-tab
231 ("{\\\\\"\\\\i}" "ï")
333 ("\\\\\"{\\\\i}" "ï")
381 ("{\\\\copyright}" "\251")
382 ("\\\\copyright{}" "\251")
383 ("{\\\\pounds}" "£" )
386 ("\\\\pounds{}" "£" )
394 "Translation table for translating TeX sequences to ISO 8859-1 characters.
395 This table is not exhaustive (and due to TeX's power can never be). It only
396 contains commonly used sequences.")
398 (defun iso-tex2iso ()
399 "Translate TeX sequences to ISO 8859-1 characters."
401 (iso-translate-conventions iso-tex2iso-trans-tab
))
403 (defvar iso-gtex2iso-trans-tab
414 ("{\\\\\"\\\\i}" "ï")
516 ("\\\\\"{\\\\i}" "ï")
564 ("{\\\\copyright}" "\251")
565 ("\\\\copyright{}" "\251")
566 ("{\\\\pounds}" "£" )
569 ("\\\\pounds{}" "£" )
585 "Translation table for translating German TeX sequences to ISO 8859-1.
586 This table is not exhaustive (and due to TeX's power can never be). It only
587 contains commonly used sequences.")
589 (defvar iso-iso2gtex-trans-tab
600 ("ï" "{\\\\\"\\\\i}")
644 ("\251" "{\\\\copyright}")
651 "Translation table for translating ISO 8859-1 characters to German TeX.")
653 (defun iso-gtex2iso ()
654 "Translate German TeX sequences to ISO 8859-1 characters."
656 (iso-translate-conventions iso-gtex2iso-trans-tab
))
659 (defun iso-iso2gtex ()
660 "Translate ISO 8859-1 characters to German TeX sequences."
662 (iso-translate-conventions iso-iso2gtex-trans-tab
))
665 (defun iso-german-tex-p ()
666 "Check if tex buffer is German LaTeX."
670 (goto-char (point-min))
671 (re-search-forward "\\\\documentstyle\\[.*german.*\\]" nil t
))))
673 (defun iso-fix-iso2tex ()
674 "Turn ISO 8859-1 (aka. ISO Latin-1) buffer into TeX sequences.
675 If German TeX is used, German TeX sequences are generated."
676 (if (or (equal major-mode
'latex-mode
)
677 (equal major-mode
'LaTeX-mode
)) ; AucTeX wants this
678 (if (iso-german-tex-p)
681 (if (or (equal major-mode
'tex-mode
)
682 (equal major-mode
'TeX-mode
) ; AucTeX wants this
683 (equal major-mode
'plain-tex-mode
))
686 (defun iso-fix-tex2iso ()
687 "Turn TeX sequences into ISO 8859-1 (aka. ISO Latin-1) characters.
688 This function recognizes German TeX buffers."
689 (if (or (equal major-mode
'latex-mode
)
690 (equal major-mode
'Latex-mode
)) ; AucTeX wants this
691 (if (iso-german-tex-p)
694 (if (or (equal major-mode
'tex-mode
)
695 (equal major-mode
'TeX-mode
) ; AucTeX wants this
696 (equal major-mode
'plain-tex-mode
))
699 (defun iso-cvt-ffh ()
700 "find-file-hook for iso-cvt.el."
702 (set-buffer-modified-p nil
))
704 (defun iso-cvt-wfh ()
705 "write file hook for iso-cvt.el."
708 (defun iso-cvt-ash ()
709 "after save hook for iso-cvt.el."
711 (set-buffer-modified-p nil
))
713 (add-hook 'find-file-hooks
'iso-cvt-ffh
)
714 (add-hook 'write-file-hooks
'iso-cvt-wfh
)
715 (add-hook 'after-save-hook
'iso-cvt-ash
)
717 ;;; iso-cvt.el ends here