TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to have \newtheorem{teo}{Teorema}[chapter] if the book class is loaded but \newtheorem{teo}{Teorema}[section] if the article class is loaded. Can I do this with some sort of conditional?

\newtheorem{teo}{Teorema}[chapter] %if book
\newtheorem{teo}{Teorema}[section] %if article


share|improve this question
I think this question Which document class is being used? should answer your question. – Alan Munn Aug 10 '11 at 3:49
For others that can't work out solutions here: I had a similar need but the place where knowledge of class was needed was inside a style file (.sty). Solutions here had LaTeX fail. It worked using \@ifclassloaded along with bits taken from: conditionals - Test if a package (or package option) is loaded - TeX - LaTeX Stack Exchange – Stéphane Gourichon Mar 5 '14 at 8:57
up vote 9 down vote accepted

Altough, the link Alan points to has the required info, that page assumes that you already know about \makeatletter/\makeatother macros, which depending on the experience level one may not have encountered.

The following is intended to exit if a class other than book or article is used. You can remove the \QUITHERE macro if that is not desired.


    \newtheorem{teo}{Teorema}[chapter]%if book
    \typeout{Using book class.}%
        \newtheorem{teo}{Teorema}[section]%if article
        \typeout{Using article class.}%
        \typeout{Error: Unsupported class: only 'article' and 'book' are suported.}\QUITHERE

share|improve this answer
Thank you !!!!! – Regis da Silva Aug 10 '11 at 4:14
Also see similar question on how to configure fancyhdr depending on the document class – Peter Grill Aug 12 '11 at 4:39

It seems your aim is to make theorem numbers subordinate to the highest (non-\part) sectioning level defined in the respective document class -- \chapter for the book class, and \section for article. Therefore, I suggest to test not for the name of the loaded class, but for the availability of the \chapter command. If this command is undefined (or its meaning is \relax), number theorems per section, else, per chapter. This method will also work for, e.g., the report class and the KOMA-Script classes.



  \newtheorem{teo}{Teorema}[section]% if \chapter not defined
  \typeout{Numbering theorems per section.}%
  \newtheorem{teo}{Teorema}[chapter]% if \chapter defined
  \typeout{Numbering theorems per chapter.}%


A theorem.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.