6

I searched for this topic, but I didn't find anything, so I hope this isn't a duplicate.

I've got the following code:

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[german]{babel}

\begin{document}

\newcount\testA
\testA=1

\newcounter{testB}
\setcounter{testB}{1}

\ifnum\testA=\testB
TRUE
\else
FALSE
\fi

That is not working. It gets an error message. I also tried:

\newcount\testA
\testA=1

\newcounter{testB}
\setcounter{testB}{1}

\ifnum\testA=\value{\testB} %edit: solution is \value{testB}
TRUE
\else
FALSE
\fi

This works neither and gets an error message "undefined".

The workaround worked:

\newcount\testA
\testA=1

\newcounter{testB}
\setcounter{testB}{1}

\newcounter{temp}
\setcounter{temp}{\testA}

\arabic{temp}

\ifnum\temp=\testB
TRUE
\else
FALSE
\fi

How can I get this to work without the workaround? Is there a direct way.

2
  • it's \ifnum\testA=\value{testB}
    – touhami
    Apr 15, 2016 at 6:37
  • Of course. I supposed, that it is simple like that. Didn't see it though. Would you like to post this as an answer? Apr 15, 2016 at 6:40

2 Answers 2

10

The name of the internal counter is \c@testB. And \value will work if you remove the backslash.

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[german]{babel}

\begin{document}

\newcount\testA
\testA=1

\newcounter{testB}
\setcounter{testB}{1}

\makeatletter
\ifnum\testA=\c@testB
TRUE
\else
FALSE
\fi
\makeatother


\ifnum\testA=\value{testB}
TRUE
\else
FALSE
\fi
\end{document}

enter image description here

9

The solution is to use

\ifnum\testA=\value{testB}

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.