File:  [LON-CAPA] / loncom / interface / entities.pm
Revision 1.8: download - view: text, annotated - select for diffs
Mon Apr 21 11:02:43 2008 UTC (16 years, 1 month ago) by foxr
Branches: MAIN
CVS tags: HEAD
1. Correct mis-spelling of ℏ
2. Re-order some symbols relative to numbers for consistency.

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>