1

For some reason I can't use some commands, such as \def in the name of a theorem when using apxproof's repeated theorems. And I can't understand why. It does not seem to be related to the fact that the theorem is repeated or not, since adding the [appendix=strip] option to the apxproof package does not fix the problem.

\documentclass[]{article}
\usepackage{apxproof}
\newtheoremrep{thm}{Theorem}
\begin{document}

\newcommand{\nicecommand}{(Nice command)}
%\newcommand{\notnicecommand}{a\\b}
\newcommand{\notnicecommand}{\def\mything{a}}

% thmrep with any some commands in the name works
\begin{thmrep}[Name A\nicecommand]
    Text A
\end{thmrep}

% thm with any command in the name works
\begin{thm}[Name B\notnicecommand]
    Text B
\end{thm}

% thm with any command in the name works, even when pushed to the appendix
\begin{toappendix}
    \begin{thm}[Name C\notnicecommand]
        Text C
    \end{thm}
\end{toappendix}

% thm rep with a not nice command in the name does not work
\begin{thmrep}[Name D\notnicecommand]
    Text D
\end{thmrep}% Undefined control sequence. \end{thmrep}

\end{document}

My real use case is that I want to use a macro that uses this one in the name of a theorem:

\newcommand{\latexiteeq}[4]{%
  \def\tmpa{#1}%
  \def\tmpb{#2}%
  \ifx\tmpa\tmpb%
    #3
  \else%
    #4
  \fi%
}

Edit: I managed to rewrite \latexiteeq in a way that avoids using \def but I still have the same problem because some other part of the macro I use uses \def.

6
  • Most likely thmrep tries to expand \notnicecommand, which isn't possible, because it has a \def inside.
    – user31729
    Feb 1 '18 at 16:25
  • Try \ifnum0=\pdfstrcmp{#1}{#2}\relax#3\else#4\fi instead of \def\tmpa{#1}..\ifx...\fi inside that macro. \pdfstrcmp works for pdftex and pdflatex only, however, but is expandable
    – user31729
    Feb 1 '18 at 17:14
  • @ChristianHupfer Thanks. This does remove the problems caused by \latexiteeq. But apparently, I have other macros that use \def or some other "not nice" commands. And those are in complicated packages that I'd rather not mess with.
    – xavierm02
    Feb 1 '18 at 17:17
  • Yes, but the other macros are not in your posted example, are they?
    – user31729
    Feb 1 '18 at 17:24
  • @ChristianHupfer The commented \notnicecommand makes it fail too. And I just found a new one: \scalebox{0.5}{a}.
    – xavierm02
    Feb 1 '18 at 17:27
1

Use \robustify from etoolbox.

\documentclass[]{article}
\usepackage{apxproof}
\usepackage{etoolbox}         %  <----------------- added this package
\newtheoremrep{thm}{Theorem}
\begin{document}

\newcommand{\nicecommand}{(Nice command)}
%\newcommand{\notnicecommand}{a\\b}
\newcommand{\notnicecommand}{\def\mything{a}}
\robustify{\notnicecommand}  % <----------------- added this line

\begin{thmrep}[Name A\nicecommand]
    Text A
\end{thmrep}

\begin{thm}[Name B\notnicecommand]
    Text B
\end{thm}

\begin{toappendix}
    \begin{thm}[Name C\notnicecommand]
        Text C
    \end{thm}
\end{toappendix}

\begin{thmrep}[Name D\notnicecommand]
    Text D
\end{thmrep}

\end{document}

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.