# First reference to equation underlined

In these days I'm writing at my Bachelor's Thesis and I've got a new problem. I have to underline the first reference to figures, tables and equations. By searching in the Internet I've already found a solution for the figures an the tables. But I didn't succeed editing the code, so that is would work with equations. Does anybody know, how to change the solution of figures/tables for the equations? I'm using the align-environment for the equations, labeling it with the prefix eqn: (\ref{eqn:abc})

My Code-Sample:

\documentclass[
pagesize,
DIV = calc,
liststotoc,
bibtotoc,
idxtotoc]{scrreprt}

\usepackage{amsmath}

\newif\ifMeinFormat
%\MeinFormattrue
\MeinFormatfalse

\makeatletter
\@ifdefinable\evtlfett{%
\ifMeinFormat
\let\evtlfett\@firstofone
\else
\let\evtlfett\underline
\fi
}%

\def\p@figure{\expandafter\p@@figure}%
\def\p@@figure#1{\@figmkdef{#1}}%
\DeclareRobustCommand\@figmkdef[1]{%
\@ifundefined{figmk#1}
{%
\global\@namedef{figmk#1}{}%
\evtlfett{Abbildung #1}%
}%
{Abbildung #1}%
}%

\def\p@table{\expandafter\p@@table}%
\def\p@@table#1{\@tablemkdef{#1}}%
\DeclareRobustCommand\@tablemkdef[1]{%
\@ifundefined{tblmk#1}
{%
\global\@namedef{tblmk#1}{}%
\evtlfett{Tabelle #1}%
}%
{Tabelle #1}%
}%

\makeatother

\begin{document}
\section{test}
{\begingroup erster Verweis auf die Figur: \ref{fig} \endgroup}\\
zweiter Verweis auf die Figur: \ref{fig}\\
erster Verweis auf die Table: \ref{tab}\\
zweiter Verweis auf die Table: \ref{tab}\\
erster Verweis auf die Gleichung: \ref{eqn:abc}\\
zweiter Verweis auf die Gleichung: \ref{eqn:abc}\\

\begin{figure}
Irgend ne Figur
\caption{\label{fig}Text}
\end{figure}

\begin{table}
Irgend ne Table
\caption{\label{tab}Text}
\end{table}

\begin{align}
a + b = c \label{eqn:abc}
\end{align}

\end{document}

• Good lord, who develops such strange requirements?! The professor should be forced to do this stuff himself only once... Apr 9 '13 at 20:25
• He does this crap in his own stuff too, but using Word. One of the PhD students asked me, if I could dispose them my tex-template for the students. But I don't know yet ;-) Apr 9 '13 at 21:02
• How about hooking into \eqref, and always using that?
– mafp
Apr 10 '13 at 0:01
• Can you (or some wizard reading this) hack the figure or table environment so that it doesn't float, but so that you can still take advantage of the solution you have for those? Then put your equations in the new environment. Positioning the equation number might be a problem. Apr 10 '13 at 0:26
• I already tried to edit the section beginning with \def\p@table, but I don't know, what to write instead of tblmk and so on for the equation-area. The align-enviroment does exactly what I want, it's just the reference. Apr 10 '13 at 0:55

With added improvements, suggested by egreg it is now:

\documentclass[
pagesize,
DIV = calc,
liststotoc,
bibtotoc,
idxtotoc]{scrreprt}

\usepackage{amsmath}
\usepackage{letltxmacro}
\usepackage[ngerman]{cleveref}

\AtBeginDocument{%
\LetLtxMacro\oldcref\cref%
\renewcommand{\cref}[1]{%
\ifcsname[#1]\endcsname\relax%
{\oldcref{#1}}%
\else%
{\underline{\oldcref{#1}}%
}%
\expandafter\gdef\csname[#1]\endcsname{1}%
\fi%
}%
}

\begin{document}
\section{test}
erster Verweis auf die Figur: \cref{fig} \\
zweiter Verweis auf die Figur: \cref{fig}\\
erster Verweis auf die Table: \cref{tab}\\
zweiter Verweis auf die Table: \cref{tab}\\
erster Verweis auf die Gleichung: \cref{eqn:abc} \\
zweiter Verweis auf die Gleichung: \cref{eqn:abc}\\
dritte Verweis auf die Gleichung:  \cref{eqn:abc}\\

\begin{figure}
Irgend ne Figur
\caption{\label{fig}Text}
\end{figure}

\begin{table}
Irgend ne Table
\caption{\label{tab}Text}
\end{table}

\begin{align}
a + b = c \label{eqn:abc}
\end{align}

\end{document}

• Hi, the underlining is also done by the command \evtlfett in the macro above. In your solution there is only the number underlined. I also need the "Abbildung", "Tabelle" or "Gleichung" underlined. So the best way would be to change this part: \def\p@table{\expandafter\p@@table}% \def\p@@table#1{\@tablemkdef{#1}}% \DeclareRobustCommand\@tablemkdef[1]{% \@ifundefined{tblmk#1} {% \global\@namedef{tblmk#1}{}% \evtlfett{Tabelle #1}% }% {Tabelle #1}% }% Apr 10 '13 at 22:33
• I'd use \expandafter\gdef\csname[#1]\endcsname to take care of the case the reference happens to be in a group. For underlining also the name, probably cleveref is a good candidate. Apr 10 '13 at 22:41
• If you use \cref instead of \ref loading \usepackage[ngerman]{cleverer} you get what's desired (which is horrible and completely useless). Apr 10 '13 at 22:48
• Is it possible that you give a little example so that I get the correct order of the commands? Thanks a lot! Apr 10 '13 at 22:58
• @mafp: now I saw it! I missed the update! Apr 11 '13 at 10:36