Commits

Georg Brandl  committed 8250822

#393: Fix the usage of Unicode characters in mathematic formulas when using the ``pngmath`` extension.

  • Participants
  • Parent commits 70d8841

Comments (0)

Files changed (2)

 Release 0.6.6 (in development)
 ==============================
 
+* #393: Fix the usage of Unicode characters in mathematic formulas
+  when using the ``pngmath`` extension.
+
 * #404: Make ``\and`` work properly in the author field of the
   ``latex_documents`` setting.
 

File sphinx/ext/pngmath.py

 """
 
 import re
+import codecs
 import shutil
 import tempfile
 import posixpath
 
 DOC_HEAD = r'''
 \documentclass[12pt]{article}
-\usepackage[utf8]{inputenc}
+\usepackage[utf8x]{inputenc}
 \usepackage{amsmath}
 \usepackage{amsthm}
 \usepackage{amssymb}
 
     latex = DOC_HEAD + self.builder.config.pngmath_latex_preamble
     latex += (use_preview and DOC_BODY_PREVIEW or DOC_BODY) % math
-    if isinstance(latex, unicode):
-        latex = latex.encode('utf-8')
 
     # use only one tempdir per build -- the use of a directory is cleaner
     # than using temporary files, since we can clean up everything at once
     else:
         tempdir = self.builder._mathpng_tempdir
 
-    tf = open(path.join(tempdir, 'math.tex'), 'w')
+    tf = codecs.open(path.join(tempdir, 'math.tex'), 'w', 'utf-8')
     tf.write(latex)
     tf.close()
 
     try:
         fname, depth = render_math(self, '$'+node['latex']+'$')
     except MathExtError, exc:
-        sm = nodes.system_message(str(exc), type='WARNING', level=2,
+        msg = unicode(str(exc), 'utf-8', 'replace')
+        sm = nodes.system_message(msg, type='WARNING', level=2,
                                   backrefs=[], source=node['latex'])
         sm.walkabout(self)
         self.builder.warn('display latex %r: ' % node['latex'] + str(exc))