[Python-checkins] r65625 - in doctools/branches/0.4.x/sphinx: builder.py highlighting.py latexwriter.py util/__init__.py util/texescape.py
georg.brandl
python-checkins at python.org
Sun Aug 10 13:25:41 CEST 2008
Author: georg.brandl
Date: Sun Aug 10 13:25:41 2008
New Revision: 65625
Log:
Make tex escapes a module.
Added:
doctools/branches/0.4.x/sphinx/util/texescape.py (contents, props changed)
Modified:
doctools/branches/0.4.x/sphinx/builder.py
doctools/branches/0.4.x/sphinx/highlighting.py
doctools/branches/0.4.x/sphinx/latexwriter.py
doctools/branches/0.4.x/sphinx/util/__init__.py
Modified: doctools/branches/0.4.x/sphinx/builder.py
==============================================================================
--- doctools/branches/0.4.x/sphinx/builder.py (original)
+++ doctools/branches/0.4.x/sphinx/builder.py Sun Aug 10 13:25:41 2008
@@ -25,7 +25,7 @@
from docutils.readers.doctree import Reader as DoctreeReader
from sphinx import addnodes
-from sphinx.util import ensuredir, relative_uri, SEP, os_path
+from sphinx.util import ensuredir, relative_uri, SEP, os_path, texescape
from sphinx.htmlhelp import build_hhx
from sphinx.htmlwriter import HTMLWriter, HTMLTranslator, SmartyPantsHTMLTranslator
from sphinx.textwriter import TextWriter
@@ -809,6 +809,7 @@
def init(self):
self.docnames = []
self.document_data = []
+ texescape.init()
def get_outdated_docs(self):
return 'all documents' # for now
Modified: doctools/branches/0.4.x/sphinx/highlighting.py
==============================================================================
--- doctools/branches/0.4.x/sphinx/highlighting.py (original)
+++ doctools/branches/0.4.x/sphinx/highlighting.py Sun Aug 10 13:25:41 2008
@@ -14,7 +14,7 @@
import re
import parser
-from sphinx.util import tex_hl_escape_map
+from sphinx.util.texescape import tex_hl_escape_map
try:
import pygments
Modified: doctools/branches/0.4.x/sphinx/latexwriter.py
==============================================================================
--- doctools/branches/0.4.x/sphinx/latexwriter.py (original)
+++ doctools/branches/0.4.x/sphinx/latexwriter.py Sun Aug 10 13:25:41 2008
@@ -21,7 +21,7 @@
from sphinx import addnodes
from sphinx import highlighting
-from sphinx.util import tex_escape_map
+from sphinx.util.texescape import tex_escape_map
from sphinx.util.smartypants import educateQuotesLatex
HEADER = r'''%% Generated by Sphinx.
Modified: doctools/branches/0.4.x/sphinx/util/__init__.py
==============================================================================
--- doctools/branches/0.4.x/sphinx/util/__init__.py (original)
+++ doctools/branches/0.4.x/sphinx/util/__init__.py Sun Aug 10 13:25:41 2008
@@ -260,100 +260,3 @@
def make_filename(string):
return no_fn_re.sub('', string)
-
-
-_tex_replacements = [
- # map TeX special chars
- (u'$', ur'\$'),
- (u'%', ur'\%'),
- (u'&', ur'\&'),
- (u'#', ur'\#'),
- (u'_', ur'\_'),
- (u'{', ur'\{'),
- (u'}', ur'\}'),
- (u'[', ur'{[}'),
- (u']', ur'{]}'),
- (u'\\',ur'\textbackslash{}'),
- (u'~', ur'\textasciitilde{}'),
- (u'<', ur'\textless{}'),
- (u'>', ur'\textgreater{}'),
- (u'^', ur'\textasciicircum{}'),
- # map special Unicode characters to TeX commands
- (u'¶', ur'\P{}'),
- (u'§', ur'\S{}'),
- (u'€', ur'\texteuro{}'),
- (u'∞', ur'\(\infty\)'),
- (u'±', ur'\(\pm\)'),
- (u'→', ur'\(\rightarrow\)'),
- (u'‣', ur'\(\rightarrow\)'),
- # map some special Unicode characters to similar ASCII ones
- (u'─', ur'-'),
- (u'⎽', ur'\_'),
- (u'╲', ur'\textbackslash{}'),
- (u'│', ur'|'),
- (u'ℯ', ur'e'),
- (u'ⅈ', ur'i'),
- (u'₁', ur'1'),
- (u'₂', ur'2'),
- # map Greek alphabet
- (u'α', ur'\(\alpha\)'),
- (u'β', ur'\(\beta\)'),
- (u'γ', ur'\(\gamma\)'),
- (u'δ', ur'\(\delta\)'),
- (u'ε', ur'\(\epsilon\)'),
- (u'ζ', ur'\(\zeta\)'),
- (u'η', ur'\(\eta\)'),
- (u'θ', ur'\(\theta\)'),
- (u'ι', ur'\(\iota\)'),
- (u'κ', ur'\(\kappa\)'),
- (u'λ', ur'\(\lambda\)'),
- (u'μ', ur'\(\mu\)'),
- (u'ν', ur'\(\nu\)'),
- (u'ξ', ur'\(\xi\)'),
- (u'ο', ur'o'),
- (u'π', ur'\(\pi\)'),
- (u'ρ', ur'\(\rho\)'),
- (u'σ', ur'\(\sigma\)'),
- (u'τ', ur'\(\tau\)'),
- (u'υ', u'\\(\\upsilon\\)'),
- (u'φ', ur'\(\phi\)'),
- (u'χ', ur'\(\chi\)'),
- (u'ψ', ur'\(\psi\)'),
- (u'ω', ur'\(\omega\)'),
- (u'Α', ur'A'),
- (u'Β', ur'B'),
- (u'Γ', ur'\(\Gamma\)'),
- (u'Δ', ur'\(\Delta\)'),
- (u'Ε', ur'E'),
- (u'Ζ', ur'Z'),
- (u'Η', ur'H'),
- (u'Θ', ur'\(\Theta\)'),
- (u'Ι', ur'I'),
- (u'Κ', ur'K'),
- (u'Λ', ur'\(\Lambda\)'),
- (u'Μ', ur'M'),
- (u'Ν', ur'N'),
- (u'Ξ', ur'\(\Xi\)'),
- (u'Ο', ur'O'),
- (u'Π', ur'\(\Pi\)'),
- (u'Ρ', ur'P'),
- (u'Σ', ur'\(\Sigma\)'),
- (u'Τ', ur'T'),
- (u'Υ', u'\\(\\Upsilon\\)'),
- (u'Φ', ur'\(\Phi\)'),
- (u'Χ', ur'X'),
- (u'Ψ', ur'\(\Psi\)'),
- (u'Ω', ur'\(\Omega\)'),
- (u'Ω', ur'\(\Omega\)'),
-]
-
-tex_escape_map = {}
-for a, b in _tex_replacements:
- tex_escape_map[ord(a)] = b
-
-_new_cmd_chars = {ord(u'\\'): u'@', ord(u'{'): u'[', ord(u'}'): u']'}
-
-tex_hl_escape_map = {}
-for a, b in _tex_replacements:
- if a in u'[]{}\\': continue
- tex_hl_escape_map[ord(a)] = b.translate(_new_cmd_chars)
Added: doctools/branches/0.4.x/sphinx/util/texescape.py
==============================================================================
--- (empty file)
+++ doctools/branches/0.4.x/sphinx/util/texescape.py Sun Aug 10 13:25:41 2008
@@ -0,0 +1,107 @@
+# -*- coding: utf-8 -*-
+"""
+ sphinx.util.texescape
+ ~~~~~~~~~~~~~~~~~~~~~
+
+ TeX escaping helper.
+
+ :copyright: 2008 by Georg Brandl.
+ :license: BSD.
+"""
+
+tex_replacements = [
+ # map TeX special chars
+ (u'$', ur'\$'),
+ (u'%', ur'\%'),
+ (u'&', ur'\&'),
+ (u'#', ur'\#'),
+ (u'_', ur'\_'),
+ (u'{', ur'\{'),
+ (u'}', ur'\}'),
+ (u'[', ur'{[}'),
+ (u']', ur'{]}'),
+ (u'\\',ur'\textbackslash{}'),
+ (u'~', ur'\textasciitilde{}'),
+ (u'<', ur'\textless{}'),
+ (u'>', ur'\textgreater{}'),
+ (u'^', ur'\textasciicircum{}'),
+ # map special Unicode characters to TeX commands
+ (u'¶', ur'\P{}'),
+ (u'§', ur'\S{}'),
+ (u'€', ur'\texteuro{}'),
+ (u'∞', ur'\(\infty\)'),
+ (u'±', ur'\(\pm\)'),
+ (u'→', ur'\(\rightarrow\)'),
+ (u'‣', ur'\(\rightarrow\)'),
+ # map some special Unicode characters to similar ASCII ones
+ (u'─', ur'-'),
+ (u'⎽', ur'\_'),
+ (u'╲', ur'\textbackslash{}'),
+ (u'│', ur'|'),
+ (u'ℯ', ur'e'),
+ (u'ⅈ', ur'i'),
+ (u'₁', ur'1'),
+ (u'₂', ur'2'),
+ # map Greek alphabet
+ (u'α', ur'\(\alpha\)'),
+ (u'β', ur'\(\beta\)'),
+ (u'γ', ur'\(\gamma\)'),
+ (u'δ', ur'\(\delta\)'),
+ (u'ε', ur'\(\epsilon\)'),
+ (u'ζ', ur'\(\zeta\)'),
+ (u'η', ur'\(\eta\)'),
+ (u'θ', ur'\(\theta\)'),
+ (u'ι', ur'\(\iota\)'),
+ (u'κ', ur'\(\kappa\)'),
+ (u'λ', ur'\(\lambda\)'),
+ (u'μ', ur'\(\mu\)'),
+ (u'ν', ur'\(\nu\)'),
+ (u'ξ', ur'\(\xi\)'),
+ (u'ο', ur'o'),
+ (u'π', ur'\(\pi\)'),
+ (u'ρ', ur'\(\rho\)'),
+ (u'σ', ur'\(\sigma\)'),
+ (u'τ', ur'\(\tau\)'),
+ (u'υ', u'\\(\\upsilon\\)'),
+ (u'φ', ur'\(\phi\)'),
+ (u'χ', ur'\(\chi\)'),
+ (u'ψ', ur'\(\psi\)'),
+ (u'ω', ur'\(\omega\)'),
+ (u'Α', ur'A'),
+ (u'Β', ur'B'),
+ (u'Γ', ur'\(\Gamma\)'),
+ (u'Δ', ur'\(\Delta\)'),
+ (u'Ε', ur'E'),
+ (u'Ζ', ur'Z'),
+ (u'Η', ur'H'),
+ (u'Θ', ur'\(\Theta\)'),
+ (u'Ι', ur'I'),
+ (u'Κ', ur'K'),
+ (u'Λ', ur'\(\Lambda\)'),
+ (u'Μ', ur'M'),
+ (u'Ν', ur'N'),
+ (u'Ξ', ur'\(\Xi\)'),
+ (u'Ο', ur'O'),
+ (u'Π', ur'\(\Pi\)'),
+ (u'Ρ', ur'P'),
+ (u'Σ', ur'\(\Sigma\)'),
+ (u'Τ', ur'T'),
+ (u'Υ', u'\\(\\Upsilon\\)'),
+ (u'Φ', ur'\(\Phi\)'),
+ (u'Χ', ur'X'),
+ (u'Ψ', ur'\(\Psi\)'),
+ (u'Ω', ur'\(\Omega\)'),
+ (u'Ω', ur'\(\Omega\)'),
+]
+
+tex_escape_map = {}
+tex_hl_escape_map = {}
+_new_cmd_chars = {ord(u'\\'): u'@', ord(u'{'): u'[', ord(u'}'): u']'}
+
+def init():
+ for a, b in tex_replacements:
+ tex_escape_map[ord(a)] = b
+
+ for a, b in tex_replacements:
+ if a in u'[]{}\\': continue
+ tex_hl_escape_map[ord(a)] = b.translate(_new_cmd_chars)
More information about the Python-checkins
mailing list