matplotlib

Travis-CI:

Table Of Contents

Related Topics

This Page

dviread

matplotlib.dviread

A 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:

with Dvi(filename, 72) as dvi:
    # iterate over pages:
    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.Box(x, y, height, width)

Bases: tuple

Create new instance of Box(x, y, height, width)

height

Alias for field number 2

width

Alias for field number 3

x

Alias for field number 0

y

Alias for field number 1

class matplotlib.dviread.Dvi(filename, dpi)

Bases: object

A reader for a dvi (“device-independent”) file, as produced by TeX. The current implementation can only iterate through pages in order, and does not even attempt to verify the postamble.

This class can be used as a context manager to close the underlying file upon exit. Pages can be read via iteration. Here is an overly simple way to extract text without trying to detect whitespace:

>>> with matplotlib.dviread.Dvi('input.dvi', 72) as dvi:
>>>     for page in dvi:
>>>         print ''.join(unichr(t.glyph) for t in page.text)

Read the data from the file named filename and convert TeX’s internal units to units of dpi per inch. dpi only sets the units and does not limit the resolution. Use None to return TeX’s internal units.

close()

Close the underlying file if it is open.

dispatch = functools.partial(<function _dispatch>, [<function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char_immediate>, <function Dvi._set_char>, <function Dvi._set_char>, <function Dvi._set_char>, <function Dvi._set_char>, <function Dvi._set_rule>, <function Dvi._put_char>, <function Dvi._put_char>, <function Dvi._put_char>, <function Dvi._put_char>, <function Dvi._put_rule>, <function Dvi._nop>, <function Dvi._bop>, <function Dvi._eop>, <function Dvi._push>, <function Dvi._pop>, <function Dvi._right>, <function Dvi._right>, <function Dvi._right>, <function Dvi._right>, <function Dvi._right_w>, <function Dvi._right_w>, <function Dvi._right_w>, <function Dvi._right_w>, <function Dvi._right_w>, <function Dvi._right_x>, <function Dvi._right_x>, <function Dvi._right_x>, <function Dvi._right_x>, <function Dvi._right_x>, <function Dvi._down>, <function Dvi._down>, <function Dvi._down>, <function Dvi._down>, <function Dvi._down_y>, <function Dvi._down_y>, <function Dvi._down_y>, <function Dvi._down_y>, <function Dvi._down_y>, <function Dvi._down_z>, <function Dvi._down_z>, <function Dvi._down_z>, <function Dvi._down_z>, <function Dvi._down_z>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num_immediate>, <function Dvi._fnt_num>, <function Dvi._fnt_num>, <function Dvi._fnt_num>, <function Dvi._fnt_num>, <function Dvi._xxx>, <function Dvi._xxx>, <function Dvi._xxx>, <function Dvi._xxx>, <function Dvi._fnt_def>, <function Dvi._fnt_def>, <function Dvi._fnt_def>, <function Dvi._fnt_def>, <function Dvi._pre>, <function Dvi._post>, <function Dvi._post_post>, <function Dvi._malformed>, <function Dvi._malformed>, <function Dvi._malformed>, <function Dvi._malformed>, <function Dvi._malformed>, <function Dvi._malformed>])
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.Page(text, boxes, height, width, descent)

Bases: tuple

Create new instance of Page(text, boxes, height, width, descent)

boxes

Alias for field number 1

descent

Alias for field number 4

height

Alias for field number 2

text

Alias for field number 0

width

Alias for field number 3

matplotlib.dviread.PsFont

alias of Font

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.Text(x, y, font, glyph, width)

Bases: tuple

Create new instance of Text(x, y, font, glyph, width)

font

Alias for field number 2

glyph

Alias for field number 3

width

Alias for field number 4

x

Alias for field number 0

y

Alias for field number 1

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. It’s also available as part of MikTeX, a popular distribution on Windows.

See also

Kpathsea documentation
The library that kpsewhich is part of.
matplotlib.dviread.ord(x)