11 April 2009

Emacs as a latex environment

I use the AUCTex mode in Emacs, which has lots of useful features. Here is a mix of commands and additions that help me improve the Emacs-Latex experience:
RefTex (actually you will already use this if you use AUCTex mode), Greek Emacs input, PDFSync and Orgmode tables.

RefTex

There is much to say about reftex But I'll just show the two commands that I use regularly:
   C-c =
This will open a buffer where you can navigate through your document's toc.
This comes very handy for large projects like PhD thesis :-). With python I use something like outline mode for roughly the same purpose, but this is perfect for my latex documents.
The other shortcut I use is:
   C-c [
 
This command will ask you for your citation style

and for a regulare expression for searching your bibtex file to find the reference.

Then you can navigate through the matching references and choose the one that you want.

With a single bibtex file containing about 1000 references this feature is very handy.

Xelatex for greek input

If you are using texlive / xetex, then you have full utf-8 support built-in. Now you need a way to use it :-) If you write in a language other then english, you probably already use this feature. Just typing
    äöüß
    
instead of
    \"a\"o\"u\ss{}
    
is already good. But being able to also type:
    $αβγ = 3μm$
instead of
    $\alpha\beta\gamma = 3\mum$
    
is really a good thing, both for readability and for typing speed. Update: actually it's not that simple. But it got simpler with TexLive 2009. I have something like this in the preamble of my documents:
    \usepackage{mathspec}
    \setmainfont[Mapping=tex-text]{CMU Serif}
    \setsansfont[Mapping=tex-text]{CMU Sans Serif}
    \setmathsfont(Greek,Latin){CMU Serif}
    \setmathsfont(Digits){Neo Euler}
To insert greek characters in emacs, just type:
    C-\ greek RET
    
From then on, the
    
    C-\ 
    
will switch between greek input and your normal input.

PDFSync

Sometimes in larger documents, you want to jump directly from a line in your latex file to the corresponding line in the pdf file. With pdfsync and xpdf, this is possible (note that with TexShop the other way is also possible, but not with emacs at the moment). In you Latex file, insert the following:
    \usepackage{pdfsync}

Now just type:
    C-c C-v
and the line will be displayed in xpdf. Nice.

OrgMode Tables

The Emacs Org mode is a great mode for table editing (and other things). The table editing mode can be called separate from the complete Org mode, which is a great tool for example for Latex, where the table editing is something very unpleasant! The following work flow helps a lot, but check out the full example here for more advanced options: OrgMode Manual
Let's start with a Latex file with the comment package (the org mode table is within a comment environment, so your latex does not get messed up!):
    \documentclass{article}
    \usepackage{comment}
    \begin{document}
    Hallo!\\
    \end{document}
Then type:
    M-x orgtbl-mode
    M-x orgtbl-insert-radio-table
This will ask you for a table name, let's say: atesttable
Now the document looks like this:
    \documentclass{article}
    \usepackage{comment}
    \begin{document}
    Hallo!\\
    % BEGIN RECEIVE ORGTBL atesttable
    % END RECEIVE ORGTBL atesttable
    \begin{comment}
    #+ORGTBL: SEND atesttable orgtbl-to-latex :splice nil :skip 0
    | | |
    \end{comment}
    \end{document}
And then you can change the table using the great OrgMode capabilities! Once you have done this, type
    C-c C-c
This will update the latex table to something like this:
    \documentclass{article}
    \usepackage{comment}
    \begin{document}
    Hallo!\\
    % BEGIN RECEIVE ORGTBL atesttable
    \begin{tabular}{rll}
    Times [sec] & Names & something else \\
    \hline
    3 & John & hi \\
    4 & Elisa & ho \\
    5 & Nobody & hiho \\
     &  &  \\
    \end{tabular}
    % END RECEIVE ORGTBL atesttable
    \begin{comment}
    #+ORGTBL: SEND atesttable orgtbl-to-latex :splice nil :skip 0
    | Times [sec] | Names  | something else |
    |-------------+--------+----------------|
    |           3 | John   | hi             |
    |           4 | Elisa  | ho             |
    |           5 | Nobody | hiho           |
    |             |        |                |
    \end{comment}
    \end{document}
That's it. My current setup and usage of Emacs as a Latex IDE.
comments powered by Disqus