I was trying to define a command to behave differently when the text is italic, and I came across a difference between \newcommand
and \newcommand*
(or rather, I think, a behavior of \long
definitions or of \ifx
) that I don't understand. Basically, I define a command \@it
to be it
. Then, I want to check whether the text is italic or not using \ifx\f@shape\@it
. This test works when \@it
is defined using \def
or \newcommand*
, but not when \@it
is defined using \long\def
or \newcommand
.
The following example should make everything clear.
\documentclass{article}
\makeatletter
\def\@defit{it}
\long\def\@longdefit{it}
\newcommand{\@ncit}{it}
\newcommand*{\@ncsit}{it}
\newcommand{\itcheck}{%
\ifx\f@shape\@defit
The test from \textnormal{\textbackslash\texttt{def}} found the italic shape.
\else
The test from \textnormal{\textbackslash\texttt{def}} did not found the italic shape.
\fi\par
\ifx\f@shape\@longdefit
The test from \textnormal{\textbackslash\texttt{long}\textbackslash\texttt{def}} found the italic shape.
\else
The test from \textnormal{\textbackslash\texttt{long}\textbackslash\texttt{def}} did not found the italic shape.
\fi\par
\ifx\f@shape\@ncit
The test from \textnormal{\textbackslash\texttt{newcommand}} found the italic shape.
\else
The test from \textnormal{\textbackslash\texttt{newcommand}} did not found the italic shape.
\fi\par
\ifx\f@shape\@ncsit
The test from \textbackslash\textnormal{\texttt{newcommand*}} found the italic shape.
\else
The test from \textbackslash\textnormal{\texttt{newcommand*}} did not found the italic shape.
\fi%
}
\makeatother
\begin{document}
\itshape\itcheck
\end{document}
I would have expected all tests to return true. Why is it not the case?