It may seem rather silly, but I can't find an answer for this question. (I've been looking for one for a while already).
Suppose I want to have a macro with a single parameter. When this parameter equals 1, I want the macro to append the singular form of a word to the parameter, otherwise use the plural form.
I have the following code:
\newcommand{\sth}[1]{\textbf{(#1
\if1#1thing)\else things)\fi}}
It works fine for any parameter except when it is a number greater than 1 but starting with 1 (e. gr. 11).
I am aware \if
compares two tokens which in this case are characters. I am also aware there are solutions that either assume #1
is always a number (e.g. using \ifnum) or use additional packages (like ifthen or pdftexcmds). I don't want to assume #1
is a number, because it seems cleaner to me, and I still wonder whether there is a core LaTeX solution to this (w/o using further packages).
Edit: the question is, is there a way of knowing if the argument is exactly '1' without assuming it is a number nor using additional packages?
Thanks in advance
\if
isn't the right tool for comparing numbers. Using\ifnum
is the "core TeX" way.#1
can also be a non-number, then the comparison with1
can be done with\ifnum\pdf@strcmp{#1}{1}=0 ...
(\pdf@strcmp
of packagepdftexcmds
(pdfTeX, XeTeX, LuaTeX).