Archive

Posts Tagged ‘latex’

LaTeX and BibTeX Search Path

October 22nd, 2009

I often write papers in LaTeX that use the ACM SIG Proceedings Template. Previously, I would put a copy of the LaTeX style file (.sty) in every directory where I had a LaTeX document that used it. Then I discovered I could set an environment variable to automatically have LaTeX search a path for a style file.

The TEXINPUTS environment variable works similar to the PATH environment variable: it is a list of paths where LaTeX should search for necessary class and style dependencies. I created a folder in my home directory where I keep the ACM SIG Proceedings Template LaTeX style file. I set the TEXINPUTS variable in my .bashrc.

There is also a BIBINPUTS environment variable to search for BibTeX files. I have started putting all the references I use in a single file, to avoid having small BibTeX files all over the place. I put my central BibTeX file in the same location as the LaTeX style file and set the BIBINPUTS variable in my .bashrc.

The following few lines in my .bashrc set the two environment variables:

# Include shared LaTeX classes and BibTeX files in path, if LaTeX folder exists
if [ -d "~/latex" ]; then
    export TEXINPUTS=".:~/latex/:"
    export BIBINPUTS=".:~/latex/:"
fi

Linux , ,

Including Code Blocks in LaTeX

September 23rd, 2009

I recently had a need to include a block of C code in a report I was writing in LaTeX. I discovered the listings package provides mechanisms for nicely displaying code. Include the package in your file by placing

\usepackage{listings}

somewhere before your \begin{document}. Wherever you want the block of C code (or code in a multitude of other supported languages) insert

\begin{lstlisting}[language=C,frame=single]
CODE GOES HERE
\end{lstlisting}

You can specify other options besides language and frame. For more details on the package see the LaTex Wikibook.

Linux

Conditions in LaTeX

July 1st, 2009

You can use the ifthen LaTeX package to add conditions to your LaTeX document that affect the generated output. I used it to achieve behavior similar to the C preprocessor macros #define and #ifdef. Below is an example.

I wanted something that worked like (in psuedocode):

#define var
#ifdef var
\section{Included Section}
#else
\section{Excluded Section}
#endif

The actual LaTeX is:

\newboolean{var}
\setboolean{var}{true}
\ifthenelse{\boolean{var}}
{ \section{Included Section} }
{ \section{Excluded Section} }

Uncategorized