local_cmmds.tex: Add \iref, \fref, and \xref
authorW. Trevor King <wking@tremily.us>
Thu, 9 May 2013 00:33:19 +0000 (20:33 -0400)
committerW. Trevor King <wking@tremily.us>
Thu, 9 May 2013 00:33:19 +0000 (20:33 -0400)
This makes it easy to get consistent (and flexible) formatting for
references to external equations, figures, etc.  I'm surprised that
this isn't somehow bundled into cleveref or natbib.  If I get time, I
may try and pull it out into its own package.

Based Joseph Wright's answer [2] to a question about switch statements
[1].

[1]: http://tex.stackexchange.com/questions/29133/how-to-create-switch-structure-comparing-strings-in-latex
[2]: http://tex.stackexchange.com/a/29139

src/local_cmmds.tex
src/packages.tex

index 347a86e8293bcba056c1233bb3706506484faf70..6c003ced54680d8f95f808ac1df6c6667035521f 100644 (file)
@@ -1,3 +1,35 @@
+% String comparison for \fref
+\makeatletter
+\long\def\isequal#1#2{\pdf@strcmp{#1}{#2}}
+\makeatother
+
+% An reference index from an unspecified source
+% usage: \iref{value}
+% for example: \iref{75}
+\newcommand{\iref}[1]{(#1)}
+
+% A formatted reference from an unspecified source
+% usage: \fref{environment}{value}
+% for example: \fref{figure}{75}
+\newcommand{\fref}[2]{%
+  \switch
+  \case{\isequal{#1}{equation}}
+    Eqn.~\iref{#2}
+  \case{\isequal{#1}{figure}}
+    Fig.~\iref{#2}
+  \otherwise
+    \PackageError{fref}{
+      \MessageBreak
+      environment value >#2< unknown \MessageBreak
+    }{possible values are: equation. \MessageBreak}
+  \endswitch
+}
+
+% References to external figures, equations, etc.
+% usage: \xref{key}{environment}{value}
+% for example: \xref{roman12}{figure}{75}
+\newcommand{\xref}[3]{\citet{#1}'s \fref{#2}{#3}}
+
 % Fourier Transform to angular momentum space
 \newcommand{\Four}[1]{\ensuremath{{\mathcal F}\left\{ {#1} \right\}}}
 % Fourier Transform to frequency space
index 3191a36c738c34f2082550163db16a07243c51d0..fdb63ccdb288d0bb02d7af55ce1219433f79e73e 100644 (file)
 % Nicer references with \cref, \Cref, etc.
 \usepackage[capitalize]{cleveref}
 
+% For defining my own \fref command
+\usepackage{boolexpr}
+\usepackage{pdftexcmds}
+
 % Epigraphs (chapter-leading quotations)
 \usepackage{epigraph}