I want to redefine by hand a "restatable" environment for theorems. I have to do so because for some obscure reason the jloganal
class (for the Journal of Logic and Analysis) mess it up: when restated, theorems have a new number corresponding to the section they are restated in. The journal suggests to "fake the environment" and rewrite it entirely. I do not like this "solution". By the way, this exercise is a good occasion to improve my Latex skills.
Here is an attempt:
\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{xparse}
\NewDocumentEnvironment{restate}{mmmb}{
\expandafter\xdef\csname #2\endcsname{#4}
\begin{#1}\label{#3}#4\end{#1}
}{}
\newtheorem{thm}{Theorem}
\begin{document}
\begin{restate}{thm}{thmun}{thmlabel}
test-text $\forall x\in\mathbb{R}\quad f(x)=1$
\end{restate}
\thmun
\end{document}
My problem is that \mathbb{R}
leads to an error:
26: Undefined control sequence. \end
26: Undefined control sequence. \end
26: Undefined control sequence. \end
26: Undefined control sequence. \end
27: Missing { inserted. \thmun
: File ended while scanning text of \errhelp.
Also I am looking for a command that would behave like this: \getEnvName{thm}
would write Theorem
.
Thank you for your help.
Best Answer
Why
\xdef
? You just want\gdef
.A better way would be to store alse
\begin{thm}
and\end{thm}
and also locally redefining\thethm
in the restatement, so the number agree.Note that
inputenc
withutf8
is no longer needed, nor isxparse
.I used the “modern”
\ExpandArgs{c}\gdef{...}
instead of the clumsierFor your particular setting, I wouldn't look for greater generality.