File:  [LON-CAPA] / loncom / interface / entities.pm
Revision 1.11: download - view: text, annotated - select for diffs
Mon May 5 10:46:19 2008 UTC (16 years ago) by foxr
Branches: MAIN
CVS tags: version_2_7_X, version_2_7_1, version_2_7_0, version_2_6_99_1, version_2_6_99_0, HEAD
Added ♥ to the entities-> utf-8 table.

    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     => '\ensuremath{f}',
  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     => '\"{}',
  230:     'uml'   => '\"{}',
  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     => "\\'{}",
  254:     'acute' => "\\'{}",
  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     => '\DH',
  310:     'ETH'   => '\DH',
  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:     223     => '{\ss}',
  338:     'szlig' => '{\ss}',
  339:     224     => '\\`{a}',
  340:     'agrave'=> '\\`{a}',
  341:     225     => "\\'{a}",
  342:     'aacute'=> "\\'{a}",
  343:     226     => '\\^{a}',
  344:     'acirc' => '\\^{a}',
  345:     227     => '\\~{a}',
  346:     'atilde'=> '\\~{a}',
  347:     228     => '\\"{a}',
  348:     'auml'  => '\\"{a}',
  349:     229     => '\aa',
  350:     'aring' => '\aa',
  351:     230     => '\ae',
  352:     'aelig' => '\ae',
  353:     231     => '\c{c}',
  354:     'ccedil'=> '\c{c}',
  355:     232     => '\\`{e}',
  356:     'egrave'=> '\\`{e}',
  357:     233     => "\\'{e}",
  358:     'eacute'=> "\\'{e}",
  359:     234     => '\\^{e}',
  360:     'ecirc' => '\\^{e}',
  361:     235     => '\\"{e}',
  362:     'euml'  => '\\"{e}',
  363:     236     => '\\`{i}',
  364:     'igrave'=> '\\`{i}',
  365:     237     => "\\'{i}",
  366:     'iacute'=> "\\'{i}",
  367:     238     => '\\^{i}',
  368:     'icirc' => '\\^{i}',
  369:     239     => '\\"{i}',
  370:     'iuml'  => '\\"{i}',
  371:     241     => '\\~{n}',
  372:     'ntilde'=> '\\~{n}',
  373:     242     => '\\`{o}',
  374:     'ograve'=> '\\`{o}',
  375:     243     => "\\'{o}",
  376:     'oacute'=> "\\'{o}",
  377:     244     => '\\^{o}',
  378:     'ocirc' => '\\^{o}',
  379:     245     => '\\~{o}',
  380:     'otilde'=> '\\~{o}',
  381:     246     => '\\"{o}',
  382:     'ouml'  => '\\"{o}',
  383:     247     => '\ensuremath{\div}',
  384:     'divide'=> '\ensuremath{\div}',
  385:     248     => '{\o}',
  386:     'oslash'=> '{\o}',
  387:     249     => '\\`{u}',
  388:     'ugrave'=> '\\`{u}',
  389:     250     => "\\'{u}",
  390:     'uacute'=> "\\'{u}",
  391:     251     => '\\^{u}',
  392:     'ucirc' => '\\^{u}',
  393:     252     => '\\"{u}',
  394:     'uuml'  => '\\"{u}',
  395:     253     => "\\'{y}",
  396:     'yacute'=> "\\'{y}",
  397:     255     => '\\"{y}',
  398:     'yuml'  => '\\"{y}',
  399: 
  400:     # hbar entity number comes from the unicode charater:
  401:     # see e.g. http://www.unicode.org/charts/PDF/U0100.pdf
  402:     # ISO also documents a 'planck' entity.
  403: 
  404:     295     => '\ensuremath{\hbar}',
  405:     'planck' => '\ensuremath{\hbar}',
  406: 
  407:     # Latin extended-A HTML 4.01 entities:
  408: 
  409:     338      => '\OE',
  410:     'OElig'  => '\OE',
  411:     339      => '\oe',
  412:     'oelig'  => '\oe',
  413:     352      => '\v{S}',
  414:     'Scaron' => '\v{S}',
  415:     353      => '\v{s}',
  416:     'scaron' => '\v{s}',
  417:     376      => '\\"{Y}',
  418:     'Yuml'   => '\\"{Y}', 
  419: 
  420: 
  421:     # Latin extended B HTML 4.01 entities
  422: 
  423:     402      => '\ensuremath{f}',
  424:     'fnof'   => '\ensuremath{f}',
  425: 
  426:     # Spacing modifier letters:
  427:     
  428:     710      => '\^{}',
  429:     'circ'   => '\^{}',
  430:     732      => '\~{}',
  431:     'tilde'  => '\~{}',
  432: 
  433:     # Greek uppercase:
  434: 
  435:     913      => '\ensuremath{\mathrm{A}}',
  436:     'Alpha'  => '\ensuremath{\mathrm{A}}',
  437:     914      => '\ensuremath{\mathrm{B}}',
  438:     'Beta'   => '\ensuremath{\mathrm{B}}',
  439:     915      => '\ensuremath{\Gamma}',
  440:     'Gamma'  => '\ensuremath{\Gamma}',
  441:     916      => '\ensuremath{\Delta}',
  442:     'Delta'  => '\ensuremath{\Delta}',
  443:     917      => '\ensuremath{\mathrm{E}}',
  444:     'Epsilon'=> '\ensuremath{\mathrm{E}}',
  445:     918      => '\ensuremath{\mathrm{Z}}',
  446:     'Zeta'   => '\ensuremath{\mathrm{Z}}',
  447:     919      => '\ensuremath{\mathrm{H}}',
  448:     'Eta'    => '\ensuremath{\mathrm{H}}',
  449:     920      => '\ensuremath{\Theta}',
  450:     'Theta'  => '\ensuremath{\Theta}',
  451:     921      => '\ensuremath{\mathrm{I}}',
  452:     'Iota'   => '\ensuremath{\mathrm{I}}',
  453:     922      => '\ensuremath{\mathrm{K}}',
  454:     'Kappa'  => '\ensuremath{\mathrm{K}}',
  455:     923      => '\ensuremath{\Lambda}',
  456:     'Lambda' => '\ensuremath{\Lambda}',
  457:     924      => '\ensuremath{\mathrm{M}}',
  458:     'Mu'     => '\ensuremath{\mathrm{M}}',
  459:     925      => '\ensuremath{\mathrm{N}}',
  460:     'Nu'     => '\ensuremath{\mathrm{N}}',
  461:     926      => '\ensuremath{\mathrm{\Xi}}',
  462:     'Xi'     => '\ensuremath{\mathrm{\Xi}}',
  463:     927      => '\ensuremath{\mathrm{O}}',
  464:     'Omicron'=> '\ensuremath{\mathrm{O}}',
  465:     928      => '\ensuremath{\Pi}',
  466:     'Pi'     => '\ensuremath{\Pi}',
  467:     929      => '\ensuremath{\mathrm{P}}',
  468:     'Rho'    => '\ensuremath{\mathrm{P}}',
  469:    
  470:     # Skips 930
  471: 
  472:     931      => '\ensuremath{\Sigma}',
  473:     'Sigma'  => '\ensuremath{\Sigma}',
  474:     932      => '\ensuremath{\mathrm{T}}',
  475:     'Tau'    => '\ensuremath{\mathrm{T}}',
  476:     933      => '\ensuremath{\Upsilon}',
  477:     'Upsilon'=> '\ensuremath{\Upsilon}',
  478:     934      => '\ensuremath{\Phi}',
  479:     'Phi'    => '\ensuremath{\Phi}',
  480:     935      => '\ensuremath{\mathrm{X}}',
  481:     'Chi'    => '\ensuremath{\mathrm{X}}',
  482:     936      => '\ensuremath{\Psi}',
  483:     'Psi'    => '\ensuremath{\Psi}',
  484:     937      => '\ensuremath{\Omega}',
  485:     'Omega'  => '\ensuremath{\Omega}',
  486: 
  487: 
  488:     # Greek lowercase:
  489: 
  490:     945      => '\ensuremath{\alpha}',
  491:     'alpha'  => '\ensuremath{\alpha}',
  492:     946      => '\ensuremath{\beta}',
  493:     'beta'   => '\ensuremath{\beta}',
  494:     947      => '\ensuremath{\gamma}',
  495:     'gamma'  => '\ensuremath{\gamma}',
  496:     948      => '\ensuremath{\delta}',
  497:     'delta'  => '\ensuremath{\delta}',
  498:     949      => '\ensuremath{\epsilon}',
  499:     'epsilon'=> '\ensuremath{\epsilon}',
  500:     950      => '\ensuremath{\zeta}',
  501:     'zeta'   => '\ensuremath{\zeta}',
  502:     951      => '\ensuremath{\eta}',
  503:     'eta'    => '\ensuremath{\eta}',
  504:     952      => '\ensuremath{\theta}',
  505:     'theta'  => '\ensuremath{\theta}',
  506:     953      => '\ensuremath{\iota}',
  507:     'iota'   => '\ensuremath{\iota}',
  508:     954      => '\ensuremath{\kappa}',
  509:     'kappa'  => '\ensuremath{\kappa}',
  510:     955      => '\ensuremath{\lambda}',
  511:     'lambda' => '\ensuremath{\lambda}',
  512:     956      => '\ensuremath{\mu}',
  513:     'mu'     => '\ensuremath{\mu}',
  514:     957      => '\ensuremath{\nu}',
  515:     'nu'     => '\ensuremath{\nu}',
  516:     958      => '\ensuremath{\xi}',
  517:     'xi'     => '\ensuremath{\xi}',
  518:     959      => '\ensuremath{o}',
  519:     'omicron'=> '\ensuremath{o}',
  520:     960      => '\ensuremath{\pi}',
  521:     'pi'     => '\ensuremath{\pi}',
  522:     961      => '\ensuremath{\rho}',
  523:     'rho'    => '\ensuremath{\rho}',
  524:     962      => '\ensuremath{\varsigma}',
  525:     'sigmaf' => '\ensuremath{\varsigma}',
  526:     963      => '\ensuremath{\sigma}',
  527:     'sigma'  => '\ensuremath{\sigma}',
  528:     964      => '\ensuremath{\tau}',
  529:     'tau'    => '\ensuremath{\tau}',
  530:     965      => '\ensuremath{\upsilon}',
  531:     'upsilon'=> '\ensuremath{\upsilon}',
  532:     966      => '\ensuremath{\phi}',
  533:     'phi'    => '\ensuremath{\phi}',
  534:     967      => '\ensuremath{\chi}',
  535:     'chi'    => '\ensuremath{\chi}',
  536:     968      => '\ensuremath{\psi}',
  537:     'psi'    => '\ensuremath{\psi}',
  538:     969      => '\ensuremath{\omega}',
  539:     'omega'  => '\ensuremath{\omega}',
  540:     977      => '\ensuremath{\vartheta}',
  541:     'thetasym'=>'\ensuremath{\vartheta}',
  542:     978      => '\ensuremath{\mathit{\Upsilon}}',
  543:     'upsih'  => '\ensuremath{\mathit{\Upsilon}}',
  544:     982      => '\ensuremath{\varpi}',
  545:     'piv'    => '\ensuremath{\varpi}',
  546: 
  547:     
  548:     # The general punctuation set:
  549: 
  550:     8194,    => '\hspace{.5em}',
  551:     'enspc'  => '\hspace{.5em}',
  552:     8195     => '\hspace{1.0em}',
  553:     'emspc'  => '\hspace{1.0em}',
  554:     8201     => '\hspace{0.167em}',
  555:     'thinsp' => '\hspace{0.167em}',
  556:     8204     => '{}',
  557:     'zwnj'   => '{}',
  558:     8205     => '',
  559:     'zwj'    => '',
  560:     8206     => '',
  561:     'lrm'    => '',
  562:     8207     => '',
  563:     'rlm'    => '',
  564:     8211     => '--',
  565:     'ndash'  => '--',
  566:     8212     => '---',
  567:     'mdash'  => '---',
  568:     8216     => '`',
  569:     'lsquo'  => '`',
  570:     8217     => "'",
  571:     'rsquo'  => "'",
  572:     8218     => '\quotesinglbase',
  573:     'sbquo'  => '\quotesinglbase',
  574:     8220     => '``',
  575:     'ldquo'  => '``',
  576:     8221     => "''",
  577:     'rdquo'  => "''",
  578:     8222     => '\quotedblbase',
  579:     'bdquo'  => '\quotedblbase',
  580:     8224     => '\ensuremath{\dagger}',
  581:     'dagger' => '\ensuremath{\dagger}',
  582:     '8225'   => '\ensuremath{\ddag}',
  583:     'Dagger' => '\ensuremath{\ddag}',
  584:     8226     => '\textbullet',
  585:     'bull'   => '\textbullet',
  586:     8230     => '\textellipsis',
  587:     'hellep' => '\textellipsis',
  588:     8240     => '\textperthousand',
  589:     permil   => '\textperthousand',
  590:     8242     => '\textquotesingle',
  591:     'prime'  => '\textquotesingle',
  592:     8243     => '\textquotedbl',
  593:     'Prime'  => '\textquotedbl',
  594:     8249     => '\guilsinglleft',
  595:     'lsaquo' => '\guilsinglleft',
  596:     8250     => '\guilsinglright',
  597:     'rsaquo' => '\guilsinglright',
  598:     8254     => '\textasciimacron',
  599:     oline    => '\textasciimacron',
  600:     8260     => '\textfractionsolidus',
  601:     'frasl'  => '\textfractionsolidus',
  602:     8364     => '\texteuro',
  603:     'euro'   => '\texteuro',
  604: 
  605:     # Letter like symbols
  606: 
  607:     
  608:     8472     => '\ensuremath{\wp}',
  609:     'weierp' => '\ensuremath{\wp}',
  610:     8465     => '\ensuremath{\Im}',
  611:     'image'  => '\ensuremath{\Im}',
  612:     8476     => '\ensuremath{\Re}',
  613:     'real'   => '\ensuremath{\Re}',
  614:     8482     => '\texttrademark',
  615:     'trade'  => '\texttrademark',
  616:     8501     => '\ensuremath{\aleph}',
  617:     'alefsym'=> '\ensuremath{\aleph}',
  618: 
  619:     # Arrows and then some (harpoons from Hon Kie).
  620: 
  621:     8592     => '\textleftarrow',
  622:     'larr'   => '\textleftarrow',
  623:     8593     => '\textuparrow',
  624:     'uarr'   => '\textuparrow',
  625:     8594     => '\textrightarrow',
  626:     'rarr'   => '\textrightarrow',
  627:     8595     => '\textdownarrow',
  628:     'darr'   => '\textdownarrow',
  629:     8596     => '\ensuremath{\leftrightarrow}',
  630:     'harr'   => '\ensuremath{\leftrightarrow}',
  631:     8598     => '\ensuremath{\nwarrow}',
  632:     8599     => '\ensuremath{\nearrow}',
  633:     8600     => '\ensuremath{\searrow}',
  634:     8601     => '\ensuremath{\swarrow}',
  635:     8605     => '\ensuremath{\leadsto}',
  636:     8614     => '\ensuremath{\mapsto}',
  637:     8617     => '\ensuremath{\hookleftarrow}',
  638:     8618     => '\ensuremath{\hookrightarrow}',
  639:     8629     => '\ensuremath{\hookleftarrow}', # not an exact match but best I know.
  640:     'crarr'  => '\ensuremath{\hookleftarrow}', # not an exact match but best I know.
  641:     8636     => '\ensuremath{\leftharpoonup}',
  642:     8637     => '\ensuremath{\leftharpoondown}',
  643:     8640     => '\ensuremath{\rightharpoonup}',
  644:     8641     => '\ensuremath{\rightharpoondown}',
  645:     8652     => '\ensuremath{\rightleftharpoons}',
  646:     8656     => '\ensuremath{\Leftarrow}',
  647:     'lArr'   => '\ensuremath{\Leftarrow}',
  648:     8657     => '\ensuremath{\Uparrow}',
  649:     'uArr'   => '\ensuremath{\Uparrow}',
  650:     8658     => '\ensuremath{\Rightarrow}',
  651:     'rArr'   => '\ensuremath{\Rightarrow}',
  652:     8659     => '\ensuremath{\Downarrow}',
  653:     'dArr'   => '\ensuremath{\Downarrow}',
  654:     8660     => '\ensuremath{\Leftrightarrow}',
  655:     'hArr'   => '\ensuremath{\Leftrightarrow}',
  656:     8661     => '\ensuremath{\Updownarrow}',
  657:     'vArr'   => '\ensuremath{\Updownarrow}',
  658:     8666     => '\ensuremath{\Lleftarrow}',
  659:     'lAarr'   => '\ensuremath{\Lleftarrow}',
  660:     8667     => '\ensuremath{\Rrightarrow}',
  661:     'rAarr'  => '\ensuremath{\Rrightarrow}',
  662:     8669     => '\ensuremath{\rightsquigarrow}',
  663:     'rarrw'  => '\ensuremath{\rightsquigarrow}',
  664:     
  665: 
  666:     # Mathematical operators.
  667: 	
  668:     
  669:     'forall' => '\ensuremath{\forall}',
  670:     8704     => '\ensuremath{\forall}',
  671:     'comp'   => '\ensuremath{\complement}',
  672:     8705     => '\ensuremath{\complement}',
  673:     'part'   => '\ensuremath{\partial}',
  674:     8706     => '\ensuremath{\partial}',
  675:     'exist'  => '\ensuremath{\exists}',
  676:     8707     => '\ensuremath{\exists}',
  677:     'nexist' => '\ensuremath{\nexists}',
  678:     8708     => '\ensuremath{\nexists}',
  679:     'empty'  => '\ensuremath{\emptyset}',
  680:     8709     => '\ensuremath{\emptyset}',
  681:     8710     => '\ensuremath{\Delta}',
  682:     'nabla'  => '\ensuremath{\nabla}',
  683:     8711     => '\ensuremath{\nabla}',
  684:     'isin'   => '\ensuremath{\in}',
  685:     8712     => '\ensuremath{\in}',
  686:     'notin'  => '\ensuremath{\notin}',
  687:     8713     => '\ensuremath{\notin}',
  688:     ni       => '\ensuremath{\ni}',
  689:     8715     => '\ensuremath{\ni}',
  690:     8716     => '\ensuremath{\not\ni}',
  691:     'prod'   => '\ensuremath{\prod}',
  692:     8719     => '\ensuremath{\prod}',
  693:     8720     => '\ensuremath{\coprod}',
  694:     'sum'    => '\ensuremath{\sum}',
  695:     8721     => '\ensuremath{\sum}',
  696:     'minus'  => '\ensuremath{-}',
  697:     8722     => '\ensuremath{-}',
  698:     8723     => '\ensuremath{\mp}',
  699:     8724     => '\ensuremath{\dotplus}',
  700:     8725     => '\ensuremath{\diagup}',
  701:     8726     => '\ensuremath{\smallsetminus}',
  702:     'lowast' => '\ensuremath{*}',
  703:     8727     => '\ensuremath{*}',
  704:     8728     => '\ensuremath{\circ}',
  705:     8729     => '\ensuremath{\bullet}',
  706:     'radic'  => '\ensuremath{\surd}',
  707:     8730     => '\ensuremath{\surd}',
  708:     8731     => '\ensuremath{\sqrt[3]{}}',
  709:     8732     => '\ensuremath{\sqrt[4]{}}',
  710:     'prop'   => '\ensuremath{\propto}',
  711:     8733     => '\ensuremath{\propto}',
  712:     'infin'  => '\ensuremath{\infty}',
  713:     8734     => '\ensuremath{\infty}',
  714: #
  715: #   The items below require the isoent latex package which I can't find at least for FC5.
  716: #   Temporarily commented out.
  717: #
  718: #    'ang90'  => '\ensuremath{\sqangle}',
  719: #    8735     => '\ensuremath{\sqangle}',
  720:     'ang'    => '\ensuremath{\angle}',
  721:     8736     => '\ensuremath{\angle}',
  722:     'angmsd' => '\ensuremath{\measuredangle}',
  723:     8737     => '\ensuremath{\measuredangle}',
  724:     'angsph' => '\ensuremath{\sphericalangle}',
  725:     8738     => '\ensuremath{\sphericalangle}',
  726:     8739     => '\ensuremath{\vert}',
  727:     8740     => '\ensuremath{\Vert}',
  728:     'and'    => '\ensuremath{\land}',
  729:     8743     => '\ensuremath{\land}',
  730:     'or'     => '\ensuremath{\lor}',
  731:     8744     => '\ensuremath{\lor}',
  732:     'cap'    => '\ensuremath{\cap}',
  733:     8745     => '\ensuremath{\cap}',
  734:     'cup'    => '\ensuremath{\cup}',
  735:     8746     => '\ensuremath{\cup}',
  736:     'int'    => '\ensuremath{\int}',
  737:     8747     => '\ensuremath{\int}',
  738:     'conint' => '\ensuremath{\oint}',
  739:     8750     => '\ensuremath{\oint}',
  740:     'there4' => '\ensuremath{\therefore}',
  741:     8756     => '\ensuremath{\therefore}',
  742:     'becaus' => '\ensuremath{\because}',
  743:     8757     => '\ensuremath{\because}',
  744:     8758     => '\ensuremath{:}',
  745:     8759     => '\ensuremath{::}',
  746:     'sim'    => '\ensuremath{\sim}',
  747:     8764     => '\ensuremath{\sim}',
  748:     8765     => '\ensuremath{\backsim}',
  749:     'wreath' => '\ensuremath{\wr}',
  750:     8768     => '\ensuremath{\wr}',
  751:     'nsim'   => '\ensuremath{\not\sim}',
  752:     8769     => '\ensuremath{\not\sim}',
  753: #    'asymp'  => '\ensuremath{\asymp}',  &asymp; is actually a different glyph.
  754:     8771     => '\ensuremath{\asymp}',
  755:     8772     => '\ensuremath{\not\asymp}',
  756:     'cong'   => '\ensuremath{\cong}',
  757:     8773     => '\ensuremath{\cong}',
  758:     8775     => '\ensuremath{\ncong}',
  759:     8778     => '\ensuremath{\approxeq}',
  760:     8784     => '\ensuremath{\doteq}',
  761:     8785     => '\ensuremath{\doteqdot}',
  762:     8786     => '\ensuremath{\fallingdotseq}',
  763:     8787     => '\ensuremath{\risingdotseq}',
  764:     8788     => '\ensuremath{:=}',
  765:     8789     => '\ensuremath{=:}',
  766:     8790     => '\ensuremath{\eqcirc}',
  767:     8791     => '\ensuremath{\circeq}',
  768:     'wedgeq' => '\ensuremath{\stackrel{\wedge}{=}}',
  769:     8792     => '\ensuremath{\stackrel{\wedge}{=}}',
  770:     8794     => '\ensuremath{\stackrel{\vee}{=}}',
  771:     8795     => '\ensuremath{\stackrel{\star}{=}}',
  772:     8796     => '\ensuremath{\triangleq}',
  773:     8797     => '\ensuremath{\stackrel{def}{=}}',
  774:     8798     => '\ensuremath{\stackrel{m}{=}}',
  775:     8799     => '\ensuremath{\stackrel{?}{=}}',
  776:     'ne'     => '\ensuremath{\neq}',
  777:     8800     => '\ensuremath{\neq}',
  778:     'equiv'  => '\ensuremath{\equiv}',
  779:     8801     => '\ensuremath{\equiv}',
  780:     8802     => '\ensuremath{\not\equiv}',
  781:     'le'     => '\ensuremath{\leq}',
  782:     8804     => '\ensuremath{\leq}',
  783:     'ge'     => '\ensuremath{\geq}',
  784:     8805     => '\ensuremath{\geq}',
  785:     8806     => '\ensuremath{\leqq}',
  786:     8807     => '\ensuremath{\geqq}',
  787:     8810     => '\ensuremath{\ll}',
  788:     8811     => '\ensuremath{\gg}',
  789:     'twixt'  => '\ensuremath{\between}',
  790:     8812     => '\ensuremath{\between}',
  791:     8813     => '\ensuremath{\not\asymp}',
  792:     8814     => '\ensuremath{\not<}',
  793:     8815     => '\ensuremath{\not>}',
  794:     8816     => '\ensuremath{\not\leqslant}',
  795:     8817     => '\ensuremath{\not\geqslant}',
  796:     8818     => '\ensuremath{\lesssim}',
  797:     8819     => '\ensuremath{\gtrsim}',
  798:     8820     => '\ensuremath{\stackrel{<}{>}}',
  799:     8821     => '\ensuremath{\stackrel{>}{<}}',
  800:     8826     => '\ensuremath{\prec}',
  801:     8827     => '\ensuremath{\succ}',
  802:     8828     => '\ensuremath{\preceq}',
  803:     8829     => '\ensuremath{\succeq}',
  804:     8830     => '\ensuremath{\not\prec}',
  805:     8831     => '\ensuremath{\not\succ}',
  806:     'sub'    => '\ensuremath{\subset}',
  807:     8834     => '\ensuremath{\subset}',
  808:     'sup'    => '\ensuremath{\supset}',
  809:     8835     => '\ensuremath{\supset}',
  810:     'nsub'   => '\ensuremath{\not\subset}',
  811:     8836     => '\ensuremath{\not\subset}',
  812:     8837     => '\ensuremath{\not\supset}',
  813:     'sube'   => '\ensuremath{\subseteq}',
  814:     8838     => '\ensuremath{\subseteq}',
  815:     'supe'   => '\ensuremath{\supseteq}',
  816:     8839     => '\ensuremath{\supseteq}',
  817:     8840     => '\ensuremath{\nsubseteq}',
  818:     8841     => '\ensuremath{\nsupseteq}',
  819:     8842     => '\ensuremath{\subsetneq}',
  820:     8843     => '\ensuremath{\supsetneq}',
  821:     8847     => '\ensuremath{\sqsubset}',
  822:     8848     => '\ensuremath{\sqsupset}',
  823:     8849     => '\ensuremath{\sqsubseteq}',
  824:     8850     => '\ensuremath{\sqsupseteq}',
  825:     8851     => '\ensuremath{\sqcap}',
  826:     8852     => '\ensuremath{\sqcup}',
  827:     'oplus'  => '\ensuremath{\oplus}',
  828:     8853     => '\ensuremath{\oplus}',
  829:     8854     => '\ensuremath{\ominus}',
  830:     'otimes' => '\ensuremath{\otimes}',
  831:     8855     => '\ensuremath{\otimes}',
  832:     8856     => '\ensuremath{\oslash}',
  833:     8857     => '\ensuremath{\odot}',
  834:     8858     => '\ensuremath{\circledcirc}',
  835:     8859     => '\ensuremath{\circledast}',
  836:     8861     => '\ensuremath{\ominus}', # Close enough for government work.
  837:     8862     => '\ensuremath{\boxplus}',
  838:     8863     => '\ensuremath{\boxminus}',
  839:     8864     => '\ensuremath{\boxtimes}',
  840:     8865     => '\ensuremath{\boxdot}',
  841:     'vdash'  => '\ensuremath{\vdash}',
  842:     8866     => '\ensuremath{\vdash}',
  843:     'dashv'  => '\ensuremath{\dashv}',
  844:     8867     => '\ensuremath{\dashv}',
  845:     'perp'   => '\ensuremath{\perp}',
  846:     8869     => '\ensuremath{\perp}',
  847:     8871     => '\ensuremath{\models}',
  848:     8872     => '\ensuremath{\vDash}',    
  849:     8873     => '\ensuremath{\Vdash}',
  850:     8874     => '\ensuremath{\Vvdash}',
  851:     8876     => '\ensuremath{\nvdash}',
  852:     8877     => '\ensuremath{\nvDash}',
  853:     8878     => '\ensuremath{\nVdash}',
  854:     8880     => '\ensuremath{\prec}',
  855:     8881     => '\ensuremath{\succ}',
  856:     8882     => '\ensuremath{\vartriangleleft}',
  857:     8883     => '\ensuremath{\vartriangleright}',
  858:     8884     => '\ensuremath{\trianglelefteq}',
  859:     8885     => '\ensuremath{\trianglerighteq}',
  860:     8891     => '\ensuremath{\veebar}',
  861:     8896     => '\ensuremath{\land}',
  862:     8897     => '\ensuremath{\lor}',
  863:     8898     => '\ensuremath{\cap}',
  864:     8899     => '\ensuremath{\cup}',
  865:     8900     => '\ensuremath{\diamond}',
  866:     'sdot'   => '\ensuremath{\cdot}',
  867:     8901     => '\ensuremath{\cdot}',
  868:     8902     => '\ensuremath{\star}',
  869:     8903     => '\ensuremath{\divideontimes}',
  870:     8904     => '\ensuremath{\bowtie}',
  871:     8905     => '\ensuremath{\ltimes}',
  872:     8906     => '\ensuremath{\rtimes}',
  873:     8907     => '\ensuremath{\leftthreetimes}',
  874:     8908     => '\ensuremath{\rightthreetimes}',
  875:     8909     => '\ensuremath{\simeq}',
  876:     8910     => '\ensuremath{\curlyvee}',
  877:     8911     => '\ensuremath{\curlywedge}',
  878:     8912     => '\ensuremath{\Subset}',
  879:     8913     => '\ensuremath{\Supset}',
  880:     8914     => '\ensuremath{\Cap}',
  881:     8915     => '\ensuremath{\Cup}',
  882:     8916     => '\ensuremath{\pitchfork}',
  883:     8918     => '\ensuremath{\lessdot}',
  884:     8919     => '\ensuremath{\gtrdot}',
  885:     8920     => '\ensuremath{\lll}',
  886:     8921     => '\ensuremath{\ggg}',
  887:     8922     => '\ensuremath{\gtreqless}',
  888:     8923     => '\ensuremath{\lesseqgtr}',
  889:     8924     => '\ensuremath{\eqslantless}',
  890:     8925     => '\ensuremath{\eqslantgtr}',
  891:     8926     => '\ensuremath{\curlyeqprec}',
  892:     8927     => '\ensuremath{\curlyeqsucc}',
  893:     8928     => '\ensuremath{\not\preccurlyeq}',
  894:     8929     => '\ensuremath{\not\succcurlyeq}',
  895:     8930     => '\ensuremath{\not\sqsupseteq}',
  896:     8931     => '\ensuremath{\not\sqsubseteq}',
  897:     8938     => '\ensuremath{\not\vartriangleleft}',
  898:     8939     => '\ensuremath{\not\vartriangleright}',
  899:     8940     => '\ensuremath{\not\trianglelefteq}',
  900:     8941     => '\ensuremath{\not\trianglerighteq}',
  901:     8942     => '\ensuremath{\vdots}',
  902:     8960     => '\ensuremath{\varnothing}',
  903:     'lceil'  => '\ensuremath{\lceil}',
  904:     8968     => '\ensuremath{\lceil}',
  905:     'rceil'  => '\ensuremath{\rceil}',
  906:     8969     => '\ensuremath{\rceil}',
  907:     'lfloor' => '\ensuremath{\lfloor}',
  908:     8970     => '\ensuremath{\lfloor}',
  909:     'rfloor' => '\ensuremath{\rfloor}',
  910:     8971     => '\ensuremath{\rfloor}',
  911:     'lang'   => '\ensuremath{\langle}',
  912:     9001     => '\ensuremath{\langle}',
  913:     'rang'   => '\ensuremath{\rangle}',
  914:     9002     => '\ensuremath{\rangle}',
  915:     'loz'    => '\ensuremath{\lozenge}',
  916:     9674     => '\ensuremath{\lozenge}',
  917:     'spades' => '\ensuremath{\spadesuit}',
  918:     9824     => '\ensuremath{\spadesuit}',
  919:     9825     => '\ensuremath{\heartsuit}',
  920:     9826     => '\ensuremath{\diamondsuit}',
  921:     'clubs'  => '\ensuremath{\clubsuit}',
  922:     9827     => '\ensuremath{\clubsuit}',
  923:     'diams'  => '\ensuremath{\blacklozenge}',
  924:     9830     => '\ensuremath{\blacklozenge}'
  925:     
  926: );
  927: 
  928: #  There are some named entities that don't have a good
  929: #  latex equivalent, these are converted to utf-8 via this table
  930: #  of entity name -> unicode number.
  931: 
  932: my  %utf_table = (
  933:     'THORN'  => 222,
  934:     'thorn'  => 254,
  935:     'eth'    => 240,
  936:     'hearts' => 9829
  937: );
  938: 
  939: # 
  940: #  Convert a numerical entity (that does not exist in our hash)
  941: #  to its UTF-8 equivalent representation.
  942: #  This allows us to support, to some extent, any entity for which
  943: #  dvipdf can find a gylph (given that LaTeX is now UTF-8 clean).
  944: #
  945: # Parameters:
  946: #   unicode  - The unicode for the character.  This is assumed to
  947: #              be a decimal value
  948: # Returns:
  949: #   The UTF-8 equiavalent of the value.
  950: #
  951: sub entity_to_utf8 {
  952:     my ($unicode) = @_;
  953:     my $result =  pack("U", $unicode);
  954:     return $result;
  955: }
  956: 
  957: 
  958: #
  959: #  Convert an entity to the corresponding LateX if possible.
  960: #  If not possible, and the entity is numeric,
  961: #  the entity is treated like a Unicode character and converted
  962: #  to UTF-8 which should display as long as dvipdf can find the
  963: #  appropriate glyph.
  964: #
  965: #  The entity is assumed to have already had the 
  966: #  &# ;  or & ; removed
  967: #
  968: # Parameters:
  969: #   entity    - Name of entity to convert.
  970: # Returns:
  971: #  One of the following:
  972: #   - Latex string that produces the entity.
  973: #   - UTF-8 equivalent of a numeric entity for which we don't have a latex string.
  974: #   - ' ' for text entities for which there's no latex equivalent.
  975: #
  976: sub entity_to_latex {
  977:     my ($entity) = @_;
  978: 
  979:     # Try to look up the entity (text or numeric) in the hash:
  980: 
  981: 
  982:     my $latex = $entities{"$entity"};
  983:     if (defined $latex) {
  984: 	return $latex;
  985:     }
  986:     # If the text is purely numeric we can do the UTF-8 conversion:
  987:     # Otherwise there are a few textual entities that don't have good latex
  988:     # which can be converted to unicode:
  989:     #
  990:     if ($entity =~ /^\d+$/) {
  991: 	return &entity_to_utf8($entity);
  992:     } else {
  993: 	my $result = $utf_table{"$entity"};
  994: 	if (defined $result) {
  995: 	    return &entity_to_utf8($result);
  996: 	}
  997:     }
  998:     #  Can't do the conversion`< ...
  999: 
 1000:     return " ";
 1001: }
 1002: 
 1003: #
 1004: #  Convert all the entities in a string.
 1005: #  We locate all the entities, pass them into entity_to_latex and 
 1006: #  and replace occurences in the input string.
 1007: #  The assumption is that there are few entities in any string/document
 1008: #  so this looping is not too bad.  The advantage of looping vs. regexping is
 1009: #  that we now can use lookup tables for the translation in entity_to_latex above.
 1010: #
 1011: # Parameters:
 1012: #   input   - Input string/document
 1013: # Returns
 1014: #   input with entities replaced by latexable stuff (UTF-8 encodings or
 1015: #   latex control strings to produce the entity.
 1016: #
 1017: #
 1018: sub replace_entities {
 1019:     my ($input)  = @_;
 1020:     my $start;
 1021:     my $end;
 1022:     my $entity;
 1023:     my $latex;
 1024:     
 1025:     # First the &#nnn; entities:
 1026: 
 1027:     while ($input =~ /(&\#\d+;)/) {
 1028: 	($start) = @-;
 1029: 	($end)   = @+;
 1030: 	$entity  = substr($input, $start+2, $end-$start-3);
 1031: 	$latex = &entity_to_latex($entity);
 1032: 	substr($input, $start, $end-$start) = $latex;
 1033:     }
 1034:     # Now the &text; entites;
 1035:     
 1036:     while ($input =~/(&\w+;)/) {
 1037: 	($start) = @-;
 1038: 	($end)   = @+;
 1039: 	$entity   = substr($input, $start+1, $end-$start-2);
 1040: 	$latex    = &entity_to_latex($entity);
 1041: 	substr($input, $start, $end-$start) = $latex;
 1042: 	
 1043:    }
 1044:     return $input;
 1045: }
 1046: 
 1047: 1; 
 1048: 
 1049: __END__

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