# Current document class name [duplicate]

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.

-

## marked as duplicate by Seamus, lockstep, Caramdir, Loop Space, Martin Scharrer♦Jul 27 '11 at 21:03

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

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.

-