Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Possible Duplicate:
Which documentclass is being used?

Is it possible to get the name of the current document class name from a package being used by that document? An example of what I mean:

In the document:

\documentclass{article}
\usepackage{foo}
\begin{document}
Foo claims \bar! What does he know?
\end{document}

In the package foo used above:

\newcommand{\bar}{the current document class is \DocumentClassName}

I'm actually interested in using this to modify the behavior of some of my own macros slightly, based on the document class. I've currently worked around this issue, by defining options based on class names. I thought I could keep these options to force certain behaviors, but it would be nice if the default could be chosen based on the document class name.

It suffices for my purposes to differentiate between books, reports, articles, and "other" (anything else). Testing for the existence of a chapter counter almost works, except that it can't differentiate between books and reports.

share|improve this question
3  
Have a look at Which documentclass is being used? –  lockstep Jul 27 '11 at 17:54
    
Ah, seems perfect! If only my search-fu had been better. –  cljacobs Jul 27 '11 at 18:17
add comment

marked as duplicate by Seamus, lockstep, Caramdir, Andrew Stacey, Martin Scharrer Jul 27 '11 at 21:03

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.

1 Answer

if you do not need the second optional argument for a specifix class date, this should work:

\RequirePackage{filecontents}
\makeatletter
\def\ProvidesClass#1{%
  \xdef\CName{#1}%
  \@ifnextchar[\@pr@videpackage{\@pr@videpackage[]}}%]
\makeatother

\documentclass{book}

\begin{filecontents}{foo.sty}
\newcommand\baz{the current document class is \CName}
\end{filecontents}

\usepackage{foo}
\begin{document}

Foo claims \baz! What does he know?

\end{document}

The problem is that we have to redefine the \ProvidesClass before the class itself is loaded.

share|improve this answer
add comment

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