LaTeX, Subversion and Emacs

Some notes on using LaTeX with Subversion (SVN) and Emacs. This is what I use in Ubuntu Linux using TexLive, but most could probably be applied in other setups.

Files and Paths

I have style and bibliography files stored in the following directories. These are in SVN repositories so I can easily use them on different computers (so long as I checkout the repository in the same directory, i.e. /home/sgordon/svn). The instructions work for these paths - you need to modify them to suit your setup.

Assume your bibliography (.bib) file is in:


And a style file your using is in:


Your current LaTeX document is:


Your current working directory is:


Use shell paths for style and biblio files

LaTeX looks for inputs in the current directory as well as others according to some shell environment variables such as: TEXINPUTS (for .tex, .cls and .sty files), BSTINPUTS (for biblio style files) and BIBINPUTS (for .bib files). You can set these variables to include the paths of your BIB and CLS files. Using Ubuntu Linux, add the following lines to the file .bash_aliases in your home directory:

export TEXINPUTS=${TEXINPUTS}:.:/home/sgordon/svn/Common/Styles
export BSTINPUTS=${BSTINPUTS}:.:/home/sgordon/svn/Common/Styles
export BIBINPUTS=${BIBINPUTS}:.:/home/sgordon/svn/Common/Biblio

Now when you run latex (or pdflatex or similar) it will also look in the directories you specified.

LaTeX and SVN: Keywords

SVN attaches properties to files checked in, such as Revision, Author, URL and Date. You can access the values of these parameters inside the LaTeX file. First make sure the keywords are associated with the check in file.

# Commit the file (if you haven't done so already)
$ svn commit abc.tex

# Associate svn keywords with the file
$ svn propset svn:keywords "Author URL Revision Date" abc.tex

# And commit again to include the properties
$ svn commit abc.tex

You only need to do this once. Now the properties are set for the file. To access the properties in the LaTeX source, you must include the "svn" package and then extract the parameters. Then you can use the special LaTeX svn commands \SVNRevision, \SVNDate, \SVNURL, \SVNAuthor anywhere in your document. An example:

\SVN $Revision: 401 $
\SVN $Author: sgordon $
\SVN $Date: 2012-04-26 09:42:18 +0700 (Thu, 26 Apr 2012) $
\SVN $URL: $


This is revision \SVNRevision created on \SVNDate.


Manually using the propset command on all your .tex files can be time consuming, and often you may forget about it. As part of the Subversion configuration on your computer you can automatically set properties for all files of a particular type. Look in the file:


and towards the bottom you'll see [auto-props] section. Adding something like this will automatically set the properties for all .tex files that you commit.

*.tex = svn:eol-style=native;svn:keywords=Author Date Id Rev URL;

LaTeX and SVN: Ignoring Files

LaTeX creates a number of output files. Normally there is no need to include them in a SVN repository. Include just the source .tex file is sufficient (even the .pdf output does not need to be included). When you svn add a directory for the first time it automatically adds all files in that directory to SVN - this may include all the Latex output files that you don't want. You can set Subversion options to ignore files (not add them) of particular types. In the file:


in the [miscellany] section you can set the files to ignore when adding files to SVN:

global-ignores = *.o *.lo *.la *.al .libs *.so *.so.[0-9]* *.a *.pyc *.pyo

Output LaTeX files to another directory

Ignoring files is one way to make sure the LaTeX output files are not included in SVN. Another approach, which also helps keep your current working directory clean, is to put the output files in a different directory. Here is my approach:

# Current working direcotry
$ pwd

# Create a directory for the Latex output files
$ mkdir out

# Now compile your .tex using pdflatex and the option to set the output directory
$ pdflatex -output-directory out abc.tex

All of the LaTeX output files (including PDF) will be stored in the out directory. There is no need to add this out directory to SVN; only add abc.tex. Again, this could be done manually or you could setup a global-ignore to ignore the out directory (I think it can be applied to directories).

Alias for pdflatex

Typing in:

pdflatex -output-directory out abc.tex

everytime you want to compile can be time consuming. You can setup an alias in .bash_aliases file in your home directory. For example, I have:

alias plo='pdflatex -halt-on-error -output-directory out'

The -halt-on-error option means pdflatex will not continue if there is an error - a good way to force yourself to fix errors in the source. On the command line I now run:

$ plo abc.tex

where plo stands for PdfLatex with Output directory. You can name it what you like.

Emacs Compiling and PDF Viewing

If you are using Emacs as your text editor then it has shortcuts to compile the LaTeX source and view the pdf output. By default they are:

where uppercase C means Ctrl.

But if you want to use the output-directory option and view the PDF in the out directory, you need to change how the shortcuts work.

In my home directory my .emacs file contains:

;; SDG 27-07-2011
;; Setup TeX/LaTeX
(setq latex-run-command "pdflatex -halt-on-error -output-directory out")

;; SDG 27-07-2011
;; Stuff set automatically by Emacs is below 
  ;; custom-set-variables was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(inhibit-startup-screen t)
 '(tex-dvi-view-command (quote (tex-send-command "evince" (tex-append "out/" (tex-append (file-name-nondirectory tex-print-file) ".pdf")) t))))

Now the Emacs shortcuts work, i.e. the compile the .tex source, putting the output files in the out directory and open the PDF in the out directory.