RRC|BIOSTATISTICS

Latex, Auctex, and Emacs

Combined as one! Emacs and LaTeX! Together at last! Here’s everything you need in one place to compile, preview and edit LaTeX files in Emacs, and view the generated PDF.

Get LaTeX

To get LaTeX on Linux, install something called “Tex Live” from this webpage: http://www.tug.org/texlive/acquire-netinstall.html Download the tarball called install-tl-unx.tar.gz and unpack it!

Install. But first, are you root?

Now that you’ve unpacked your tarball with tar -xvf install-tl-unx.tar.gz, you have to enter the folder and begin the installation.

1
2
cd /install-tl-unx
./install-tl

Then a very long series of statements go by as the pre-intallation set up will occur. You’ll see this: Enter command: Type in “i” so it looks like this Enter command: i and press ENTER.

Then, Tex Live should download its files off the internet (WARNING: This takes hours upon hours) and install.

However, this ERROR may happen:

1
2
3
Enter command: i
Installing to: /usr/local/texlive/2009
./install-tl: mkdir(/usr/local/texlive/) failed, goodbye: Permission denied

Its not installing it because you’re not established as “Root”. But seriously, “Goodbye”?!

You can either try sudo ./install-tl or switch to your root account with the command sudo -i It’ll probably make your life easier to just use sudo before the installation command.

Welcome to TexLive! Now add MANPATHS!

1
2
3
4
5
6
7
8
 Add /usr/local/texlive/2009/texmf/doc/man to MANPATH.
 Add /usr/local/texlive/2009/texmf/doc/info to INFOPATH.

 Most importantly, add /usr/local/texlive/2009/bin/x86_64-linux
 to your PATH for current and future sessions.

 Welcome to TeX Live!
Logfile: /usr/local/texlive/2009/install-tl.log

I had no idea what this meant at first. I used the command sudo emacs /etc/environment to get to the MANPATH and INFOPATH. Make sure its spelled etc and not ect. The only listing I had there was this jumble: PATH=“/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games”

To make the Tex executables work, I had to add /usr/local/texlive/2009/bin/x86_64-linux to the path like so, with a colon separatating the new addition from the rest. Look for “/usr/local/sbin” to make sure you’ve installed it in front correctly.

PATH=“/usr/local/texlive/2009/bin/x86_64-linux:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games”

Add the two new lines under it so your /etc/environment looks like this:

1
2
3
PATH="/usr/local/texlive/2009/bin/x86_64-linux:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
MANPATH="/usr/local/texlive/2009/texmf/doc/man"
INFOPATH="/usr/local/texlive/2009/texmf/doc/info"

Installing AucTex

Now you can get started with getting Emacs to harness the power of LaTeX. Open up a terminal, and use the following command: sudo apt-get install auctex preview-latex

After it installs, go to your .emacs file with the command emacs .emacs
Make sure these lines are at the very end of your .emacs file!

1
2
3
(require `tex-site)
(require `tex-style)
(add-hook `LaTeX-mode-hook `turn-on-reftex)

The “require ‘tex-site” is what will activate AucTex. Feel free to add a few more hooks to your .emacs file to improve your Emacs/LaTeX use.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
;; 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)

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

Where is it?

Open up a .tex file. If you want a test file, use the command C-x C-f test.tex You will see a cute little lion icon with the words “Latex” next to it, and a glasses icon with “View” next to it.

The default preview mode is DVI. You can toggle between DVI and PDF mode with the command in emacs: Ctr-c-t-p, meaning you press on the control button with your pinky and type the three letters “c, t, p” Finally, to view your compiled DVI/PDF, use the command C-c

Comments