OK, here's the patch! :)
Andrew Straw wrote:
Hi All (esp. Darren),
The attached patch adds unicode support for LaTeX. Given the recent
discussion about adding preambles, I thought I'd run it past here first.
Anyone opposed if I check this in?
Note that I specifically added the rcParam text.latex.unicode to enable
this and a default False value to turn this off by default. I hope this
prevents breakage for folks who don't have the ucs and inputenc latex
packages installed while allowing unicode for those of us that do.
-Andrew
-
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
___
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
Index: CHANGELOG
===
--- CHANGELOG (revision 3278)
+++ CHANGELOG (working copy)
@@ -1,3 +1,7 @@
+2007-05-17 Added LaTeX unicode support. Enable with the
+ 'text.latex.unicode' rcParam. This requires the ucs and
+ inputenc LaTeX packages. - ADS
+
2007-04-23 Fixed some problems with polar -- dded general polygon
clipping to clip the lines a nd grids to the polar axes.
Added support for set_rmax to easily change the maximum
Index: lib/matplotlib/__init__.py
===
--- lib/matplotlib/__init__.py (revision 3278)
+++ lib/matplotlib/__init__.py (working copy)
@@ -775,6 +775,7 @@
# text props
'text.color': ['k', validate_color], # black
'text.usetex' : [False, validate_usetex],
+'text.latex.unicode': [False, validate_bool],
'text.latex.preamble': ['', validate_latex_preamble],
'text.dvipnghack': [False, validate_bool],
'text.fontstyle': ['normal', str],
Index: lib/matplotlib/texmanager.py
===
--- lib/matplotlib/texmanager.py (revision 3278)
+++ lib/matplotlib/texmanager.py (working copy)
@@ -165,7 +165,8 @@
def get_basefile(self, tex, fontsize, dpi=None):
s = tex + self._fontconfig + ('%f'%fontsize) + self.get_custom_preamble()
if dpi: s += ('%s'%dpi)
-return os.path.join(self.texcache, md5.md5(s).hexdigest())
+bytes = unicode(s).encode('utf-8') # make sure hash is consistent for all strings, regardless of encoding
+return os.path.join(self.texcache, md5.md5(bytes).hexdigest())
def get_font_config(self):
return self._fontconfig
@@ -197,17 +198,35 @@
'monospace' : r'{\ttfamily %s}'}.get(self.font_family,
r'{\rmfamily %s}')
tex = fontcmd % tex
+
+if rcParams['text.latex.unicode']:
+unicode_preamble = \usepackage{ucs}
+\usepackage[utf8x]{inputenc}
+else:
+unicode_preamble = ''
s = r\documentclass{article}
%s
%s
+%s
\usepackage[papersize={72in,72in}, body={70in,70in}, margin={1in,1in}]{geometry}
\pagestyle{empty}
\begin{document}
\fontsize{%f}{%f}%s
\end{document}
- % (self._font_preamble, custom_preamble, fontsize, fontsize*1.25, tex)
-fh.write(s)
+ % (self._font_preamble, custom_preamble, unicode_preamble,
+ fontsize, fontsize*1.25, tex)
+if rcParams['text.latex.unicode']:
+fh.write(s.encode('utf8'))
+else:
+try:
+fh.write(s)
+except UnicodeEncodeError, err:
+verbose.report(You are using unicode and latex, but have
+ not enabled the matplotlib 'text.latex.unicode'
+ rcParam., 'helpful')
+raise
+
fh.close()
return texfile
Index: lib/matplotlib/backends/backend_ps.py
===
--- lib/matplotlib/backends/backend_ps.py (revision 3278)
+++ lib/matplotlib/backends/backend_ps.py (working copy)
@@ -1272,9 +1272,16 @@
if orientation=='landscape': angle = 90
else: angle = 0
-print latexh, r\documentclass{article}
+if rcParams['text.latex.unicode']:
+unicode_preamble = \usepackage{ucs}
+\usepackage[utf8x]{inputenc}
+else:
+unicode_preamble = ''
+
+s = r\documentclass{article}
%s
%s
+%s
\usepackage[dvips, papersize={%sin,%sin}, body={%sin,%sin}, margin={0in,0in}]{geometry}
\usepackage{psfrag}
\usepackage[dvips]{graphicx}
@@ -1288,8 +1295,21 @@
\includegraphics*[angle=%s]{%s}
\end{figure}
\end{document}
-% (font_preamble, custom_preamble, paperWidth, paperHeight, paperWidth,