Computer Scientist, Graduate Student, and Geek

Tag: latex

Makefile for ACM Publications in LaTeX

October 18, 2011

Below is the Makefile I use for compiling ACM publications. The LATEX, BIBTEX, PDF, and PS variables should be changed to the absolute paths of latex, bibtex, ps2pdf, and dvips, respectively, if they cannot be found from your PATH environment variable. The variables WORKINGBASE and CAMERABASE should be changed to the name of the main LaTeX file (excluding .tex extension) for your working (i.e., draft) and camera-ready versions, respectively. Use the working (or default) target to compile the working version and the camera target to compile the camera-ready version.

Makefile

LATEX = latex
BIBTEX = bibtex

PDF = ps2pdf
PDF_FLAGS = -dMaxSubsetPct=100 -dCompatibilityLevel=1.2 -dSubsetFonts=true \
-dEmbedAllFonts=true  -dEPSCrop=true

PS = dvips
PS_FLAGS = -P cmz -t letter

WORKINGBASE = main
CAMERABASE = final

default: working

working: version $(WORKINGBASE).pdf

camera: $(CAMERABASE).pdf
    gs -q -dNOPAUSE -dBATCH -dPDFSETTINGS=/prepress -sDEVICE=pdfwrite \
-sOutputFile=$<.tmp $<
    mv $<.tmp $<

version:
    svnversion > version.tex

%.pdf: %.ps
    $(PDF) $(PDF_FLAGS) $< 

.PRECIOUS:%.ps
%.ps: %.dvi
    $(PS) $(PS_FLAGS) $< -o $@

$(WORKINGBASE).dvi: $(wildcard *.tex) $(wildcard *.bib) $(wildcard images/*.eps)
    $(LATEX) ${@:.dvi=}
    $(BIBTEX) ${@:.dvi=}
    $(LATEX) ${@:.dvi=}
    $(LATEX) ${@:.dvi=}

$(CAMERABASE).dvi: $(wildcard *.tex) $(wildcard *.bib) $(wildcard images/*.eps)
    $(LATEX) ${@:.dvi=}
    $(LATEX) ${@:.dvi=}
    $(LATEX) ${@:.dvi=}

clean:
    rm -rRf *.dvi *.aux *.blg *.log *.ps *~ *.bbl *.pdf *.out

I also set the svn:ignore property on the subversion directories in which LaTeX files and Makefile are stored. Run

svn propedit svn:ignore .
and add the following:
*.aux
*.bbl
*.blg
*.log
*.dvi
*.ps
version.tex
main.pdf

(Change main.pdf to whatever is stored in the WORKINGBASE variable in the Makefile, plus the .pdf extension.)

Categories: Uncategorized

Tags: acm, latex


Compiling LaTeX Publications for Conference Proceedings

July 25, 2011

As a computer science graduate student, compiling LaTeX publications for conferences is a frequent task. For the draft and submission versions, compilation settings are not as particular, but a final camera ready version has certain requirements, such as a PDF with embedded fonts. I have built a Makefile that allows me to compile everything from my early drafts to the final camera-ready version that meets the requirements of typical ACM publications.

The Makefile assumes your main LaTeX file is called main.tex (change the value assigned to the BASE variable if yours is different). Also, the camera-ready compilation process assumes you have a single latex file called camera.tex that contains all tex files and the bbl, the compiled bibliography (change the value assigned to the CAMERABASE variable if yours is different).

LATEX = latex
BIBTEX = bibtex

PDF = ps2pdf
PDF_FLAGS = -dPDFSETTINGS=/prepress

PS = dvips
PS_FLAGS = -t letter

BASE = main
CAMERABASE = camera

.PRECIOUS:$(CAMERABASE).ps

all: version $(BASE).pdf

camera: $(CAMERABASE).pdf

version:
    svnversion > version.tex

%.pdf: %.ps
    $(PDF) $(PDF_FLAGS) $< 

%.ps: %.dvi
    $(PS) $(PS_FLAGS) $< -o $@

$(BASE).dvi: $(wildcard *.tex) $(wildcard *.bib) $(wildcard images/*.eps)
    $(LATEX) ${@:.dvi=}
    $(BIBTEX) ${@:.dvi=}
    $(LATEX) ${@:.dvi=}
    $(LATEX) ${@:.dvi=}

$(CAMERABASE).dvi: $(wildcard *.tex) $(wildcard *.bib) $(wildcard images/*.eps)
    $(LATEX) ${@:.dvi=}
    $(LATEX) ${@:.dvi=}
    $(LATEX) ${@:.dvi=}

clean:
    rm -rf *.dvi *.aux *.blg *.log $ *~ *.bbl *.out
    rm -rf (BASE).ps $(BASE).pdf $(CAMERABASE).pdf

Categories: Uncategorized

Tags: latex, subversion


Cropping eps Figures

January 27, 2011

When writing documents in LaTeX, I need figures to be in eps format. Depending on the original format of the figure, converting the figure to eps may result in an eps figure with extra white space. Even gnuplot graphs, which can be exported directly to eps, include unnecessary which space.

To crop an existing eps (or ps) file, simply run ps2eps:

ps2eps input.eps

A cropped eps file will be produced, named input.eps.eps for the command above.

Categories: Linux

Tags: eps, latex


LaTeX and BibTeX Search Path

October 22, 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

Categories: Linux

Tags: bash, bibtex, latex


Including Code Blocks in LaTeX

September 23, 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.

Categories: Development

Tags: latex


Conditions in LaTeX

July 01, 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} }

Categories: Linux

Tags: latex