1

Possible Duplicate:
How to configure theorems depending on the document class?

I would like to have if the book class is loaded but if the article class is loaded. Can I do this with some sort of conditional?

I tried, but failed.

\makeatletter%
\@ifclassloaded{book}{%
  \renewcommand{\chaptermark}[1]{\markboth{#1}{}}
  \renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
  \fancyhead{}
  \renewcommand{\chaptermark}[1]{\markboth{\thechapter.\ #1}{}}
  \fancyhead[LE]{\bfseries\leftmark}
  \fancyhead[RO]{\bfseries\rightmark}
  \fancyfoot{}
  \fancyfoot[LE,RO]{\bfseries\thepage}
  \fancyfoot[LO,RE]{Régis}
  \renewcommand{\headrulewidth}{0.5pt}
  \renewcommand{\footrulewidth}{0.5pt}
  \addtolength{\headheight}{0.5pt}
  \fancypagestyle{plain}{%
  \fancyhead{}
  \renewcommand{\headrulewidth}{0pt}
  }
  \typeout{Using book class.}%
}{%
\@ifclassloaded{article}{%
%   \renewcommand{\chaptermark}[1]{\markboth{#1}{}}
  \renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
  \fancyhead{}
%   \renewcommand{\chaptermark}[1]{\markboth{\thechapter.\ #1}{}}
  \fancyhead[R]{\bfseries\rightmark}
  \fancyfoot{}
  \fancyfoot[R]{\bfseries\thepage}
  \fancyfoot[L]{Régis}
  \renewcommand{\headrulewidth}{0.5pt}
  \renewcommand{\footrulewidth}{0.5pt}
  \addtolength{\headheight}{0.5pt}
  \fancypagestyle{plain}{%
  \fancyhead{}
  \renewcommand{\headrulewidth}{0pt}
  }
  \typeout{Using article class.}%
}{%
\@ifclassloaded{report}{%
  \renewcommand{\chaptermark}[1]{\markboth{#1}{}}
  \renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
  \fancyhead{}
  \renewcommand{\chaptermark}[1]{\markboth{\thechapter.\ #1}{}}
  \fancyhead[L]{\bfseries\leftmark}
  \fancyhead[R]{\bfseries\rightmark}
  \fancyfoot{}
  \fancyfoot[R]{\bfseries\thepage}
  \fancyfoot[L]{Régis}
  \renewcommand{\headrulewidth}{0.5pt}
  \renewcommand{\footrulewidth}{0.5pt}
  \addtolength{\headheight}{0.5pt}
  \fancypagestyle{plain}{%
  \fancyhead{}
  \renewcommand{\headrulewidth}{0pt}
  }
  \typeout{Using report class.}%
}{%
  \typeout{Error: Unsupported class: 'article' or 'report' or 'book' are suported.}\QUITHERE
}%
}%
\makeatother%

marked as duplicate by Caramdir, Alan Munn, Werner, frabjous, Seamus Aug 12 '11 at 10:06

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3

This should get you started. Just add the appropriate settings to BookHeader, ArticleHead, and ReportHead. Within these three you can use #1 to refer to what was passed to \SetHeaders.

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

\documentclass{article}

\newcommand*{\BookHeader}[1]{% Add any customizations for book class here.
  \typeout{Using book class.}%
}%

\newcommand*{\ArticleHead}[1]{% Add any customizations for article class here.
  \typeout{Using article class.}%
}%

\newcommand*{\ReportHead}[1]{% Add any customizations for report class here.
  \typeout{Using report class.}%
}%

\makeatletter%
\newcommand*{\SetHeaders}[1]{%
    \@ifclassloaded{book}{\BookHeader{#1}%
    }{\@ifclassloaded{article}{\ArticleHead{#1}%
    }{\@ifclassloaded{report}{\ReportHead{#1}}{%
      \typeout{Error: Unsupported class: 'article' or 'report' or 'book' are suported.}\QUITHERE
    }}}%
}%
\makeatother%

\SetHeaders{foo}%


\begin{document}
Testing...
\end{document}
  • This is definitely easier to read code. (The original code also worked; see my comment above.) Also, @Regis Peter has the pseudo-code macro \QUITHERE; this document will fail inelegantly if an unsupported document class is used. – Alan Munn Aug 12 '11 at 5:20
  • How to use \renewcommand{\chaptermark}[1]{\markboth{\thechapter.\ #1}{}} for appear 1.foo (name of chapter) without CHAPTER 1.foo. Is failed in Report. – Regis da Silva Aug 12 '11 at 5:24
  • @Alan: Thanks, have added the comment about \QUITHERE. I find it very useful to exit for cases that I have not yet handled in the code. – Peter Grill Aug 12 '11 at 5:25
  • It's also possible to use \PackageError{<package name>}{<error text>}{<help text>} inside a document. – Alan Munn Aug 12 '11 at 6:05

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