matplotlib

This Page

matplotlib.dviread

An experimental module for reading dvi files output by TeX. Several limitations make this not (currently) useful as a general-purpose dvi preprocessor, but it is currently used by the pdf backend for processing usetex text.

Interface:

dvi = Dvi(filename, 72)
# iterate over pages (but only one page is supported for now):
for page in dvi:
    w, h, d = page.width, page.height, page.descent
    for x,y,font,glyph,width in page.text:
        fontname = font.texname
        pointsize = font.size
        ...
    for x,y,height,width in page.boxes:
        ...
class matplotlib.dviread.Dvi(filename, dpi)

Bases: object

A dvi (“device-independent”) file, as produced by TeX. The current implementation only reads the first page and does not even attempt to verify the postamble.

Initialize the object. This takes the filename as input and opens the file; actually reading the file happens when iterating through the pages of the file.

close()

Close the underlying file if it is open.

class matplotlib.dviread.DviFont(scale, tfm, texname, vf)

Bases: object

Object that holds a font’s texname and size, supports comparison, and knows the widths of glyphs in the same units as the AFM file. There are also internal attributes (for use by dviread.py) that are not used for comparison.

The size is in Adobe points (converted from TeX points).

texname

Name of the font as used internally by TeX and friends. This is usually very different from any external font names, and dviread.PsfontsMap can be used to find the external name of the font.

size

Size of the font in Adobe points, converted from the slightly smaller TeX points.

widths

Widths of glyphs in glyph-space units, typically 1/1000ths of the point size.

size
texname
widths
class matplotlib.dviread.Encoding(filename)

Bases: object

Parses a *.enc file referenced from a psfonts.map style file. The format this class understands is a very limited subset of PostScript.

Usage (subject to change):

for name in Encoding(filename):
    whatever(name)
encoding
class matplotlib.dviread.PsfontsMap(filename)

Bases: object

A psfonts.map formatted file, mapping TeX fonts to PS fonts. Usage:

>>> map = PsfontsMap(find_tex_file('pdftex.map'))
>>> entry = map['ptmbo8r']
>>> entry.texname
'ptmbo8r'
>>> entry.psname
'Times-Bold'
>>> entry.encoding
'/usr/local/texlive/2008/texmf-dist/fonts/enc/dvips/base/8r.enc'
>>> entry.effects
{'slant': 0.16700000000000001}
>>> entry.filename

For historical reasons, TeX knows many Type-1 fonts by different names than the outside world. (For one thing, the names have to fit in eight characters.) Also, TeX’s native fonts are not Type-1 but Metafont, which is nontrivial to convert to PostScript except as a bitmap. While high-quality conversions to Type-1 format exist and are shipped with modern TeX distributions, we need to know which Type-1 fonts are the counterparts of which native fonts. For these reasons a mapping is needed from internal font names to font file names.

A texmf tree typically includes mapping files called e.g. psfonts.map, pdftex.map, dvipdfm.map. psfonts.map is used by dvips, pdftex.map by pdfTeX, and dvipdfm.map by dvipdfm. psfonts.map might avoid embedding the 35 PostScript fonts (i.e., have no filename for them, as in the Times-Bold example above), while the pdf-related files perhaps only avoid the “Base 14” pdf fonts. But the user may have configured these files differently.

class matplotlib.dviread.Tfm(filename)

Bases: object

A TeX Font Metric file. This implementation covers only the bare minimum needed by the Dvi class.

checksum

Used for verifying against the dvi file.

design_size

Design size of the font (in what units?)

width

Width of each character, needs to be scaled by the factor specified in the dvi file. This is a dict because indexing may not start from 0.

height

Height of each character.

depth

Depth of each character.

checksum
depth
design_size
height
width
class matplotlib.dviread.Vf(filename)

Bases: matplotlib.dviread.Dvi

A virtual font (*.vf file) containing subroutines for dvi files.

Usage:

vf = Vf(filename)
glyph = vf[code]
glyph.text, glyph.boxes, glyph.width
matplotlib.dviread.find_tex_file(filename, format=None)

Call kpsewhich to find a file in the texmf tree. If format is not None, it is used as the value for the --format option.

Apparently most existing TeX distributions on Unix-like systems use kpathsea. I hear MikTeX (a popular distribution on Windows) doesn’t use kpathsea, so what do we do? (TODO)

See also

Kpathsea documentation
The library that kpsewhich is part of.