summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgrubert <grubert@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2007-02-27 15:04:28 +0000
committergrubert <grubert@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2007-02-27 15:04:28 +0000
commit9ea3523ada23ac7a903fb5017d3546def760239e (patch)
treeca82e23cf44d3c5650ad8b94f32ceb679c408c45
parenta8edf353974ecde6c0f70d2c19fa0c5303fef935 (diff)
downloaddocutils-9ea3523ada23ac7a903fb5017d3546def760239e.tar.gz
Put ensuremath around some latin1 chars.plugins@4951
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@4951 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
-rw-r--r--HISTORY.txt1
-rw-r--r--docutils/writers/latex2e/__init__.py12
2 files changed, 13 insertions, 0 deletions
diff --git a/HISTORY.txt b/HISTORY.txt
index c1c0178d6..111ff38cf 100644
--- a/HISTORY.txt
+++ b/HISTORY.txt
@@ -109,6 +109,7 @@ Changes Since 0.4
* docutils/writers/latex2e/__init__.py:
+ - Put ensuremath around some latin1 chars.
- Set ``usepackage[utf8x]{inputenc}`` for utf-8.
- New option ``--use-bibtex=style,db1,db2``.
- New option ``--reference-label`` to allow usage of LaTeX ref for
diff --git a/docutils/writers/latex2e/__init__.py b/docutils/writers/latex2e/__init__.py
index e643d77c6..7f7ef3570 100644
--- a/docutils/writers/latex2e/__init__.py
+++ b/docutils/writers/latex2e/__init__.py
@@ -823,6 +823,17 @@ class LaTeXTranslator(nodes.NodeVisitor):
text = text.replace(uchar,self.latex_equivalents[uchar])
return text
+ def ensure_math(self, text):
+ if not self.__dict__.has_key('ensure_math_re'):
+ chars = {
+ # lnot,pm,twosuperior,threesuperior,mu,onesuperior,times,div
+ 'latin1' : '\xac\xb1\xb2\xb3\xb5\xb9\xd7\xf7' ,
+ # also latin5 and latin9
+ }
+ self.ensure_math_re = re.compile('([%s])' % chars['latin1'])
+ text = self.ensure_math_re.sub(r'\\ensuremath{\1}', text)
+ return text
+
def encode(self, text):
"""
Encode special characters (``# $ % & ~ _ ^ \ { }``) in `text` & return
@@ -910,6 +921,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
text = text.replace(' ', '~')
if self.latex_encoding != 'utf8':
text = self.unicode_to_latex(text)
+ text = self.ensure_math(text)
return text
def attval(self, text,