5

I'm trying to create a new enviroment using restatable, but it doesn't work. What am I doing wrong?

\documentclass{article}

\usepackage{amsmath}
\usepackage{thmtools,thm-restate}

\newenvironment{restat}{\begin{restatable}{theorem}{A}}{\end{restatable}}

\begin{document}
  \begin{restat}A\end{restat}
\end{document}

I'm getting the following error message:

Runaway argument?

! File ended while scanning use of \thmt@collect@body.
<inserted text> 
                \par 
<*> pr

Thank you for your help.

  • 1
    Welcome! It is not a regular environment. It is collecting the entire body of the environment and then processing it. It is probably doing this by collecting everything up until \end{restatable}. But it never finds this because it is not there to be found. That is, it needs this to literally come somewhere in the source after \begin{restatable}. This is making some assumptions as I've not really looked carefully through the code, but I think they are fairly safe assumptions. It seems to work like e.g. environ. – cfr Nov 17 '15 at 2:58
  • You can probably nest them if you are careful, though. I've done that with environ environments. – cfr Nov 17 '15 at 2:59
6

The restatable environment needs to see an explicit \end{restatable} since it's actually collecting the entire environment body. As such, you need to capture the contents yourself:

\documentclass{article}

\usepackage{amsmath,environ}
\usepackage{thmtools,thm-restate}

\NewEnviron{restat}{%
  \begin{restatable}{theorem}{A}
  \BODY
  \end{restatable}%
}

\begin{document}
\begin{restat}
something
\end{restat}
\end{document}
  • 1
    This is actually what I've used before. This time, I did it differently because of the comments in the manual about amsmath. Do you know when the alternative version given there is actually preferable, by any chance? I'm not clear whether it matters in this case or not. – cfr Nov 17 '15 at 3:24
4

The problem is that restatable is not a regular environment. Rather, it scans forward to collect the entire body of the environment and then processes it. The code for \end{restatable} is, in fact, empty.

This depends on it literally finding \end{restatable} in the input stream. But since that is not in your document's source (after \begin{restatable}, it never finishes looking for it. It reaches \end{document} or whatever first.

To create a wrapper around an environment of this kind, you need to collect the body of your environment in the same way and then feed it to the wrapped environment. environ enables you to do this conveniently.

Here's a solution using the example from page 3 of environ's manual. I did it this way because it suggests this may be especially suitable if using amsmath although I'm not altogether sure whether it matters in this case.

It helps to avoid, I think, the possibility of conflicts with \BODY.

\documentclass{article}
\usepackage{amsmath}
\usepackage{environ}
\usepackage{thmtools,thm-restate}
\makeatletter
% mnodified from page 3 of environ manual
\newcommand\wrap[1]{\begin{restatable}{theorem}{A}#1\end{restatable}}
\newenvironment{restat}{\Collect@Body\wrap}{}
\makeatother

\begin{document}
 \begin{restat}A\end{restat}
\end{document}
4

You just need to use \restatable and \endrestatable as it's often the case with environments that need to grab their contents.

\documentclass{article}

\usepackage{amsmath}
\usepackage{thmtools,thm-restate}
\newtheorem{theorem}{Theorem}

\newenvironment{restat}
 {\restatable{theorem}{important}}
 {\endrestatable}

\begin{document}

\begin{restat}
A restatable theorem
\end{restat}

Let's restate it

\important*

\end{document}

enter image description here

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.