# How to define a new counter independent of section

I am trying to create exercises within a paper, by which the numbering will be as one would expect (1, 2, 3, ...). However, when defining a new counter and theoremstyle:

\documentclass{article}
\usepackage{amsthm}
\newtheoremstyle{exercise}
{\topsep}   % above space
{\topsep}   % below space
{\it}  % body font
{0pt}       % indent
{5pt plus 1pt minus 1pt} % HEADSPACE

\theoremstyle{exercise}
\newcounter{exercises}
\def\theexercises{}

\newtheorem{exer}{Exercise}[exercises]

\begin{document}

\begin{exer}\end{exer}

\end{document}


This code results in a counter with periods before the values without the line

How do I get rid of the period the precedes the counter? Also, if it helps, without the line

\def\theexercises{}


the counter will have the leading zero, right before the period.

• You're using the \newtheorem the wrong way: \newtheorem{exer}[exercises]{Exercise}, mind the order of the arguments and their meanings. But in fact, the \newtheorem{exer}{Exercise} would define the exer counter automatically. The first version just tells to use another counter which is already predefined – user31729 Jun 9 '15 at 3:11
• Thank you so much! I will upvote your answer as soon as I have sufficient reputation. – mvarble Jun 9 '15 at 3:16
• The counter exer is "chained" to the counter exercises, but the latter isn't being stepped. Hence the .1, .2, .3, look. – Mico Jun 9 '15 at 4:56

The \newtheorem command has two mutually exclusive optional arguments, their meaning depending on the position:

1. \newtheorem{foo}{Foo} defines the environment foo, a counter named foo and entitles it Foo

2. \newtheorem{foo}[otherfoo]{Foo} defines the environment foo, uses (shares) the already existing counter otherfoo and the title Foo

3. \newtheorem{foo}{Foo}[otherfoo] does the definition as in 1), but tells to define the counter foo being driven by otherfoo, i.e. it's reset if otherfoo is stepped (like being defined \newcounter{foo}[otherfoo], compare the standard chapter/section behaviour)

So, either use version 1) or 2). The first version is to be preferred if the environment should have a new counter, the second, if the counter already exists.

You can see the difference by explicitly setting the exercises counter to 19, just for example.

\documentclass{article}
\usepackage{amsthm}
\newtheoremstyle{exercise}
{\topsep}   % above space
{\topsep}   % below space
{\itshape}  % body font
{0pt}       % indent
{5pt plus 1pt minus 1pt} % HEADSPACE

\theoremstyle{exercise}
\newcounter{exercises}

\setcounter{exercises}{19} % Just for demonstration

\newtheorem{exer}[exercises]{Exercise}

\newtheorem{exers}{Exer}

\begin{document}

\begin{exer}\end{exer}

\begin{exers}
This is the exers env with counter number \theexers
\end{exers}

\end{document}


• Body font should be set with \itshape, not with \it. – GuM Jun 9 '15 at 4:42
• @GustavoMezzetti: Yes, that was in the original version of the OP... I did not change because it's not important for the question, but I changed it now – user31729 Jun 9 '15 at 4:44
• Of course, it was just a minor remark. But I think it's always better to show the correct way of doing things in an answer. :-) – GuM Jun 9 '15 at 4:51
• I'd prefer if the answer just showed the \newtheorem{exer}{Exercise} solution without the complication of the new counter that doesn't seem really useful. With chngcntr, one can also say \counterwithin*{exer}{section} so the exer counter is reset when section is stepped. – egreg Jun 9 '15 at 9:56
• @egreg: Yes and no (concerning the exercises counter). The MWE does not seem to be useful with this exercises counter. In this case the version with the exer theorem is better. If there's more background, we could leave the exercises counter. That's why I used both 'ideas'... I'll edit the answer and include your suggestion about the chngcntr` way. Thanks for your comment! – user31729 Jun 9 '15 at 10:04