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}
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.