# Check what kind of document class is used

I have defined a .sty-file which I use in a report, which holds a lot of good information and styles for how my documents should look like. This have been working great, until when I tried making a letter. My own style loads the titling-package among others, and this seems to cause errors. I of course do not really need the titling-package in my letter, but it is necessary in my other documents. I was wondering if I could write some kind of check to only load the titling-package if the document class is not a letter. That way, it will work with all my other documents, and my letters.

In the included example, I have only loaded the titling-package, and not my personal style. The errors produced are the same.

\documentclass{letter}
\usepackage{lipsum,
titling
}
\begin{document}
\begin{letter}{Company name \\ Street\\ City\\ Country}
\lipsum[1-2]
\closing{Yours Faithfully,}
\encl{Enclosures.}
\end{letter}
\end{document}

• \@ifclassloaded{...} perhaps? – user31729 Nov 19 '15 at 20:26

The LaTeX core defines \@ifclassloaded{classname}{true branch}{false branch} which is basically the same as \@ifpackageloaded for checking whether a certain package is loaded.

The class name has to be specified without the usual .cls extension.

Since @ occurs in the macro name \@ifclassloaded, \makeatletter...\makeatother is needed in the document preamble, if the check occurs in a self-written package, \makeatletter...\makeatother must not appear there!

\documentclass{letter}
\usepackage{lipsum}

\makeatletter
\typeout{this uses letter class}%
}{%
\usepackage{titling}
\typeout{this uses another class}%
}
\makeatother