How to use the command 'tex' (with examples)
This article provides examples of how to use the ’tex’ command to compile a DVI document from TeX source files.
Command Description:
The ’tex’ command is used to compile a TeX document and generate a DVI (Device Independent) file. TeX is a typesetting system designed for producing professional-quality documents, particularly those that contain a lot of mathematical and scientific symbols. The ’tex’ command processes the TeX source files and produces a DVI file that can be further processed or printed.
Use case 1: Compile a DVI document
Code:
tex source.tex
Motivation:
The first use case demonstrates the basic usage of the ’tex’ command to compile a DVI document from a TeX source file. This is the most common use case when working with TeX documents.
Explanation:
- ’tex’: The name of the command used to compile the TeX document.
- ‘source.tex’: The path to the TeX source file to be compiled.
Example Output:
If the compilation is successful, the ’tex’ command will generate a DVI file named ‘source.dvi’ in the same directory as the source file. There will be no additional output or confirmation message if the compilation completes without errors.
Use case 2: Compile a DVI document, specifying an output directory
Code:
tex -output-directory=path/to/directory source.tex
Motivation:
This use case is helpful when you want to specify a different output directory for the DVI file. It can be useful for organizing your project files or separating the output files from the source files.
Explanation:
- ’tex’: The name of the command used to compile the TeX document.
- ‘-output-directory=path/to/directory’: This option tells the ’tex’ command to place the generated DVI file in the specified directory instead of the current working directory.
- ‘source.tex’: The path to the TeX source file to be compiled.
Example Output:
If the compilation is successful, the ’tex’ command will generate a DVI file named ‘source.dvi’ in the specified output directory.
Use case 3: Compile a DVI document, exiting on each error
Code:
tex -halt-on-error source.tex
Motivation:
In some cases, it is beneficial to immediately terminate the compilation process if an error is encountered instead of continuing to process the document. This use case allows you to halt the compilation on the first error.
Explanation:
- ’tex’: The name of the command used to compile the TeX document.
- ‘-halt-on-error’: This option tells the ’tex’ command to exit immediately when it encounters any error during the compilation process. This is useful when you want to quickly identify and fix errors in your TeX source files.
- ‘source.tex’: The path to the TeX source file to be compiled.
Example Output:
If the ’tex’ command encounters an error, it will display an error message and exit immediately without generating a DVI file. The error message will provide information about the nature of the error encountered, allowing you to investigate and resolve the issue.
Conclusion:
The ’tex’ command is a powerful tool for compiling TeX documents and generating DVI files. It provides various options to customize the compilation process, such as specifying output directories or terminating the compilation on errors. By understanding and utilizing these options, you can efficiently process your TeX source files and generate professional-quality documents.