[Tex/LaTex] How to test the value of two counters

conditionalscounters

I'd like to test the value of counters (preferably as vanilla TeX as it gets).

\documentclass{article}
\newcounter{counterA}
\newcounter{counterB}
\setcounter{counterA}{2}
\setcounter{counterB}{2}

\newcommand\maccommand{
  \ifx\the\value{counterA}=\the\value{counterB} 
    Just so you know, counterA (= \the\value{counterA}) holds the same value as counterB (= \the\value{counterB}).
  \else 
    Sorry, but the counterA (= \the\value{counterA}) is not equal to counterB (= \the\value{counterB}).
  \fi

Yet in TeX you can write:

\ifx\counterA>2 
  Just so you know, counterA is greater to than 2.
\else 
  Just so you know, counterA is not greater than 2.
\fi
}

Why can't you write

\ifx\counterA=2 
  Just so you know, counterA is equal to 2.
\else 
  Just so you know, counterA is not equal to 2.
\fi
}

OR

\ifx\counterA=\counterB 
  Just so you know, counterA is equal to counterB.
\else 
  Just so you know, counterA is not equal to counterB.
\fi
}

Best Answer

\thecounterA works only if the counter wasn't redefined:

\documentclass{article}
\newcounter{counterA}\renewcommand\thecounterA{A\arabic{counterA}}
\newcounter{counterB}\renewcommand\thecounterB{B\arabic{counterB}}
\setcounter{counterA}{2}
\setcounter{counterB}{2}

\newcommand\maccommand{%
  \ifnum\value{counterA}=\value{counterB}
    Just so you know, counterA (= \thecounterA) holds the same value as 
    counterB (=\thecounterB).%
  \else 
    Sorry, but the counterA (= \thecounterA) is not equal to counterB 
    (=\thecounterB).%
\fi}

\begin{document}
\maccommand

\stepcounter{counterA}
\maccommand

\end{document}

The TeX way:

\makeatletter
\newcommand\maccommand{%
  \ifnum\c@counterA=\c@counterB
    Just so you know, counterA (= \thecounterA) holds the same value as 
    counterB (=\thecounterB).%
  \else 
    Sorry, but the counterA (= \thecounterA) is not equal to counterB 
    (=\thecounterB).%
  \fi}
\makeatother

Internally \c@counterA holds the value and \thecounterA is the representation. On LaTeX level \c@counterA shouldn't be used.