1: # The LearningOnline Network
2: # entity -> tex.
3: #
4: # $Id: entities.pm,v 1.22 2014/10/14 18:30:23 raeburn Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA 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 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA 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 LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: # http://www.lon-capa.org/
26: #
27: #
28:
29: package Apache::entities;
30: use strict;
31:
32: =pod
33:
34: =head1 TABLES ASCII code page
35:
36: =over
37:
38: =item (7-13)
39:
40: Translation to empty strings
41:
42: =item (32-126)
43:
44: Translations to simple characters
45:
46: =item (130-140)
47:
48: Controls and Latin-1 supplement. Note that some entities that have
49: visible effect are not printing unicode characters. Specifically
50: ‚- 
51:
52: =item (145-156)
53:
54: There's a gap here in my entity table
55:
56: =item (159-255)
57:
58: Another short gap
59:
60: =item (295)
61:
62: hbar entity number comes from the unicode character:
63: see e.g. http://www.unicode.org/charts/PDF/U0100.pdf
64: ISO also documents a 'planck' entity.
65:
66: =item (338-376)
67:
68: Latin extended-A HTML 4.01 entities
69:
70: =item (402)
71:
72: Latin extended B HTML 4.01 entities
73:
74: =item (710 & 732)
75:
76: Spacing modifier letters
77:
78: =item (913-937)
79:
80: Greek uppercase (skipss 930)
81:
82: =item (945-982)
83:
84: Greek lowercase
85:
86: =item (8194-8364)
87:
88: The general punctuation set
89:
90: =item (8462-8501)
91:
92: Letter like symbols
93:
94: =item (8592-8669)
95:
96: Arrows and then some (harpoons from Hon Kie).
97:
98: =item (8704-8734)
99:
100: Mathematical operators.
101:
102: =item (8735-9830)
103:
104: The items below require the isoent latex package which I can't find at least for FC5.
105: Temporarily commented out.
106:
107: =back
108:
109: =cut
110:
111: my %entities = (
112:
113: # Translation to empty strings:
114:
115: 7 => "",
116: 9 => "",
117: 10 => "",
118: 13 => "",
119:
120: # Translations to simple characters:
121:
122: 32 => " ",
123: 33 => "!",
124: 34 => '"',
125: 'quot' => '"',
126: 35 => '\\#',
127: 36 => '\\$',
128: 37 => '\%',
129: 38 => '\&',
130: 'amp' => '\&',
131: 39 => '\'', # Apostrophe
132: 40 => '(',
133: 41 => ')',
134: 42 => '*',
135: 43 => '+',
136: 44 => ',', # comma
137: 45 => '-',
138: 46 => '.',
139: 47 => '/',
140: 48 => '0',
141: 49 => '1',
142: 50 => '2',
143: 51 => '3',
144: 52 => '4',
145: 53 => '5',
146: 54 => '6',
147: 55 => '7',
148: 56 => '8',
149: 57 => '9',
150: 58 => ':',
151: 59 => ';',
152: 60 => '\ensuremath{<}',
153: 'lt' => '\ensuremath{<}',
154: 61 => '\ensuremath{=}',
155: 62 => '\ensuremath{>}',
156: 'gt' => '\ensuremath{>}',
157: 63 => '?',
158: 64 => '@',
159: 65 => 'A',
160: 66 => 'B',
161: 67 => 'C',
162: 68 => 'D',
163: 69 => 'E',
164: 70 => 'F',
165: 71 => 'G',
166: 72 => 'H',
167: 73 => 'I',
168: 74 => 'J',
169: 75 => 'K',
170: 76 => 'L',
171: 77 => 'M',
172: 78 => 'N',
173: 79 => 'O',
174: 80 => 'P',
175: 81 => 'Q',
176: 82 => 'R',
177: 83 => 'S',
178: 84 => 'T',
179: 85 => 'U',
180: 86 => 'V',
181: 87 => 'W',
182: 88 => 'X',
183: 89 => 'Y',
184: 90 => 'Z',
185: 91 => '[',
186: 92 => '\ensuremath{\setminus}', # \setminus is \ with special spacing.
187: 93 => ']',
188: 94 => '\ensuremath{\wedge}',
189: 95 => '\underline{\makebox[2mm]{\strut}}', # Underline 2mm of space for _
190: 96 => '`',
191: 97 => 'a',
192: 98 => 'b',
193: 99 => 'c',
194: 100 => 'd',
195: 101 => 'e',
196: 102 => 'f',
197: 103 => 'g',
198: 104 => 'h',
199: 105 => 'i',
200: 106 => 'j',
201: 107 => 'k',
202: 108 => 'l',
203: 109 => 'm',
204: 110 => 'n',
205: 111 => 'o',
206: 112 => 'p',
207: 113 => 'q',
208: 114 => 'r',
209: 115 => 's',
210: 116 => 't',
211: 117 => 'u',
212: 118 => 'v',
213: 119 => 'w',
214: 120 => 'x',
215: 121 => 'y',
216: 122 => 'z',
217: 123 => '\{',
218: 124 => '|',
219: 125 => '\}',
220: 126 => '\~',
221:
222: # Controls and Latin-1 supplement.
223:
224: 130 => ',',
225: 131 => '\ensuremath{f}',
226: 132 => ',,', # Low double left quotes.
227: 133 => '\ensuremath{\ldots}',
228: 134 => '\ensuremath{\dagger}',
229: 135 => '\ensuremath{\ddagger}',
230: 136 => '\ensuremath{\wedge}',
231: 137 => '\textperthousand ',
232: 138 => '\v{S}',
233: 139 => '\ensuremath{<}',
234: 140 => '{\OE}',
235:
236: # There's a gap here in my entity table
237:
238: 145 => '`',
239: 146 => '\'',
240: 147 => '``',
241: 148 => '\'\'',
242: 149 => '\ensuremath{\bullet}',
243: 150 => '--',
244: 151 => '---',
245: 152 => '\ensuremath{\sim}',
246: 153 => '\texttrademark',
247: 154 => '\v{s}',
248: 155 => '\ensuremath{>}',
249: 156 => '\oe ',
250:
251: # Another short gap:
252:
253: 159 => '\"Y',
254: 160 => '~',
255: 'nbsp' => '~',
256: 161 => '\textexclamdown ',
257: 'iexcl' => '\textexclamdown ',
258: 162 => '\textcent ',
259: 'cent' => '\textcent ',
260: 163 => '\pounds ',
261: 'pound' => '\pounds ',
262: 164 => '\textcurrency ',
263: 'curren' => '\textcurrency ',
264: 165 => '\textyen ',
265: 'yen' => '\textyen ',
266: 166 => '\textbrokenbar ',
267: 'brvbar' => '\textbrokenbar ',
268: 167 => '\textsection ',
269: 'sect' => '\textsection ',
270: 168 => '\"{}',
271: 'uml' => '\"{}',
272: 169 => '\copyright ',
273: 'copy' => '\copyright ',
274: 170 => '\textordfeminine ',
275: 'ordf' => '\textordfeminine ',
276: 171 => '\ensuremath{\ll}', # approximation of left angle quote.
277: 'laquo' => '\ensuremath{\ll}', # ""
278: 172 => '\ensuremath{\neg}',
279: 'not' => '\ensuremath{\neg}',
280: 173 => ' - ',
281: 'shy' => ' - ',
282: 174 => '\textregistered ',
283: 'reg' => '\textregistered ',
284: 175 => '\ensuremath{^{-}}',
285: 'macr' => '\ensuremath{^{-}}',
286: 176 => '\ensuremath{^{\circ}}',
287: 'deg' => '\ensuremath{^{\circ}}',
288: 177 => '\ensuremath{\pm}',
289: 'plusmn' => '\ensuremath{\pm}',
290: 178 => '\ensuremath{^2}',
291: 'sup2' => '\ensuremath{^2}',
292: 179 => '\ensuremath{^3}',
293: 'sup3' => '\ensuremath{^3}',
294: 180 => "\\'{}",
295: 'acute' => "\\'{}",
296: 181 => '\ensuremath{\mu}',
297: 'micro' => '\ensuremath{\mu}',
298: 182 => '\P ',
299: para => '\P ',
300: 183 => '\ensuremath{\cdot}',
301: 'middot' => '\ensuremath{\cdot}',
302: 184 => '\c{\strut}',
303: 'cedil' => '\c{\strut}',
304: 185 => '\ensuremath{^1}',
305: sup1 => '\ensuremath{^1}',
306: 186 => '\textordmasculine ',
307: 'ordm' => '\textordmasculine ',
308: 187 => '\ensuremath{\gg}',
309: 'raquo' => '\ensuremath{\gg}',
310: 188 => '\textonequarter ',
311: 'frac14' => '\textonequarter ',
312: 189 => '\textonehalf' ,
313: 'frac12' => '\textonehalf' ,
314: 190 => '\textthreequarters ',
315: 'frac34' => '\textthreequarters ',
316: 191 => '\textquestiondown ',
317: 'iquest' => '\textquestiondown ',
318: 192 => '\\`{A}',
319: 'Agrave' => '\\`{A}',
320: 193 => "\\'{A}",
321: 'Aacute' => "\\'{A}",
322: 194 => '\^{A}',
323: 'Acirc' => '\^{A}',
324: 195 => '\~{A}',
325: 'Atilde'=> '\~{A}',
326: 196 => '\\"{A}',
327: 'Auml' => '\\"{A}',
328: 197 => '{\AA}',
329: 'Aring' => '{\AA}',
330: 198 => '{\AE}',
331: 'AElig' => '{\AE}',
332: 199 => '\c{c}',
333: 'Ccedil'=> '\c{c}',
334: 200 => '\\`{E}',
335: 'Egrave'=> '\\`{E}',
336: 201 => "\\'{E}",
337: 'Eacute'=> "\\'{E}",
338: 202 => '\\^{E}',
339: 'Ecirc' => '\\^{E}',
340: 203 => '\\"{E}',
341: 'Euml' => '\\"{E}',
342: 204 => '\\`{I}',
343: 'Igrave'=> '\\`{I}',
344: 205 => "\\'{I}",
345: 'Iacute'=> "\\'{I}",
346: 206 => '\\^{I}',
347: 'Icirc' => '\\^{I}',
348: 207 => '\\"{I}',
349: 'Iuml' => '\\"{I}',
350: 208 => '\DH',
351: 'ETH' => '\DH',
352: 209 => '\~{N}',
353: 'Ntilde'=> '\~{N}',
354: 210 => '\\`{O}',
355: 'Ograve'=> '\\`{O}',
356: 211 => "\\'{O}",
357: 'Oacute'=> "\\'{O}",
358: 212 => '\\^{O}',
359: 'Ocirc' => '\\^{O}',
360: 213 => '\~{O}',
361: 'Otilde'=> '\~{O}',
362: 214 => '\\"{O}',
363: 'Ouml' => '\\"{O}',
364: 215 => '\ensuremath{\times}',
365: 'times' => '\ensuremath{\times}',
366: 216 => '\O',
367: 'Oslash'=> '\O',
368: 217 => '\\`{U}',
369: 'Ugrave'=> '\\`{U}',
370: 218 => "\\'{U}",
371: 'Uacute'=> "\\'{U}",
372: 219 => '\\^{U}',
373: 'Ucirc' => '\\^{U}',
374: 220 => '\\"{U}',
375: 'Uuml' => '\\"{U}',
376: 221 => "\\'{Y}",
377: 'Yacute'=> "\\'{Y}",
378: 223 => '{\ss}',
379: 'szlig' => '{\ss}',
380: 224 => '\\`{a}',
381: 'agrave'=> '\\`{a}',
382: 225 => "\\'{a}",
383: 'aacute'=> "\\'{a}",
384: 226 => '\\^{a}',
385: 'acirc' => '\\^{a}',
386: 227 => '\\~{a}',
387: 'atilde'=> '\\~{a}',
388: 228 => '\\"{a}',
389: 'auml' => '\\"{a}',
390: 229 => '\aa',
391: 'aring' => '\aa',
392: 230 => '\ae',
393: 'aelig' => '\ae',
394: 231 => '\c{c}',
395: 'ccedil'=> '\c{c}',
396: 232 => '\\`{e}',
397: 'egrave'=> '\\`{e}',
398: 233 => "\\'{e}",
399: 'eacute'=> "\\'{e}",
400: 234 => '\\^{e}',
401: 'ecirc' => '\\^{e}',
402: 235 => '\\"{e}',
403: 'euml' => '\\"{e}',
404: 236 => '\\`{i}',
405: 'igrave'=> '\\`{i}',
406: 237 => "\\'{i}",
407: 'iacute'=> "\\'{i}",
408: 238 => '\\^{i}',
409: 'icirc' => '\\^{i}',
410: 239 => '\\"{i}',
411: 'iuml' => '\\"{i}',
412: 241 => '\\~{n}',
413: 'ntilde'=> '\\~{n}',
414: 242 => '\\`{o}',
415: 'ograve'=> '\\`{o}',
416: 243 => "\\'{o}",
417: 'oacute'=> "\\'{o}",
418: 244 => '\\^{o}',
419: 'ocirc' => '\\^{o}',
420: 245 => '\\~{o}',
421: 'otilde'=> '\\~{o}',
422: 246 => '\\"{o}',
423: 'ouml' => '\\"{o}',
424: 247 => '\ensuremath{\div}',
425: 'divide'=> '\ensuremath{\div}',
426: 248 => '{\o}',
427: 'oslash'=> '{\o}',
428: 249 => '\\`{u}',
429: 'ugrave'=> '\\`{u}',
430: 250 => "\\'{u}",
431: 'uacute'=> "\\'{u}",
432: 251 => '\\^{u}',
433: 'ucirc' => '\\^{u}',
434: 252 => '\\"{u}',
435: 'uuml' => '\\"{u}',
436: 253 => "\\'{y}",
437: 'yacute'=> "\\'{y}",
438: 255 => '\\"{y}',
439: 'yuml' => '\\"{y}',
440:
441:
442: # hbar entity number comes from the unicode character:
443:
444: 295 => '\ensuremath{\hbar}',
445: 'planck' => '\ensuremath{\hbar}',
446:
447: # Latin extended-A HTML 4.01 entities:
448:
449: 338 => '\OE',
450: 'OElig' => '\OE',
451: 339 => '\oe',
452: 'oelig' => '\oe',
453: 352 => '\v{S}',
454: 'Scaron' => '\v{S}',
455: 353 => '\v{s}',
456: 'scaron' => '\v{s}',
457: 376 => '\\"{Y}',
458: 'Yuml' => '\\"{Y}',
459:
460: # Latin extended B HTML 4.01 entities
461:
462: 402 => '\ensuremath{f}',
463: 'fnof' => '\ensuremath{f}',
464:
465: # Spacing modifier letters:
466:
467: 710 => '\^{}',
468: 'circ' => '\^{}',
469: 732 => '\~{}',
470: 'tilde' => '\~{}',
471:
472: # Greek uppercase:
473:
474: 913 => '\ensuremath{\mathrm{A}}',
475: 'Alpha' => '\ensuremath{\mathrm{A}}',
476: 914 => '\ensuremath{\mathrm{B}}',
477: 'Beta' => '\ensuremath{\mathrm{B}}',
478: 915 => '\ensuremath{\Gamma}',
479: 'Gamma' => '\ensuremath{\Gamma}',
480: 916 => '\ensuremath{\Delta}',
481: 'Delta' => '\ensuremath{\Delta}',
482: 917 => '\ensuremath{\mathrm{E}}',
483: 'Epsilon'=> '\ensuremath{\mathrm{E}}',
484: 918 => '\ensuremath{\mathrm{Z}}',
485: 'Zeta' => '\ensuremath{\mathrm{Z}}',
486: 919 => '\ensuremath{\mathrm{H}}',
487: 'Eta' => '\ensuremath{\mathrm{H}}',
488: 920 => '\ensuremath{\Theta}',
489: 'Theta' => '\ensuremath{\Theta}',
490: 921 => '\ensuremath{\mathrm{I}}',
491: 'Iota' => '\ensuremath{\mathrm{I}}',
492: 922 => '\ensuremath{\mathrm{K}}',
493: 'Kappa' => '\ensuremath{\mathrm{K}}',
494: 923 => '\ensuremath{\Lambda}',
495: 'Lambda' => '\ensuremath{\Lambda}',
496: 924 => '\ensuremath{\mathrm{M}}',
497: 'Mu' => '\ensuremath{\mathrm{M}}',
498: 925 => '\ensuremath{\mathrm{N}}',
499: 'Nu' => '\ensuremath{\mathrm{N}}',
500: 926 => '\ensuremath{\mathrm{\Xi}}',
501: 'Xi' => '\ensuremath{\mathrm{\Xi}}',
502: 927 => '\ensuremath{\mathrm{O}}',
503: 'Omicron'=> '\ensuremath{\mathrm{O}}',
504: 928 => '\ensuremath{\Pi}',
505: 'Pi' => '\ensuremath{\Pi}',
506: 929 => '\ensuremath{\mathrm{P}}',
507: 'Rho' => '\ensuremath{\mathrm{P}}',
508: 931 => '\ensuremath{\Sigma}',
509: 'Sigma' => '\ensuremath{\Sigma}',
510: 932 => '\ensuremath{\mathrm{T}}',
511: 'Tau' => '\ensuremath{\mathrm{T}}',
512: 933 => '\ensuremath{\Upsilon}',
513: 'Upsilon'=> '\ensuremath{\Upsilon}',
514: 934 => '\ensuremath{\Phi}',
515: 'Phi' => '\ensuremath{\Phi}',
516: 935 => '\ensuremath{\mathrm{X}}',
517: 'Chi' => '\ensuremath{\mathrm{X}}',
518: 936 => '\ensuremath{\Psi}',
519: 'Psi' => '\ensuremath{\Psi}',
520: 937 => '\ensuremath{\Omega}',
521: 'Omega' => '\ensuremath{\Omega}',
522:
523: # Greek lowercase:
524:
525: 945 => '\ensuremath{\alpha}',
526: 'alpha' => '\ensuremath{\alpha}',
527: 946 => '\ensuremath{\beta}',
528: 'beta' => '\ensuremath{\beta}',
529: 947 => '\ensuremath{\gamma}',
530: 'gamma' => '\ensuremath{\gamma}',
531: 948 => '\ensuremath{\delta}',
532: 'delta' => '\ensuremath{\delta}',
533: 949 => '\ensuremath{\epsilon}',
534: 'epsilon'=> '\ensuremath{\epsilon}',
535: 950 => '\ensuremath{\zeta}',
536: 'zeta' => '\ensuremath{\zeta}',
537: 951 => '\ensuremath{\eta}',
538: 'eta' => '\ensuremath{\eta}',
539: 952 => '\ensuremath{\theta}',
540: 'theta' => '\ensuremath{\theta}',
541: 953 => '\ensuremath{\iota}',
542: 'iota' => '\ensuremath{\iota}',
543: 954 => '\ensuremath{\kappa}',
544: 'kappa' => '\ensuremath{\kappa}',
545: 955 => '\ensuremath{\lambda}',
546: 'lambda' => '\ensuremath{\lambda}',
547: 956 => '\ensuremath{\mu}',
548: 'mu' => '\ensuremath{\mu}',
549: 957 => '\ensuremath{\nu}',
550: 'nu' => '\ensuremath{\nu}',
551: 958 => '\ensuremath{\xi}',
552: 'xi' => '\ensuremath{\xi}',
553: 959 => '\ensuremath{o}',
554: 'omicron'=> '\ensuremath{o}',
555: 960 => '\ensuremath{\pi}',
556: 'pi' => '\ensuremath{\pi}',
557: 961 => '\ensuremath{\rho}',
558: 'rho' => '\ensuremath{\rho}',
559: 962 => '\ensuremath{\varsigma}',
560: 'sigmaf' => '\ensuremath{\varsigma}',
561: 963 => '\ensuremath{\sigma}',
562: 'sigma' => '\ensuremath{\sigma}',
563: 964 => '\ensuremath{\tau}',
564: 'tau' => '\ensuremath{\tau}',
565: 965 => '\ensuremath{\upsilon}',
566: 'upsilon'=> '\ensuremath{\upsilon}',
567: 966 => '\ensuremath{\phi}',
568: 'phi' => '\ensuremath{\phi}',
569: 967 => '\ensuremath{\chi}',
570: 'chi' => '\ensuremath{\chi}',
571: 968 => '\ensuremath{\psi}',
572: 'psi' => '\ensuremath{\psi}',
573: 969 => '\ensuremath{\omega}',
574: 'omega' => '\ensuremath{\omega}',
575: 977 => '\ensuremath{\vartheta}',
576: 'thetasym'=>'\ensuremath{\vartheta}',
577: 978 => '\ensuremath{\mathit{\Upsilon}}',
578: 'upsih' => '\ensuremath{\mathit{\Upsilon}}',
579: 982 => '\ensuremath{\varpi}',
580: 'piv' => '\ensuremath{\varpi}',
581:
582: # The general punctuation set:
583:
584: 8194, => '\hspace{.5em}',
585: 'enspc' => '\hspace{.5em}',
586: 8195 => '\hspace{1.0em}',
587: 'emspc' => '\hspace{1.0em}',
588: 8201 => '\hspace{0.167em}',
589: 'thinsp' => '\hspace{0.167em}',
590: 8204 => '{}',
591: 'zwnj' => '{}',
592: 8205 => '',
593: 'zwj' => '',
594: 8206 => '',
595: 'lrm' => '',
596: 8207 => '',
597: 'rlm' => '',
598: 8211 => '--',
599: 'ndash' => '--',
600: 8212 => '---',
601: 'mdash' => '---',
602: 8216 => '`',
603: 'lsquo' => '`',
604: 8217 => "'",
605: 'rsquo' => "'",
606: 8218 => '\quotesinglbase',
607: 'sbquo' => '\quotesinglbase',
608: 8220 => '``',
609: 'ldquo' => '``',
610: 8221 => "''",
611: 'rdquo' => "''",
612: 8222 => '\quotedblbase',
613: 'bdquo' => '\quotedblbase',
614: 8224 => '\ensuremath{\dagger}',
615: 'dagger' => '\ensuremath{\dagger}',
616: '8225' => '\ensuremath{\ddag}',
617: 'Dagger' => '\ensuremath{\ddag}',
618: 8226 => '\textbullet',
619: 'bull' => '\textbullet',
620: 8230 => '\textellipsis',
621: 'hellep' => '\textellipsis',
622: 8240 => '\textperthousand',
623: permil => '\textperthousand',
624: 8242 => '\textquotesingle',
625: 'prime' => '\textquotesingle',
626: 8243 => '\textquotedbl',
627: 'Prime' => '\textquotedbl',
628: 8249 => '\guilsinglleft',
629: 'lsaquo' => '\guilsinglleft',
630: 8250 => '\guilsinglright',
631: 'rsaquo' => '\guilsinglright',
632: 8254 => '\textasciimacron',
633: oline => '\textasciimacron',
634: 8260 => '\textfractionsolidus',
635: 'frasl' => '\textfractionsolidus',
636: 8364 => '\texteuro',
637: 'euro' => '\texteuro',
638:
639: # Letter like symbols
640:
641: 8462 => '\ensuremath{h}',
642: 'planckh' => '\ensuremath{h}',
643: 8463 => '\ensuremath{\hbar}',
644: 'hbar' => '\ensuremath{\hbar}',
645: 8472 => '\ensuremath{\wp}',
646: 'weierp' => '\ensuremath{\wp}',
647: 8465 => '\ensuremath{\Im}',
648: 'image' => '\ensuremath{\Im}',
649: 8476 => '\ensuremath{\Re}',
650: 'real' => '\ensuremath{\Re}',
651: 8482 => '\texttrademark',
652: 'trade' => '\texttrademark',
653: 8501 => '\ensuremath{\aleph}',
654: 'alefsym'=> '\ensuremath{\aleph}',
655:
656: # Arrows and then some (harpoons from Hon Kie).
657:
658: 8592 => '\ensuremath{\leftarrow}',
659: 'larr' => '\ensuremath{\leftarrow}',
660: 8593 => '\ensuremath{\uparrow}',
661: 'uarr' => '\ensuremath{\uparrow}',
662: 8594 => '\ensuremath{\rightarrow}',
663: 'rarr' => '\ensuremath{\rightarrow}',
664: 'rightarrow' => '\ensuremath{\rightarrow}',
665: 8595 => '\ensuremath{\downarrow}',
666: 'darr' => '\ensuremath{\downarrow}',
667: 8596 => '\ensuremath{\leftrightarrow}',
668: 'harr' => '\ensuremath{\leftrightarrow}',
669: 8598 => '\ensuremath{\nwarrow}',
670: 8599 => '\ensuremath{\nearrow}',
671: 8600 => '\ensuremath{\searrow}',
672: 8601 => '\ensuremath{\swarrow}',
673: 8605 => '\ensuremath{\leadsto}',
674: 8614 => '\ensuremath{\mapsto}',
675: 8617 => '\ensuremath{\hookleftarrow}',
676: 8618 => '\ensuremath{\hookrightarrow}',
677: 8629 => '\ensuremath{\hookleftarrow}', # not an exact match but best I know.
678: 'crarr' => '\ensuremath{\hookleftarrow}', # not an exact match but best I know.
679: 8636 => '\ensuremath{\leftharpoonup}',
680: 8637 => '\ensuremath{\leftharpoondown}',
681: 8640 => '\ensuremath{\rightharpoonup}',
682: 8641 => '\ensuremath{\rightharpoondown}',
683: 8652 => '\ensuremath{\rightleftharpoons}',
684: 8656 => '\ensuremath{\Leftarrow}',
685: 'lArr' => '\ensuremath{\Leftarrow}',
686: 8657 => '\ensuremath{\Uparrow}',
687: 'uArr' => '\ensuremath{\Uparrow}',
688: 8658 => '\ensuremath{\Rightarrow}',
689: 'rArr' => '\ensuremath{\Rightarrow}',
690: 8659 => '\ensuremath{\Downarrow}',
691: 'dArr' => '\ensuremath{\Downarrow}',
692: 8660 => '\ensuremath{\Leftrightarrow}',
693: 'hArr' => '\ensuremath{\Leftrightarrow}',
694: 8661 => '\ensuremath{\Updownarrow}',
695: 'vArr' => '\ensuremath{\Updownarrow}',
696: 8666 => '\ensuremath{\Lleftarrow}',
697: 'lAarr' => '\ensuremath{\Lleftarrow}',
698: 8667 => '\ensuremath{\Rrightarrow}',
699: 'rAarr' => '\ensuremath{\Rrightarrow}',
700: 8669 => '\ensuremath{\rightsquigarrow}',
701: 'rarrw' => '\ensuremath{\rightsquigarrow}',
702:
703: # Mathematical operators.
704:
705: 'forall' => '\ensuremath{\forall}',
706: 8704 => '\ensuremath{\forall}',
707: 'comp' => '\ensuremath{\complement}',
708: 8705 => '\ensuremath{\complement}',
709: 'part' => '\ensuremath{\partial}',
710: 8706 => '\ensuremath{\partial}',
711: 'exist' => '\ensuremath{\exists}',
712: 8707 => '\ensuremath{\exists}',
713: 'nexist' => '\ensuremath{\nexists}',
714: 8708 => '\ensuremath{\nexists}',
715: 'empty' => '\ensuremath{\emptyset}',
716: 8709 => '\ensuremath{\emptyset}',
717: 8710 => '\ensuremath{\Delta}',
718: 'nabla' => '\ensuremath{\nabla}',
719: 8711 => '\ensuremath{\nabla}',
720: 'isin' => '\ensuremath{\in}',
721: 8712 => '\ensuremath{\in}',
722: 'notin' => '\ensuremath{\notin}',
723: 8713 => '\ensuremath{\notin}',
724: ni => '\ensuremath{\ni}',
725: 8715 => '\ensuremath{\ni}',
726: 8716 => '\ensuremath{\not\ni}',
727: 'prod' => '\ensuremath{\prod}',
728: 8719 => '\ensuremath{\prod}',
729: 8720 => '\ensuremath{\coprod}',
730: 'sum' => '\ensuremath{\sum}',
731: 8721 => '\ensuremath{\sum}',
732: 'minus' => '\ensuremath{-}',
733: 8722 => '\ensuremath{-}',
734: 8723 => '\ensuremath{\mp}',
735: 8724 => '\ensuremath{\dotplus}',
736: 8725 => '\ensuremath{\diagup}',
737: 8726 => '\ensuremath{\smallsetminus}',
738: 'lowast' => '\ensuremath{*}',
739: 8727 => '\ensuremath{*}',
740: 8728 => '\ensuremath{\circ}',
741: 8729 => '\ensuremath{\bullet}',
742: 'radic' => '\ensuremath{\surd}',
743: 8730 => '\ensuremath{\surd}',
744: 8731 => '\ensuremath{\sqrt[3]{}}',
745: 8732 => '\ensuremath{\sqrt[4]{}}',
746: 'prop' => '\ensuremath{\propto}',
747: 8733 => '\ensuremath{\propto}',
748: 'infin' => '\ensuremath{\infty}',
749: 8734 => '\ensuremath{\infty}',
750:
751: # The items below require the isoent latex package which I can't find at least for FC5.
752: # Temporarily commented out.
753:
754: 'ang90' => '\ensuremath{\sqangle}',
755: 8735 => '\ensuremath{\sqangle}',
756:
757: 'ang' => '\ensuremath{\angle}',
758: 8736 => '\ensuremath{\angle}',
759: 'angmsd' => '\ensuremath{\measuredangle}',
760: 8737 => '\ensuremath{\measuredangle}',
761: 'angsph' => '\ensuremath{\sphericalangle}',
762: 8738 => '\ensuremath{\sphericalangle}',
763: 8739 => '\ensuremath{\vert}',
764: 8740 => '\ensuremath{\Vert}',
765: 'and' => '\ensuremath{\land}',
766: 8743 => '\ensuremath{\land}',
767: 'or' => '\ensuremath{\lor}',
768: 8744 => '\ensuremath{\lor}',
769: 'cap' => '\ensuremath{\cap}',
770: 8745 => '\ensuremath{\cap}',
771: 'cup' => '\ensuremath{\cup}',
772: 8746 => '\ensuremath{\cup}',
773: 'int' => '\ensuremath{\int}',
774: 8747 => '\ensuremath{\int}',
775: 'conint' => '\ensuremath{\oint}',
776: 8750 => '\ensuremath{\oint}',
777: 'there4' => '\ensuremath{\therefore}',
778: 8756 => '\ensuremath{\therefore}',
779: 'becaus' => '\ensuremath{\because}',
780: 8757 => '\ensuremath{\because}',
781: 8758 => '\ensuremath{:}',
782: 8759 => '\ensuremath{::}',
783: 'sim' => '\ensuremath{\sim}',
784: 8764 => '\ensuremath{\sim}',
785: 8765 => '\ensuremath{\backsim}',
786: 'wreath' => '\ensuremath{\wr}',
787: 8768 => '\ensuremath{\wr}',
788: 'nsim' => '\ensuremath{\not\sim}',
789: 8769 => '\ensuremath{\not\sim}',
790: # 'asymp' => '\ensuremath{\asymp}', ≈ is actually a different glyph.
791: 8771 => '\ensuremath{\asymp}',
792: 8772 => '\ensuremath{\not\asymp}',
793: 'cong' => '\ensuremath{\cong}',
794: 8773 => '\ensuremath{\cong}',
795: 8775 => '\ensuremath{\ncong}',
796: 8776 => '\ensuremath{\approx}',
797: 'approx' => '\ensuremath{\approx}',
798: 8778 => '\ensuremath{\approxeq}',
799: 'approxeq' => '\ensuremath{\approxeq}',
800: 8784 => '\ensuremath{\doteq}',
801: 8785 => '\ensuremath{\doteqdot}',
802: 8786 => '\ensuremath{\fallingdotseq}',
803: 8787 => '\ensuremath{\risingdotseq}',
804: 8788 => '\ensuremath{:=}',
805: 8789 => '\ensuremath{=:}',
806: 8790 => '\ensuremath{\eqcirc}',
807: 8791 => '\ensuremath{\circeq}',
808: 'wedgeq' => '\ensuremath{\stackrel{\wedge}{=}}',
809: 8792 => '\ensuremath{\stackrel{\wedge}{=}}',
810: 8794 => '\ensuremath{\stackrel{\vee}{=}}',
811: 8795 => '\ensuremath{\stackrel{\star}{=}}',
812: 8796 => '\ensuremath{\triangleq}',
813: 8797 => '\ensuremath{\stackrel{def}{=}}',
814: 8798 => '\ensuremath{\stackrel{m}{=}}',
815: 8799 => '\ensuremath{\stackrel{?}{=}}',
816: 'ne' => '\ensuremath{\neq}',
817: 8800 => '\ensuremath{\neq}',
818: 'equiv' => '\ensuremath{\equiv}',
819: 8801 => '\ensuremath{\equiv}',
820: 8802 => '\ensuremath{\not\equiv}',
821: 'le' => '\ensuremath{\leq}',
822: 8804 => '\ensuremath{\leq}',
823: 'ge' => '\ensuremath{\geq}',
824: 8805 => '\ensuremath{\geq}',
825: 8806 => '\ensuremath{\leqq}',
826: 8807 => '\ensuremath{\geqq}',
827: 8810 => '\ensuremath{\ll}',
828: 8811 => '\ensuremath{\gg}',
829: 'twixt' => '\ensuremath{\between}',
830: 8812 => '\ensuremath{\between}',
831: 8813 => '\ensuremath{\not\asymp}',
832: 8814 => '\ensuremath{\not<}',
833: 8815 => '\ensuremath{\not>}',
834: 8816 => '\ensuremath{\not\leqslant}',
835: 8817 => '\ensuremath{\not\geqslant}',
836: 8818 => '\ensuremath{\lesssim}',
837: 8819 => '\ensuremath{\gtrsim}',
838: 8820 => '\ensuremath{\stackrel{<}{>}}',
839: 8821 => '\ensuremath{\stackrel{>}{<}}',
840: 8826 => '\ensuremath{\prec}',
841: 8827 => '\ensuremath{\succ}',
842: 8828 => '\ensuremath{\preceq}',
843: 8829 => '\ensuremath{\succeq}',
844: 8830 => '\ensuremath{\not\prec}',
845: 8831 => '\ensuremath{\not\succ}',
846: 'sub' => '\ensuremath{\subset}',
847: 8834 => '\ensuremath{\subset}',
848: 'sup' => '\ensuremath{\supset}',
849: 8835 => '\ensuremath{\supset}',
850: 'nsub' => '\ensuremath{\not\subset}',
851: 8836 => '\ensuremath{\not\subset}',
852: 8837 => '\ensuremath{\not\supset}',
853: 'sube' => '\ensuremath{\subseteq}',
854: 8838 => '\ensuremath{\subseteq}',
855: 'supe' => '\ensuremath{\supseteq}',
856: 8839 => '\ensuremath{\supseteq}',
857: 8840 => '\ensuremath{\nsubseteq}',
858: 8841 => '\ensuremath{\nsupseteq}',
859: 8842 => '\ensuremath{\subsetneq}',
860: 8843 => '\ensuremath{\supsetneq}',
861: 8847 => '\ensuremath{\sqsubset}',
862: 8848 => '\ensuremath{\sqsupset}',
863: 8849 => '\ensuremath{\sqsubseteq}',
864: 8850 => '\ensuremath{\sqsupseteq}',
865: 8851 => '\ensuremath{\sqcap}',
866: 8852 => '\ensuremath{\sqcup}',
867: 'oplus' => '\ensuremath{\oplus}',
868: 8853 => '\ensuremath{\oplus}',
869: 8854 => '\ensuremath{\ominus}',
870: 'otimes' => '\ensuremath{\otimes}',
871: 8855 => '\ensuremath{\otimes}',
872: 8856 => '\ensuremath{\oslash}',
873: 8857 => '\ensuremath{\odot}',
874: 8858 => '\ensuremath{\circledcirc}',
875: 8859 => '\ensuremath{\circledast}',
876: 8861 => '\ensuremath{\ominus}', # Close enough for government work.
877: 8862 => '\ensuremath{\boxplus}',
878: 8863 => '\ensuremath{\boxminus}',
879: 8864 => '\ensuremath{\boxtimes}',
880: 8865 => '\ensuremath{\boxdot}',
881: 'vdash' => '\ensuremath{\vdash}',
882: 8866 => '\ensuremath{\vdash}',
883: 'dashv' => '\ensuremath{\dashv}',
884: 8867 => '\ensuremath{\dashv}',
885: 'perp' => '\ensuremath{\perp}',
886: 8869 => '\ensuremath{\perp}',
887: 8871 => '\ensuremath{\models}',
888: 8872 => '\ensuremath{\vDash}',
889: 8873 => '\ensuremath{\Vdash}',
890: 8874 => '\ensuremath{\Vvdash}',
891: 8876 => '\ensuremath{\nvdash}',
892: 8877 => '\ensuremath{\nvDash}',
893: 8878 => '\ensuremath{\nVdash}',
894: 8880 => '\ensuremath{\prec}',
895: 8881 => '\ensuremath{\succ}',
896: 8882 => '\ensuremath{\vartriangleleft}',
897: 8883 => '\ensuremath{\vartriangleright}',
898: 8884 => '\ensuremath{\trianglelefteq}',
899: 8885 => '\ensuremath{\trianglerighteq}',
900: 8891 => '\ensuremath{\veebar}',
901: 8896 => '\ensuremath{\land}',
902: 8897 => '\ensuremath{\lor}',
903: 8898 => '\ensuremath{\cap}',
904: 8899 => '\ensuremath{\cup}',
905: 8900 => '\ensuremath{\diamond}',
906: 'sdot' => '\ensuremath{\cdot}',
907: 8901 => '\ensuremath{\cdot}',
908: 8902 => '\ensuremath{\star}',
909: 8903 => '\ensuremath{\divideontimes}',
910: 8904 => '\ensuremath{\bowtie}',
911: 8905 => '\ensuremath{\ltimes}',
912: 8906 => '\ensuremath{\rtimes}',
913: 8907 => '\ensuremath{\leftthreetimes}',
914: 8908 => '\ensuremath{\rightthreetimes}',
915: 8909 => '\ensuremath{\simeq}',
916: 8910 => '\ensuremath{\curlyvee}',
917: 8911 => '\ensuremath{\curlywedge}',
918: 8912 => '\ensuremath{\Subset}',
919: 8913 => '\ensuremath{\Supset}',
920: 8914 => '\ensuremath{\Cap}',
921: 8915 => '\ensuremath{\Cup}',
922: 8916 => '\ensuremath{\pitchfork}',
923: 8918 => '\ensuremath{\lessdot}',
924: 8919 => '\ensuremath{\gtrdot}',
925: 8920 => '\ensuremath{\lll}',
926: 8921 => '\ensuremath{\ggg}',
927: 8922 => '\ensuremath{\gtreqless}',
928: 8923 => '\ensuremath{\lesseqgtr}',
929: 8924 => '\ensuremath{\eqslantless}',
930: 8925 => '\ensuremath{\eqslantgtr}',
931: 8926 => '\ensuremath{\curlyeqprec}',
932: 8927 => '\ensuremath{\curlyeqsucc}',
933: 8928 => '\ensuremath{\not\preccurlyeq}',
934: 8929 => '\ensuremath{\not\succcurlyeq}',
935: 8930 => '\ensuremath{\not\sqsupseteq}',
936: 8931 => '\ensuremath{\not\sqsubseteq}',
937: 8938 => '\ensuremath{\not\vartriangleleft}',
938: 8939 => '\ensuremath{\not\vartriangleright}',
939: 8940 => '\ensuremath{\not\trianglelefteq}',
940: 8941 => '\ensuremath{\not\trianglerighteq}',
941: 8942 => '\ensuremath{\vdots}',
942: 8960 => '\ensuremath{\varnothing}',
943: 'lceil' => '\ensuremath{\lceil}',
944: 8968 => '\ensuremath{\lceil}',
945: 'rceil' => '\ensuremath{\rceil}',
946: 8969 => '\ensuremath{\rceil}',
947: 'lfloor' => '\ensuremath{\lfloor}',
948: 8970 => '\ensuremath{\lfloor}',
949: 'rfloor' => '\ensuremath{\rfloor}',
950: 8971 => '\ensuremath{\rfloor}',
951: 'lang' => '\ensuremath{\langle}',
952: 9001 => '\ensuremath{\langle}',
953: 'rang' => '\ensuremath{\rangle}',
954: 9002 => '\ensuremath{\rangle}',
955: 'loz' => '\ensuremath{\lozenge}',
956: 9674 => '\ensuremath{\lozenge}',
957: 'spades' => '\ensuremath{\spadesuit}',
958: 9824 => '\ensuremath{\spadesuit}',
959: 9825 => '\ensuremath{\heartsuit}',
960: 9826 => '\ensuremath{\diamondsuit}',
961: 'clubs' => '\ensuremath{\clubsuit}',
962: 9827 => '\ensuremath{\clubsuit}',
963: 'diams' => '\ensuremath{\blacklozenge}',
964: 9830 => '\ensuremath{\blacklozenge}'
965:
966: );
967:
968: =pod
969:
970: =head1 UNICODE TABLE
971:
972: =over
973:
974: There are some named entities that don't have a good
975: latex equivalent, these are converted to utf-8 via this table
976: of entity name -> unicode number.
977:
978: =back
979:
980: =cut
981:
982: my %utf_table = (
983: 'THORN' => 222,
984: 'thorn' => 254,
985: 'eth' => 240,
986: 'hearts' => 9829
987: );
988:
989: sub entity_to_utf8 {
990: my ($unicode) = @_;
991: my $result = pack("U", $unicode);
992: return $result;
993: }
994:
995:
996:
997: sub entity_to_latex {
998: my ($entity) = @_;
999:
1000: # Try to look up the entity (text or numeric) in the hash:
1001:
1002:
1003:
1004: my $latex = $entities{"$entity"};
1005: if (defined $latex) {
1006: return $latex;
1007: }
1008: # If the text is purely numeric we can do the UTF-8 conversion:
1009: # Otherwise there are a few textual entities that don't have good latex
1010: # which can be converted to unicode:
1011: #
1012: if ($entity =~ /^\d+$/) {
1013: return &entity_to_utf8($entity);
1014: } else {
1015: my $result = $utf_table{"$entity"};
1016: if (defined $result) {
1017: return &entity_to_utf8($result);
1018: }
1019: }
1020: # Can't do the conversion`< ...
1021:
1022: return " ";
1023: }
1024:
1025:
1026: sub replace_entities {
1027: my ($input) = @_;
1028: my $start;
1029: my $end;
1030: my $entity;
1031: my $latex;
1032:
1033: # First the &#nnn; entities:
1034:
1035: while ($input =~ /(&\#\d+;)/) {
1036: ($start) = @-;
1037: ($end) = @+;
1038: $entity = substr($input, $start+2, $end-$start-3);
1039: $latex = &entity_to_latex($entity);
1040: substr($input, $start, $end-$start) = $latex;
1041: }
1042:
1043: # Hexadecimal entities:
1044:
1045: while ($input =~ /&\#x(\d|[a-f,A-f])+;/) {
1046: ($start) = @-;
1047: ($end) = @+;
1048: $entity = "0" . substr($input, $start+2, $end-$start-3); # 0xhexnumber
1049: $latex = &entity_to_latex(hex($entity));
1050: substr($input, $start, $end-$start) = $latex;
1051: }
1052:
1053:
1054: # Now the &text; entites;
1055:
1056: while ($input =~/(&\w+;)/) {
1057: ($start) = @-;
1058: ($end) = @+;
1059: $entity = substr($input, $start+1, $end-$start-2);
1060: $latex = &entity_to_latex($entity);
1061: substr($input, $start, $end-$start) = $latex;
1062:
1063: }
1064: return $input;
1065: }
1066:
1067: 1;
1068:
1069: __END__
1070:
1071: =pod
1072:
1073: =head1 NAME
1074:
1075: Apache::entities.pm
1076:
1077: =head1 SYNOPSIS
1078:
1079: This file contains a table driven entity-->latex converter.
1080:
1081: This is part of the LearningOnline Network with CAPA project
1082: described at http://www.lon-capa.org.
1083:
1084: =head1 OVERVIEW
1085:
1086:
1087: Assumptions:
1088: The number of entities in a resource is small compared with the
1089: number of possible entities that might be translated.
1090: Therefore the strategy is to match a general entity pattern
1091: &.+; over and over, pull out the match look it up in an entity -> tex hash
1092: and do the replacement.
1093:
1094: In order to simplify the hash, the following reductions are done:
1095: &#d+; have the &# and ; stripped and is converted to an int.
1096: &#.+; have the &#x and ; stripped and is converted to an int as a hex
1097: value.
1098: All others have the & and ; stripped.
1099:
1100:
1101: The hash: Add new conversions here; leave off the leading & and the trailing ;
1102: all numeric entities need only appear as their decimal versions
1103: (e.g. no need for 1234 is sufficient, no need for 0x4d2 as well.
1104:
1105: This entity table is mercilessly cribbed from the HTML pocket reference
1106: table starting at pg 82. In most cases the LaTeX equivalent codes come from
1107: the original massive regular expression replacements originally by
1108: A. Sakharuk in lonprintout.pm
1109:
1110: I also want to acknowledge
1111: ISO Character entities and their LaTeX equivalents by
1112: Vidar Bronken Gundersen, and Rune Mathisen
1113: http://www.bitjungle.com/isoent-ref.pdf
1114:
1115:
1116: Note numerical entities are essentially unicode character codes.
1117:
1118:
1119: =head1 SUBROUTINES
1120:
1121: =over
1122:
1123: =item entity_to_utf8()
1124:
1125:
1126: Convert a numerical entity (that does not exist in our hash)
1127: to its UTF-8 equivalent representation.
1128: This allows us to support, to some extent, any entity for which
1129: dvipdf can find a gylph (given that LaTeX is now UTF-8 clean).
1130:
1131: Parameters:
1132: unicode - The unicode for the character. This is assumed to
1133: be a decimal value
1134: Returns:
1135: The UTF-8 equiavalent of the value.
1136:
1137: =item entity_to_latex()
1138:
1139: Convert an entity to the corresponding LateX if possible.
1140: If not possible, and the entity is numeric,
1141: the entity is treated like a Unicode character and converted
1142: to UTF-8 which should display as long as dvipdf can find the
1143: appropriate glyph.
1144:
1145: The entity is assumed to have already had the
1146: &; or & ; removed
1147:
1148: Parameters:
1149: entity - Name of entity to convert.
1150: Returns:
1151: One of the following:
1152: - Latex string that produces the entity.
1153: - UTF-8 equivalent of a numeric entity for which we don't have a latex string.
1154: - ' ' for text entities for which there's no latex equivalent.
1155:
1156:
1157: =item replace_entities()
1158:
1159: Convert all the entities in a string.
1160: We locate all the entities, pass them into entity_to_latex and
1161: and replace occurences in the input string.
1162: The assumption is that there are few entities in any string/document
1163: so this looping is not too bad. The advantage of looping vs. regexping is
1164: that we now can use lookup tables for the translation in entity_to_latex above.
1165:
1166: Parameters:
1167: input - Input string/document
1168: Returns
1169: input with entities replaced by latexable stuff (UTF-8 encodings or
1170: latex control strings to produce the entity.
1171:
1172: =back
1173:
1174: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>