From: W. Trevor King Date: Thu, 9 May 2013 00:33:19 +0000 (-0400) Subject: local_cmmds.tex: Add \iref, \fref, and \xref X-Git-Tag: v1.0~224 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=1a276a376aafa6d8818aa45daf11c027f8297a2a;p=thesis.git local_cmmds.tex: Add \iref, \fref, and \xref 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 --- diff --git a/src/local_cmmds.tex b/src/local_cmmds.tex index 347a86e..6c003ce 100644 --- a/src/local_cmmds.tex +++ b/src/local_cmmds.tex @@ -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 diff --git a/src/packages.tex b/src/packages.tex index 3191a36..fdb63cc 100644 --- a/src/packages.tex +++ b/src/packages.tex @@ -23,6 +23,10 @@ % 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}