iso-cvt.el 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907
  1. ;;; iso-cvt.el --- translate ISO 8859-1 from/to various encodings -*- coding: iso-latin-1 -*-
  2. ;; This file was formerly called gm-lingo.el.
  3. ;; Copyright (C) 1993-1998, 2000-2012 Free Software Foundation, Inc.
  4. ;; Author: Michael Gschwind <mike@vlsivie.tuwien.ac.at>
  5. ;; Keywords: tex, iso, latin, i18n
  6. ;; This file is part of GNU Emacs.
  7. ;; GNU Emacs is free software: you can redistribute it and/or modify
  8. ;; it under the terms of the GNU General Public License as published by
  9. ;; the Free Software Foundation, either version 3 of the License, or
  10. ;; (at your option) any later version.
  11. ;; GNU Emacs is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;; GNU General Public License for more details.
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  17. ;;; Commentary:
  18. ;; This lisp code is a general framework for translating various
  19. ;; representations of the same data.
  20. ;; among other things it can be used to translate TeX, HTML, and compressed
  21. ;; files to ISO 8859-1. It can also be used to translate different charsets
  22. ;; such as IBM PC, Macintosh or HP Roman8.
  23. ;; Note that many translations use the GNU recode tool to do the actual
  24. ;; conversion. So you might want to install that tool to get the full
  25. ;; benefit of iso-cvt.el
  26. ; TO DO:
  27. ; Cover more cases for translation. (There is an infinite number of ways to
  28. ; represent accented characters in TeX)
  29. ;; SEE ALSO:
  30. ; If you are interested in questions related to using the ISO 8859-1
  31. ; characters set (configuring emacs, Unix, etc. to use ISO), then you
  32. ; can get the ISO 8859-1 FAQ via anonymous ftp from
  33. ; ftp.vlsivie.tuwien.ac.at in /pub/8bit/FAQ-ISO-8859-1
  34. ;;; Code:
  35. (defvar iso-spanish-trans-tab
  36. '(
  37. ("~n" "ñ")
  38. ("\([a-zA-Z]\)#" "\\1ñ")
  39. ("~N" "Ñ")
  40. ("\\([-a-zA-Z\"`]\\)\"u" "\\1ü")
  41. ("\\([-a-zA-Z\"`]\\)\"U" "\\1Ü")
  42. ("\\([-a-zA-Z]\\)'o" "\\1ó")
  43. ("\\([-a-zA-Z]\\)'O" "\\Ó")
  44. ("\\([-a-zA-Z]\\)'e" "\\1é")
  45. ("\\([-a-zA-Z]\\)'E" "\\1É")
  46. ("\\([-a-zA-Z]\\)'a" "\\1á")
  47. ("\\([-a-zA-Z]\\)'A" "\\1A")
  48. ("\\([-a-zA-Z]\\)'i" "\\1í")
  49. ("\\([-a-zA-Z]\\)'I" "\\1Í")
  50. )
  51. "Spanish translation table.")
  52. (defun iso-translate-conventions (from to trans-tab)
  53. "Translate between FROM and TO using the translation table TRANS-TAB."
  54. (save-excursion
  55. (save-restriction
  56. (narrow-to-region from to)
  57. (goto-char from)
  58. (let ((work-tab trans-tab)
  59. (buffer-read-only nil)
  60. (case-fold-search nil))
  61. (while work-tab
  62. (save-excursion
  63. (let ((trans-this (car work-tab)))
  64. (while (re-search-forward (car trans-this) nil t)
  65. (replace-match (car (cdr trans-this)) t nil)))
  66. (setq work-tab (cdr work-tab)))))
  67. (point-max))))
  68. ;;;###autoload
  69. (defun iso-spanish (from to &optional buffer)
  70. "Translate net conventions for Spanish to ISO 8859-1.
  71. Translate the region between FROM and TO using the table
  72. `iso-spanish-trans-tab'.
  73. Optional arg BUFFER is ignored (for use in `format-alist')."
  74. (interactive "*r")
  75. (iso-translate-conventions from to iso-spanish-trans-tab))
  76. (defvar iso-aggressive-german-trans-tab
  77. '(
  78. ("\"a" "ä")
  79. ("\"A" "Ä")
  80. ("\"o" "ö")
  81. ("\"O" "Ö")
  82. ("\"u" "ü")
  83. ("\"U" "Ü")
  84. ("\"s" "ß")
  85. ("\\\\3" "ß")
  86. )
  87. "German translation table.
  88. This table uses an aggressive translation approach
  89. and may erroneously translate too much.")
  90. (defvar iso-conservative-german-trans-tab
  91. '(
  92. ("\\([-a-zA-Z\"`]\\)\"a" "\\1ä")
  93. ("\\([-a-zA-Z\"`]\\)\"A" "\\1Ä")
  94. ("\\([-a-zA-Z\"`]\\)\"o" "\\1ö")
  95. ("\\([-a-zA-Z\"`]\\)\"O" "\\1Ö")
  96. ("\\([-a-zA-Z\"`]\\)\"u" "\\1ü")
  97. ("\\([-a-zA-Z\"`]\\)\"U" "\\1Ü")
  98. ("\\([-a-zA-Z\"`]\\)\"s" "\\1ß")
  99. ("\\([-a-zA-Z\"`]\\)\\\\3" "\\1ß")
  100. )
  101. "German translation table.
  102. This table uses a conservative translation approach
  103. and may translate too little.")
  104. (defvar iso-german-trans-tab iso-aggressive-german-trans-tab
  105. "Currently active translation table for German.")
  106. ;;;###autoload
  107. (defun iso-german (from to &optional buffer)
  108. "Translate net conventions for German to ISO 8859-1.
  109. Translate the region FROM and TO using the table
  110. `iso-german-trans-tab'.
  111. Optional arg BUFFER is ignored (for use in `format-alist')."
  112. (interactive "*r")
  113. (iso-translate-conventions from to iso-german-trans-tab))
  114. (defvar iso-iso2tex-trans-tab
  115. '(
  116. ("ä" "{\\\\\"a}")
  117. ("à" "{\\\\`a}")
  118. ("á" "{\\\\'a}")
  119. ("ã" "{\\\\~a}")
  120. ("â" "{\\\\^a}")
  121. ("ë" "{\\\\\"e}")
  122. ("è" "{\\\\`e}")
  123. ("é" "{\\\\'e}")
  124. ("ê" "{\\\\^e}")
  125. ("ï" "{\\\\\"\\\\i}")
  126. ("ì" "{\\\\`\\\\i}")
  127. ("í" "{\\\\'\\\\i}")
  128. ("î" "{\\\\^\\\\i}")
  129. ("ö" "{\\\\\"o}")
  130. ("ò" "{\\\\`o}")
  131. ("ó" "{\\\\'o}")
  132. ("õ" "{\\\\~o}")
  133. ("ô" "{\\\\^o}")
  134. ("ü" "{\\\\\"u}")
  135. ("ù" "{\\\\`u}")
  136. ("ú" "{\\\\'u}")
  137. ("û" "{\\\\^u}")
  138. ("Ä" "{\\\\\"A}")
  139. ("À" "{\\\\`A}")
  140. ("Á" "{\\\\'A}")
  141. ("Ã" "{\\\\~A}")
  142. ("Â" "{\\\\^A}")
  143. ("Ë" "{\\\\\"E}")
  144. ("È" "{\\\\`E}")
  145. ("É" "{\\\\'E}")
  146. ("Ê" "{\\\\^E}")
  147. ("Ï" "{\\\\\"I}")
  148. ("Ì" "{\\\\`I}")
  149. ("Í" "{\\\\'I}")
  150. ("Î" "{\\\\^I}")
  151. ("Ö" "{\\\\\"O}")
  152. ("Ò" "{\\\\`O}")
  153. ("Ó" "{\\\\'O}")
  154. ("Õ" "{\\\\~O}")
  155. ("Ô" "{\\\\^O}")
  156. ("Ü" "{\\\\\"U}")
  157. ("Ù" "{\\\\`U}")
  158. ("Ú" "{\\\\'U}")
  159. ("Û" "{\\\\^U}")
  160. ("ñ" "{\\\\~n}")
  161. ("Ñ" "{\\\\~N}")
  162. ("ç" "{\\\\c c}")
  163. ("Ç" "{\\\\c C}")
  164. ("ß" "{\\\\ss}")
  165. ("\306" "{\\\\AE}")
  166. ("\346" "{\\\\ae}")
  167. ("\305" "{\\\\AA}")
  168. ("\345" "{\\\\aa}")
  169. ("\251" "{\\\\copyright}")
  170. ("£" "{\\\\pounds}")
  171. ("¶" "{\\\\P}")
  172. ("§" "{\\\\S}")
  173. ("¿" "{?`}")
  174. ("¡" "{!`}")
  175. )
  176. "Translation table for translating ISO 8859-1 characters to TeX sequences.")
  177. ;;;###autoload
  178. (defun iso-iso2tex (from to &optional buffer)
  179. "Translate ISO 8859-1 characters to TeX sequences.
  180. Translate the region between FROM and TO using the table
  181. `iso-iso2tex-trans-tab'.
  182. Optional arg BUFFER is ignored (for use in `format-alist')."
  183. (interactive "*r")
  184. (iso-translate-conventions from to iso-iso2tex-trans-tab))
  185. (defvar iso-tex2iso-trans-tab
  186. '(
  187. ("{\\\\\"a}" "ä")
  188. ("{\\\\`a}" "à")
  189. ("{\\\\'a}" "á")
  190. ("{\\\\~a}" "ã")
  191. ("{\\\\^a}" "â")
  192. ("{\\\\\"e}" "ë")
  193. ("{\\\\`e}" "è")
  194. ("{\\\\'e}" "é")
  195. ("{\\\\^e}" "ê")
  196. ("{\\\\\"\\\\i}" "ï")
  197. ("{\\\\`\\\\i}" "ì")
  198. ("{\\\\'\\\\i}" "í")
  199. ("{\\\\^\\\\i}" "î")
  200. ("{\\\\\"i}" "ï")
  201. ("{\\\\`i}" "ì")
  202. ("{\\\\'i}" "í")
  203. ("{\\\\^i}" "î")
  204. ("{\\\\\"o}" "ö")
  205. ("{\\\\`o}" "ò")
  206. ("{\\\\'o}" "ó")
  207. ("{\\\\~o}" "õ")
  208. ("{\\\\^o}" "ô")
  209. ("{\\\\\"u}" "ü")
  210. ("{\\\\`u}" "ù")
  211. ("{\\\\'u}" "ú")
  212. ("{\\\\^u}" "û")
  213. ("{\\\\\"A}" "Ä")
  214. ("{\\\\`A}" "À")
  215. ("{\\\\'A}" "Á")
  216. ("{\\\\~A}" "Ã")
  217. ("{\\\\^A}" "Â")
  218. ("{\\\\\"E}" "Ë")
  219. ("{\\\\`E}" "È")
  220. ("{\\\\'E}" "É")
  221. ("{\\\\^E}" "Ê")
  222. ("{\\\\\"I}" "Ï")
  223. ("{\\\\`I}" "Ì")
  224. ("{\\\\'I}" "Í")
  225. ("{\\\\^I}" "Î")
  226. ("{\\\\\"O}" "Ö")
  227. ("{\\\\`O}" "Ò")
  228. ("{\\\\'O}" "Ó")
  229. ("{\\\\~O}" "Õ")
  230. ("{\\\\^O}" "Ô")
  231. ("{\\\\\"U}" "Ü")
  232. ("{\\\\`U}" "Ù")
  233. ("{\\\\'U}" "Ú")
  234. ("{\\\\^U}" "Û")
  235. ("{\\\\~n}" "ñ")
  236. ("{\\\\~N}" "Ñ")
  237. ("{\\\\c c}" "ç")
  238. ("{\\\\c C}" "Ç")
  239. ("\\\\\"a" "ä")
  240. ("\\\\`a" "à")
  241. ("\\\\'a" "á")
  242. ("\\\\~a" "ã")
  243. ("\\\\^a" "â")
  244. ("\\\\\"e" "ë")
  245. ("\\\\`e" "è")
  246. ("\\\\'e" "é")
  247. ("\\\\^e" "ê")
  248. ;; Discard spaces and/or one EOF after macro \i.
  249. ;; Converting it back will use braces.
  250. ("\\\\\"\\\\i *\n\n" "ï\n\n")
  251. ("\\\\\"\\\\i *\n?" "ï")
  252. ("\\\\`\\\\i *\n\n" "ì\n\n")
  253. ("\\\\`\\\\i *\n?" "ì")
  254. ("\\\\'\\\\i *\n\n" "í\n\n")
  255. ("\\\\'\\\\i *\n?" "í")
  256. ("\\\\^\\\\i *\n\n" "î\n\n")
  257. ("\\\\^\\\\i *\n?" "î")
  258. ("\\\\\"i" "ï")
  259. ("\\\\`i" "ì")
  260. ("\\\\'i" "í")
  261. ("\\\\^i" "î")
  262. ("\\\\\"o" "ö")
  263. ("\\\\`o" "ò")
  264. ("\\\\'o" "ó")
  265. ("\\\\~o" "õ")
  266. ("\\\\^o" "ô")
  267. ("\\\\\"u" "ü")
  268. ("\\\\`u" "ù")
  269. ("\\\\'u" "ú")
  270. ("\\\\^u" "û")
  271. ("\\\\\"A" "Ä")
  272. ("\\\\`A" "À")
  273. ("\\\\'A" "Á")
  274. ("\\\\~A" "Ã")
  275. ("\\\\^A" "Â")
  276. ("\\\\\"E" "Ë")
  277. ("\\\\`E" "È")
  278. ("\\\\'E" "É")
  279. ("\\\\^E" "Ê")
  280. ("\\\\\"I" "Ï")
  281. ("\\\\`I" "Ì")
  282. ("\\\\'I" "Í")
  283. ("\\\\^I" "Î")
  284. ("\\\\\"O" "Ö")
  285. ("\\\\`O" "Ò")
  286. ("\\\\'O" "Ó")
  287. ("\\\\~O" "Õ")
  288. ("\\\\^O" "Ô")
  289. ("\\\\\"U" "Ü")
  290. ("\\\\`U" "Ù")
  291. ("\\\\'U" "Ú")
  292. ("\\\\^U" "Û")
  293. ("\\\\~n" "ñ")
  294. ("\\\\~N" "Ñ")
  295. ("\\\\\"{a}" "ä")
  296. ("\\\\`{a}" "à")
  297. ("\\\\'{a}" "á")
  298. ("\\\\~{a}" "ã")
  299. ("\\\\^{a}" "â")
  300. ("\\\\\"{e}" "ë")
  301. ("\\\\`{e}" "è")
  302. ("\\\\'{e}" "é")
  303. ("\\\\^{e}" "ê")
  304. ("\\\\\"{\\\\i}" "ï")
  305. ("\\\\`{\\\\i}" "ì")
  306. ("\\\\'{\\\\i}" "í")
  307. ("\\\\^{\\\\i}" "î")
  308. ("\\\\\"{i}" "ï")
  309. ("\\\\`{i}" "ì")
  310. ("\\\\'{i}" "í")
  311. ("\\\\^{i}" "î")
  312. ("\\\\\"{o}" "ö")
  313. ("\\\\`{o}" "ò")
  314. ("\\\\'{o}" "ó")
  315. ("\\\\~{o}" "õ")
  316. ("\\\\^{o}" "ô")
  317. ("\\\\\"{u}" "ü")
  318. ("\\\\`{u}" "ù")
  319. ("\\\\'{u}" "ú")
  320. ("\\\\^{u}" "û")
  321. ("\\\\\"{A}" "Ä")
  322. ("\\\\`{A}" "À")
  323. ("\\\\'{A}" "Á")
  324. ("\\\\~{A}" "Ã")
  325. ("\\\\^{A}" "Â")
  326. ("\\\\\"{E}" "Ë")
  327. ("\\\\`{E}" "È")
  328. ("\\\\'{E}" "É")
  329. ("\\\\^{E}" "Ê")
  330. ("\\\\\"{I}" "Ï")
  331. ("\\\\`{I}" "Ì")
  332. ("\\\\'{I}" "Í")
  333. ("\\\\^{I}" "Î")
  334. ("\\\\\"{O}" "Ö")
  335. ("\\\\`{O}" "Ò")
  336. ("\\\\'{O}" "Ó")
  337. ("\\\\~{O}" "Õ")
  338. ("\\\\^{O}" "Ô")
  339. ("\\\\\"{U}" "Ü")
  340. ("\\\\`{U}" "Ù")
  341. ("\\\\'{U}" "Ú")
  342. ("\\\\^{U}" "Û")
  343. ("\\\\~{n}" "ñ")
  344. ("\\\\~{N}" "Ñ")
  345. ("\\\\c{c}" "ç")
  346. ("\\\\c{C}" "Ç")
  347. ("{\\\\ss}" "ß")
  348. ("{\\\\AE}" "\306")
  349. ("{\\\\ae}" "\346")
  350. ("{\\\\AA}" "\305")
  351. ("{\\\\aa}" "\345")
  352. ("{\\\\copyright}" "\251")
  353. ("\\\\copyright{}" "\251")
  354. ("{\\\\pounds}" "£" )
  355. ("{\\\\P}" "¶" )
  356. ("{\\\\S}" "§" )
  357. ("\\\\pounds{}" "£" )
  358. ("\\\\P{}" "¶" )
  359. ("\\\\S{}" "§" )
  360. ("{\\?`}" "¿")
  361. ("{!`}" "¡")
  362. ("\\?`" "¿")
  363. ("!`" "¡")
  364. )
  365. "Translation table for translating TeX sequences to ISO 8859-1 characters.
  366. This table is not exhaustive (and due to TeX's power can never be).
  367. It only contains commonly used sequences.")
  368. ;;;###autoload
  369. (defun iso-tex2iso (from to &optional buffer)
  370. "Translate TeX sequences to ISO 8859-1 characters.
  371. Translate the region between FROM and TO using the table
  372. `iso-tex2iso-trans-tab'.
  373. Optional arg BUFFER is ignored (for use in `format-alist')."
  374. (interactive "*r")
  375. (iso-translate-conventions from to iso-tex2iso-trans-tab))
  376. (defvar iso-gtex2iso-trans-tab
  377. '(
  378. ("{\\\\\"a}" "ä")
  379. ("{\\\\`a}" "à")
  380. ("{\\\\'a}" "á")
  381. ("{\\\\~a}" "ã")
  382. ("{\\\\^a}" "â")
  383. ("{\\\\\"e}" "ë")
  384. ("{\\\\`e}" "è")
  385. ("{\\\\'e}" "é")
  386. ("{\\\\^e}" "ê")
  387. ("{\\\\\"\\\\i}" "ï")
  388. ("{\\\\`\\\\i}" "ì")
  389. ("{\\\\'\\\\i}" "í")
  390. ("{\\\\^\\\\i}" "î")
  391. ("{\\\\\"i}" "ï")
  392. ("{\\\\`i}" "ì")
  393. ("{\\\\'i}" "í")
  394. ("{\\\\^i}" "î")
  395. ("{\\\\\"o}" "ö")
  396. ("{\\\\`o}" "ò")
  397. ("{\\\\'o}" "ó")
  398. ("{\\\\~o}" "õ")
  399. ("{\\\\^o}" "ô")
  400. ("{\\\\\"u}" "ü")
  401. ("{\\\\`u}" "ù")
  402. ("{\\\\'u}" "ú")
  403. ("{\\\\^u}" "û")
  404. ("{\\\\\"A}" "Ä")
  405. ("{\\\\`A}" "À")
  406. ("{\\\\'A}" "Á")
  407. ("{\\\\~A}" "Ã")
  408. ("{\\\\^A}" "Â")
  409. ("{\\\\\"E}" "Ë")
  410. ("{\\\\`E}" "È")
  411. ("{\\\\'E}" "É")
  412. ("{\\\\^E}" "Ê")
  413. ("{\\\\\"I}" "Ï")
  414. ("{\\\\`I}" "Ì")
  415. ("{\\\\'I}" "Í")
  416. ("{\\\\^I}" "Î")
  417. ("{\\\\\"O}" "Ö")
  418. ("{\\\\`O}" "Ò")
  419. ("{\\\\'O}" "Ó")
  420. ("{\\\\~O}" "Õ")
  421. ("{\\\\^O}" "Ô")
  422. ("{\\\\\"U}" "Ü")
  423. ("{\\\\`U}" "Ù")
  424. ("{\\\\'U}" "Ú")
  425. ("{\\\\^U}" "Û")
  426. ("{\\\\~n}" "ñ")
  427. ("{\\\\~N}" "Ñ")
  428. ("{\\\\c c}" "ç")
  429. ("{\\\\c C}" "Ç")
  430. ("\\\\\"a" "ä")
  431. ("\\\\`a" "à")
  432. ("\\\\'a" "á")
  433. ("\\\\~a" "ã")
  434. ("\\\\^a" "â")
  435. ("\\\\\"e" "ë")
  436. ("\\\\`e" "è")
  437. ("\\\\'e" "é")
  438. ("\\\\^e" "ê")
  439. ("\\\\\"\\\\i" "ï")
  440. ("\\\\`\\\\i" "ì")
  441. ("\\\\'\\\\i" "í")
  442. ("\\\\^\\\\i" "î")
  443. ("\\\\\"i" "ï")
  444. ("\\\\`i" "ì")
  445. ("\\\\'i" "í")
  446. ("\\\\^i" "î")
  447. ("\\\\\"o" "ö")
  448. ("\\\\`o" "ò")
  449. ("\\\\'o" "ó")
  450. ("\\\\~o" "õ")
  451. ("\\\\^o" "ô")
  452. ("\\\\\"u" "ü")
  453. ("\\\\`u" "ù")
  454. ("\\\\'u" "ú")
  455. ("\\\\^u" "û")
  456. ("\\\\\"A" "Ä")
  457. ("\\\\`A" "À")
  458. ("\\\\'A" "Á")
  459. ("\\\\~A" "Ã")
  460. ("\\\\^A" "Â")
  461. ("\\\\\"E" "Ë")
  462. ("\\\\`E" "È")
  463. ("\\\\'E" "É")
  464. ("\\\\^E" "Ê")
  465. ("\\\\\"I" "Ï")
  466. ("\\\\`I" "Ì")
  467. ("\\\\'I" "Í")
  468. ("\\\\^I" "Î")
  469. ("\\\\\"O" "Ö")
  470. ("\\\\`O" "Ò")
  471. ("\\\\'O" "Ó")
  472. ("\\\\~O" "Õ")
  473. ("\\\\^O" "Ô")
  474. ("\\\\\"U" "Ü")
  475. ("\\\\`U" "Ù")
  476. ("\\\\'U" "Ú")
  477. ("\\\\^U" "Û")
  478. ("\\\\~n" "ñ")
  479. ("\\\\~N" "Ñ")
  480. ("\\\\\"{a}" "ä")
  481. ("\\\\`{a}" "à")
  482. ("\\\\'{a}" "á")
  483. ("\\\\~{a}" "ã")
  484. ("\\\\^{a}" "â")
  485. ("\\\\\"{e}" "ë")
  486. ("\\\\`{e}" "è")
  487. ("\\\\'{e}" "é")
  488. ("\\\\^{e}" "ê")
  489. ("\\\\\"{\\\\i}" "ï")
  490. ("\\\\`{\\\\i}" "ì")
  491. ("\\\\'{\\\\i}" "í")
  492. ("\\\\^{\\\\i}" "î")
  493. ("\\\\\"{i}" "ï")
  494. ("\\\\`{i}" "ì")
  495. ("\\\\'{i}" "í")
  496. ("\\\\^{i}" "î")
  497. ("\\\\\"{o}" "ö")
  498. ("\\\\`{o}" "ò")
  499. ("\\\\'{o}" "ó")
  500. ("\\\\~{o}" "õ")
  501. ("\\\\^{o}" "ô")
  502. ("\\\\\"{u}" "ü")
  503. ("\\\\`{u}" "ù")
  504. ("\\\\'{u}" "ú")
  505. ("\\\\^{u}" "û")
  506. ("\\\\\"{A}" "Ä")
  507. ("\\\\`{A}" "À")
  508. ("\\\\'{A}" "Á")
  509. ("\\\\~{A}" "Ã")
  510. ("\\\\^{A}" "Â")
  511. ("\\\\\"{E}" "Ë")
  512. ("\\\\`{E}" "È")
  513. ("\\\\'{E}" "É")
  514. ("\\\\^{E}" "Ê")
  515. ("\\\\\"{I}" "Ï")
  516. ("\\\\`{I}" "Ì")
  517. ("\\\\'{I}" "Í")
  518. ("\\\\^{I}" "Î")
  519. ("\\\\\"{O}" "Ö")
  520. ("\\\\`{O}" "Ò")
  521. ("\\\\'{O}" "Ó")
  522. ("\\\\~{O}" "Õ")
  523. ("\\\\^{O}" "Ô")
  524. ("\\\\\"{U}" "Ü")
  525. ("\\\\`{U}" "Ù")
  526. ("\\\\'{U}" "Ú")
  527. ("\\\\^{U}" "Û")
  528. ("\\\\~{n}" "ñ")
  529. ("\\\\~{N}" "Ñ")
  530. ("\\\\c{c}" "ç")
  531. ("\\\\c{C}" "Ç")
  532. ("{\\\\ss}" "ß")
  533. ("{\\\\AE}" "\306")
  534. ("{\\\\ae}" "\346")
  535. ("{\\\\AA}" "\305")
  536. ("{\\\\aa}" "\345")
  537. ("{\\\\copyright}" "\251")
  538. ("\\\\copyright{}" "\251")
  539. ("{\\\\pounds}" "£" )
  540. ("{\\\\P}" "¶" )
  541. ("{\\\\S}" "§" )
  542. ("\\\\pounds{}" "£" )
  543. ("\\\\P{}" "¶" )
  544. ("\\\\S{}" "§" )
  545. ("?`" "¿")
  546. ("!`" "¡")
  547. ("{?`}" "¿")
  548. ("{!`}" "¡")
  549. ("\"a" "ä")
  550. ("\"A" "Ä")
  551. ("\"o" "ö")
  552. ("\"O" "Ö")
  553. ("\"u" "ü")
  554. ("\"U" "Ü")
  555. ("\"s" "ß")
  556. ("\\\\3" "ß")
  557. )
  558. "Translation table for translating German TeX sequences to ISO 8859-1.
  559. This table is not exhaustive (and due to TeX's power can never be).
  560. It only contains commonly used sequences.")
  561. (defvar iso-iso2gtex-trans-tab
  562. '(
  563. ("ä" "\"a")
  564. ("à" "{\\\\`a}")
  565. ("á" "{\\\\'a}")
  566. ("ã" "{\\\\~a}")
  567. ("â" "{\\\\^a}")
  568. ("ë" "{\\\\\"e}")
  569. ("è" "{\\\\`e}")
  570. ("é" "{\\\\'e}")
  571. ("ê" "{\\\\^e}")
  572. ("ï" "{\\\\\"\\\\i}")
  573. ("ì" "{\\\\`\\\\i}")
  574. ("í" "{\\\\'\\\\i}")
  575. ("î" "{\\\\^\\\\i}")
  576. ("ö" "\"o")
  577. ("ò" "{\\\\`o}")
  578. ("ó" "{\\\\'o}")
  579. ("õ" "{\\\\~o}")
  580. ("ô" "{\\\\^o}")
  581. ("ü" "\"u")
  582. ("ù" "{\\\\`u}")
  583. ("ú" "{\\\\'u}")
  584. ("û" "{\\\\^u}")
  585. ("Ä" "\"A")
  586. ("À" "{\\\\`A}")
  587. ("Á" "{\\\\'A}")
  588. ("Ã" "{\\\\~A}")
  589. ("Â" "{\\\\^A}")
  590. ("Ë" "{\\\\\"E}")
  591. ("È" "{\\\\`E}")
  592. ("É" "{\\\\'E}")
  593. ("Ê" "{\\\\^E}")
  594. ("Ï" "{\\\\\"I}")
  595. ("Ì" "{\\\\`I}")
  596. ("Í" "{\\\\'I}")
  597. ("Î" "{\\\\^I}")
  598. ("Ö" "\"O")
  599. ("Ò" "{\\\\`O}")
  600. ("Ó" "{\\\\'O}")
  601. ("Õ" "{\\\\~O}")
  602. ("Ô" "{\\\\^O}")
  603. ("Ü" "\"U")
  604. ("Ù" "{\\\\`U}")
  605. ("Ú" "{\\\\'U}")
  606. ("Û" "{\\\\^U}")
  607. ("ñ" "{\\\\~n}")
  608. ("Ñ" "{\\\\~N}")
  609. ("ç" "{\\\\c c}")
  610. ("Ç" "{\\\\c C}")
  611. ("ß" "\"s")
  612. ("\306" "{\\\\AE}")
  613. ("\346" "{\\\\ae}")
  614. ("\305" "{\\\\AA}")
  615. ("\345" "{\\\\aa}")
  616. ("\251" "{\\\\copyright}")
  617. ("£" "{\\\\pounds}")
  618. ("¶" "{\\\\P}")
  619. ("§" "{\\\\S}")
  620. ("¿" "{?`}")
  621. ("¡" "{!`}")
  622. )
  623. "Translation table for translating ISO 8859-1 characters to German TeX.")
  624. ;;;###autoload
  625. (defun iso-gtex2iso (from to &optional buffer)
  626. "Translate German TeX sequences to ISO 8859-1 characters.
  627. Translate the region between FROM and TO using the table
  628. `iso-gtex2iso-trans-tab'.
  629. Optional arg BUFFER is ignored (for use in `format-alist')."
  630. (interactive "*r")
  631. (iso-translate-conventions from to iso-gtex2iso-trans-tab))
  632. ;;;###autoload
  633. (defun iso-iso2gtex (from to &optional buffer)
  634. "Translate ISO 8859-1 characters to German TeX sequences.
  635. Translate the region between FROM and TO using the table
  636. `iso-iso2gtex-trans-tab'.
  637. Optional arg BUFFER is ignored (for use in `format-alist')."
  638. (interactive "*r")
  639. (iso-translate-conventions from to iso-iso2gtex-trans-tab))
  640. (defvar iso-iso2duden-trans-tab
  641. '(("ä" "ae")
  642. ("Ä" "Ae")
  643. ("ö" "oe")
  644. ("Ö" "Oe")
  645. ("ü" "ue")
  646. ("Ü" "Ue")
  647. ("ß" "ss"))
  648. "Translation table for translating ISO 8859-1 characters to Duden sequences.")
  649. ;;;###autoload
  650. (defun iso-iso2duden (from to &optional buffer)
  651. "Translate ISO 8859-1 characters to Duden sequences.
  652. Translate the region between FROM and TO using the table
  653. `iso-iso2duden-trans-tab'.
  654. Optional arg BUFFER is ignored (for use in `format-alist')."
  655. (interactive "*r")
  656. (iso-translate-conventions from to iso-iso2duden-trans-tab))
  657. (defvar iso-iso2sgml-trans-tab
  658. '(("À" "&Agrave;")
  659. ("Á" "&Aacute;")
  660. ("Â" "&Acirc;")
  661. ("Ã" "&Atilde;")
  662. ("Ä" "&Auml;")
  663. ("Å" "&Aring;")
  664. ("Æ" "&AElig;")
  665. ("Ç" "&Ccedil;")
  666. ("È" "&Egrave;")
  667. ("É" "&Eacute;")
  668. ("Ê" "&Ecirc;")
  669. ("Ë" "&Euml;")
  670. ("Ì" "&Igrave;")
  671. ("Í" "&Iacute;")
  672. ("Î" "&Icirc;")
  673. ("Ï" "&Iuml;")
  674. ("Ð" "&ETH;")
  675. ("Ñ" "&Ntilde;")
  676. ("Ò" "&Ograve;")
  677. ("Ó" "&Oacute;")
  678. ("Ô" "&Ocirc;")
  679. ("Õ" "&Otilde;")
  680. ("Ö" "&Ouml;")
  681. ("Ø" "&Oslash;")
  682. ("Ù" "&Ugrave;")
  683. ("Ú" "&Uacute;")
  684. ("Û" "&Ucirc;")
  685. ("Ü" "&Uuml;")
  686. ("Ý" "&Yacute;")
  687. ("Þ" "&THORN;")
  688. ("ß" "&szlig;")
  689. ("à" "&agrave;")
  690. ("á" "&aacute;")
  691. ("â" "&acirc;")
  692. ("ã" "&atilde;")
  693. ("ä" "&auml;")
  694. ("å" "&aring;")
  695. ("æ" "&aelig;")
  696. ("ç" "&ccedil;")
  697. ("è" "&egrave;")
  698. ("é" "&eacute;")
  699. ("ê" "&ecirc;")
  700. ("ë" "&euml;")
  701. ("ì" "&igrave;")
  702. ("í" "&iacute;")
  703. ("î" "&icirc;")
  704. ("ï" "&iuml;")
  705. ("ð" "&eth;")
  706. ("ñ" "&ntilde;")
  707. ("ò" "&ograve;")
  708. ("ó" "&oacute;")
  709. ("ô" "&ocirc;")
  710. ("õ" "&otilde;")
  711. ("ö" "&ouml;")
  712. ("ø" "&oslash;")
  713. ("ù" "&ugrave;")
  714. ("ú" "&uacute;")
  715. ("û" "&ucirc;")
  716. ("ü" "&uuml;")
  717. ("ý" "&yacute;")
  718. ("þ" "&thorn;")
  719. ("ÿ" "&yuml;")))
  720. (defvar iso-sgml2iso-trans-tab
  721. '(("&Agrave;" "À")
  722. ("&Aacute;" "Á")
  723. ("&Acirc;" "Â")
  724. ("&Atilde;" "Ã")
  725. ("&Auml;" "Ä")
  726. ("&Aring;" "Å")
  727. ("&AElig;" "Æ")
  728. ("&Ccedil;" "Ç")
  729. ("&Egrave;" "È")
  730. ("&Eacute;" "É")
  731. ("&Ecirc;" "Ê")
  732. ("&Euml;" "Ë")
  733. ("&Igrave;" "Ì")
  734. ("&Iacute;" "Í")
  735. ("&Icirc;" "Î")
  736. ("&Iuml;" "Ï")
  737. ("&ETH;" "Ð")
  738. ("&Ntilde;" "Ñ")
  739. ("&Ograve;" "Ò")
  740. ("&Oacute;" "Ó")
  741. ("&Ocirc;" "Ô")
  742. ("&Otilde;" "Õ")
  743. ("&Ouml;" "Ö")
  744. ("&Oslash;" "Ø")
  745. ("&Ugrave;" "Ù")
  746. ("&Uacute;" "Ú")
  747. ("&Ucirc;" "Û")
  748. ("&Uuml;" "Ü")
  749. ("&Yacute;" "Ý")
  750. ("&THORN;" "Þ")
  751. ("&szlig;" "ß")
  752. ("&agrave;" "à")
  753. ("&aacute;" "á")
  754. ("&acirc;" "â")
  755. ("&atilde;" "ã")
  756. ("&auml;" "ä")
  757. ("&aring;" "å")
  758. ("&aelig;" "æ")
  759. ("&ccedil;" "ç")
  760. ("&egrave;" "è")
  761. ("&eacute;" "é")
  762. ("&ecirc;" "ê")
  763. ("&euml;" "ë")
  764. ("&igrave;" "ì")
  765. ("&iacute;" "í")
  766. ("&icirc;" "î")
  767. ("&iuml;" "ï")
  768. ("&eth;" "ð")
  769. ("&ntilde;" "ñ")
  770. ("&nbsp;" " ")
  771. ("&ograve;" "ò")
  772. ("&oacute;" "ó")
  773. ("&ocirc;" "ô")
  774. ("&otilde;" "õ")
  775. ("&ouml;" "ö")
  776. ("&oslash;" "ø")
  777. ("&ugrave;" "ù")
  778. ("&uacute;" "ú")
  779. ("&ucirc;" "û")
  780. ("&uuml;" "ü")
  781. ("&yacute;" "ý")
  782. ("&thorn;" "þ")
  783. ("&yuml;" "ÿ")))
  784. ;;;###autoload
  785. (defun iso-iso2sgml (from to &optional buffer)
  786. "Translate ISO 8859-1 characters in the region to SGML entities.
  787. Use entities from \"ISO 8879:1986//ENTITIES Added Latin 1//EN\".
  788. Optional arg BUFFER is ignored (for use in `format-alist')."
  789. (interactive "*r")
  790. (iso-translate-conventions from to iso-iso2sgml-trans-tab))
  791. ;;;###autoload
  792. (defun iso-sgml2iso (from to &optional buffer)
  793. "Translate SGML entities in the region to ISO 8859-1 characters.
  794. Use entities from \"ISO 8879:1986//ENTITIES Added Latin 1//EN\".
  795. Optional arg BUFFER is ignored (for use in `format-alist')."
  796. (interactive "*r")
  797. (iso-translate-conventions from to iso-sgml2iso-trans-tab))
  798. ;;;###autoload
  799. (defun iso-cvt-read-only (&rest ignore)
  800. "Warn that format is read-only."
  801. (interactive)
  802. (error "This format is read-only; specify another format for writing"))
  803. ;;;###autoload
  804. (defun iso-cvt-write-only (&rest ignore)
  805. "Warn that format is write-only."
  806. (interactive)
  807. (error "This format is write-only"))
  808. ;;;###autoload
  809. (defun iso-cvt-define-menu ()
  810. "Add submenus to the File menu, to convert to and from various formats."
  811. (interactive)
  812. (let ((load-as-menu-map (make-sparse-keymap "Load As..."))
  813. (insert-as-menu-map (make-sparse-keymap "Insert As..."))
  814. (write-as-menu-map (make-sparse-keymap "Write As..."))
  815. (translate-to-menu-map (make-sparse-keymap "Translate to..."))
  816. (translate-from-menu-map (make-sparse-keymap "Translate from..."))
  817. (menu menu-bar-file-menu))
  818. (define-key menu [load-as-separator] '("--"))
  819. (define-key menu [load-as] '("Load As..." . iso-cvt-load-as))
  820. (fset 'iso-cvt-load-as load-as-menu-map)
  821. ;;(define-key menu [insert-as] '("Insert As..." . iso-cvt-insert-as))
  822. (fset 'iso-cvt-insert-as insert-as-menu-map)
  823. (define-key menu [write-as] '("Write As..." . iso-cvt-write-as))
  824. (fset 'iso-cvt-write-as write-as-menu-map)
  825. (define-key menu [translate-separator] '("--"))
  826. (define-key menu [translate-to] '("Translate to..." . iso-cvt-translate-to))
  827. (fset 'iso-cvt-translate-to translate-to-menu-map)
  828. (define-key menu [translate-from] '("Translate from..." . iso-cvt-translate-from))
  829. (fset 'iso-cvt-translate-from translate-from-menu-map)
  830. (dolist (file-type (reverse format-alist))
  831. (let ((name (car file-type))
  832. (str-name (cadr file-type)))
  833. (if (stringp str-name)
  834. (progn
  835. (define-key load-as-menu-map (vector name)
  836. (cons str-name
  837. `(lambda (file)
  838. (interactive ,(format "FFind file (as %s): " name))
  839. (format-find-file file ',name))))
  840. (define-key insert-as-menu-map (vector name)
  841. (cons str-name
  842. `(lambda (file)
  843. (interactive (format "FInsert file (as %s): " ,name))
  844. (format-insert-file file ',name))))
  845. (define-key write-as-menu-map (vector name)
  846. (cons str-name
  847. `(lambda (file)
  848. (interactive (format "FWrite file (as %s): " ,name))
  849. (format-write-file file ',name))))
  850. (define-key translate-to-menu-map (vector name)
  851. (cons str-name
  852. `(lambda ()
  853. (interactive)
  854. (format-encode-buffer ',name))))
  855. (define-key translate-from-menu-map (vector name)
  856. (cons str-name
  857. `(lambda ()
  858. (interactive)
  859. (format-decode-buffer ',name))))))))))
  860. (provide 'iso-cvt)
  861. ;;; iso-cvt.el ends here