Issue with SageTeX's sageplot functionality

177 views
Skip to first unread message

Michael Anselmi

unread,
Feb 6, 2011, 12:17:48 AM2/6/11
to sage-support
Hello all. I would like to inform you of an issue I'm having with
SageTeX's sageplot functionality, and I'm hoping you can help me
resolve the issue. This is my first time posting in sage-support, let
alone in any Google group or newsgroup-like setting. Hopefully I'm
doing this right. :)

When generating a plot with SageTeX's sageplot command, I would like
all text in the plot to be processed by LaTeX by default. I've read
that this can be done by changing the appropriate setting in Sage's
`matplotlibrc' file. So I copied `matplotlibrc' from
$SAGE_ROOT/local/lib/python2.6/site-packages/matplotlib/mpl-data/
matplotlibrc
to
$DOT_SAGE/matplotlib-1.0.0/matplotlibrc
and changed line 131 of the $SAGE_ROOT copy of `matplotlibrc' from
#text.usetex : False
to
text.usetex : True
According to matplotlib's documentation, this is the recommended way
to modify matplotlib's default behavior.

However, when running sage on an auto-generated .sage file after this
change, I receive the following output:


Processing Sage code for test.tex...
Code block begin...end
Initializing plots directory
Plot 0

**** Error in Sage code on line 21 of test.tex! Traceback follows.
Traceback (most recent call last):
File "test.py", line 25, in <module>
_st_.plot(_sage_const_0 , format='notprovided', _p_=figure)
File "/opt/local/sage/local/lib/python2.6/site-packages/sagetex.py",
line 145, in plot
_p_.save(filename=plotfilename, **kwargs)
File "/opt/local/sage/local/lib/python2.6/site-packages/sage/plot/
plot.py", line 2417, in save
figure.savefig(filename,dpi=dpi,bbox_inches='tight',**options)
File "/opt/local/sage/local/lib/python2.6/site-packages/matplotlib/
figure.py", line 1084, in savefig
self.canvas.print_figure(*args, **kwargs)
File "/opt/local/sage/local/lib/python2.6/site-packages/matplotlib/
backend_bases.py", line 1852, in print_figure
**kwargs)
File "/opt/local/sage/local/lib/python2.6/site-packages/matplotlib/
backend_bases.py", line 1696, in print_pdf
return pdf.print_pdf(*args, **kwargs)
File "/opt/local/sage/local/lib/python2.6/site-packages/matplotlib/
backends/backend_pdf.py", line 2156, in print_pdf
self.figure.draw(renderer)
File "/opt/local/sage/local/lib/python2.6/site-packages/matplotlib/
artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/opt/local/sage/local/lib/python2.6/site-packages/matplotlib/
figure.py", line 798, in draw
func(*args)
File "/opt/local/sage/local/lib/python2.6/site-packages/matplotlib/
artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/opt/local/sage/local/lib/python2.6/site-packages/matplotlib/
axes.py", line 1934, in draw
a.draw(renderer)
File "/opt/local/sage/local/lib/python2.6/site-packages/matplotlib/
artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/opt/local/sage/local/lib/python2.6/site-packages/matplotlib/
axis.py", line 1017, in draw
tick.draw(renderer)
File "/opt/local/sage/local/lib/python2.6/site-packages/matplotlib/
artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/opt/local/sage/local/lib/python2.6/site-packages/matplotlib/
axis.py", line 234, in draw
self.label1.draw(renderer)
File "/opt/local/sage/local/lib/python2.6/site-packages/matplotlib/
artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/opt/local/sage/local/lib/python2.6/site-packages/matplotlib/
text.py", line 567, in draw
self._fontproperties, angle)
File "/opt/local/sage/local/lib/python2.6/site-packages/matplotlib/
backends/backend_pdf.py", line 1549, in draw_tex
psfont = self.tex_font_mapping(dvifont.texname)
File "/opt/local/sage/local/lib/python2.6/site-packages/matplotlib/
backends/backend_pdf.py", line 1365, in tex_font_mapping
dviread.PsfontsMap(dviread.find_tex_file('pdftex.map'))
File "/opt/local/sage/local/lib/python2.6/site-packages/matplotlib/
dviread.py", line 668, in __init__
self._parse(file)
File "/opt/local/sage/local/lib/python2.6/site-packages/matplotlib/
dviread.py", line 701, in _parse
self._register(words)
File "/opt/local/sage/local/lib/python2.6/site-packages/matplotlib/
dviread.py", line 727, in _register
assert encoding is None
AssertionError

**** Running Sage on test.sage failed! Fix test.tex and try again.


The EPS image file is generated and saved as expected, but the PDF
image file is nowhere to be found. It seems that SageTeX is hanging
up on generating and/or saving the PDF file.

Before editing `matplotlibrc', Sage processes the .sage file as
expected, and EPS and PDF image files are generated and saved as
expected. Here's the output:


Processing Sage code for test.tex...
Code block begin...end
Initializing plots directory
Plot 0
Sage processing complete. Run LaTeX on test.tex again.


Here's the test LaTeX file I used in both cases (`test.tex'):


\documentclass{article}
\usepackage{sagetex}

\begin{document}

\title{SageTeX sageplot test}
\author{Michael Anselmi}
\date{\today}
\maketitle

\begin{sagesilent}
f0 = lambda x:0
f1 = lambda x:x
f2 = lambda x:2-x
f = Piecewise([ [(-1,0), f0], [(0,1), f1], [(1,2), f2], [(2,3),
f0] ])
figure = plot(f)
figure.axes_labels([r'$x$', r'$f(x)$'])
\end{sagesilent}

\begin{center}
\sageplot[width=0.5\textwidth]{figure}
\end{center}

\end{document}


Here's some potentially relevant information about my system:


Operating system:
Ubuntu 10.10 (64-bit)
Sage version:
4.6.1 (compiled from source with `make test', all tests passed)
LaTeX version:
TeX Live 2010
$PATH:
[TeX Live 2010 binary dir]:$SAGE_ROOT:[the usual PATH entries]


I'd very much like to find out what's going wrong here, be it an issue
with SageTeX or external programs/libraries. Please let me know what
else I may do to help identify the problem.

-Michael

Volker Braun

unread,
Feb 6, 2011, 9:35:12 AM2/6/11
to sage-s...@googlegroups.com
Just tripped over the same issue. Seems to be a incompatibility with texlive2010. Can you file a trac ticket?

Somebody also wrote this on the matplotlib mailinglist: http://article.gmane.org/gmane.comp.python.matplotlib.general/26110

Minimal testcase:

sage: from matplotlib.dviread import *
sage: PsfontsMap(find_tex_file('pdftex.map'))
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)

/home/vbraun/Documents/24cell/<ipython console> in <module>()

/home/vbraun/Sage/sage/local/lib/python2.6/site-packages/matplotlib/dviread.pyc in __init__(self, filename)
    666         file = open(filename, 'rt')
    667         try:
--> 668             self._parse(file)
    669         finally:
    670             file.close()

/home/vbraun/Sage/sage/local/lib/python2.6/site-packages/matplotlib/dviread.pyc in _parse(self, file)
    699                 while pos < len(line) and line[pos] == ' ':
    700                     pos += 1
--> 701             self._register(words)
    702 
    703     def _register(self, words):

/home/vbraun/Sage/sage/local/lib/python2.6/site-packages/matplotlib/dviread.pyc in _register(self, words)
    725                     encoding = word[1:]
    726                 elif word.endswith('.enc'):
--> 727                     assert encoding is None
    728                     encoding = word
    729                 else:

AssertionError: 

Michael Anselmi

unread,
Feb 6, 2011, 4:03:18 PM2/6/11
to sage-support
As matplotlib does not have a bug ticketing system (at least not one I
can find), I submitted a bug report to the matplotlib-users mailing
list:

http://article.gmane.org/gmane.comp.python.matplotlib.general/26250

Michael Anselmi

unread,
Feb 7, 2011, 2:42:37 PM2/7/11
to sage-s...@googlegroups.com
Thanks to matplotlib developer Jouni Seppänen, this issue has (hopefully) been fixed upstream:

>> In the meantime, I will commit a quick workaround that just disables
>> the fonts we can't handle instead of aborting with an assert.

> Now committed in revision 8955 (1.0 maintenance branch) and 8956
> (svn trunk). Please test on your system.

Jouni's patch to `dviread.py' works for me.

Dan Drake

unread,
Feb 7, 2011, 7:27:31 PM2/7/11
to sage-s...@googlegroups.com

Putting that fix into Sage's matplotlib spkg is #10753:

http://trac.sagemath.org/sage_trac/ticket/10753

Dan

--
--- Dan Drake
----- http://mathsci.kaist.ac.kr/~drake
-------

signature.asc
Reply all
Reply to author
Forward
0 new messages