10

I have noticed the following strange behavior when using a custom counter in certain situations in amsart document class. Here is an example:

\documentclass{amsart}
\newcounter{exercise}
\newcommand{\exercise}{\stepcounter{exercise}
                       \subsection*{Exercise \theexercise}}
\begin{document}
\exercise
% Text.
\exercise
\end{document}

This prints 2 times "Exercise 2". The behavior goes back to "normal" if i either:

  1. replace amsart with article, or
  2. replace \subsection with \section, or
  3. uncomment the text "Text.".

This will not cause a problem in a useful document because when there is some text between \exercise's, the problem goes away, but i think this can indicate some bug in amsart, so i wanted to report it, but i didn't find where. What should i do?

  • 1
    To avoid this, you need to set something that is a non-heading. For this, you could use \newcommand{\exercise}{\stepcounter{exercise}\subsection*{Exercise \theexercise}\mbox{}} for your definition of \exercise. – Werner Sep 30 '13 at 17:06
  • @Werner or better just use the subsection counter as intended instead of a new exercise counter – David Carlisle Sep 30 '13 at 19:53
  • 1
    the e-mail address for reporting bugs to ams is included in the comments at the top of every file distributed by ams. or, in this case, as david points out, since this is a "required" latex file, it can be reported via the latex-bugs facility. but, as david also says, this isn't a bug, but a feature based on how \subsection is defined. you might consider an alternative approach, though -- the \newtheorem facility would seem to fit nicely, using \theoremstyle{definition}. – barbara beeton Sep 30 '13 at 20:23
  • @DavidCarlisle, exercises are not subsections, there is no reason to try to use subsection counter to count exercises. This also would not work if i have both subsections and exercises. – Alexey Oct 1 '13 at 6:58
  • @Alexey well in that case don't use the subsection command:-) You should copy the definition of subsection (which is only a couple of lines) using your own counter. – David Carlisle Oct 1 '13 at 8:49
19

You can report AMS bugs direct to them or using the LaTeX bug database form at

http://www.latex-project.org/bugs.html

(category AMS LaTeX).

This isn't really a bug though as \subsubsection is an inline heading in the AMS class and so the heading doesn't get set until the following paragraph starts. The standard LaTeX sectioning code takes care of the counter increment but if you suppress that with * but then simply \stepcounter your own counter this will not work (nor can you \label the section.)

You see identical behaviour with \paragraph* in article class.


enter image description here

\documentclass{amsart}

\newcommand{\exercise}{\subsection{}}
\renewcommand\thesubsection{Exercise \arabic{subsection}}

\begin{document}

\exercise
% Text.
\exercise
\end{document}
  • Could you explain please what inline heading is, or give a link to where it is explained? – Alexey Oct 1 '13 at 8:46
  • Ok, i've understood what it is. I am still wondering however why inline headings behave like this. – Alexey Oct 1 '13 at 8:48
  • Headings in latex are either display (block) headings where the heading has vertical space between it and the following paragraph or inline headings where the heading is set as part of the first line of the paragraph. in article the lowest level heading set inline is \paragraph but amsart sets \subsection and below inline. The latex companion or other latex tutorials should have details or just search this site for \@startsection – David Carlisle Oct 1 '13 at 8:53
  • 1
    @Alexey The heading is held back and not set until the start of the paragraph, and in the usage you have you have already incremented the counter a second time by the time the first heading is set. – David Carlisle Oct 1 '13 at 8:54

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.