9

Is there a way to use \ref{} inside the test part of \ifnum. The following example runs into an error.

\documentclass{article}

\begin{document}

\begin{table}
    \caption{ex}
    \label{tab:ex}
\end{table}

\def\a{\ref{tab:ex}}
\ifnum\a>0 y\else n\fi

\end{document}
moewe
  • 175,683
masu
  • 6,571

1 Answers1

8

You can use the command \getrefnumber from the package refcount and define \a as

\def\a{\getrefnumber{tab:ex}}

At this point change your MWE to

\documentclass{article}
\usepackage{refcount}

\begin{document}

\begin{table}
    \caption{ex}
    \label{tab:ex}
\end{table}

\def\a{\getrefnumber{tab:ex}}
\ifnum\a>0 y\else n\fi

\end{document} 

and you will get what you want.

karlkoeller
  • 124,410