Monday, November 23, 2009

Ode to \vref

I'm using LaTeX to write my thesis, and there is this great command: vref. I have a figure called Variability_transcript_abundance. When I'm talking about it in the text, I can create a reference to it. This:

...this approach is illustrated in Figure \ref{Variability_transcript_abundance}...

becomes
...this approach is illustrated in Figure 2.2...

sometimes i want to have a page number too. i use this

...this approach is illustrated in Figure \vref{Variability_transcript_abundance} on page \pageref{Variability_transcript_abundance}...

to get

...this approach is illustrated in Figure 2.2 on page 32...

The genius of vref is this: the same code gets you different types of references, depending on the distance between where your text is and where your figure is. so

...this approach is illustrated in Figure \vref{Variability_transcript_abundance}...

gets you whichever of these:

...this approach is illustrated in Figure 2.2 on the following page...

...this approach is illustrated in Figure 2.2 on page 32...

...this approach is illustrated in Figure 2.2...

applies. when the figure is on the same page, no need to mention the page! of particular joy is that this package was last updated in 1999. such stability. ahhh, LaTeX.