2

I am currently stating theorems in the body of my document and then proving them in the appendix (using thmtools). I will currently write something like

\begin{restatable}[Proof in \Cref{whatever}]{lemma}{whatever}
       Lemma stuff
\end{restatable}

When I restate the lemma in the appendix, I don't want the optional argument (saying where the proof is) to reappear. Is there a way to get thmtools, or some other package to do this?

Edit: Below I have included a working example

\documentclass{article}
\usepackage{amsthm}
\usepackage{thmtools}
\begin{document}
\newtheorem{lemma}{Lemma}
\begin{restatable}[Proof in Foo]{lemma}{whatever}
       Lemma stuff
\end{restatable}
\section{Hmm}
\whatever*
\appendix
\section{Wow}
\whatever*
\end{document}

1 Answer 1

2

The apptools package provides the \IfAppendix{<true>}{<false} which can be used to detect \appendix, using xpatch we can hook into the definition of \thmt@restatable (the macro called by \begin{restatable}) and adjust how the optional argument is used, the pertinent part being \csname #2\@xa\endcsname\ifx\@nx#1\@nx\else[{#1}]\fi. We can set it up to branch such that optional argument only gets used if we are not in the appendix, therefore replacing that snippet with \IfAppendix{\csname #2\@xa\endcsname}{\csname #2\@xa\endcsname\ifx\@nx#1\@nx\else[{#1}]\fi such that the \ifx which checks whether #1 is non-empty and then passes it on is only included outside of the appendix.

\documentclass{article}
\usepackage{xpatch}
\usepackage{thmtools}
\usepackage{apptools}

\makeatletter
\xpatchcmd{\thmt@restatable}% Edit \thmt@restatable
{\csname #2\@xa\endcsname\ifx\@nx#1\@nx\else[{#1}]\fi}% Replace this code
{\IfAppendix{\csname #2\@xa\endcsname}{\csname #2\@xa\endcsname\ifx\@nx#1\@nx\else[{#1}]\fi}}% with this code
{}{} % execute code for success/failure instances
\makeatother

\newtheorem{lemma}{Lemma}

\begin{document}

\begin{restatable}[Proof in Foo]{lemma}{whatever}
       Lemma stuff
\end{restatable}

\whatever*

\appendix

\whatever*

\end{document}

produces

Theorems with source omitted in appendices

8
  • 1
    Actually, it appears as though somehow the brackets aren't being evaluated properly, since the contents "Proof in Foo" are no longer passed as an optional argument to the theorem environment (i.e., they should be surrounded in parentheses in the formatted output).
    – brett1479
    May 11, 2017 at 7:28
  • To fix the issue I have replaced way more of the line in thm-restate.sty, but I am not sure if there is a better way.
    – brett1479
    May 11, 2017 at 7:36
  • @brett1479 perhaps you can edit your question to provide an MWE which demonstrates this? Or if you have a functional solution perhaps you could add a self-answer. The code I have works for this basic example, so it sounds like it breaks when you add in/try to do something extra, unless I've misunderstood?
    – Dai Bowen
    May 11, 2017 at 9:04
  • I have added a working example.
    – brett1479
    May 11, 2017 at 17:27
  • @brett1479 I see, seems like the \IfAppendix is too late and either interferes with the expansion or hides the [ so it's not found when expected, I can't really explain it but it seems that using \xpatchcmd{\thmt@restatable}{\csname #2\@xa\endcsname\ifx\@nx#1\@nx\else[{#1}]\fi}{\IfAppendix{\csname #2\@xa\endcsname}{\csname #2\@xa\endcsname\ifx\@nx#1\@nx\else[{#1}]\fi}}{}{} instead seems to work.
    – Dai Bowen
    May 11, 2017 at 18:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .