Useful options for composing LaTeX documents in GNU Emacs + AUCTeX GNU Emacs, as I have said, is a powerful text editor that allows you to do everything and more. There are many functions that allow you to help you write code in many programming languages, including, of course LaTeX (although in this case as "programming language" is not entirely appropriate). One of the many reasons why Emacs is popular is its customization and expansion: there are hundreds of extensions that increase the potential of this text editor over the functions provided natively. There is (obviously) an extension for LaTeX: AUCTeX
(but is also useful for ConTeXt, docTeX, Texinfo, and plain TeX: Many of the settings that we will see will be valid for all these languages, although I usually refer only to LaTeX). is not my intention here to explain how to install Emacs nor AUCTeX (also because these packages are provided by the Most GNU / Linux, the installation is very simple if you know the operation of its own package manager), but rather explain what are the options for AUCTeX (Emacs and some of his own) that I find personally useful. I'll assume that you have at least familiar with Emacs, with the notation of the shortcuts and commands and also with AUCTeX (but sometimes remember how to perform certain operations.) Before you begin remember that you can consult the manual (in English) at AUCTeX http://www.gnu.org/software/auctex/manual/auctex.html
or directly inside Emacs with Ch idm AUCTeX RET
. For editing of much of the following AUCTeX will already be loaded. I'm not an expert in Emacs, I might sometimes say silly things, I hope you forgive me and tips are welcome (in any way I can assure you that by following this guide you do not break out the pc:-D). In AUCTeX, you can perform various tasks such as compiling, running bibtex, makeindex execution, deletion of temporary files, etc. ... using Cc Cc (followed by the command you want to use). The deletion of temporary files is performed using the list of file extensions stored in the variable LaTeX-clean-intermediate-suffixes
. Change this variable (as all variables in Emacs, of course substituting the name where appropriate) you can use the command (remember that the commands can be entered with Mx, where M is called the Meta key and can be obtained by 'ALT, or, if there is such a key, with ESC (release after pressing ESC)): customize-variable RET LaTeX-clean-intermediate-suffixes RET
To add new extensions INS
select and insert side Regexp:
's regular expression (for more information on regular expressions in Emacs, consult the manual or see Elisp in Emacs here) corresponding to the extension that you want to add. For example, I added the extensions .
tex ~ (backup files created by Emacs) and
. Run.xml
(file used to create the bibliography with the package
biblatex
) with the following regular expressions: \\. tex ~ \\. run \\.
xml To finalize the changes for future sessions, select Save
(you'll need to do the same every time you use customize-variable
).
Emacs is also concerned
indent the code correctly, including the various environments. You can set the editor in particular so that when pressed the Enter key (or, in the notation of Emacs,
with the command: customize-variable RET TeX-newline-function RET Select Value Menu and select
newline-and-indent
. You can also change the behavior of Emacs indentation in certain environments changing the variable LaTeX-indent-environment-list
, always with the command: customize-variable RET LaTeX-indent-environment-list RET
I, for example, I added the environment lstlisting
to do so did not add that Emacs automatically indents the text in this environment. To do this I selected INS, written lstlisting
beside Environment:
and after putting the check in Function:
I wrote in its space current-indentation (just as is the default for '
verbatim environment).
Emacs also allows the ' syntax highlighting of LaTeX, but in some (rare) cases may go into distress. For example, I had problems with the aforementioned environment lstlisting
as not AUCTeX 11.86 conosce bene il suo funzionamento (per esempio l'inserimento del simbolo del dollaro $
rovina tutta l'evidenziazione del documento). Per fortuna è possibile spiegargli che lo deve trattare allo stesso modo dell'ambiente verbatim
(in pratica tutto ciò che si trova all'interno di questo ambiente non viene interpretato da Emacs per quanto riguarda l'evidenziazione della sintassi) modificando la variabile LaTeX-verbatim-environments
: customize-variable RET LaTeX-verbatim-environments RET aggiungete
lstlisting
(penso che ormai avrete capito come funziona questo tipo di interfaccia di modifica delle variabili) e il gioco è fatto.
In maniera default Emacs compile documents in DVI
. If you want to set as a default PDF format
must change the value of the variable TeX-PDF-mode
:
customize-variable RET TeX-PDF-mode RET
Select
Toggle until you get to
on (non-nil)
.
If you installed a distribution of latex in a location that is immediately recognized by Emacs and AUCTeX will need to change some variables. For example, I have installed TeX Live 2010 by following this guide
of Henry Gregory and all the LaTeX files are in subfolders
/ usr/local/texlive/2010 / (where Emacs e AUCTeX normalmente non cercano). Fra le variabili che potrebbero dover essere cambiate ci sono
TeX-macro-global (contiene, ricorsivamente, le cartelle in cui AUCTeX cercherà i file di stile) e
exec-path
(contiene i percorsi in cui Emacs cerca i programmi da eseguire). La modifica di queste variabili è simile a quanto visto finora. Per la prima variabile ho aggiunto il percorso
/usr/local/texlive/2010/texmf-dist/tex/
, mentre per
exec-path ho aggiunto
/usr/local/texlive/2010/bin/i386-linux/ (su architetture diverse dal 32 bit questo percorso sarà sicuramente diverso. Controllate per bene la posizione in cui avete installato la distribuzione).
To change the program that opens the output document (be it in DVI, PDF, HTML, etc.) via
Cc Cc RET View
must change the variable TeX-view-program-selection . As usual you can customize the variable use
customize-variable RET TeX-view-program-selection RET
settings've seen so far are saved automatically
Emacs initialization file ~ /.
emacs (I recall that the tilde
~ is an abbreviation of the location of your home directory, but files that have names beginning with a dot are hidden
). All these settings can also be stored manually editing the file
. emacs (so you can do this yourself but you must know the language
Emacs Lisp). Now let's see some other useful options you set by editing the file
. emacs (this however can always be set using the interface
customize-variable). The
of AUCTeX manual suggests adding a
.
emacs the following lines:
(setq TeX-auto-save t)
(setq TeX-parse-self t) so that getting support for LaTeX packages that are used in your documents (option TeX-parse-self
performed Emacs parsing
of the document and the information will be collected in a subfolder of the directory of the revised document called
Car
. If you do not want to crowd into their own folders, you may not want to activate these two options). If you use frequently divide their LaTeX documents into multiple parts to be included in the main file with the commands \\ input or
\\ include
may be useful to add the file .
option emacs (setq-default TeX-master nil) In this way, the opening of LaTeX documents Emacs will ask what is the associated main file (which should, for example, run compilation commands). You can make sure that you open a document LaTeX Emacs spell check on the fly by adding a .
option emacs (add-hook 'TeX-mode-hook' flyspell-mode) Also, if you often use LaTeX to compose mathematical documents might be useful to add the option
(add-hook 'TeX-mode-hook' LaTeX-math-mode) that allows the rapid integration of several mathematical symbols (see manual). Finally, make sure to wrap the cursor after the insertion of a fixed number of characters per line (ovviamene Emacs is smart, does not break a word into two, wrap in so that the line appears along
than the fixed number of characters) you can add the
(add-hook 'TeX-mode-hook' turn-on-auto-fill) The number of characters line after which Emacs will start a new line is stored in the variable fill-column . Left as an exercise to find out how you change that variable (ok, I leave a clue: you can always use the usual command:-D).