Useful LaTeX Tricks
LaTeX is a wonderful document preparation and typesetting program used in academic publishing. Sometimes it can be a little cumbersome to use. Here are some tips that I’ve found helpful.
Hiding Metafiles
Metafiles are extra files created for indices, bibliography processing and other
auxiliary functions needed during processing. These are worth keeping around
while actively working and typesetting a document, but they pollute the
directory in which the main .tex
file resides.
I personally prefer having only the .tex
and .pdf
product files in
my directory. I store metafiles in a hidden subdirectory, .metafiles
,
and use a hard-link to the produced pdf. I also use latexmk to typeset my LaTex documents since it
intelligently runs pdflatex
, bibtex
, biber
, makeindex
and other commands to typeset the final document.
The following are the settings of my .latexmkrc
file, which resides in
my home directory.
# Generate PDFs automatically
$pdf_mode = 1;
# Store created files in the .metafiles hidden subdirectory
$out_dir = ".metafiles";
# Typeset with pdflatex by first creating the .metafiles subdirectory,
# typesetting the document, then creating a hard link to the finished product.
$pdflatex = "mkdir -p .metafiles && pdflatex %O %S && ln -f %D .";
Cleaning Metafiles
The following command lists all the LaTeX metafiles in the current directory and subdirectories. The results of this search can be piped for removal.
alias lstex='find . -type f
-name "*.aux" -o
-name "*.fls" -o
-name "*.log" -o
-name "*.out" -o
-name "*.synctex.gz" -o
-name "*fdb_latexmk" -o
-name "*.bbl" -o
-name "*.blg" -o
-name "*.idx" -o
-name "*.ilg" -o
-name "*.ind" -o
-name "*.tdo" -o
-name "*.toc"'
Managing Assets
Assets are images and files that get included in LaTeX documents. Rather than
have these scattered throughout my filesystem, I store them in one place:
~/Documents/Assets
I use the following command and GNU Stow to create symbolic links to my Asset subdirectories.
alias assets='mkdir -p Assets&&stow -d ~/Documents/ -t ./Assets Assets'
Whenever I need to create a new LaTeX document directory, I simply type
assets
within that directory to create the Assets directory. This
command will also update the symbolic links in the Assets directory, if the
document’s directory is moved.