Skip to main content

1.3.2 Creating and viewing output, debugging

1.3.2.1 One Command for LaTeX, helpers, viewers, and printing​

If you have typed some text and want to run LaTeX (or TeX, or other programs—see below) on it, type C-c C-c. If applicable, you will be asked whether you want to save changes, and which program you want to invoke. In many cases, the choice that AUCTeX suggests will be just what you want: first latex, then a viewer. If a latex run produces or changes input files for makeindex, the next suggestion will be to run that program, and AUCTeX knows that you need to run latex again afterwards—the same holds for BibTeX.

When no processor invocation is necessary anymore, AUCTeX will suggest to run a viewer, or you can chose to create a PostScript file using dvips, or to directly print it.

Actually, there is another command which comes in handy to compile documents: type C-c C-a (TeX-command-run-all) and AUCTeX will compile the document for you until it is ready and then run the viewer. This is the same as issuing repeatedly C-c C-c and letting AUCTeX guess the next command to run.

At this place, a warning needs to be given: First, although AUCTeX is really good in detecting the standard situations when an additional latex run is necessary, it cannot detect it always. Second, the creation of PostScript files or direct printing currently only works when your output file is a DVI file, not a PDF file.

Ah, you didn’t know you can do both? That brings us to the next topic.

1.3.2.2 Choosing an output format​

From a LaTeX file, you can produce DVI output, or a PDF file directly via pdflatex. You can switch on source specials for easier navigation in the output file, or tell latex to stop after an error (usually \noninteractive is used, to allow you to detect all errors in a single run).

These options are controlled by toggles, the keystrokes should be easy to memorize:

C-c C-t C-p​

This command toggles between DVI and PDF output

C-c C-t C-i​

toggles interactive mode

C-c C-t C-s​

toggles source specials support

C-c C-t C-o​

toggles usage of Omega/lambda.

There is also another possibility: compile the document with tex (or latex) and then convert the resulting DVI file to PDF using dvips–ps2pdf sequence. If you want to go by this route, when TeX-PDF-via-dvips-ps2pdf variable is non-nil, AUCTeX will suggest you to run the appropriate command when you type C-C C-c. For details, see Processor Options.

1.3.2.3 Debugging LaTeX​

When AUCTeX runs a program, it creates an output buffer in which it displays the output of the command. If there is a syntactical error in your file, latex will not complete successfully. AUCTeX will tell you that, and you can get to the place where the first error occured by pressing C-c ` (the last character is a backtick). The view will be split in two windows, the output will be displayed in the lower buffer, and both buffers will be centered around the place where the error ocurred. You can then try to fix it in the document buffer, and use the same keystrokes to get to the next error. This procedure may be repeated until all errors have been dealt with. By pressing C-c C-w (TeX-toggle-debug-boxes) you can toggle whether AUCTeX should notify you of overfull and underfull boxes in addition to regular errors.

Issue M-x TeX-error-overview RET to see a nicely formatted list of all errors and warnings reported by the compiler.

If a command got stuck in a seemingly infinite loop, or you want to stop execution for other reasons, you can use C-c C-k (for “kill"). Similar to C-l, which centers the buffer you are in around your current position, C-c C-l centers the output buffer so that the last lines added at the bottom become visible.

1.3.2.4 Running LaTeX on parts of your document​

If you want to check how some part of your text looks like, and do not want to wait until the whole document has been typeset, then mark it as a region and use C-c C-r. It behaves just like C-c C-c, but it only uses the document preamble and the region you marked.

If you are using \include or \input to structure your document, try C-c C-b while you are editing one of the included files. It will run latex only on the current buffer, using the preamble from the master file.