views:

49

answers:

2

I'm working on a LaTeX package which might need to do some things differently depending on the class that's being used. I'm wondering if there's a way to auto-detect or test the document class.

One could certainly look up the class files and test for the existence of a specific macro defined by that class, but is there a smarter way? I looked at the definition of the \ProvidesClass macro and can't see if it saves the class name anywhere except \@currname. I believe \@currname is just the name of the current package or class being read.

Basically I want to execute

\author{\longauthorname}

in the article class but

\author[\shortauthorname]{\longauthorname}

in the beamer class.

+2  A: 

IMHO, you should not check the name of your class (or version). You should check the functionality.

For example, class article has \@titlepagefalse and class book has \@titlepagetrue. Write

\if@titlepage yes \else no \fi

and recognize the presence of title page.

Alexey Malistov
I tend to agree with you. The reason I want to know the class is that in some classes I use the `\author` macro takes an optional argument and in some it doesn't. So I guess the best thing to do is check for the existence of whatever auxiliary macro the class sets up to give `\author` that different signature.
Matthew Leingang
What's the high-level LaTeX command to check if a macro is defined?
Matthew Leingang
`\author` is `\gdef\@autor{#1}`, isn't? To check if a macro is defined write `\ifx\command\undefined undefined\else defined\fi`
Alexey Malistov
A: 

After refining my question I'll show how I answered it. Along the lines of what dmckee was saying. Just test for the functionality.

\ifcsname beamer@author\endcsname
  \author[\shortauthorname]{\longauthorname}
\else
  \author{\longauthorname}
\fi

\ifcsame is available on all e-TeX builds and is documented (along with other ways to check if a command is defined) here.

You can't check for the actual signature of the \author macro (i.e., does it take an optional argument?) but you can check for some of the auxiliary macros defined to implement optional arguments. \beamer@author is one of those in the beamer class.

Matthew Leingang