You are reading an old version of the documentation (v2.0.1). For the latest version see


Table Of Contents

Related Topics

This Page



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.


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 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 that are not used for comparison.

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


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 of the font in Adobe points, converted from the slightly smaller TeX points.


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

class matplotlib.dviread.Encoding(filename)

Bases: object

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

Usage (subject to change):

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

Bases: object

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

>>> map = PsfontsMap(find_tex_file(''))
>>> entry = map['ptmbo8r']
>>> entry.texname
>>> entry.psname
>>> entry.encoding
>>> 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.,, is used by dvips, by pdfTeX, and by dvipdfm. 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.


Used for verifying against the dvi file.


Design size of the font (in what units?)


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 of each character.


Depth of each character.

class matplotlib.dviread.Vf(filename)

Bases: matplotlib.dviread.Dvi

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


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.