LaTeX Tools and Hacks

Michael vs the dragonSince I began fighting the good fight for my thesis, I've been exposed to several of the vagaries and idiosyncrasies of LaTeX. I decided to collect together some of the most useful things I've learned, for my own future reference and to help any other desperate soul battling the same demon.


LaTeX is the demon.

If you have your own tricks you'd like to share, please send them my way and I'll include them here.

Format Links

You can personalize how links are formatted with hypersetup. (Make sure to include the hyperref package!)

Here's a list of some of the important options below. (This is how my thesis is set up. The commented out lines are options I decided against, but someone else might like.)

  breaklinks=true,     % Break up links across two lines 
                       % if needed
  colorlinks =true,    % Font in color, otherwise in 
                       % frame (yuck)
  bookmarksnumbered,   % Table of contents with numbering
  hypertexnames=false, % Needed for correct links to
                       % figures
  plainpages =true,    % Do page number anchors as plain 
                       % Arabic
  %linktocpage=true,   % Make page number not text link 
                       % on TOC
  %linktoc=none,       % No links on TOC
  linkcolor=MyBlue,    % Color of links within document
  citecolor=MyGreen,   % Color of links to bibliography
  urlcolor =MyRed,     % Color of external url links
  filecolor=blue,      % Color of file links
  %pagebackref=true,   % Adds 'backlink' text to the end 
                       % of each item in the 
                       % bibliography, as a list of page 
                       % numbers.

A complete list of options is available here (pdf).

To personalize the colors of your links, include the color package, "\usepackage{color}". Then specify your colors (using rgb), like so:



Modify PDF Meta Data with hyperref

The hypersetup options are just crawling with goodies. You can specify meta information, how the pdf looks when it's opened, how links are formatted, etc. A complete list of options is available here (pdf).

Here are some of the settings I use,

  pdfstartview=FitH,   % Set by page width
  pdfborder={0 0 0},   % document border
  pdfauthor={Cassandra R. Hunt},
  pdftitle ={My Title},
  pdfsubject  = {Ph.D. Thesis},
  pdfkeywords = {My,Keywords,Separated,by,Commas},
  pdfcreator  = {LaTeX with hyperref package},
  pdfproducer = {pdflatex}

(When using hypersetup, make sure to include the hyperref package!)


Format the Bibliography

How difficult should it be to have a bibliography that has these basic features:

  • Numbered references. (Who in their right mind thinks monstrosities like [GBlahman2001] scattered throughout their text are helpful?)
  • User set-able number of authors before using et al.
  • Shows the title, without weird formatting. (There is nothing more eye-bleeding than reading a chemical formula in all lower case.)
  • Includes links to the articles.

This is pretty basic stuff people. And yet I could not find such a .bst file anywhere. My husband had gone part of the way with his thesis, modifying the APS standard apsrev4-1.bst to allow you to set the number of entries before using et al. as well as the number of authors to include when et al. is used. I started from his version and we modified it further to by default include article titles in quotes, without additional formatting. This required a bit of fiddling, because LaTeX programming consists mostly of archaic runes and secret enchantments, all but lost to the ages.

But it is done. And only a few minor demons were accidentally summoned in the process. I present our bastard progeny:


Here's how the citations look:


How to use this file

You're going to need the same packages as the standard apsrev4-1.bst file requires. You can find a list on the APS website. Hope there is no pain getting it working, but if there is, you are on your own. Don't ask me. I'm not a LaTeX guru, just another lost soul.

If you're wondering where to put these files, well that depends on how your LaTeX libraries are organized and how your interpreter knows how to search for the files it needs. I'm using Kile, which is a bit of a magic program that comes batteries included. For me it's just been plug and play. Including the .bst file in the appropriate directory (the same one as my .tex file) was all I needed to do. The style files and packages were already downloaded.

Include natbib like so: "\usepackage[numbers]{natbib}" if you want to have numbered entries. And don't forget to include the hyperref package to have linked references. For the LaTeX newbies, include packages at the top of your file (after \documentclass{...} and before \begin{document}). Then, before \end{document}, include the bibliography as follows:

\bibliographystyle{apsrev4-1-etal} \bibliography{link/to/bib/file}

Make sure the link to your .bib file doesn't actually include the .bib extension. (How to write a .bib file.)

Author settings

To set the number of authors, the solution is inelegant. I did say this was a bastard child. Search for the text %%%MODIFIED-ETAL-START in apsrev4-1-etal.bst. The text should look as follows:

et. al.

The default number of authors to show when using et al. is set to 4 and the maximum number of authors to display without using et al. is set to 7. Change these numbers to whatever you like.

If someone who actually knows how to set variables in LaTeX wants to improve on this, please let me know.

What if I don't want titles?

It is infuriating isn't it, not finding exactly what you're looking for? Especially when it's something so straightforward. If you like the et al. feature but don't want titles, you can easily comment out this part of the code. Search for the text %%%MODIFIED-ATITLE-START in apsrev4-1-etal.bst. It'll look like this:


Comment out the code between %%%MODIFIED-ATITLE-START and %%%MODIFIED-ATITLE-END to suppress titles.


Force an image into a section

There's no silver bullet for getting your images where you want them with LaTeX. But this is something that's help me keep a little sanity when my figures want to wander too far afield: placeins. Use the command \FloatBarrier throughout your text to specify boundaries that figures may not cross. I like to do this at the end of subsections.

Import the package as "\usepackage[sections]{placeins}" to keep figures within sections. Use the keyword "below", "\usepackage[below]{placeins}", to allow images in the following section, assuming that at least part of the previous section is on the same page.


Load images from sub-directories

Is a little structure too much to ask?

If you want to LaTeX to search sub-directories to find images, you can use \graphicspath{} to do it. In the part of your tex file where you include packages, add the sub-directories that need to be searched as follows:


These paths need to be located in subfolders of the one housing your tex file. (Sorry, I haven't found a way around that constraint yet. The standard unix "../" doesn't do the trick.)


Share your LaTeX Tricks

Was there some useful package or interesting hack that helped you while writing your thesis? (Or just using LaTeX in general.) Let me know about it! I can share it here or provide a link to the information.

Please do not use this form to ask questions about the information provided above. I'm by no means an expert. I devoted enough time to getting this stuff working for me--I can't play at IT support. (Maybe try the LaTeX community here.)

However, if you have a problem and figure out the solution, do please let me know! I'll post it here and others can benefit from your toil.


LaTeX, my love, why must we fight?