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 XEmacs.
11 ;; XEmacs 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 ;; XEmacs 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 XEmacs; 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.
26 ;;; Synched up with: FSF 19.34.
30 ;; This lisp code serves two purposes, both of which involve
31 ;; the translation of various conventions for representing European
32 ;; character sets to ISO 8859-1.
35 ;; Various conventions exist in Newsgroups on how to represent national
36 ;; characters. The functions provided here translate these net conventions
39 ;; Calling `iso-german' will turn the net convention for umlauts ("a etc.)
40 ;; into ISO latin1 umlauts for easy reading.
41 ;; 'iso-spanish' will turn net conventions for representing spanish
42 ;; to ISO latin1. (Note that accents are omitted in news posts most
43 ;; of the time, only enye is escaped.)
46 ;; This mode installs hooks which change TeX files to ISO Latin-1 for
47 ;; simplified editing. When the TeX file is saved, ISO latin1 characters are
48 ;; translated back to escape sequences.
50 ;; An alternative is a TeX style that handles 8 bit ISO files
51 ;; (available on ftp.vlsivie.tuwien.ac.at in /pub/8bit)
52 ;; - but these files are difficult to transmit ... so while the net is
53 ;; still @ 7 bit this may be useful
56 ;; The net support should install hooks (like TeX support does)
57 ;; which recognizes certain news groups and translates all articles from
60 ;; Cover more cases for translation (There is an infinite number of ways to
61 ;; represent accented characters in TeX)
64 ;; If you are interested in questions related to using the ISO 8859-1
65 ;; characters set (configuring emacs, Unix, etc. to use ISO), then you
66 ;; can get the ISO 8859-1 FAQ via anonymous ftp from
67 ;; ftp.vlsivie.tuwien.ac.at in /pub/bit/FAQ-ISO-8859-1
73 (defvar iso-spanish-trans-tab
76 ("\([a-zA-Z]\)#" "\\1ñ")
78 ("\\([-a-zA-Z\"`]\\)\"u" "\\1ü")
79 ("\\([-a-zA-Z\"`]\\)\"U" "\\1Ü")
80 ("\\([-a-zA-Z]\\)'o" "\\1ó")
81 ("\\([-a-zA-Z]\\)'O" "\\Ó")
82 ("\\([-a-zA-Z]\\)'e" "\\1é")
83 ("\\([-a-zA-Z]\\)'E" "\\1É")
84 ("\\([-a-zA-Z]\\)'a" "\\1á")
85 ("\\([-a-zA-Z]\\)'A" "\\1A")
86 ("\\([-a-zA-Z]\\)'i" "\\1í")
87 ("\\([-a-zA-Z]\\)'I" "\\1Í")
89 "Spanish translation table.")
91 (defun iso-translate-conventions (trans-tab)
92 "Use the translation table TRANS-TAB to translate the current buffer."
94 (goto-char (point-min))
95 (let ((work-tab trans-tab)
96 (buffer-read-only nil)
97 (case-fold-search nil))
100 (let ((trans-this (car work-tab)))
101 (while (re-search-forward (car trans-this) nil t)
102 (replace-match (car (cdr trans-this)) t nil)))
103 (setq work-tab (cdr work-tab)))))))
105 (defun iso-spanish ()
106 "Translate net conventions for Spanish to ISO 8859-1."
108 (iso-translate-conventions iso-spanish-trans-tab))
110 (defvar iso-aggressive-german-trans-tab
121 "German translation table.
122 This table uses an aggressive translation approach and may erroneously
123 translate too much.")
125 (defvar iso-conservative-german-trans-tab
127 ("\\([-a-zA-Z\"`]\\)\"a" "\\1ä")
128 ("\\([-a-zA-Z\"`]\\)\"A" "\\1Ä")
129 ("\\([-a-zA-Z\"`]\\)\"o" "\\1ö")
130 ("\\([-a-zA-Z\"`]\\)\"O" "\\1Ö")
131 ("\\([-a-zA-Z\"`]\\)\"u" "\\1ü")
132 ("\\([-a-zA-Z\"`]\\)\"U" "\\1Ü")
133 ("\\([-a-zA-Z\"`]\\)\"s" "\\1ß")
134 ("\\([-a-zA-Z\"`]\\)\\\\3" "\\1ß")
136 "German translation table.
137 This table uses a conservative translation approach and may translate too
141 (defvar iso-german-trans-tab iso-aggressive-german-trans-tab
142 "Currently active translation table for German.")
145 "Translate net conventions for German to ISO 8859-1."
147 (iso-translate-conventions iso-german-trans-tab))
149 (defvar iso-iso2tex-trans-tab
160 ("ï" "{\\\\\"\\\\i}")
204 ("\251" "{\\\\copyright}")
211 "Translation table for translating ISO 8859-1 characters to TeX sequences.")
216 (defun iso-iso2tex ()
217 "Translate ISO 8859-1 characters to TeX sequences."
219 (iso-translate-conventions iso-iso2tex-trans-tab))
222 (defvar iso-tex2iso-trans-tab
233 ("{\\\\\"\\\\i}" "ï")
335 ("\\\\\"{\\\\i}" "ï")
383 ("{\\\\copyright}" "\251")
384 ("\\\\copyright{}" "\251")
385 ("{\\\\pounds}" "£" )
388 ("\\\\pounds{}" "£" )
396 "Translation table for translating TeX sequences to ISO 8859-1 characters.
397 This table is not exhaustive (and due to TeX's power can never be). It only
398 contains commonly used sequences.")
400 (defun iso-tex2iso ()
401 "Translate TeX sequences to ISO 8859-1 characters."
403 (iso-translate-conventions iso-tex2iso-trans-tab))
405 (defvar iso-gtex2iso-trans-tab
416 ("{\\\\\"\\\\i}" "ï")
518 ("\\\\\"{\\\\i}" "ï")
566 ("{\\\\copyright}" "\251")
567 ("\\\\copyright{}" "\251")
568 ("{\\\\pounds}" "£" )
571 ("\\\\pounds{}" "£" )
587 "Translation table for translating German TeX sequences to ISO 8859-1.
588 This table is not exhaustive (and due to TeX's power can never be). It only
589 contains commonly used sequences.")
591 (defvar iso-iso2gtex-trans-tab
602 ("ï" "{\\\\\"\\\\i}")
646 ("\251" "{\\\\copyright}")
653 "Translation table for translating ISO 8859-1 characters to German TeX.")
655 (defun iso-gtex2iso ()
656 "Translate German TeX sequences to ISO 8859-1 characters."
658 (iso-translate-conventions iso-gtex2iso-trans-tab))
661 (defun iso-iso2gtex ()
662 "Translate ISO 8859-1 characters to German TeX sequences."
664 (iso-translate-conventions iso-iso2gtex-trans-tab))
667 (defun iso-german-tex-p ()
668 "Check if tex buffer is German LaTeX."
672 (goto-char (point-min))
673 (re-search-forward "\\\\documentstyle\\[.*german.*\\]" nil t))))
675 (defun iso-fix-iso2tex ()
676 "Turn ISO 8859-1 (aka. ISO Latin-1) buffer into TeX sequences.
677 If German TeX is used, German TeX sequences are generated."
678 (if (or (equal major-mode 'latex-mode)
679 (equal major-mode 'LaTeX-mode)) ; AucTeX wants this
680 (if (iso-german-tex-p)
683 (if (or (equal major-mode 'tex-mode)
684 (equal major-mode 'TeX-mode) ; AucTeX wants this
685 (equal major-mode 'plain-tex-mode))
688 (defun iso-fix-tex2iso ()
689 "Turn TeX sequences into ISO 8859-1 (aka. ISO Latin-1) characters.
690 This function recognizes German TeX buffers."
691 (if (or (equal major-mode 'latex-mode)
692 (equal major-mode 'Latex-mode)) ; AucTeX wants this
693 (if (iso-german-tex-p)
696 (if (or (equal major-mode 'tex-mode)
697 (equal major-mode 'TeX-mode) ; AucTeX wants this
698 (equal major-mode 'plain-tex-mode))
701 (defun iso-cvt-ffh ()
702 "find-file-hook for iso-cvt.el."
704 (set-buffer-modified-p nil))
706 (defun iso-cvt-wfh ()
707 "write file hook for iso-cvt.el."
710 (defun iso-cvt-ash ()
711 "after save hook for iso-cvt.el."
713 (set-buffer-modified-p nil))
715 (add-hook 'find-file-hooks 'iso-cvt-ffh)
716 (add-hook 'write-file-hooks 'iso-cvt-wfh)
717 (add-hook 'after-save-hook 'iso-cvt-ash)
719 ;;; iso-cvt.el ends here