# Check what kind of document class is used with MWE

I try to autodefine the preamble using this and that approach but do get Undefined control sequence. \@ifundefined{\KOMAClassName } in case I write report for scrreprt. for both options.

\documentclass[12pt,a4paper,notitlepage,oneside]{report}
%NOTE Packages, my Macros und Formatdefinitions
\usepackage[T1]{fontenc}            % Allows different font encodings and hyphenation -> ctan.org/pkg/fontenc
\usepackage[utf8]{inputenc}         % Translates input encodings into LaTeX internal language -> ctan.org/pkg/inputenc
\usepackage{blindtext}
\makeatletter
\makeatother
\begin{document}
\section{hi}
\test \\
\testb\\
\end{document}


Using scrreprt or report I get printed num1 and num2 for \test and \testb (which isnt also the case)

• \@ifundefined{KOMAClassName}{...}{...}, i.e. no backslash – user31729 Apr 11 '16 at 19:55
• Well, you need \@ifclassloaded{\KOMAClassName}{...}{...}, since this does not expect a macro name. Your code tests whether the class KOMAClassName is loaded, which is not the case – user31729 Apr 11 '16 at 20:00

Use \@ifundefined{KOMAClassName}{...}{...} since \@ifundefined calls

\expandafter\ifx\csname #1 \endcsname (after a test), i.e. it constructs the command sequence.

Here's the definition in latex.ltx.

\def\@ifundefined#1{%
\expandafter\ifx\csname#1\endcsname\relax
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi}


But for \@ifclassloaded you need the class name, i.e. what \KOMAClassName provides for you.

The difference between the commands is just that \@ifundefined checks for a command name comparing it with \relax whereas \@ifclassloaded checks for a token, i.e. a class name. KOMAClassName means a class named KOMAClassName and not what \KOMAClassName provides (scrreprt, expectedly?)

I am not sure what the \test and \testb commands should do, but I think the setup should be something like

\documentclass[12pt,a4paper,notitlepage,oneside]{scrreprt}
%NOTE Packages, my Macros und Formatdefinitions
\usepackage[T1]{fontenc}            % Allows different font encodings and hyphenation -> ctan.org/pkg/fontenc
\usepackage[utf8]{inputenc}         % Translates input encodings into LaTeX internal language -> ctan.org/pkg/inputenc
\usepackage{blindtext}
%    \providecommand{\test}{}
%    \providecommand{\testb{}
\newif\ifstandardreport
\makeatletter
\@ifundefined{KOMAClassName}{%
\standardreporttrue
\newcommand{\test}{num1}
}{%
\newcommand{\test}{num2}  %option1
}
\ifstandardreport
\newcommand{\testb}{num1}
\else
\newcommand{\testb}{num2}
}{
\newcommand{\testb}{num1}
} %option2
\fi
\makeatother
\begin{document}
\section{hi}
\test \\
\testb\\
\end{document}


Alternatively use \providecommand{\test}{...} and do \renewcommand{\test}{...} later on in the \@ifclassloaded tests.

• Of course, the \KOMAClassName test must fail if the class is not a KOMA class – user31729 Apr 11 '16 at 20:10
• So \@ifclassloaded{\KOMAClassName} without interweaving it with other solutions (\@ifundefined and \newif) can not be used for that purpose as \KOMAClassName would be undefined -> compile error – qrtLs Apr 11 '16 at 20:41
• @ItsmeJulian: Of course not, see my possible solution I've posted already half an hour ago, which circumvents this. Blame KOMA, not LaTeX ;-) – user31729 Apr 11 '16 at 20:44
• @ItsmeJulian KOMAClassName is not the name of any class, so it is useless and pointless to test for it. This is neither LaTeX nor KOMAs fault, this is simple user error. – Johannes_B Aug 6 '16 at 11:19

\KOMAClassName can be used to test if a KOMA-class is used, as they all define that command. It cannot be used to test for a special class.

\documentclass[12pt,a4paper,notitlepage,oneside]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{blindtext}
\makeatletter
\@ifundefined{KOMAClassName}{%
\typeout{A standard class is used, but which one?}
\typeout{This is an article document}
}{%
\typeout{This is a report document}
}{%
\typeout{This is a book document}
}{%
\typeout{Memoir is in use}
}{%
\typeout{Something else is going on}
}
}
}
}
}{%
\typeout{A KOMA class is used, but which one?}
}{%
\typeout{scrreprt is used}
}{%