buildframework/helium/external/python/lib/2.5/Sphinx-0.5.1-py2.5.egg/sphinx/util/texescape.py
changeset 179 d8ac696cc51f
parent 1 be27ed110b50
child 180 e02a83d4c571
child 592 3215c239276a
equal deleted inserted replaced
1:be27ed110b50 179:d8ac696cc51f
     1 # -*- coding: utf-8 -*-
       
     2 """
       
     3     sphinx.util.texescape
       
     4     ~~~~~~~~~~~~~~~~~~~~~
       
     5 
       
     6     TeX escaping helper.
       
     7 
       
     8     :copyright: 2008 by Georg Brandl.
       
     9     :license: BSD.
       
    10 """
       
    11 
       
    12 tex_replacements = [
       
    13     # map TeX special chars
       
    14     (u'$', ur'\$'),
       
    15     (u'%', ur'\%'),
       
    16     (u'&', ur'\&'),
       
    17     (u'#', ur'\#'),
       
    18     (u'_', ur'\_'),
       
    19     (u'{', ur'\{'),
       
    20     (u'}', ur'\}'),
       
    21     (u'[', ur'{[}'),
       
    22     (u']', ur'{]}'),
       
    23     (u'`', ur'{}`'),
       
    24     (u'\\',ur'\textbackslash{}'),
       
    25     (u'~', ur'\textasciitilde{}'),
       
    26     (u'<', ur'\textless{}'),
       
    27     (u'>', ur'\textgreater{}'),
       
    28     (u'^', ur'\textasciicircum{}'),
       
    29     # map special Unicode characters to TeX commands
       
    30     (u'¶', ur'\P{}'),
       
    31     (u'§', ur'\S{}'),
       
    32     (u'€', ur'\texteuro{}'),
       
    33     (u'∞', ur'\(\infty\)'),
       
    34     (u'±', ur'\(\pm\)'),
       
    35     (u'→', ur'\(\rightarrow\)'),
       
    36     (u'‣', ur'\(\rightarrow\)'),
       
    37     # used to separate -- in options
       
    38     (u'', ur'{}'),
       
    39     # map some special Unicode characters to similar ASCII ones
       
    40     (u'─', ur'-'),
       
    41     (u'⎽', ur'\_'),
       
    42     (u'╲', ur'\textbackslash{}'),
       
    43     (u'│', ur'|'),
       
    44     (u'ℯ', ur'e'),
       
    45     (u'ⅈ', ur'i'),
       
    46     (u'₁', ur'1'),
       
    47     (u'₂', ur'2'),
       
    48     # map Greek alphabet
       
    49     (u'α', ur'\(\alpha\)'),
       
    50     (u'β', ur'\(\beta\)'),
       
    51     (u'γ', ur'\(\gamma\)'),
       
    52     (u'δ', ur'\(\delta\)'),
       
    53     (u'ε', ur'\(\epsilon\)'),
       
    54     (u'ζ', ur'\(\zeta\)'),
       
    55     (u'η', ur'\(\eta\)'),
       
    56     (u'θ', ur'\(\theta\)'),
       
    57     (u'ι', ur'\(\iota\)'),
       
    58     (u'κ', ur'\(\kappa\)'),
       
    59     (u'λ', ur'\(\lambda\)'),
       
    60     (u'μ', ur'\(\mu\)'),
       
    61     (u'ν', ur'\(\nu\)'),
       
    62     (u'ξ', ur'\(\xi\)'),
       
    63     (u'ο', ur'o'),
       
    64     (u'π', ur'\(\pi\)'),
       
    65     (u'ρ', ur'\(\rho\)'),
       
    66     (u'σ', ur'\(\sigma\)'),
       
    67     (u'τ', ur'\(\tau\)'),
       
    68     (u'υ', u'\\(\\upsilon\\)'),
       
    69     (u'φ', ur'\(\phi\)'),
       
    70     (u'χ', ur'\(\chi\)'),
       
    71     (u'ψ', ur'\(\psi\)'),
       
    72     (u'ω', ur'\(\omega\)'),
       
    73     (u'Α', ur'A'),
       
    74     (u'Β', ur'B'),
       
    75     (u'Γ', ur'\(\Gamma\)'),
       
    76     (u'Δ', ur'\(\Delta\)'),
       
    77     (u'Ε', ur'E'),
       
    78     (u'Ζ', ur'Z'),
       
    79     (u'Η', ur'H'),
       
    80     (u'Θ', ur'\(\Theta\)'),
       
    81     (u'Ι', ur'I'),
       
    82     (u'Κ', ur'K'),
       
    83     (u'Λ', ur'\(\Lambda\)'),
       
    84     (u'Μ', ur'M'),
       
    85     (u'Ν', ur'N'),
       
    86     (u'Ξ', ur'\(\Xi\)'),
       
    87     (u'Ο', ur'O'),
       
    88     (u'Π', ur'\(\Pi\)'),
       
    89     (u'Ρ', ur'P'),
       
    90     (u'Σ', ur'\(\Sigma\)'),
       
    91     (u'Τ', ur'T'),
       
    92     (u'Υ', u'\\(\\Upsilon\\)'),
       
    93     (u'Φ', ur'\(\Phi\)'),
       
    94     (u'Χ', ur'X'),
       
    95     (u'Ψ', ur'\(\Psi\)'),
       
    96     (u'Ω', ur'\(\Omega\)'),
       
    97     (u'Ω', ur'\(\Omega\)'),
       
    98 ]
       
    99 
       
   100 tex_escape_map = {}
       
   101 tex_hl_escape_map = {}
       
   102 _new_cmd_chars = {ord(u'\\'): u'@', ord(u'{'): u'[', ord(u'}'): u']'}
       
   103 
       
   104 def init():
       
   105     for a, b in tex_replacements:
       
   106         tex_escape_map[ord(a)] = b
       
   107 
       
   108     for a, b in tex_replacements:
       
   109         if a in u'[]{}\\': continue
       
   110         tex_hl_escape_map[ord(a)] = b.translate(_new_cmd_chars)