File:  [LON-CAPA] / loncom / interface / entities.pm
Revision 1.14: download - view: text, annotated - select for diffs
Mon Nov 17 20:22:42 2008 UTC (15 years, 7 months ago) by jms
Branches: MAIN
CVS tags: HEAD
no message

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

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