DVI (TeX Device Independent)
| Full name | DeVice Independent file format |
|---|---|
| Extensions | .dvi, .xdv (XeTeX extended DVI) |
| MIME type | application/x-dvi |
| Type | binary page description (typeset text and rules), fonts and images referenced by name |
| Starts with | F7 02 (pre opcode, DVI version 2); XeTeX .xdv files start with F7 07 |
| Specification | DVI driver standard, level 0 (PDF); the format is also documented in dvitype.web |
| Maintained by | TeX Users Group community (the format itself is frozen) |
| License | open, 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#
- Use as an intermediate step:
latex→ DVI →dvipdfmx(PDF),dvips(PostScript),dvisvgm(SVG for the web) ordvipng(PNG, e.g. formula images). - Use for fast preview while editing a large LaTeX document, with a viewer that reloads the file.
- Avoid for sending documents: the receiver needs the same fonts and image files. Send PDF.
- Avoid when you need Unicode text extraction or search: DVI stores font character codes, not text.
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:
- Preamble:
pre(247), DVI versioni(2), unit numerator and denominator, magnification, and a comment. - Pages: each starts with
bop(139) and ends witheop(140).bophas the ten TeX page counters\count0-\count9and a pointer to the previousbop, so pages form a linked list from the end. - 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, thenpost_post(249), a pointer topost, the version byte, and four to sevenDF(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#
- XDV (
.xdv, version byte 7, earlier 5 or 6): written by XeTeX; adds opcodes for OpenType/TrueType fonts referenced by file name and for positioned glyph arrays.xdvipdfmxconverts it. - pTeX/upTeX DVI (version byte 3 when vertical writing is used) adds a direction command for Japanese vertical text.
Converting DVI#
All converters come with TeX Live and MiKTeX:
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#
- The DVI Driver Standard, Level 0 (TUG DVI Driver Standards Committee, PDF): the file format and what a driver must do
- dvitype.web by Donald Knuth: the reference DVI reader, with the format described in its comments (texware on CTAN)
- dvipdfmx manual and dvips manual: the specials each driver supports
- Kpathsea: how drivers find TFM, PK and font files
- Device independent file format on Wikipedia
Software that opens DVI files#
| Software | Windows | macOS | Linux | Web | Can | Notes |
|---|---|---|---|---|---|---|
| SumatraPDF | ✓ | view | free, open source; opens .dvi when a TeX distribution is installed, by converting it to PDF | |||
| Yap | ✓ | view | the DVI viewer of MiKTeX, with forward and inverse search | |||
| xdvi | ✓ | ✓ | view | classic X11 DVI viewer, part of TeX Live | ||
| Okular | ✓ | view | KDE document viewer with a DVI backend | |||
| Evince | ✓ | view | GNOME document viewer; DVI support depends on the distribution build | |||
| dviout | ✓ | view | Windows DVI previewer, popular in Japan | |||
| dvipdfmx | ✓ | ✓ | ✓ | convert | DVI and XDV to PDF; part of TeX Live and MiKTeX | |
| dvips | ✓ | ✓ | ✓ | convert | DVI to PostScript | |
| dvisvgm | ✓ | ✓ | ✓ | convert | DVI, EPS and PDF to SVG | |
| dvipng | ✓ | ✓ | ✓ | convert | DVI to PNG or GIF, used for formula images | |
| TeX Live | ✓ | ✓ | ✓ | create, convert | TeX distribution with all the tools above | |
| MiKTeX | ✓ | ✓ | ✓ | create, view, convert | TeX distribution with Yap |
Libraries#
Few libraries read DVI; most programs convert it with the TeX Live tools instead. See all DVI libraries.
| Go | star-tex dvi |
|---|---|
| Python | Matplotlib dviread |
Related formats#
- PDF: what DVI is normally converted to, with fonts and images embedded
- PostScript: the output of
dvips - EPS: the graphics format that
latex+dvipsincludes - SVG:
dvisvgmoutput, for formulas and figures on the web