Gentoo Wiki




This HOWTO will give you a short overview how to get LaTeX running on your box. I will only show a very simple example to verify your LaTeX setup. There are many good tutorials out there for starting using LaTeX. You can find some good resources in the links section at the bottom of the page to get you really started with this. Since I think this HOWTO will be mainly read by LaTeX beginners I will refer to a KDE application Kile and AmyEdit for Gnome, which makes using LaTeX pretty easy. Please contact if you want to help with the redaction.

Installation of the needed software

Installing the packages

After you prepared your box, you can emerge the TeXLive package. In addition, it is very nice to have an editor with syntax highlight and some special features for LaTeX. Kile is an excellent choice if you are using KDE. AmyEdit is another good choice if you are using Gnome, both are LaTeX IDEs. There are many other IDEs out there. Basically you can use any editor with or without LaTeX syntax highlighting. Emerge the packages by typing:

emerge kile
emerge virtual/latex-base amyedit

Verification of your LaTeX setup

After all packages have been emerged, fire up Kile. Select New from the File menu. From the wizard choose Article. You will end up with a text file like this:

File: Unnamed.tex

You can now edit the text file by adding some example content, for example like this:

File: Unnamed.tex
 \title{The mini LaTeX HOWTO}
 \author{Unknown author}
 This is a very short abstract of short article.
 This is the first section. Enter your text here.

To verify that your LaTeX setup is working now choose QuickBuild from the Build menu. A DVI viewer should open, showing you your rendered LaTeX document.

LaTeX on the command line

If you are not going to use the X environment, or if your text editor does not have full support for LaTeX you can run it from the command line.

latex Unnamed # Where Unnamed.tex is the name of your document, note the lack of '.tex' in the command
latex Unnamed # If your document has references or figures it is a good idea to run latex twice

This gives you file.dvi, which can be printed directly, viewed, or converted into other formats for distribution.

Using a DVI file

xdvi Unnamed    #to view the file, emerge xdvik
dvipdf Unnamed  #convert the file to pdf, emerge dvipdfm
dvips Unnamed   #convert the file to post script

Have a look in the portage tree at /dev-pdf/ for more dvi utilities

Creating a PDF file directly from source document

pdflatex Unnamed

pdflatex allows you to use the JPEG or PNG format for images instead of EPS.

Alternative: rubber

Another easier solution is to use the rubber package, which is a tool to automate latex compilations.

emerge rubber

To obtain a pdf file directly, you now just have to run

rubber -d foo.tex

and rubber will find out how many latex passes are needed, and also run metapost/bibtex/dvips/...

Editing LaTeX files in Emacs

What is AUCTeX

To ease writing, compilation and viewing of your LaTeX documents, you can edit them directly in emacs. The AUCTeX package provides an emacs / Xemacs environment to edit, format, compile and view your documents. It contains also two useful modes:

Compilation is automatic, by typing C-c C-c. And so is viewing by typing once more C-c C-c, once compilation is over. Several commands ease writing of your documents (note that for many of these commands, you can type <TAB> to view the available choices):

Most of these key bindings are listed in the AUCTeX manual:

Installing AUCTeX

The installation is quite straightforward. First, you need to manually edit the preview mode (this mode is mostly interesting for edition of mathematical formulas, skip this step if you don't plan to use LaTeX to this end):

nano -w /etc/portage/package.use

Add the line:

app-emacs/auctex preview-latex

Then emerge AUCTeX:

emerge -av app-emacs/auctex
Note: Before this, make sure you did use "jpeg" when emerging gd.

Next, you need to make Emacs aware of the AUCTeX package. You can configure it for you account only or system-wide. For the latter:

nano -w /usr/share/emacs/site-lisp/site-start.el

If it is not yet present, add the following line:

(load "/usr/share/emacs/site-lisp/site-gentoo")

Now, opening a TeX file in emacs (.tex extension) should show a Latex menu, along with a Command menu and a Preview menu (if you enabled the preview mode).

There are a few remaining steps, to customize auctex. These can be skipped safely.

nano -w ~/.emacs

Add the following lines:

(setq TeX-auto-save t)
(setq TeX-parse-self t)
(setq-default TeX-master nil)
(add-hook 'TeX-language-dk-hook
         (lambda () (ispell-change-dictionary "francais"))) ; using "\usepackage[francais]{babel}" in your latex file will activate this style.
(add-hook 'LaTeX-mode-hook 'turn-on-reftex)   ; with AUCTeX LaTeX mode
(add-hook 'latex-mode-hook 'turn-on-reftex)   ; with Emacs latex mode
(custom-set-variables '(global-font-lock-mode t nil (font-lock)))

Many other options can configured. Either consult or, directly in Emacs, type M-x customize-variable <RET> and then type LaTeX <TAB> to see a list of available options for AUCTeX.

For any other information, consult the manuals:

Writing presentations in LaTeX

Beamer is the most convenient package to write presentations directly in LaTeX. It is available as a package but is now included by default in tetex. It should thus work right out of the box.

Remember you need to use pdflatex to be able to compile Beamer presentations.

For a Beamer howto, look for instance at For Beamer examples, look in the /usr/share/texmf/tex/latex/beamer/ directory.


Kile has a self diagnostic tool (Settings -> System Check), however this can be slightly misleading. If you have a LaTeX command in an open document that calls itself then the diagnostic will tell you that the kile does not have access to latex. An example would be:


The reason for this is that latex itself halts if it encounters such a case. Before you repeatedly uninstall and reinstall to get kile working, check you don't have this happening in one of your open documents (I just wasted the past 2 hours, it's pretty easy to do, especially after an upgrade and not using latex for a while)

Latex Compilation is very slow Running the latex or pdftex command tooks a very long time, because latex was checking my complete home directory recursive for additional files. My Problem was a slash at the end of my $HOME-Path. I had:

$ echo $HOME

instead of


Because of this latex had a path with a doubled backslash like


and this causes latex to search my homedir recursively, which takes the long time. Vide


I solved this with adding


to my ~/.bashrc. This is just my little workaround, feel free to add better solutions and corrections.

See also

Retrieved from ""

Last modified: Sat, 06 Sep 2008 12:02:00 +0000 Hits: 29,004