LaTeX - Compile a DVI Document (with examples)
Use Case 1: Compile a DVI document
Code:
latex source.tex
Motivation:
When working with LaTeX, it is common to write documents using plain text editors and then compile them into a readable format. Compiling a DVI (Device Independent) document from LaTeX source files allows us to convert the raw text into a format that can be easily viewed and printed.
Explanation:
The latex
command is used to compile a DVI document from LaTeX source files. In this use case, source.tex
refers to the LaTeX source file that we want to compile.
Example Output:
Running the above code will generate a source.dvi
file, which contains the compiled document in DVI format. This file can then be converted to other formats, such as PDF, using additional tools like dvipdf
or dvips
.
Use Case 2: Compile a DVI document, specifying an output directory
Code:
latex -output-directory=path/to/directory source.tex
Motivation:
By default, the latex
command places the generated DVI file in the same directory as the source file. However, it is often useful to specify a different output directory to organize generated files or when the source file is located in a read-only directory.
Explanation:
The -output-directory
option followed by the desired output directory path is used to specify where the generated DVI file should be placed. In this example, path/to/directory
represents the target directory where the DVI file will be saved. The source.tex
argument is the path to the LaTeX source file.
Example Output:
When executing the above command, the resulting DVI file source.dvi
will be saved in the specified output directory (path/to/directory
). This allows easy organization and separation of generated files from the source files.
Use Case 3: Compile a DVI document, exiting on each error
Code:
latex -halt-on-error source.tex
Motivation:
When developing LaTeX documents, it can be beneficial to stop the compilation process immediately upon encountering any errors. This allows quick identification and resolution of issues, ensuring the resulting document is error-free.
Explanation:
The -halt-on-error
option is used to instruct the latex
command to terminate the compilation process as soon as it encounters an error. In this example, source.tex
refers to the LaTeX source file being compiled.
Example Output:
If any errors are encountered during the compilation process, the latex
command will stop and display the error message along with relevant information. This helps in identifying the cause of the error and fixing it promptly, improving the quality of the final document.