4

I'm using thmtools for defining several environments for theorems, lemmas, etc.

Among these is an environment for corollaries. (I give the full definition of this environment at the end of this post). I'm restricting the designation of corollaries to immediate consequences of earlier items that I want to be able to refer to, but for which, instead of proofs, I will just provide cross-references to whatever earlier items they follow immediately from. For example, if corollary III.4.5 is the immediate consequence of items I.2.3 and II.3.4, I want something like:

Corollary III.4.5 (I.2.3 and II.3.4). Foo is equivalent to bar. ⬜

To do this in a way most consistent with the typographic conventions used elsewhere in the document (with the parenthesized reference coming before the period at the end of the corollary's head, as shown above), the thing to do is to use the built-in optional argument for theorem-like environments defined through thmtools' \declaretheorem. In fact, I do get the desired placement of the cross-references in the corollary's head if I specify something like

\begin{corollary}[some theorem and some definition]
Foo is equivalent to bar. \qed
\end{corollary}

This indeed compiles without any problem, but, of course, puts the string "(some theorem and some definition)" in the place where there should be proper cross references (as illustrated above):

Corollary III.4.5 (some theorem and some definition). Foo is equivalent to bar. ⬜

But when I try to specify proper cross-references with:

\begin{corollary}[\ref{some theorem} and \ref{some definition}]
%% ...

...I get the error

! Missing \endcsname inserted.
<to be read again>
                   \protect
l.345 ...{some theorem} and \ref{some definition}]

? 

Is there any way to protect the cross references so to avoid this error? (Edit: BTW, I get the same error even if I use \MakeRobustCommand\ref from the makerobust package. FWIW.)

PS: FWIW, below are the relevant definitions for the code shown earlier:

\def\qed{\hfill $\Box$}
\declaretheoremstyle[%
  spaceabove=4ex%
]{thmstyle}
\declaretheorem[%
  name={Theorem},%
  numberwithin=section,%
  style=thmstyle,%
]{thm}
\declaretheorem[%
  name={Corollary},%
  style=thmstyle,%
  sharenumber=thm,%
]{corollary}

EDIT BY LOCKSTEP: The following example works for me:

\documentclass{article}

\usepackage{amsthm}
\usepackage{thmtools}

\declaretheoremstyle[%
  spaceabove=4ex%
]{thmstyle}
\declaretheorem[%
  name={Theorem},%
  numberwithin=section,%
  style=thmstyle,%
]{thm}
\declaretheorem[%
  name={Corollary},%
  style=thmstyle,%
  sharenumber=thm,%
]{corollary}

\begin{document}

\section{foo}

\begin{thm}\label{a}
Some text.
\end{thm}

\begin{corollary}[\ref{a}]
Some text.
\end{corollary}

\end{document}

EDIT BY KJO: I copied and pasted lockstep's example, and ran it, but it does not work for me; the error I get is pretty much the same as the ones I got before:

! Missing \endcsname inserted.
<to be read again>
                   \protect
l.28 \begin{corollary}[\ref{a}]

? x

I re-ran the same code after prepending the \listfiles command to it, and put the generated log file here. Please, let me know what other info I should post to zero in on the reason for this discrepancy.

6
  • 2
    As lockstep's edit shows, I was also able to produce a minimal example that compiles with references. You must have "more" going on in the background. Consequently, please provide a minimal working example (MWE) that highlights the problem.
    – Werner
    Sep 24, 2011 at 14:58
  • @Werner: please see my response to lockstep, at the end of the original post.
    – kjo
    Sep 24, 2011 at 15:51
  • 1
    Your version of thmtools (50) is outdated. My version number is 61, and this is also the version curently listed at CTAN.
    – lockstep
    Sep 24, 2011 at 16:02
  • @kjo: It is obvious that you need to update your thmtools package. Your distribution lists it as 2010/08/09 v50 while the most up-to-date bundle on CTAN is 2011/06/02 v61. Try this and report back.
    – Werner
    Sep 24, 2011 at 16:03
  • @lockstep: okay, thanks for the info; I'd just installed the latest MacTeX bundle for OSX a few days ago, so I thought it was up-to-date. Clearly not... Thanks!
    – kjo
    Sep 24, 2011 at 16:05

3 Answers 3

2

Your version of thmtools (50) is outdated. My version number is 61, and this is also the version currently listed at CTAN. Updating your TeX distribution should resolve the error.

2

although this advice is usually given for amsthm, which you're not using, it may still work.

use \protect for your \refs, as

\begin{corollary}[\protect\ref{some theorem} and \protect\ref{some definition}]
1
  • I get pretty much the same error when I do this.
    – kjo
    Sep 24, 2011 at 15:54
1

I wonder -- but I can't be sure, of course, as you haven't provided information on how and where you create the labels and what names you choose for the labels -- if the problem lies in the way and/or the location whereby you create the labels of the theorems that you subsequently try to cross-reference. Normally, one would start a theorem-like environment as follows:

\begin{theorem}[Einstein] \label{th:emc2}
\[ E = mc^2\]
\end{theorem}

Note that the label must come after the start of the theorem. Elsewhere, you'd cross-reference this result with \ref{th:emc2} -- not as \ref[Einstein], to be sure.

I hope these comments help.

You must log in to answer this question.

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