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

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

Latexmk is a command-line tool used to compile LaTeX source files into finished documents. It automates the process of running LaTeX multiple times when necessary to ensure correct typesetting. Latexmk is a powerful tool that helps streamline the LaTeX document compilation process.

Use case 1: Compile a DVI document from every source

Code:

latexmk

Motivation: Compiling a DVI document from every source is a common use case when working with LaTeX. By simply running the latexmk command without any arguments, Latexmk will automatically search for all the LaTeX source files in the current working directory and compile them into DVI documents.

Explanation: The latexmk command is used without any additional arguments, which tells Latexmk to compile all LaTeX source files found in the current directory. It internally invokes the LaTeX compiler to generate the DVI output.

Example output: If you have three LaTeX source files named file1.tex, file2.tex, and file3.tex in the current working directory, running latexmk will compile all of them into DVI documents.

Use case 2: Compile a DVI document from a specific source file

Code:

latexmk source.tex

Motivation: Sometimes, you may only want to compile a specific LaTeX source file. In such cases, you can pass the file name (including the extension) as an argument to the latexmk command.

Explanation: In this use case, the latexmk command is followed by the name of the specific source file, such as source.tex. This tells Latexmk to compile only that particular file into a DVI document.

Example output: Running latexmk source.tex will compile the specified source.tex file into a DVI document.

Use case 3: Compile a PDF document

Code:

latexmk -pdf source.tex

Motivation: PDF is a widely used format for distributing documents. You may prefer to compile your LaTeX source files directly into PDF documents rather than DVI. The -pdf option allows you to do this.

Explanation: The -pdf option is specified after the latexmk command, followed by the name of the source file (source.tex). This tells Latexmk to generate a PDF document instead of the default DVI document.

Example output: Running latexmk -pdf source.tex will compile the specified source.tex file into a PDF document.

Use case 4: Force the generation of a document even if there are errors

Code:

latexmk -f source.tex

Motivation: By default, Latexmk will stop compilation if it encounters errors in the LaTeX source file. However, there may be cases when you want to force the generation of a document even if there are errors. The -f option allows you to do this.

Explanation: The -f option is used after the latexmk command, followed by the name of the source file (source.tex). It tells Latexmk to forcibly generate a document regardless of any errors encountered during compilation.

Example output: Running latexmk -f source.tex will compile the specified source.tex file, even if there are errors present. However, it is important to note that the resulting document may not be error-free.

Use case 5: Clean up temporary TEX files created for a specific TEX file

Code:

latexmk -c source.tex

Motivation: LaTeX compilation can generate temporary files with the .aux, .log, and other extensions. These files can take up disk space and clutter the working directory. The -c option allows you to clean up these temporary files for a specific LaTeX source file.

Explanation: The -c option is provided after the latexmk command, followed by the name of the source file (source.tex). It tells Latexmk to remove all the temporary files generated during the compilation process for that specific source file.

Example output: Running latexmk -c source.tex will delete all the temporary files (e.g., .aux, .log, etc.) generated during the compilation of the specified source.tex file.

Use case 6: Clean up all temporary TEX files in the current directory

Code:

latexmk -c

Motivation: In some cases, you may want to clean up all temporary TEX files in the current directory, regardless of the source files. This can help to keep the working directory clean and free up disk space.

Explanation: In this use case, the -c option is used without specifying any source file. It tells Latexmk to remove all the temporary files generated during the compilation process for all LaTeX source files found in the current directory.

Example output: Running latexmk -c will delete all the temporary files (e.g., .aux, .log, etc.) generated during the compilation of all LaTeX source files in the current directory.

Conclusion:

Latexmk is a versatile command-line tool for compiling LaTeX source files. It provides a wide range of options and flexibility to streamline the document compilation process. Whether you need to compile a specific source file, generate PDF documents, or clean up temporary files, Latexmk has you covered. By understanding and utilizing these different use cases, you can enhance your LaTeX workflow and save time on document compilation.

Related Posts

Using the `ed` Command (with examples)

Using the `ed` Command (with examples)

1. Starting an interactive editor session with an empty document To start an interactive editor session with an empty document, simply enter the command ed in your terminal.

Read More
Managing JavaScript projects with Lerna (with examples)

Managing JavaScript projects with Lerna (with examples)

Lerna is a powerful tool for managing JavaScript projects with multiple packages.

Read More
How to use the command xzmore (with examples)

How to use the command xzmore (with examples)

The xzmore command is used to display text from xz or lzma compressed files.

Read More