3

I want to use the restatable package with a custom environment. It almost works except when I restate with \name* it does not use the original label.

Before you ask, I'm not using newtheorem because its formatting doesn't agree with me needs and using amsthm, to my dismay, is not an option.

Here's a minimal example:

\documentclass{article}

\usepackage{thmtools}

\newcounter{main}
\newcommand{\envheader}[2]{%
  \refstepcounter{main}\par\smallskip \textbf{{#2}~\thesection.\themain.}
    \if\relax\detokenize{#1}\relax\else{({#1})}\fi %% Name of the theorem
  }

\newenvironment{theorem}[1][]{\envheader{#1}{Theorem}\itshape\/}{\smallskip}
\newenvironment{lemma}[1][]{\envheader{#1}{Lemma}\itshape\/}{\smallskip}

\begin{document}

\begin{restatable}{theorem}{mytheorem}\label{thm:mytheorem}
  How you doin'?
\end{restatable}

\mytheorem*

\end{document}

Here's what I get:

Minimal example output

Madgen
  • 83

1 Answers1

4

restatable expects that the internal counter has the same name as the environment, so you should use theorem instead of main. Side remark: your definition will not prevent page breaks between the theorem title and the body.

\documentclass{article}

\usepackage{thmtools}

\newcounter{theorem}
\newcommand{\envheader}[2]{%
  \refstepcounter{theorem}\par\smallskip \textbf{{#2}~\thesection.\thetheorem.}
    \if\relax\detokenize{#1}\relax\else{({#1})}\fi %% Name of the theorem
  }

\newenvironment{theorem}[1][]{\envheader{#1}{Theorem}\itshape\/}{\smallskip}
\newenvironment{lemma}[1][]{\envheader{#1}{Lemma}\itshape\/}{\smallskip}

\begin{document}

\begin{restatable}{theorem}{mytheorem}\label{thm:mytheorem}
  How you doin'?
\end{restatable}

\mytheorem*

\end{document}

enter image description here

Ulrike Fischer
  • 327,261
  • 1
    That works but I'd like to use the same counter for theorem and lemma. I tried to create a theorem counter and do \setcounter{theorem}{\value{main}}, in the environment definition, but it doesn't seem to work... – Madgen Apr 19 '19 at 18:16
  • That's a new question so better ask a new question. – Ulrike Fischer Apr 19 '19 at 18:57
  • I'd say it's a related question that's definitely implied by my example. – Madgen Apr 19 '19 at 18:59