I want to create a function that generates a list of equation references from a comma delimited input list. e.g.
\erefs{eq:first, eq:second, eq:third}
\erefs{eq:first}
yields, the following:
(\ref{eq:first}), (\ref{eq:second}), and (\ref{eq:third})
(\ref{eq:first})
I am able to take care of the 1 item list correctly , but am having trouble generating the 'and' for the last element. Any ideas on how to add the 'and' to this code?
\documentclass{article}
\usepackage{tikz, amsmath, hyperref}
\def\erefs#1{%
\gdef\firstelement{1}
\foreach \e [count=\ni] in {#1}{%
\ifnum\firstelement=0 , \fi %
(\ref{\e})%
\gdef\firstelement{0}%
}
}
\begin{document}
\begin{equation}\label{eq:first}\end{equation}
\begin{equation}\label{eq:second}\end{equation}
\begin{equation}\label{eq:third}\end{equation}
\erefs{eq:first, eq:second, eq:third}
\erefs{eq:first}
\end{document}
I need to use hyperref and amsmath packages concurrently
ADDITION:
I frequently use \package{xr} and \externaldocument{...} to refer to a technical appendix, and like to put TA. in front of those references. It would be nice if an optional parameter could be passed for a prefix
I want to create a function that generates a list of equation references from a comma delimited input list. e.g.
\erefs{eq:first, eq:second, eq:third}
\erefs{eq:first}
\erefs[TA]{eq:first, eq:second, eq:third}
\erefs[TA]{eq:first}
yields, the following:
(\ref{eq:first}), (\ref{eq:second}), and (\ref{eq:third})
(\ref{eq:first})
(TA.\ref{eq:first}), (TA.\ref{eq:second}), and (TA.\ref{eq:third})
(TA.\ref{eq:first})





cleverefpackage? It does this sort of thing out of the box. – Paul Gessler Mar 06 '14 at 21:22forcsvlistfrometoolboxpackage might help? – Mar 06 '14 at 21:45\documentclassand the appropriate packages that sets up the problem. While solving problems can be fun, setting them up is not. Then, those trying to help can simply cut and paste your MWE and get started on solving the problem. – Peter Grill Mar 06 '14 at 21:52cleverefwork fine withamsmathandhyperref; see Difference between ref, varioref and cleveref. Decision for a thesis, for example :) – cmhughes Mar 06 '14 at 23:58