Emacs with AUCTex as a LaTex IDE

My brand new goal in life is to get more proficient with teh Emacs so I can experience the juicy goodness of the elisp that people keep telling me about. So yes, this will be another Emacs post and there will probably be another one before the end of the week. But today I won’t be talking just about emacs – this is also about LaTex.

If my calculations are correct, the combination of Emacs + LaTex should have scared away roughly 60 to 80% of the readers. Those who remain either already use Emacs, use Emacs to code LaTex, or are just sticking around to tell me I should stick with Vim. And no, I’m not abandoning the good old Vim – I will probably still use it till I die. But while vim is probably the best text editor on the planet Emacs is actually a very good general purpose IDE like framework.

For example, I do most of my coding in Kile (KDE Based LaTex IDE) and TeXnicCenter (a windows based IDE). I searched long and hard for a multi platform LaTex IDE that would work for me, and I failed. Instead I found two damn good platform specific ones. Unfortunately, when I switch from the desktop to the laptop I have to switch my LaTex editing environments, key bindings and etc..

Other than that, both systems run almost identical set of software – Firefox, Thunderbird, Eclipse, Komodo Edit and Vim. And no, none of the Tex plugins for Eclipse really worked for me. They just didn’t work the way I wanted to. Eclipse is great for Java, but that’s about it.

In my search for the perfect IDE however, I completely ignored Emacs. I mean, that’s a text editor, right? What I need an IDE with like toolbars, code completion and the whole 9 yards. Am I correct?

You can put the pitchforks and torches down! I was wrong, naturally. Saying that Emacs is just a text editor is like calling iPhone just a phone. Sure, it is that, but it can also do all other things. No other text editor has a powerful programming framework that allows you endless customization at it’s core. Elisp can be used to make Emacs do just about anything, from editing text files, fetching your email, browsing the web to playing games (try doing M-x tetris and see what happens).

In and by itself it is a very decent LaTex editor with nice syntax highlighting. But it’s not an IDE yet. What you need is some of that elisp awesomeness that I mentioned above. Enter AUCTex – a nifty little package which will turn your Emacs into a awesome LaTex IDE and blow your mind. I could just sit here listing all of it’s features, but instead of doing that, I’ll simply show you my Emacs buffer with AUCTex:

AUCTex in Action

First thing you will probably see is that with AUCTex the LaTex mode will actually use helpful visual hints in addition to just regular highlights. So section headings will actually be bigger than regular text, \textbf blocks will actually render in bolface and etc.

Second striking feature is that AUCTex lets you preview headings, formulas and image inline. Yes, it will actually compile the code, and render pretty images in the buffer. You can toggle between code and image at any time by middle mousing it or using the context menu. The only LaTex toll that does that is Lyx. But Lyx is kinda funky and I never really liked their philosophy of almost-sorta-WYSIWYG.

If you look at the menus, note the LaTex and Math ones. They are chock full of functions and key bindings for auto generating code, and auto inserting code for various characters and environments.

How do I get this big bowl of awesome, you may ask. Well, if you are running Ubuntu, you are in luck – there is actually nothing simpler:

aptitude install auctex, preview-latex

Once you restart Emacs and open a tex file you should see the AUCTex environment preloaded. To get the Math menu simply drop the following line into your .emacs file:

;; Math mode for LaTex
(add-hook 'LaTeX-mode-hook 'LaTeX-math-mode)

You may also want to add the following lines if you don’t have them there already

;; mouse scrolling
(mouse-wheel-mode t)
 
;; spellcheck in LaTex mode
(add-hook `latex-mode-hook `flyspell-mode)
(add-hook `tex-mode-hook `flyspell-mode)
(add-hook `bibtex-mode-hook `flyspell-mode)
 
;; Show line-number and column-number in the mode line
(line-number-mode 1)
(column-number-mode 1)
 
;; highlight current line
(global-hl-line-mode 1)

These don’t really have anything to do with AUCTex but they do make working with Emacs easier. Naturally don’t forget your CUA Mode settings if you need them.

If you are on Windows, then installing AUCTex might be a bit more difficult. Actually, to tell you the truth, it is a major pain in the ass. This is why it will get it’s own post that will appear here another day. Needless to say, it is doable, and it works on Windows but you might actually need to *gasp* compile something.

Anyway, I think I’m sold. I think Emacs will become my main LaTex IDE from now on. At least it’ll be consistent. :)

[tags]emacs, auctex, latex, tex, cua mode, ide, vim, editor, text editor[/tags]

This entry was posted in sysadmin notes and tagged , , , . Bookmark the permalink.



24 Responses to Emacs with AUCTex as a LaTex IDE

  1. Allan CANADA Mozilla Firefox Linux says:

    You could try texamaker for a good cross-platform IDE as well.

    http://www.xm1math.net/texmaker/index.html

    Reply  |  Quote
  2. ikaruga UNITED STATES Mozilla SeaMonkey SuSE Linux says:

    Wow! I’m sold too! That looks pretty sweet…I’ll be sure to try it out in the future.

    Reply  |  Quote
  3. ikaruga UNITED STATES Mozilla SeaMonkey SuSE Linux says:

    @allan
    Texmaker doesn’t seem to have the built-in inline preview of math equations that makes auctex so cool.

    Reply  |  Quote
  4. Luke Maciak UNITED STATES Mozilla Firefox Ubuntu Linux Terminalist says:

    Yeah… Also, I’m not sure if Texmaker has an inline spell checking, and other similar features that can be used with Emacs.

    Reply  |  Quote
  5. Surajit Das INDIA Internet Explorer Windows says:

    Hi,
    I’m using latex in windows environment. How and where (in which folder) can i install nomenclature package(nomencl.sty, nomencl.ist) and the latex beamer class package and the other required packages?

    Reply  |  Quote
  6. Luke Maciak UNITED STATES Mozilla Firefox Windows Terminalist says:

    It actually depends on which version you are using. Do you use EmacsW32 or something else?

    I’m guessing you could really put these anywhere. What you need is an appropriate entry in your .emacs file. You probably should consult the documentation for these files for details.

    Also, you may want to check out my post about AUCTex and EmacsW32.

    Reply  |  Quote
  7. Surajit Das INDIA Internet Explorer Windows says:

    Hi, I’m using Miktex2.6 and WinEdt for latex, now is it possible to install the above packages?

    Reply  |  Quote
  8. Luke Maciak UNITED STATES Mozilla Firefox Ubuntu Linux Terminalist says:

    Ah… You won’t be able to use this then. AUCTex is an extension for the GNU Emacs editor. It’s essentially just a bunch of elisp scripts and there is no way to get it to work with another text editor.

    Sorry.

    Reply  |  Quote
  9. Surajit INDIA Mozilla Firefox Linux says:

    hi,
    In open office the spacing between the words are adjusted automatically and thus reduce the chances of word-breaking at the end of a line. What can i do to reduce the frequent word-breaking at the end of a line in latex?

    Reply  |  Quote
  10. Luke Maciak UNITED STATES Mozilla Firefox Ubuntu Linux Terminalist says:

    This is called typesetting. Open Office simply stretches and compresses whitespace to prevent breaking words at the end of the line. This is why you will sometimes get very large spaces, or rivers of white space streaking across the page when you justify the text. When you use LaTex the spacing between words and letters is constant producing a much more professional and visually pleasing output.

    Note that all professionally published texts including books, journals and magazines have the same constant spacing and break words at the end of the line as needed. It is a desired effect, and LaTex does it in a grammatically correct way – at least for English. If you are typing in another language you might need to install an appropriate language pack.

    But, if you need it, stick these two lines in the preamble:

      \hyphenpenalty=5000
      \tolerance=1000

    If you increase tolerance up to 10,000 it will eliminate almost all word breaking but it may produce a rather ugly output. Try playing with the numbers fr best results. :)

    Reply  |  Quote
  11. Surajit Das INDIA Internet Explorer Windows says:

    Many many thanks Luke, it is working.

    Reply  |  Quote
  12. Luke Maciak UNITED STATES Mozilla Firefox Windows Terminalist says:

    I’m glad I could help. :)

    Reply  |  Quote
  13. Try reftex-mode !!! with simple keystrokes you can add references to bibtex entries.

    Reply  |  Quote
  14. mks COSTA RICA Mozilla Firefox Ubuntu Linux says:

    sorry for my English, but where the .emacs file is localized?

    Thanks a lot.

    Reply  |  Quote
  15. Luke Maciak UNITED STATES Mozilla Firefox Windows Terminalist says:

    Depends on your OS. On linux it’s usually located in your home directory (but since it is a dottet (ie. hidden) file you won’t see it in Konqueror or Nautilious by default. Just open a terminal and do:

    emacs ~/.emacs

    This should open your emacs file in emacs. :)

    If you are on windows, it depends on the version of Emacs you have installed. I think EmacsW32 keeps it in %APPDATA% directory (which usually expands to C:\Documents and Settings\Your Username\Application Data\).

    Reply  |  Quote
  16. Andreas DENMARK Mozilla Firefox SuSE Linux says:

    If you liked preview latex in AUCTeX you should try whizzytex-mode togeher with AUCTeX. With whizzy you’ll have a split screen with the emacs and dvi-viewer updating as you write the text.

    Reply  |  Quote
  17. Luke Maciak UNITED STATES Mozilla Firefox Ubuntu Linux Terminalist says:

    Wow, whizzy is pretty cool. Thanks for the tip!

    My only complaint is that if you open a really big file (20+ pages) the DVI viewer just can’t keep up.

    Reply  |  Quote
  18. Surajit Das INDIA Internet Explorer Windows says:

    Hi,
    Which bibliographic style file do i need to use to get the following citation and references.

    For Example: Das et al. (2005) proposed…..; Brinson and Lin (1997) derived the formulation…..; Otsuka (2007) proposed………etc.

    References
    Brinson, L. C., Lin K. J. (1997), Finite Element Analysis……., Journal of Intelligent material, 6(2), 19-34
    Das s., Peng L. G., Yen P. S., (2005), ………..
    Otsuka J. K. (2007), ……..

    Reply  |  Quote
  19. Luke Maciak UNITED STATES Mozilla Firefox Ubuntu Linux Terminalist says:

    Surajit, there is no way to do it exactly in that format but the apalike format should be close enough:

    \bibliographystyle{apalike} 
     
    \begin{document}
     
    Reference to a paper in proceedings \cite{fanty:icassp93}.

    Will result in:

    Reference to a paper in proceedings [Fanty et al., 1993].

    References

    [Fanty et al., 1993] Fanty, M., Schmid, P., and Cole., R. (1993). City name recognition over the telephone. In Proc. International Conference on Acoustics, Speech and Signal Processing, volume I, pages 549-552, Minneapolis, U.S.A.

    Examples are from here.

    Reply  |  Quote
  20. Pingback: Terminally Incoherent » Blog Archive » Installing AUCTex with EmacsW32 UNITED STATES WordPress

  21. Dave X SWEDEN Mozilla Firefox Ubuntu Linux says:

    Sujarit,

    Check out natbib – for natural sciences – has ref styles very close to the ones you want. Otherwise makebst can produce almost anything, but takes some practice.

    Dave

    Reply  |  Quote
  22. cesar CANADA Mozilla Firefox Ubuntu Linux says:

    Thanks man! that was completely useful. From my perspective it offers a solution for Kile drawbacks

    in ubuntu intrepid i did the following

    sudo apt-get install auctex preview-latex

    the flyspell and cua are installed by default, just need to activate them from the menu.

    tools->spell checking->automatic spell checking(flyspell)

    and

    options->customize emacs->top level customization group

    then there choose

    convenience group -> cua group

    at the end of the cua group you can see

    CUA MODE

    just toggle on and enjoy

    Reply  |  Quote
  23. I’ve been an auctex user for some time, but still I find some tips mentioned in your post and the comments below very useful. thanks!

    Reply  |  Quote
  24. N.N. SWEDEN Mozilla Firefox Ubuntu Linux says:

    For another take on learning Emacs for LaTeX editing see http://tex.stackexchange.com/a/50919/5701

    Reply  |  Quote

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>