Archive for the 'emacs' Category

Installing AUCTex with EmacsW32

Tuesday, December 18th, 2007

Here is part two of my quest to make Emacs my default LaTex IDE on both windows and Linux. Installation and configuration of Emacs and the LaTex add-on AUCTex on Ubuntu was surprisingly easy and uneventful. On windows however I ran into little bit more difficulty.

Of course I could download the precompiled Emacs + AUCTex bundle from the AUCTex website but I wasn’t really thrilled about that. You see, I was already had a nice copy of Emacs on my system - on windows I’m using EmacsW32. What is the difference you ask?

Well, EmacsW32 comes with a nice MSI installer that adds all sorts of registry hooks that make it act as a first class Windows application. It also makes the GUI look more polished and native. I prefer it to other ways of getting Emacs on windows because I get an up to date binaries that work right out of the box.

AUCTex unfortunately does not ship binaries you could just “plug” into place so I had to download the sources and compile them. Compiling? From Source? On windows? Yup, that’s what I said. I can sees shock and disgust sweeping all over your faces. Before you run away let me assure you it’s easy as pie. Well, at least it was for me.

You will need a working copy of gcc and make. How do you get them on Windows? You could always get the MSYS from MinGW. Since I didn’t have MSYS but had a working Cygwin installation I used that. I simply pulled up my cygwin bash sell and did:

$ ./configure	--prefix='c:/Program Files/Emacs/emacs/' 
		--with-texmf-dir='c:/Program Files/MiKTeX 2.5' 
		--with-lispdir='c:/Program Files/Emacs/site-lisp'
$ make
$ make install

You may want to tweak the parameters for the configure script with appropriate paths. As you can see I’m using MiKTeX 2.5 on my machine. If you are using something else, you should probably change that line. Also, if you are not using EmacsW32 then you might need to change the –prefix and –with-lispdir lines to point them to your emacs installation directory. If you get an error, tweak the parameter or download dependencies and try again.

I really had no dependency problems or anything but I don’t remember what exactly did I have in my Cygwin install. It’s possible that you may need to download a package or two like maybe the cygwin Emacs version. Before you ask - I don’t use the cygwin version of Emacs because I don’t feel like running a full instance of X server for the GUI. Besides, EmacsW32 is much more responsive being that it is a native app and all.

Note that I’m using the Windows path notation with inverted searator specifying the drive as c:/ instead of the cygwin notation /cygdrive/c/. Your cygwin installation should be able to map C:/ to /cygdrive/c/. If not you may need to adjust this. If you installed your cygwin in C:\ instead of C:\cygwin then you can just use / to indicate the root drive. This is actually the “smart” way to use cygwin - Steve Yagge says so, and when Steve says something you better listen and take fucking notes.

The make install command should seamlessly slip AUCTex files into your EmacsW32 directory. Unfortunately, you will need to configure your emacs manually to use them. How to do this?

Open up your C:\Program Files\Emacs\site-lisp directory and edit site-start.el file. Add the following lines somewhere:

(load "auctex.el" nil t t)
(load "preview-latex.el" nil t t)
(require 'tex-mik)
(eval-after-load 'info
       '(add-to-list 'Info-directory-list "c:/Program Files/Emacs/share/info"))
(setq TeX-auto-save t)
(setq TeX-parse-self t)

I actually got this snippet from Oliver Sturm who figured this configuration before me.

When I tried to use the inline preview feature of AUCTex it did not work for me. It game me some odd message saying that “gs” is not a recognized command or something like that. It turns out that it was right. On windws the default ghostscript binary is not called gs but gswin32c.exe. You will need to change this - simply open some LaTex file, pull down the Preview menu, go to Customize and find the GS Command option. Set it to: C:\Program Files\gs\gs8.54\bin\gswin32c.exe. Make sure you are not using the C:\Program Files\Ghostgum\gsview\gsview32.exe binary. That is the default windows DVI viewer which ships with Ghostscript and many people confuse the two.

All that was left was to add a command to convert the DVI files into PDF. AUCTex already ships with a DVI to PS script under Command called FILE (yeah, go figure why they called it that). I simply added the following to my .emacs:

(eval-after-load "tex"
  '(add-to-list 'TeX-command-list
                '("DVI to PDF" "dvipdfm %d" TeX-run-command t t) t))

This will add a DVI to PDF option in the Command menu which will let you generate pdf files.

So, was this really hard? I thought it was a piece of cake, compared to for example setting up that nethack server.

Happy Emacsing everyone!

Emacs with AUCTex as a LaTex IDE

Thursday, December 13th, 2007

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. )