Bug in `dviread.py'

Hello all,

I believe I have found a bug in matplotlib's `dviread.py' file.

I am running Ubuntu 10.10 x86_64 and Sage 4.6.1, which includes
matplotlib 1.0.0. Also I have TeX Live 2010 installed (full install
from the web installer).

It is important to note that the issue to be described *does not occur*
when TeX Live 2009 from the Ubuntu repositories is installed instead of
TeX Live 2010.

The issue also occurs with matplotlib 1.0.1.

When trying to save a matplotlib figure as a PDF with `text.usetex =
True' in `matplotlibrc', at some point the `PsfontsMap' function in
`dviread.py' attempts to parse TeX Live 2010's `pdftex.map' file and fails.

Other people are having the same problem. See the following two links
for more information:

http://groups.google.com/group/sage-support/browse_thread/thread/dd4a97c3e06e831f
(see second post)
http://article.gmane.org/gmane.comp.python.matplotlib.general/26110

Here is a minimal test case to demonstrate:

ยทยทยท

----------------------------------------------------------------------

Sage Version 4.6.1, Release Date: 2011-01-11 |
Type notebook() for the GUI, and license() for information. |

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

/home/michael/<ipython console> in <module>()

/opt/local/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()

/opt/local/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):

/opt/local/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:
sage:

Here is some debug information (the last two lines may be relevant):

$HOME=/home/michael
CONFIGDIR=/home/michael/.sage//matplotlib-1.0.0
matplotlib data path
/opt/local/sage/local/lib/python2.6/site-packages/matplotlib/mpl-data
loaded rc file
/opt/local/sage/local/lib/python2.6/site-packages/matplotlib/mpl-data/matplotlibrc
matplotlib version 1.0.0
verbose.level debug
interactive is False
units is False
platform is linux2
loaded modules: ['numpy.lib._iotools', 'xml.sax.urlparse', 'distutils',
'numpy.lib.npyio', 'matplotlib.errno', 'matplotlib.matplotlib',
'_bisect', 'subprocess', 'gc', 'matplotlib.tempfile',
'distutils.sysconfig', 'ctypes._endian', 'encodings.encodings',
'matplotlib.colors', 'numpy.core.numerictypes', 'numpy.testing.sys',
'numpy.core.info', 'xml', 'numpy.fft.types', 'numpy.ma.cPickle',
'struct', 'numpy.matrixlib.defmatrix', 'numpy.random.info', 'tempfile',
'numpy.compat.types', 'base64', 'numpy.linalg', 'matplotlib.threading',
'numpy.core.machar', 'numpy.testing.types', 'numpy.testing',
'collections', 'numpy.polynomial.sys', 'numpy.core.umath',
'distutils.types', 'numpy.testing.operator', 'numpy.lib.numpy',
'numpy.core.scalarmath', 'numpy.ma.sys', 'zipimport', 'string',
'matplotlib.subprocess', 'numpy.testing.os', 'matplotlib.locale',
'numpy.lib.arraysetops', 'numpy.testing.unittest', 'numpy.lib.math',
'encodings.utf_8', 'matplotlib.__future__', 'ssl', 'numpy.testing.re',
'itertools', 'numpy.version', 'numpy.lib.re', 'distutils.re',
'numpy.matrixlib.sys', 'ctypes.os', 'numpy.core.os',
'numpy.lib.type_check', 'numpy.compat.sys', 'numpy.lib.__builtin__',
'signal', 'numpy.lib.types', 'numpy.lib._datasource', 'random',
'numpy.ma.extras', 'numpy.fft.fftpack_lite', 'matplotlib.cbook',
'ctypes.ctypes', 'xml.sax.xmlreader', 'numpy.polynomial.string',
'distutils.version', 'cStringIO', 'numpy.polynomial', 'numpy.numpy',
'matplotlib.StringIO', 'locale', 'numpy.add_newdocs',
'numpy.core.getlimits', 'xml.sax.saxutils', 'numpy.lib.sys',
'encodings', 'numpy.ma.itertools', 'array', 'StringIO', 'abc',
'numpy.matrixlib', 'numpy.ctypes', 'numpy.testing.decorators',
'matplotlib.warnings', 'rfc822', 'matplotlib.string', 'urllib',
'matplotlib.sys', 're', 'numpy.lib._compiled_base', 'threading', 'new',
'numpy.random.mtrand', 'urllib2', 'matplotlib.cPickle', 'math',
'numpy.fft.helper', 'fcntl', 'numpy.ma.warnings', 'matplotlib.numpy',
'UserDict', 'numpy.lib.function_base', 'distutils.os', 'matplotlib',
'numpy.fft.numpy', 'xml.sax.codecs', 'exceptions', 'numpy.lib.info',
'ctypes', 'numpy.lib.warnings', 'ctypes.struct', 'codecs',
'numpy.core._sort', 'numpy.os', '_functools', '_locale',
'numpy.__builtin__', 'matplotlib.sre_constants', 'matplotlib.os',
'thread', 'numpy.lib.ufunclike', 'numpy.core.memmap', 'traceback',
'numpy.testing.warnings', 'weakref', 'numpy.core._internal',
'numpy.compat._inspect', 'numpy.linalg.lapack_lite', 'numpy.ma',
'distutils.sys', 'os', 'marshal', 'numpy.lib.itertools', '__future__',
'matplotlib.copy', 'xml.sax.types', 'matplotlib.traceback', '_sre',
'unittest', 'numpy.core.sys', 'numpy.random', 'numpy.linalg.numpy',
'__builtin__', 'numpy.lib.twodim_base', 'numpy.ma.core',
'matplotlib.re', 'numpy.core.cPickle', 'operator',
'numpy.polynomial.polytemplate', 'numpy.core.arrayprint',
'distutils.string', 'numpy.lib.arrayterator', 'select',
'ctypes._ctypes', 'ctypes.sys', 'matplotlib.datetime', 'posixpath',
'numpy.lib.financial', 'numpy.core.multiarray', 'errno', '_socket',
'binascii', 'sre_constants', 'datetime', 'numpy.core.shape_base',
'functools', 'xml.sax.handler', 'os.path', 'numpy.core.function_base',
'numpy.compat.py3k', 'numpy.lib.stride_tricks', 'numpy.core.numpy',
'numpy', '_warnings', 'numpy.polynomial.chebyshev', 'matplotlib.types',
'xml.sax.os', 'cPickle', 'encodings.__builtin__',
'numpy.polynomial.warnings', 'matplotlib.xml', 'matplotlib.new',
'_codecs', 'numpy.lib.operator', 'numpy.polynomial.polynomial',
'numpy.__config__', '_collections', 'matplotlib.pyparsing', 'httplib',
'numpy.ma.numpy', 'copy', 'numpy.core.re', '_struct',
'numpy.core.fromnumeric', 'hashlib', 'numpy.ctypeslib', 'keyword',
'numpy.lib.scimath', 'numpy.fft', 'numpy.lib', 'bisect',
'numpy.random.numpy', 'matplotlib.urllib2', 'matplotlib.random',
'numpy.polynomial.__future__', 'posix', 'encodings.aliases',
'matplotlib.fontconfig_pattern', 'fnmatch', 'sre_parse', 'pickle',
'numpy.core.ctypes', 'mimetools', 'distutils.distutils', 'copy_reg',
'sre_compile', 'xml.sax', 'numpy.fft.fftpack', '_random', '_ctypes',
'numpy.lib.__future__', 'site', 'numpy.lib.polynomial', 'numpy.compat',
'numpy._import_tools', '__main__', 'numpy.fft.info',
'numpy.core.records', 'shutil', 'numpy.lib.cPickle', 'numpy.sys',
'matplotlib.weakref', 'xml.sax.urllib', 'numpy.core._dotblas',
'numpy.testing.traceback', 'strop', 'numpy.testing.numpytest',
'numpy.polynomial.numpy', 'numpy.core.numeric', 'numpy.linalg.info',
'encodings.codecs', '_abcoll', 'numpy.core', 'matplotlib.rcsetup',
'matplotlib.time', 'xml.sax._exceptions', 'genericpath', 'stat', '_ssl',
'numpy.lib.index_tricks', 'numpy.testing.utils', 'warnings',
'numpy.lib.utils', 'numpy.core.defchararray',
'numpy.polynomial.polyutils', 'numpy.lib.shape_base',
'numpy.core.types', 'textwrap', 'sys', '_hashlib',
'numpy.core.warnings', 'socket', 'numpy.core.__builtin__',
'xml.sax.sys', 'numpy.lib.format', 'numpy.lib.os',
'numpy.testing.nosetester', 'types', 'numpy.lib.shutil',
'matplotlib.distutils', '_weakref', 'distutils.errors',
'numpy.matrixlib.numpy', 'urlparse', 'linecache', 'matplotlib.shutil',
'numpy.lib.cStringIO', 'time', 'numpy.linalg.linalg', 'numpy.testing.numpy']
find_tex_file(pdftex.map): ['kpsewhich', 'pdftex.map']
find_tex_file result:
/usr/local/texlive/2010/texmf-var/fonts/map/pdftex/updmap/pdftex.map

Please let me know if there's anything more I may do to help fix
whatever is going awry here.

-Michael