All formats

DVI (TeX Device Independent)

Full nameDeVice Independent file format
Extensions.dvi, .xdv (XeTeX extended DVI)
MIME typeapplication/x-dvi
Typebinary page description (typeset text and rules), fonts and images referenced by name
Starts withF7 02 (pre opcode, DVI version 2); XeTeX .xdv files start with F7 07
SpecificationDVI driver standard, level 0 (PDF); the format is also documented in dvitype.web
Maintained byTeX Users Group community (the format itself is frozen)
Licenseopen, free to implement

DVI is the output of classic TeX: tex and latex (in DVI mode), uplatex, ptex and lualatex --output-format=dvi. A DVI file lists, page by page, which character of which font goes where, plus black rectangles (rules). It doesn’t contain the fonts or any images; those are found on the system when the file is displayed or converted. That makes DVI files small and fast to produce, but they only display correctly on a machine with a TeX installation.

Today DVI is mostly an intermediate format: latex writes DVI, then dvipdfmx or dvips converts it to PDF or PostScript. Some workflows still use it because it compiles faster than pdflatex, and because latex + dvips handles PostScript-based packages (PSTricks). For sharing, convert to PDF.

When to use DVI#

File structure#

A DVI file is a sequence of one-byte commands (opcodes), each followed by its parameters. Numbers are big-endian; distances are signed, in DVI units defined in the preamble (for TeX, scaled points: 1 pt = 65536 sp, 72.27 pt = 1 inch). The interpreter keeps a current position (h, v), four spacing registers (w, x, y, z), a stack for them, and a current font.

The file has 3 parts:

  1. Preamble: pre (247), DVI version i (2), unit numerator and denominator, magnification, and a comment.
  2. Pages: each starts with bop (139) and ends with eop (140). bop has the ten TeX page counters \count0-\count9 and a pointer to the previous bop, so pages form a linked list from the end.
  3. Postamble: post (248) with a pointer to the last page, maximum page height and width, stack depth and page count, then all font definitions again, then post_post (249), a pointer to post, the version byte, and four to seven DF (223) bytes.

A reader can start at the end: skip the DF bytes, read the pointer to post, and get the page count and fonts without reading every page.

F7 02                     pre, DVI version 2
01 83 92 C0               num = 25400000
1C 3B 00 00               den = 473628672   (units are scaled points)
00 00 03 E8               mag = 1000 (no magnification)
1B                        comment length 27
20 54 65 58 20 6F 75 74   " TeX output 2026.11.05:1200"
...
8B                        bop (first page)

Opcodes#

Opcode Name Meaning
0-127 set_char_0 … set_char_127 typeset character n of the current font and move right by its width
128-131 set1-set4 typeset a character with a 1-4 byte code and move right
132 set_rule draw a filled rectangle (height, width) and move right
133-136 put1-put4 typeset a character without moving
137 put_rule draw a rectangle without moving
138 nop no operation
139 bop beginning of page: 10 counters + pointer to the previous bop
140 eop end of page
141, 142 push, pop save and restore h, v, w, x, y, z
143-146 right1-right4 move right
147-151 w0-w4 move right by w (or set w and move)
152-156 x0-x4 the same with x
157-160 down1-down4 move down
161-165 y0-y4 move down by y
166-170 z0-z4 move down by z
171-234 fnt_num_0 … fnt_num_63 select font 0-63
235-238 fnt1-fnt4 select a font with a larger number
239-242 xxx1-xxx4 \special: bytes passed to the driver
243-246 fnt_def1-fnt_def4 define a font: number, checksum, scale, design size, name
247 pre preamble
248 post postamble
249 post_post end of the postamble
250-255 undefined in DVI; XeTeX’s XDV uses 251-254 for native fonts and glyph arrays

Fonts#

A font definition names a TeX font (for example cmr10) and its size. The DVI file doesn’t contain the font: a driver reads the font metrics from cmr10.tfm, then finds the glyph shapes, either a PK bitmap font or an outline (Type 1, OpenType) font through map files such as pdftex.map. TeX installations look these files up with the kpathsea library. On a system without TeX the file can’t be rendered.

Specials#

\special{...} puts arbitrary bytes into the file with xxx commands. Drivers use them for everything TeX itself can’t do: color (color push rgb 1 0 0), included graphics (PSfile=fig.eps, pdf:image), hyperlinks, landscape pages, PostScript code (ps:). Specials are driver-specific: a DVI file made for dvips may lose graphics in dvipdfmx and the other way round. Included images stay external files.

XDV and other variants#

Converting DVI#

All converters come with TeX Live and MiKTeX:

Shell
dvipdfmx paper.dvi                    # to PDF (paper.pdf)
dvips paper.dvi -o paper.ps           # to PostScript
dvisvgm --no-fonts --page=1- paper.dvi   # each page to SVG, glyphs as paths
dvipng -D 300 -T tight formula.dvi    # each page to PNG at 300 dpi, cropped

dvitype (TeX Live) prints every command of a DVI file in readable form; dviasm turns DVI into an editable text form and back.

Specifications and documentation#

Software that opens DVI files#

SoftwareWindowsmacOSLinuxWebCanNotes
SumatraPDF✓viewfree, open source; opens .dvi when a TeX distribution is installed, by converting it to PDF
Yap✓viewthe DVI viewer of MiKTeX, with forward and inverse search
xdvi✓✓viewclassic X11 DVI viewer, part of TeX Live
Okular✓viewKDE document viewer with a DVI backend
Evince✓viewGNOME document viewer; DVI support depends on the distribution build
dviout✓viewWindows DVI previewer, popular in Japan
dvipdfmx✓✓✓convertDVI and XDV to PDF; part of TeX Live and MiKTeX
dvips✓✓✓convertDVI to PostScript
dvisvgm✓✓✓convertDVI, EPS and PDF to SVG
dvipng✓✓✓convertDVI to PNG or GIF, used for formula images
TeX Live✓✓✓create, convertTeX distribution with all the tools above
MiKTeX✓✓✓create, view, convertTeX distribution with Yap

Libraries#

Few libraries read DVI; most programs convert it with the TeX Live tools instead. See all DVI libraries.

Gostar-tex dvi
PythonMatplotlib dviread