matplotlib.dviread#

A module for reading dvi files output by TeX. Several limitations makethis not (currently) useful as a general-purpose dvi preprocessor, butit is currently used by the pdf backend for processing usetex text.

Interface:

withDvi(filename,72)asdvi:# iterate over pages:forpageindvi:w,h,d=page.width,page.height,page.descentforx,y,font,glyph,widthinpage.text:fontname=font.texnamepointsize=font.size...forx,y,height,widthinpage.boxes:...
classmatplotlib.dviread.Dvi(filename,dpi)[source]#

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 underlyingfile upon exit. Pages can be read via iteration. Here is an overlysimple way to extract text without trying to detect whitespace:

>>>withmatplotlib.dviread.Dvi('input.dvi',72)asdvi:...forpageindvi:...print(''.join(chr(t.glyph)fortinpage.text))

Read the data from the file namedfilename and convertTeX's internal units to units ofdpi per inch.dpi only sets the units and does not limit the resolution.Use None to return TeX's internal units.

close()[source]#

Close the underlying file if it is open.

classmatplotlib.dviread.DviFont(scale,metrics,texname,vf)[source]#

Bases:object

Encapsulation of a font that a DVI file can refer to.

This class 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) thatarenot used for comparison.

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

Parameters:
scalefloat

Factor by which the font is scaled from its natural size.

metricsTfm | TtfMetrics

TeX font metrics for this font

texnamebytes

Name of the font as used internally in the DVI file, as an ASCIIbytestring. This is usually very different from any external fontnames;PsfontsMap can be used to find the external name of the font.

vfVf

A TeX "virtual font" file, or None if this font is not virtual.

Attributes:
texnamebytes
fnamestr

A fake filename

sizefloat

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

propertyeffects#
propertyfname#

A fake filename

classmethodfrom_luatex(scale,texname)[source]#
classmethodfrom_xetex(scale,texname,subfont,effects)[source]#
resolve_path()[source]#
propertysize#
propertysubfont#
propertywidths[source]#

[Deprecated]

Notes

Deprecated since version 3.11:

classmatplotlib.dviread.PsFont(texname,psname,effects,encoding,filename)[source]#

Bases:tuple

Create new instance of PsFont(texname, psname, effects, encoding, filename)

effects#

Alias for field number 2

encoding#

Alias for field number 3

filename#

Alias for field number 4

psname#

Alias for field number 1

texname#

Alias for field number 0

classmatplotlib.dviread.PsfontsMap(filename)[source]#

Bases:object

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

Parameters:
filenamestr or path-like

Notes

For historical reasons, TeX knows many Type-1 fonts by differentnames than the outside world. (For one thing, the names have tofit in eight characters.) Also, TeX's native fonts are not Type-1but Metafont, which is nontrivial to convert to PostScript exceptas a bitmap. While high-quality conversions to Type-1 format existand are shipped with modern TeX distributions, we need to knowwhich Type-1 fonts are the counterparts of which native fonts. Forthese reasons a mapping is needed from internal font names to fontfile names.

A texmf tree typically includes mapping files called e.g.psfonts.map,pdftex.map, ordvipdfm.map.The filepsfonts.map is used bydvips,pdftex.map bypdfTeX, anddvipdfm.mapbydvipdfm.psfonts.map might avoid embeddingthe 35 PostScript fonts (i.e., have no filename for them, as inthe Times-Bold example above), while the pdf-related files perhapsonly avoid the "Base 14" pdf fonts. But the user may haveconfigured these files differently.

Examples

>>>map=PsfontsMap(find_tex_file('pdftex.map'))>>>entry=map[b'ptmbo8r']>>>entry.texnameb'ptmbo8r'>>>entry.psnameb'Times-Bold'>>>entry.encoding'/usr/local/texlive/2008/texmf-dist/fonts/enc/dvips/base/8r.enc'>>>entry.effects{'slant': 0.16700000000000001}>>>entry.filename
classmatplotlib.dviread.TexMetrics(*,tex_width,tex_height,tex_depth)[source]#

Bases:object

Metrics of a glyph, with TeX semantics.

TeX metrics have different semantics from FreeType metrics: tex_widthcorresponds to FreeType'sadvance (i.e., including whitespace padding);tex_height tobearingY (how much the glyph extends over the baseline);tex_depth toheight-bearingY (how much the glyph extends under thebaseline, as a positive number).

tex_depth#
tex_height#
tex_width#
classmatplotlib.dviread.Tfm(filename)[source]#

Bases:object

A TeX Font Metric file.

This implementation covers only the bare minimum needed by the Dvi class.

Parameters:
filenamestr or path-like
Attributes:
checksumint

Used for verifying against the dvi file.

design_sizeint

Design size of the font (in 12.20 TeX points); unused because it isoverridden by the scale factor specified in the dvi file.

propertydepth[source]#

[Deprecated]

Notes

Deprecated since version 3.11:Use get_metrics instead.

get_metrics(idx)[source]#

Return a glyph's TexMetrics, or None if unavailable.

propertyheight[source]#

[Deprecated]

Notes

Deprecated since version 3.11:Use get_metrics instead.

propertywidth[source]#

[Deprecated]

Notes

Deprecated since version 3.11:Use get_metrics instead.

classmatplotlib.dviread.TtfMetrics(filename)[source]#

Bases:object

get_metrics(idx)[source]#
classmatplotlib.dviread.Vf(filename)[source]#

Bases:Dvi

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

Parameters:
filenamestr or path-like

Notes

The virtual font format is a derivative of dvi:http://mirrors.ctan.org/info/knuth/virtual-fontsThis class reuses some of the machinery ofDvibut replaces the_read loop and dispatch mechanism.

Examples

vf=Vf(filename)glyph=vf[code]glyph.text,glyph.boxes,glyph.width

Read the data from the file namedfilename and convertTeX's internal units to units ofdpi per inch.dpi only sets the units and does not limit the resolution.Use None to return TeX's internal units.

matplotlib.dviread.find_tex_file(filename)[source]#

Find a file in the texmf tree usingkpathsea.

The kpathsea library, provided by most existing TeX distributions, bothon Unix-like systems and on Windows (MikTeX), is invoked via a long-livedluatex process if luatex is installed, or via kpsewhich otherwise.

Parameters:
filenamestr or path-like
Raises:
FileNotFoundError

If the file is not found.