# How to configure theorems depending on the document class?

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?

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

\begin{document}

\end{document}


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.

\documentclass{book}
\usepackage{theorem}

\makeatletter%
\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
}%
}%
\makeatother%

\begin{document}
\end{document}


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.

\documentclass{book}

\usepackage{etoolbox}

\ifundef{\chapter}{%
\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.}%
}

\begin{document}

\begin{teo}
A theorem.
\end{teo}

\end{document}