1;; iso-cvt.el -- translate to ISO 8859-1 from/to net/TeX conventions 2;; Copyright � 1993 Free Software Foundation, Inc. 3;; Was formerly called gm-lingo.el. 4 5;; Author: Michael Gschwind <mike@vlsivie.tuwien.ac.at> 6;; Keywords: tex, iso, latin, i18n 7 8;; This file is part of GNU Emacs. 9 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) 13;; any later version. 14 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. 19 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. 23 24;;; Commentary: 25;; This lisp code server two purposes, both of which involve 26;; the translation of various conventions for representing European 27;; character sets to ISO 8859-1. 28 29; Net support: 30; Various conventions exist in Newsgroups on how to represent national 31; characters. The functions provided here translate these net conventions 32; to ISO. 33; 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.) 39 40; TeX support 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. 44; 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 49 50;; TO DO: 51; The net support should install hooks (like TeX support does) 52; which recognizes certains news groups and translates all articles from 53; those groups. 54; 55; Cover more cases for translation (There is an infinite number of ways to 56; represent accented characters in TeX) 57 58;; SEE ALSO: 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 63 64;;; Code: 65 66(provide 'iso-cvt) 67 68(defvar iso-spanish-trans-tab 69 '( 70 ("~n" "�") 71 ("\([a-zA-Z]\)#" "\\1�") 72 ("~N" "�") 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�") 83 ) 84 "Spanish translation table.") 85 86(defun iso-translate-conventions (trans-tab) 87 "Use the translation table argument to translate the current buffer." 88 (interactive) 89 (save-excursion 90 (widen) 91 (goto-char (point-min)) 92 (let ((work-tab trans-tab) 93 (buffer-read-only nil)) 94 (while work-tab 95 (save-excursion 96 (let ((trans-this (car work-tab))) 97 (while (re-search-forward (car trans-this) nil t) 98 (replace-match (car (cdr trans-this)) nil nil))) 99 (setq work-tab (cdr work-tab))))))) 100 101(defun iso-spanish () 102 "Translate net conventions for Spanish to ISO 8859-1." 103 (interactive) 104 (iso-translate-conventions iso-spanish-trans-tab)) 105 106(defvar iso-aggressive-german-trans-tab 107 '( 108 ("\"a" "�") 109 ("\"A" "�") 110 ("\"o" "�") 111 ("\"O" "�") 112 ("\"u" "�") 113 ("\"U" "�") 114 ("\"s" "�") 115 ("\\\\3" "�") 116 ) 117 "German translation table. 118This table uses an aggressive translation approach and may translate 119erroneously translate too much.") 120 121(defvar iso-conservative-german-trans-tab 122 '( 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�") 131 ) 132 "German translation table. 133This table uses a conservative translation approach and may translate too 134little.") 135 136 137(defvar iso-german-trans-tab iso-aggressive-german-trans-tab 138 "Currently active translation table for German.") 139 140(defun iso-german () 141 "Translate net conventions for German to ISO 8859-1." 142 (interactive) 143 (iso-translate-conventions iso-german-trans-tab)) 144 145(defvar iso-iso2tex-trans-tab 146 '( 147 ("�" "{\\\\\"a}") 148 ("�" "{\\\\`a}") 149 ("�" "{\\\\'a}") 150 ("�" "{\\\\~a}") 151 ("�" "{\\\\^a}") 152 ("�" "{\\\\\"e}") 153 ("�" "{\\\\`e}") 154 ("�" "{\\\\'e}") 155 ("�" "{\\\\^e}") 156 ("�" "{\\\\\"\\\\i}") 157 ("�" "{\\\\`\\\\i}") 158 ("�" "{\\\\'\\\\i}") 159 ("�" "{\\\\^\\\\i}") 160 ("�" "{\\\\\"o}") 161 ("�" "{\\\\`o}") 162 ("�" "{\\\\'o}") 163 ("�" "{\\\\~o}") 164 ("�" "{\\\\^o}") 165 ("�" "{\\\\\"u}") 166 ("�" "{\\\\`u}") 167 ("�" "{\\\\'u}") 168 ("�" "{\\\\^u}") 169 ("�" "{\\\\\"A}") 170 ("�" "{\\\\`A}") 171 ("�" "{\\\\'A}") 172 ("�" "{\\\\~A}") 173 ("�" "{\\\\^A}") 174 ("�" "{\\\\\"E}") 175 ("�" "{\\\\`E}") 176 ("�" "{\\\\'E}") 177 ("�" "{\\\\^E}") 178 ("�" "{\\\\\"I}") 179 ("�" "{\\\\`I}") 180 ("�" "{\\\\'I}") 181 ("�" "{\\\\^I}") 182 ("�" "{\\\\\"O}") 183 ("�" "{\\\\`O}") 184 ("�" "{\\\\'O}") 185 ("�" "{\\\\~O}") 186 ("�" "{\\\\^O}") 187 ("�" "{\\\\\"U}") 188 ("�" "{\\\\`U}") 189 ("�" "{\\\\'U}") 190 ("�" "{\\\\^U}") 191 ("�" "{\\\\~n}") 192 ("�" "{\\\\~N}") 193 ("�" "{\\\\c c}") 194 ("�" "{\\\\c C}") 195 ("�" "{\\\\ss}") 196 ("�" "{?`}") 197 ("�" "{!`}") 198 ) 199 "Translation table for translating ISO 8859-1 characters to TeX sequences.") 200 201 202 203 204(defun iso-iso2tex () 205 "Translate ISO 8859-1 characters to TeX sequences." 206 (interactive) 207 (iso-translate-conventions iso-iso2tex-trans-tab)) 208 209 210(defvar iso-tex2iso-trans-tab 211 '( 212 ("{\\\\\"a}" "�") 213 ("{\\\\`a}" "�") 214 ("{\\\\'a}" "�") 215 ("{\\\\~a}" "�") 216 ("{\\\\^a}" "�") 217 ("{\\\\\"e}" "�") 218 ("{\\\\`e}" "�") 219 ("{\\\\'e}" "�") 220 ("{\\\\^e}" "�") 221 ("{\\\\\"\\\\i}" "�") 222 ("{\\\\`\\\\i}" "�") 223 ("{\\\\'\\\\i}" "�") 224 ("{\\\\^\\\\i}" "�") 225 ("{\\\\\"i}" "�") 226 ("{\\\\`i}" "�") 227 ("{\\\\'i}" "�") 228 ("{\\\\^i}" "�") 229 ("{\\\\\"o}" "�") 230 ("{\\\\`o}" "�") 231 ("{\\\\'o}" "�") 232 ("{\\\\~o}" "�") 233 ("{\\\\^o}" "�") 234 ("{\\\\\"u}" "�") 235 ("{\\\\`u}" "�") 236 ("{\\\\'u}" "�") 237 ("{\\\\^u}" "�") 238 ("{\\\\\"A}" "�") 239 ("{\\\\`A}" "�") 240 ("{\\\\'A}" "�") 241 ("{\\\\~A}" "�") 242 ("{\\\\^A}" "�") 243 ("{\\\\\"E}" "�") 244 ("{\\\\`E}" "�") 245 ("{\\\\'E}" "�") 246 ("{\\\\^E}" "�") 247 ("{\\\\\"I}" "�") 248 ("{\\\\`I}" "�") 249 ("{\\\\'I}" "�") 250 ("{\\\\^I}" "�") 251 ("{\\\\\"O}" "�") 252 ("{\\\\`O}" "�") 253 ("{\\\\'O}" "�") 254 ("{\\\\~O}" "�") 255 ("{\\\\^O}" "�") 256 ("{\\\\\"U}" "�") 257 ("{\\\\`U}" "�") 258 ("{\\\\'U}" "�") 259 ("{\\\\^U}" "�") 260 ("{\\\\~n}" "�") 261 ("{\\\\~N}" "�") 262 ("{\\\\c c}" "�") 263 ("{\\\\c C}" "�") 264 ("\\\\\"{a}" "�") 265 ("\\\\`{a}" "�") 266 ("\\\\'{a}" "�") 267 ("\\\\~{a}" "�") 268 ("\\\\^{a}" "�") 269 ("\\\\\"{e}" "�") 270 ("\\\\`{e}" "�") 271 ("\\\\'{e}" "�") 272 ("\\\\^{e}" "�") 273 ("\\\\\"{\\\\i}" "�") 274 ("\\\\`{\\\\i}" "�") 275 ("\\\\'{\\\\i}" "�") 276 ("\\\\^{\\\\i}" "�") 277 ("\\\\\"{i}" "�") 278 ("\\\\`{i}" "�") 279 ("\\\\'{i}" "�") 280 ("\\\\^{i}" "�") 281 ("\\\\\"{o}" "�") 282 ("\\\\`{o}" "�") 283 ("\\\\'{o}" "�") 284 ("\\\\~{o}" "�") 285 ("\\\\^{o}" "�") 286 ("\\\\\"{u}" "�") 287 ("\\\\`{u}" "�") 288 ("\\\\'{u}" "�") 289 ("\\\\^{u}" "�") 290 ("\\\\\"{A}" "�") 291 ("\\\\`{A}" "�") 292 ("\\\\'{A}" "�") 293 ("\\\\~{A}" "�") 294 ("\\\\^{A}" "�") 295 ("\\\\\"{E}" "�") 296 ("\\\\`{E}" "�") 297 ("\\\\'{E}" "�") 298 ("\\\\^{E}" "�") 299 ("\\\\\"{I}" "�") 300 ("\\\\`{I}" "�") 301 ("\\\\'{I}" "�") 302 ("\\\\^{I}" "�") 303 ("\\\\\"{O}" "�") 304 ("\\\\`{O}" "�") 305 ("\\\\'{O}" "�") 306 ("\\\\~{O}" "�") 307 ("\\\\^{O}" "�") 308 ("\\\\\"{U}" "�") 309 ("\\\\`{U}" "�") 310 ("\\\\'{U}" "�") 311 ("\\\\^{U}" "�") 312 ("\\\\~{n}" "�") 313 ("\\\\~{N}" "�") 314 ("\\\\c{c}" "�") 315 ("\\\\c{C}" "�") 316 ("{\\\\ss}" "�") 317 ("?`" "�") 318 ("!`" "�") 319 ("{?`}" "�") 320 ("{!`}" "�") 321 ) 322 "Translation table for translating TeX sequences to ISO 8859-1 characters. 323This table is not exhaustive (and due to TeX's power can never be). It only 324contains commonly used sequences.") 325 326(defun iso-tex2iso () 327 "Translate TeX sequences to ISO 8859-1 characters." 328 (interactive) 329 (iso-translate-conventions iso-tex2iso-trans-tab)) 330 331(defvar iso-gtex2iso-trans-tab 332 '( 333 ("{\\\\\"a}" "�") 334 ("{\\\\`a}" "�") 335 ("{\\\\'a}" "�") 336 ("{\\\\~a}" "�") 337 ("{\\\\^a}" "�") 338 ("{\\\\\"e}" "�") 339 ("{\\\\`e}" "�") 340 ("{\\\\'e}" "�") 341 ("{\\\\^e}" "�") 342 ("{\\\\\"\\\\i}" "�") 343 ("{\\\\`\\\\i}" "�") 344 ("{\\\\'\\\\i}" "�") 345 ("{\\\\^\\\\i}" "�") 346 ("{\\\\\"i}" "�") 347 ("{\\\\`i}" "�") 348 ("{\\\\'i}" "�") 349 ("{\\\\^i}" "�") 350 ("{\\\\\"o}" "�") 351 ("{\\\\`o}" "�") 352 ("{\\\\'o}" "�") 353 ("{\\\\~o}" "�") 354 ("{\\\\^o}" "�") 355 ("{\\\\\"u}" "�") 356 ("{\\\\`u}" "�") 357 ("{\\\\'u}" "�") 358 ("{\\\\^u}" "�") 359 ("{\\\\\"A}" "�") 360 ("{\\\\`A}" "�") 361 ("{\\\\'A}" "�") 362 ("{\\\\~A}" "�") 363 ("{\\\\^A}" "�") 364 ("{\\\\\"E}" "�") 365 ("{\\\\`E}" "�") 366 ("{\\\\'E}" "�") 367 ("{\\\\^E}" "�") 368 ("{\\\\\"I}" "�") 369 ("{\\\\`I}" "�") 370 ("{\\\\'I}" "�") 371 ("{\\\\^I}" "�") 372 ("{\\\\\"O}" "�") 373 ("{\\\\`O}" "�") 374 ("{\\\\'O}" "�") 375 ("{\\\\~O}" "�") 376 ("{\\\\^O}" "�") 377 ("{\\\\\"U}" "�") 378 ("{\\\\`U}" "�") 379 ("{\\\\'U}" "�") 380 ("{\\\\^U}" "�") 381 ("{\\\\~n}" "�") 382 ("{\\\\~N}" "�") 383 ("{\\\\c c}" "�") 384 ("{\\\\c C}" "�") 385 ("\\\\\"{a}" "�") 386 ("\\\\`{a}" "�") 387 ("\\\\'{a}" "�") 388 ("\\\\~{a}" "�") 389 ("\\\\^{a}" "�") 390 ("\\\\\"{e}" "�") 391 ("\\\\`{e}" "�") 392 ("\\\\'{e}" "�") 393 ("\\\\^{e}" "�") 394 ("\\\\\"{\\\\i}" "�") 395 ("\\\\`{\\\\i}" "�") 396 ("\\\\'{\\\\i}" "�") 397 ("\\\\^{\\\\i}" "�") 398 ("\\\\\"{i}" "�") 399 ("\\\\`{i}" "�") 400 ("\\\\'{i}" "�") 401 ("\\\\^{i}" "�") 402 ("\\\\\"{o}" "�") 403 ("\\\\`{o}" "�") 404 ("\\\\'{o}" "�") 405 ("\\\\~{o}" "�") 406 ("\\\\^{o}" "�") 407 ("\\\\\"{u}" "�") 408 ("\\\\`{u}" "�") 409 ("\\\\'{u}" "�") 410 ("\\\\^{u}" "�") 411 ("\\\\\"{A}" "�") 412 ("\\\\`{A}" "�") 413 ("\\\\'{A}" "�") 414 ("\\\\~{A}" "�") 415 ("\\\\^{A}" "�") 416 ("\\\\\"{E}" "�") 417 ("\\\\`{E}" "�") 418 ("\\\\'{E}" "�") 419 ("\\\\^{E}" "�") 420 ("\\\\\"{I}" "�") 421 ("\\\\`{I}" "�") 422 ("\\\\'{I}" "�") 423 ("\\\\^{I}" "�") 424 ("\\\\\"{O}" "�") 425 ("\\\\`{O}" "�") 426 ("\\\\'{O}" "�") 427 ("\\\\~{O}" "�") 428 ("\\\\^{O}" "�") 429 ("\\\\\"{U}" "�") 430 ("\\\\`{U}" "�") 431 ("\\\\'{U}" "�") 432 ("\\\\^{U}" "�") 433 ("\\\\~{n}" "�") 434 ("\\\\~{N}" "�") 435 ("\\\\c{c}" "�") 436 ("\\\\c{C}" "�") 437 ("{\\\\ss}" "�") 438 ("?`" "�") 439 ("!`" "�") 440 ("{?`}" "�") 441 ("{!`}" "�") 442 ("\"a" "�") 443 ("\"A" "�") 444 ("\"o" "�") 445 ("\"O" "�") 446 ("\"u" "�") 447 ("\"U" "�") 448 ("\"s" "�") 449 ("\\\\3" "�") 450 ) 451 "Translation table for translating German TeX sequences to ISO 8859-1. 452This table is not exhaustive (and due to TeX's power can never be). It only 453contains commonly used sequences.") 454 455(defvar iso-iso2gtex-trans-tab 456 '( 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 ("�" "\"A") 480 ("�" "{\\\\`A}") 481 ("�" "{\\\\'A}") 482 ("�" "{\\\\~A}") 483 ("�" "{\\\\^A}") 484 ("�" "{\\\\\"E}") 485 ("�" "{\\\\`E}") 486 ("�" "{\\\\'E}") 487 ("�" "{\\\\^E}") 488 ("�" "{\\\\\"I}") 489 ("�" "{\\\\`I}") 490 ("�" "{\\\\'I}") 491 ("�" "{\\\\^I}") 492 ("�" "\"O") 493 ("�" "{\\\\`O}") 494 ("�" "{\\\\'O}") 495 ("�" "{\\\\~O}") 496 ("�" "{\\\\^O}") 497 ("�" "\"U") 498 ("�" "{\\\\`U}") 499 ("�" "{\\\\'U}") 500 ("�" "{\\\\^U}") 501 ("�" "{\\\\~n}") 502 ("�" "{\\\\~N}") 503 ("�" "{\\\\c c}") 504 ("�" "{\\\\c C}") 505 ("�" "\"s") 506 ("�" "{?`}") 507 ("�" "{!`}") 508 ) 509 "Translation table for translating ISO 8859-1 characters to German TeX.") 510 511(defun iso-gtex2iso () 512 "Translate German TeX sequences to ISO 8859-1 characters." 513 (interactive) 514 (iso-translate-conventions iso-gtex2iso-trans-tab)) 515 516 517(defun iso-iso2gtex () 518 "Translate ISO 8859-1 characters to German TeX sequences." 519 (interactive) 520 (iso-translate-conventions iso-iso2gtex-trans-tab)) 521 522 523(defun iso-german-tex-p () 524 "Check if tex buffer is German LaTeX." 525 (save-excursion 526 (widen) 527 (goto-char (point-min)) 528 (re-search-forward "\\\\documentstyle\\[.*german.*\\]" nil t))) 529 530(defun iso-fix-iso2tex () 531 "Turn ISO 8859-1 (aka. ISO Latin-1) buffer into TeX sequences. 532If German TeX is used, German TeX sequences are generated." 533 (if (or (equal major-mode 'latex-mode) 534 (equal major-mode 'LaTeX-mode)) ; AucTeX wants this 535 (if (iso-german-tex-p) 536 (iso-iso2gtex) 537 (iso-iso2tex))) 538 (if (or (equal major-mode 'tex-mode) 539 (equal major-mode 'TeX-mode)) ; AucTeX wants this 540 (iso-iso2tex))) 541 542(defun iso-fix-tex2iso () 543 "Turn TeX sequences into ISO 8859-1 (aka. ISO Latin-1) characters. 544This function recognices German TeX buffers." 545 (if (or (equal major-mode 'latex-mode) 546 (equal major-mode 'Latex-mode)) ; AucTeX wants this 547 (if (iso-german-tex-p) 548 (iso-gtex2iso) 549 (iso-tex2iso))) 550 (if (or (equal major-mode 'tex-mode) 551 (equal major-mode 'TeX-mode)) ;; AucTeX wants this 552 (iso-tex2iso))) 553 554(defun iso-cvt-ffh () 555 "find-file-hook for iso-cvt-cvt.el." 556 (iso-fix-tex2iso) 557 (set-buffer-modified-p nil)) 558 559(defun iso-cvt-wfh () 560 "write file hook for iso-cvt-cvt.el." 561 (iso-fix-iso2tex)) 562 563(defun iso-cvt-ash () 564 "after save hook for iso-cvt-cvt.el." 565 (iso-fix-tex2iso) 566 (set-buffer-modified-p nil)) 567 568(add-hook 'find-file-hooks 'iso-cvt-ffh) 569(add-hook 'write-file-hooks 'iso-cvt-wfh) 570(add-hook 'after-save-hook 'iso-cvt-ash) 571 572;;; iso-cvt.el ends here 573