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 Answers1

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

Dai Bowen
  • 6,117
  • 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 '17 at 07: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 '17 at 07: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 '17 at 09:04
  • I have added a working example. – brett1479 May 11 '17 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 '17 at 18:08
  • I would like to do something similar. I want to state a theorem in the introduction of my paper with the optional argument, and then when I restate the theorem in later sections, I do not want the optional argument to appear. How any ideas how to do this? – David Wood Jun 13 '18 at 00:50
  • @DavidWood it depends what you want exactly. If it's that beyond a certain point in the text you want all optional arguments to the theorem to be ignored (in both restated and newly created restatable theorems) then define a new \if and use that instead of \IfAppendix, I can probably edit this answer to include that case. Otherwise please ask a new question with a proper spec/MWE (and ping me here with a link and I'll take a look). – Dai Bowen Jun 13 '18 at 10:05
  • @DavidWood Ah, I see you already have – Dai Bowen Jun 13 '18 at 10:26