comparison lisp/packages/tex-latin1.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:376386a54a3c
1 ;; gm-lingo.el
2 ;; Translate to ISO from/to net/TeX conventions ...
3 ;; Copyright 1993 Michael Gschwind (mike@vlsivie.tuwien.ac.at)
4
5 ;; Keywords: tex, iso, latin, 8bit
6
7 ;; From: mike@vlsivie.tuwien.ac.at (Michael Gschwind)
8 ;; Newsgroups: gnu.emacs.sources
9 ;; Subject: tex sequence to ISO latin conversions (and back)
10 ;; Date: 13 Oct 1993 12:12:35 GMT
11 ;;
12 ;; The enclosed elisp file installs hooks which automatically translate
13 ;; TeX sequences to ISO latin1 upon loading of a TeX file in emacs. This
14 ;; allows editing of TeX documents without having to type escape
15 ;; sequences. Upon saving a file, ISO latin1 characters are converted
16 ;; back to TeX sequences. (If you have a tex style which can handle 8 bit
17 ;; characters, this part is not necessary, but the loading half is still
18 ;; neat to convert old files to 8 bit - also, 8 bit are less portable
19 ;; than 7...)
20 ;;
21 ;; It also contains a function 'german which translates net conventions
22 ;; for typing german characters into the real thing - if you install this
23 ;; in news-reader/mail/whatever hooks, you'll never again be bothered
24 ;; with having to read characters like "s or \3 or "a etc.
25 ;;
26 ;; mike
27 ;;
28
29 ;; This file works with GNU Emacs19 or higher, but is not part of GNU Emacs.
30
31 ;; This program is free software; you can redistribute it and/or modify
32 ;; it under the terms of the GNU General Public License as published by
33 ;; the Free Software Foundation; either version 2 of the License, or
34 ;; (at your option) any later version.
35 ;;
36 ;; This program is distributed in the hope that it will be useful,
37 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
38 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39 ;; GNU General Public License for more details.
40 ;;
41 ;; You should have received a copy of the GNU General Public License
42 ;; along with this program; if not, write to the Free Software
43 ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
44
45 ; it's the author's first lisp program in a long time, so don't judge
46 ; him by it :(
47
48 ; to do: translate buffer when displaying from GNUS,
49 ; use function 'german which does the Right Thing
50 ; upon saving, the buffer reverts to TeX format...
51
52 ; Description:
53 ; calling 'german will turn the net convention f. umlauts ("a etc.)
54 ; into ISO latin umlaute for easy reading.
55 ; hooks change TeX files to latin1 for editing and back to TeX sequences
56 ; for calling TeX. An alternative is a TeX style that handles
57 ; 8 bit ISO files (available on ftp.vlsivie.tuwien.ac.at in /pub/8bit)
58 ; - but these files are difficult to transmit ... so while the net is
59 ; still @ 7 bit this may be useful
60 ;
61 ; fixed bug that causes uppercase umlauts to become lower case by
62 ; conversion -- msz 960429
63
64 (defvar spanish-trans-tab '(
65 ("~n" "ñ")
66 ("\([a-zA-Z]\)#" "\\1ñ")
67 ("~N" "Ñ")
68 ( "\\([-a-zA-Z\"`]\\)\"u" "\\1ü")
69 ( "\\([-a-zA-Z\"`]\\)\"U" "\\1Ü")
70 ( "\\([-a-zA-Z]\\)'o" "\\1ó")
71 ( "\\([-a-zA-Z]\\)'O" "\\Ó")
72 ( "\\([-a-zA-Z]\\)'e" "\\1é")
73 ( "\\([-a-zA-Z]\\)'E" "\\1É")
74 ( "\\([-a-zA-Z]\\)'a" "\\1á")
75 ( "\\([-a-zA-Z]\\)'A" "\\1A")
76 ( "\\([-a-zA-Z]\\)'i" "\\1í")
77 ( "\\([-a-zA-Z]\\)'I" "\\1Í")
78 )
79 "Spanish")
80
81 (defun translate-conventions (trans-tab)
82 (interactive)
83 (save-excursion
84 (widen)
85 (goto-char (point-min))
86 (setq save-case-fold-search case-fold-search) ;; msz 960429
87 (setq case-fold-search nil) ;;
88 (let ((work-tab trans-tab)
89 (buffer-read-only nil))
90 (while work-tab
91 (save-excursion
92 (let ((trans-this (car work-tab)))
93 (while (re-search-forward (car trans-this) nil t)
94 (replace-match (car (cdr trans-this)) nil nil)))
95 (setq work-tab (cdr work-tab)))))
96 (setq case-fold-serch save-case-fold-search)))
97
98 (defun spanish ()
99 "Translate net conventions for Spanish to ISO"
100 (interactive)
101 (translate-conventions spanish-trans-tab))
102
103 (defvar aggressive-german-trans-tab '(
104 ( "\"a" "ä")
105 ( "\"A" "Ä")
106 ( "\"o" "ö")
107 ( "\"O" "Ö")
108 ( "\"u" "ü")
109 ( "\"U" "Ü")
110 ( "\"s" "ß")
111 ( "\\\\3" "ß")
112 )
113 "German - may do too much")
114
115 (defvar conservative-german-trans-tab '(
116 ( "\\([-a-zA-Z\"`]\\)\"a" "\\1ä")
117 ( "\\([-a-zA-Z\"`]\\)\"A" "\\1Ä")
118 ( "\\([-a-zA-Z\"`]\\)\"o" "\\1ö")
119 ( "\\([-a-zA-Z\"`]\\)\"O" "\\1Ö")
120 ( "\\([-a-zA-Z\"`]\\)\"u" "\\1ü")
121 ( "\\([-a-zA-Z\"`]\\)\"U" "\\1Ü")
122 ( "\\([-a-zA-Z\"`]\\)\"s" "\\1ß")
123 ( "\\([-a-zA-Z\"`]\\)\\\\3" "\\1ß")
124 )
125 "conservative German - may do too little")
126
127
128 (defvar german-trans-tab aggressive-german-trans-tab "used for char translation")
129
130 (defun german ()
131 "Translate net conventions for German to ISO"
132 (interactive)
133 (translate-conventions german-trans-tab))
134
135 (defvar iso2tex-trans-tab '(
136 ("ä" "{\\\\\"a}")
137 ("à" "{\\\\`a}")
138 ("á" "{\\\\'a}")
139 ("ã" "{\\\\~a}")
140 ("â" "{\\\\^a}")
141 ("ë" "{\\\\\"e}")
142 ("è" "{\\\\`e}")
143 ("é" "{\\\\'e}")
144 ("ê" "{\\\\^e}")
145 ("ï" "{\\\\\"\\\\i}")
146 ("ì" "{\\\\`\\\\i}")
147 ("í" "{\\\\'\\\\i}")
148 ("î" "{\\\\^\\\\i}")
149 ("ö" "{\\\\\"o}")
150 ("ò" "{\\\\`o}")
151 ("ó" "{\\\\'o}")
152 ("õ" "{\\\\~o}")
153 ("ô" "{\\\\^o}")
154 ("ü" "{\\\\\"u}")
155 ("ù" "{\\\\`u}")
156 ("ú" "{\\\\'u}")
157 ("û" "{\\\\^u}")
158 ("Ä" "{\\\\\"A}")
159 ("À" "{\\\\`A}")
160 ("Á" "{\\\\'A}")
161 ("Ã" "{\\\\~A}")
162 ("Â" "{\\\\^A}")
163 ("Ë" "{\\\\\"E}")
164 ("È" "{\\\\`E}")
165 ("É" "{\\\\'E}")
166 ("Ê" "{\\\\^E}")
167 ("Ï" "{\\\\\"I}")
168 ("Ì" "{\\\\`I}")
169 ("Í" "{\\\\'I}")
170 ("Î" "{\\\\^I}")
171 ("Ö" "{\\\\\"O}")
172 ("Ò" "{\\\\`O}")
173 ("Ó" "{\\\\'O}")
174 ("Õ" "{\\\\~O}")
175 ("Ô" "{\\\\^O}")
176 ("Ü" "{\\\\\"U}")
177 ("Ù" "{\\\\`U}")
178 ("Ú" "{\\\\'U}")
179 ("Û" "{\\\\^U}")
180 ("ñ" "{\\\\~n}")
181 ("Ñ" "{\\\\~N}")
182 ("ç" "{\\\\c c}")
183 ("Ç" "{\\\\c C}")
184 ("ß" "{\\\\ss}")
185 ("¿" "{?`}")
186 ("¡" "{!`}")
187 )
188 )
189
190
191
192
193 (defun iso2tex ()
194 "Translate ISO to TeX"
195 (interactive)
196 (translate-conventions iso2tex-trans-tab))
197
198
199 (defvar tex2iso-trans-tab '(
200 ( "{\\\\\"a}" "ä")
201 ( "{\\\\`a}" "à")
202 ( "{\\\\'a}" "á")
203 ( "{\\\\~a}" "ã")
204 ( "{\\\\^a}" "â")
205 ( "{\\\\\"e}" "ë")
206 ( "{\\\\`e}" "è")
207 ( "{\\\\'e}" "é")
208 ( "{\\\\^e}" "ê")
209 ( "{\\\\\"\\\\i}" "ï")
210 ( "{\\\\`\\\\i}" "ì")
211 ( "{\\\\'\\\\i}" "í")
212 ( "{\\\\^\\\\i}" "î")
213 ( "{\\\\\"i}" "ï")
214 ( "{\\\\`i}" "ì")
215 ( "{\\\\'i}" "í")
216 ( "{\\\\^i}" "î")
217 ( "{\\\\\"o}" "ö")
218 ( "{\\\\`o}" "ò")
219 ( "{\\\\'o}" "ó")
220 ( "{\\\\~o}" "õ")
221 ( "{\\\\^o}" "ô")
222 ( "{\\\\\"u}" "ü")
223 ( "{\\\\`u}" "ù")
224 ( "{\\\\'u}" "ú")
225 ( "{\\\\^u}" "û")
226 ( "{\\\\\"A}" "Ä")
227 ( "{\\\\`A}" "À")
228 ( "{\\\\'A}" "Á")
229 ( "{\\\\~A}" "Ã")
230 ( "{\\\\^A}" "Â")
231 ( "{\\\\\"E}" "Ë")
232 ( "{\\\\`E}" "È")
233 ( "{\\\\'E}" "É")
234 ( "{\\\\^E}" "Ê")
235 ( "{\\\\\"I}" "Ï")
236 ( "{\\\\`I}" "Ì")
237 ( "{\\\\'I}" "Í")
238 ( "{\\\\^I}" "Î")
239 ( "{\\\\\"O}" "Ö")
240 ( "{\\\\`O}" "Ò")
241 ( "{\\\\'O}" "Ó")
242 ( "{\\\\~O}" "Õ")
243 ( "{\\\\^O}" "Ô")
244 ( "{\\\\\"U}" "Ü")
245 ( "{\\\\`U}" "Ù")
246 ( "{\\\\'U}" "Ú")
247 ( "{\\\\^U}" "Û")
248 ( "{\\\\~n}" "ñ")
249 ( "{\\\\~N}" "Ñ")
250 ( "{\\\\c c}" "ç")
251 ( "{\\\\c C}" "Ç")
252 ( "\\\\\"{a}" "ä")
253 ( "\\\\`{a}" "à")
254 ( "\\\\'{a}" "á")
255 ( "\\\\~{a}" "ã")
256 ( "\\\\^{a}" "â")
257 ( "\\\\\"{e}" "ë")
258 ( "\\\\`{e}" "è")
259 ( "\\\\'{e}" "é")
260 ( "\\\\^{e}" "ê")
261 ( "\\\\\"{\\\\i}" "ï")
262 ( "\\\\`{\\\\i}" "ì")
263 ( "\\\\'{\\\\i}" "í")
264 ( "\\\\^{\\\\i}" "î")
265 ( "\\\\\"{i}" "ï")
266 ( "\\\\`{i}" "ì")
267 ( "\\\\'{i}" "í")
268 ( "\\\\^{i}" "î")
269 ( "\\\\\"{o}" "ö")
270 ( "\\\\`{o}" "ò")
271 ( "\\\\'{o}" "ó")
272 ( "\\\\~{o}" "õ")
273 ( "\\\\^{o}" "ô")
274 ( "\\\\\"{u}" "ü")
275 ( "\\\\`{u}" "ù")
276 ( "\\\\'{u}" "ú")
277 ( "\\\\^{u}" "û")
278 ( "\\\\\"{A}" "Ä")
279 ( "\\\\`{A}" "À")
280 ( "\\\\'{A}" "Á")
281 ( "\\\\~{A}" "Ã")
282 ( "\\\\^{A}" "Â")
283 ( "\\\\\"{E}" "Ë")
284 ( "\\\\`{E}" "È")
285 ( "\\\\'{E}" "É")
286 ( "\\\\^{E}" "Ê")
287 ( "\\\\\"{I}" "Ï")
288 ( "\\\\`{I}" "Ì")
289 ( "\\\\'{I}" "Í")
290 ( "\\\\^{I}" "Î")
291 ( "\\\\\"{O}" "Ö")
292 ( "\\\\`{O}" "Ò")
293 ( "\\\\'{O}" "Ó")
294 ( "\\\\~{O}" "Õ")
295 ( "\\\\^{O}" "Ô")
296 ( "\\\\\"{U}" "Ü")
297 ( "\\\\`{U}" "Ù")
298 ( "\\\\'{U}" "Ú")
299 ( "\\\\^{U}" "Û")
300 ( "\\\\~{n}" "ñ")
301 ( "\\\\~{N}" "Ñ")
302 ( "\\\\c{c}" "ç")
303 ( "\\\\c{C}" "Ç")
304 ( "{\\\\ss}" "ß")
305 ( "{?`}" "¿")
306 ( "{!`}" "¡")
307 )
308 )
309
310 (defun tex2iso ()
311 "Translate TeX to ISO"
312 (interactive)
313 (translate-conventions tex2iso-trans-tab))
314
315 (defvar gtex2iso-trans-tab '(
316 ( "\"a" "ä")
317 ( "\"A" "Ä")
318 ( "\"o" "ö")
319 ( "\"O" "Ö")
320 ( "\"u" "ü")
321 ( "\"U" "Ü")
322 ( "\"s" "ß")
323 ( "\\\\3" "ß")
324 ( "{\\\\\"a}" "ä")
325 ( "{\\\\`a}" "à")
326 ( "{\\\\'a}" "á")
327 ( "{\\\\~a}" "ã")
328 ( "{\\\\^a}" "â")
329 ( "{\\\\\"e}" "ë")
330 ( "{\\\\`e}" "è")
331 ( "{\\\\'e}" "é")
332 ( "{\\\\^e}" "ê")
333 ( "{\\\\\"\\\\i}" "ï")
334 ( "{\\\\`\\\\i}" "ì")
335 ( "{\\\\'\\\\i}" "í")
336 ( "{\\\\^\\\\i}" "î")
337 ( "{\\\\\"i}" "ï")
338 ( "{\\\\`i}" "ì")
339 ( "{\\\\'i}" "í")
340 ( "{\\\\^i}" "î")
341 ( "{\\\\\"o}" "ö")
342 ( "{\\\\`o}" "ò")
343 ( "{\\\\'o}" "ó")
344 ( "{\\\\~o}" "õ")
345 ( "{\\\\^o}" "ô")
346 ( "{\\\\\"u}" "ü")
347 ( "{\\\\`u}" "ù")
348 ( "{\\\\'u}" "ú")
349 ( "{\\\\^u}" "û")
350 ( "{\\\\\"A}" "Ä")
351 ( "{\\\\`A}" "À")
352 ( "{\\\\'A}" "Á")
353 ( "{\\\\~A}" "Ã")
354 ( "{\\\\^A}" "Â")
355 ( "{\\\\\"E}" "Ë")
356 ( "{\\\\`E}" "È")
357 ( "{\\\\'E}" "É")
358 ( "{\\\\^E}" "Ê")
359 ( "{\\\\\"I}" "Ï")
360 ( "{\\\\`I}" "Ì")
361 ( "{\\\\'I}" "Í")
362 ( "{\\\\^I}" "Î")
363 ( "{\\\\\"O}" "Ö")
364 ( "{\\\\`O}" "Ò")
365 ( "{\\\\'O}" "Ó")
366 ( "{\\\\~O}" "Õ")
367 ( "{\\\\^O}" "Ô")
368 ( "{\\\\\"U}" "Ü")
369 ( "{\\\\`U}" "Ù")
370 ( "{\\\\'U}" "Ú")
371 ( "{\\\\^U}" "Û")
372 ( "{\\\\~n}" "ñ")
373 ( "{\\\\~N}" "Ñ")
374 ( "{\\\\c c}" "ç")
375 ( "{\\\\c C}" "Ç")
376 ( "\\\\\"{a}" "ä")
377 ( "\\\\`{a}" "à")
378 ( "\\\\'{a}" "á")
379 ( "\\\\~{a}" "ã")
380 ( "\\\\^{a}" "â")
381 ( "\\\\\"{e}" "ë")
382 ( "\\\\`{e}" "è")
383 ( "\\\\'{e}" "é")
384 ( "\\\\^{e}" "ê")
385 ( "\\\\\"{\\\\i}" "ï")
386 ( "\\\\`{\\\\i}" "ì")
387 ( "\\\\'{\\\\i}" "í")
388 ( "\\\\^{\\\\i}" "î")
389 ( "\\\\\"{i}" "ï")
390 ( "\\\\`{i}" "ì")
391 ( "\\\\'{i}" "í")
392 ( "\\\\^{i}" "î")
393 ( "\\\\\"{o}" "ö")
394 ( "\\\\`{o}" "ò")
395 ( "\\\\'{o}" "ó")
396 ( "\\\\~{o}" "õ")
397 ( "\\\\^{o}" "ô")
398 ( "\\\\\"{u}" "ü")
399 ( "\\\\`{u}" "ù")
400 ( "\\\\'{u}" "ú")
401 ( "\\\\^{u}" "û")
402 ( "\\\\\"{A}" "Ä")
403 ( "\\\\`{A}" "À")
404 ( "\\\\'{A}" "Á")
405 ( "\\\\~{A}" "Ã")
406 ( "\\\\^{A}" "Â")
407 ( "\\\\\"{E}" "Ë")
408 ( "\\\\`{E}" "È")
409 ( "\\\\'{E}" "É")
410 ( "\\\\^{E}" "Ê")
411 ( "\\\\\"{I}" "Ï")
412 ( "\\\\`{I}" "Ì")
413 ( "\\\\'{I}" "Í")
414 ( "\\\\^{I}" "Î")
415 ( "\\\\\"{O}" "Ö")
416 ( "\\\\`{O}" "Ò")
417 ( "\\\\'{O}" "Ó")
418 ( "\\\\~{O}" "Õ")
419 ( "\\\\^{O}" "Ô")
420 ( "\\\\\"{U}" "Ü")
421 ( "\\\\`{U}" "Ù")
422 ( "\\\\'{U}" "Ú")
423 ( "\\\\^{U}" "Û")
424 ( "\\\\~{n}" "ñ")
425 ( "\\\\~{N}" "Ñ")
426 ( "\\\\c{c}" "ç")
427 ( "\\\\c{C}" "Ç")
428 ( "{\\\\ss}" "ß")
429 ( "{?`}" "¿")
430 ( "{!`}" "¡")
431 )
432 )
433
434 (defvar iso2gtex-trans-tab '(
435 ("ä" "\"a")
436 ("à" "{\\\\`a}")
437 ("á" "{\\\\'a}")
438 ("ã" "{\\\\~a}")
439 ("â" "{\\\\^a}")
440 ("ë" "{\\\\\"e}")
441 ("è" "{\\\\`e}")
442 ("é" "{\\\\'e}")
443 ("ê" "{\\\\^e}")
444 ("ï" "{\\\\\"\\\\i}")
445 ("ì" "{\\\\`\\\\i}")
446 ("í" "{\\\\'\\\\i}")
447 ("î" "{\\\\^\\\\i}")
448 ("ö" "\"o")
449 ("ò" "{\\\\`o}")
450 ("ó" "{\\\\'o}")
451 ("õ" "{\\\\~o}")
452 ("ô" "{\\\\^o}")
453 ("ü" "\"u")
454 ("ù" "{\\\\`u}")
455 ("ú" "{\\\\'u}")
456 ("û" "{\\\\^u}")
457 ("Ä" "\"A")
458 ("À" "{\\\\`A}")
459 ("Á" "{\\\\'A}")
460 ("Ã" "{\\\\~A}")
461 ("Â" "{\\\\^A}")
462 ("Ë" "{\\\\\"E}")
463 ("È" "{\\\\`E}")
464 ("É" "{\\\\'E}")
465 ("Ê" "{\\\\^E}")
466 ("Ï" "{\\\\\"I}")
467 ("Ì" "{\\\\`I}")
468 ("Í" "{\\\\'I}")
469 ("Î" "{\\\\^I}")
470 ("Ö" "\"O")
471 ("Ò" "{\\\\`O}")
472 ("Ó" "{\\\\'O}")
473 ("Õ" "{\\\\~O}")
474 ("Ô" "{\\\\^O}")
475 ("Ü" "\"U")
476 ("Ù" "{\\\\`U}")
477 ("Ú" "{\\\\'U}")
478 ("Û" "{\\\\^U}")
479 ("ñ" "{\\\\~n}")
480 ("Ñ" "{\\\\~N}")
481 ("ç" "{\\\\c c}")
482 ("Ç" "{\\\\c C}")
483 ("ß" "\\\\3")
484 ("¿" "{?`}")
485 ("¡" "{!`}")
486 )
487 )
488
489
490
491 (defun gtex2iso ()
492 "Translate german TeX to ISO"
493 (interactive)
494 (translate-conventions gtex2iso-trans-tab))
495
496
497 (defun iso2gtex ()
498 "Translate ISO to german TeX"
499 (interactive)
500 (translate-conventions iso2gtex-trans-tab))
501
502
503 (defun german-texP ()
504 "Check if tex buffer is german LaTeX"
505 (save-excursion
506 (widen)
507 (goto-char (point-min))
508 (re-search-forward "\\\\documentstyle\\[.*german.*\\]" nil t)))
509
510
511 (defun fix-iso2tex ()
512 "Turn ISO latin1 into TeX sequences"
513 (if (equal major-mode 'latex-mode)
514 (if (german-texP)
515 (iso2gtex)
516 (iso2tex)))
517 (if (equal major-mode 'tex-mode)
518 (iso2tex)))
519
520 (defun fix-tex2iso ()
521 "Turn TeX sequences into ISO latin1"
522 (if (equal major-mode 'latex-mode)
523 (if (german-texP)
524 (gtex2iso)
525 (tex2iso)))
526 (if (equal major-mode 'tex-mode)
527 (tex2iso)))
528
529 (add-hook 'find-file-hooks 'fix-tex2iso)
530 (add-hook 'write-file-hooks 'fix-iso2tex)