How to use the command 'tex' (with examples)

How to use the command 'tex' (with examples)

The tex command is a powerful tool used to compile documents written in the TeX typesetting system into Device Independent (DVI) files. TeX is renowned for its precision in formatting complex mathematical and scientific documents. The tex command serves a range of purposes, from simple document compilation to more advanced error management. Below, we explore various use cases of the tex command to help you understand how to compile TeX documents efficiently.

Use case 1: Compile a DVI document

Code:

tex source.tex

Motivation:

The most fundamental use of the tex command is to compile a TeX source file into a DVI file. This is the basic operation that transforms your meticulously created TeX document into a format that can be previewed and printed. When you have a TeX file ready and you want to see the output in a DVI viewer or convert it into another format (like PDF or PS), this is the command you will use.

Explanation:

  • tex: This is the command used to invoke the TeX typesetting system for processing documents.
  • source.tex: This is the placeholder for the TeX source file you intend to compile. You need to replace source.tex with the actual name of your file.

Example output:

Upon running the command, TeX processes source.tex and generates a source.dvi file. If the compilation succeeds without errors, the terminal will display messages indicating page numbers and any warnings or notes generated during the process. The output might resemble something like:

This is TeX, Version 3.14159 (your_tex_distributon_path)
(./source.tex [1] [2] [3] )
Output written on source.dvi (3 pages, 1234 bytes).
Transcript written on source.log.

Use case 2: Compile a DVI document, specifying an output directory

Code:

tex -output-directory=path/to/directory source.tex

Motivation:

In some scenarios, you may want or need to organize your compiled files in a specific directory, especially when working on large projects with multiple source files. This use case can help keep your project directory tidy by directing all generated output files to a dedicated folder.

Explanation:

  • tex: Invokes the TeX system for processing.
  • -output-directory=path/to/directory: This option allows you to specify the directory where the output files (such as .dvi and .log) will be stored. Replace path/to/directory with your desired output path.
  • source.tex: The TeX source file you intend to compile.

Example output:

The command will compile the source.tex file, but instead of placing the resulting files in the current working directory, they will be stored in path/to/directory. A typical output might be:

This is TeX, Version 3.14159 (your_tex_distributon_path)
(./source.tex [1] [2] [3] )
Output written on path/to/directory/source.dvi (3 pages, 1234 bytes).
Transcript written on path/to/directory/source.log.

Use case 3: Compile a DVI document, exiting on each error

Code:

tex -halt-on-error source.tex

Motivation:

When working with complex TeX documents, occasional errors are inevitable. The default behavior of TeX is to try to recover from errors and continue compiling. However, in scripts or automated environments, this might not be desirable. Halting on errors ensures that you are immediately alerted to issues that must be fixed, preventing the generation of incomplete or incorrect output.

Explanation:

  • tex: Initiates the TeX typesetting process.
  • -halt-on-error: This flag tells TeX to stop processing as soon as an error is encountered, rather than attempting to continue. This option is particularly helpful in catching mistakes early in the compilation process.
  • source.tex: Represents the source file you are compiling.

Example output:

If there is an error in source.tex, the program will halt immediately and will not produce a DVI file. The error message might look like:

This is TeX, Version 3.14159 (your_tex_distributon_path)
(./source.tex
! Undefined control sequence.
l.5 \unknowncommand
? 

Conclusion:

The tex command offers versatile functionalities that cater to different needs, whether for simple compilation or for managing errors efficiently. By understanding these use cases, you can leverage the full potential of TeX to create beautifully formatted documents while maintaining control over the compilation process.

Related Posts

How to use the command 'dtc' (with examples)

How to use the command 'dtc' (with examples)

The Device Tree Compiler (dtc) is a powerful tool used to recompile device trees between different formats.

Read More
How to use the command 'rpicam-raw' (with examples)

How to use the command 'rpicam-raw' (with examples)

The rpicam-raw command is an invaluable tool for anyone working with Raspberry Pi cameras.

Read More
Mastering the Command 'killall' (with examples)

Mastering the Command 'killall' (with examples)

The killall command is a versatile tool used to manage processes in various operating systems, primarily Unix and Linux.

Read More