1

Why this MWE doesn't work?

\begin{filecontents*}[overwrite]{myClass.cls}
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{myClass}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions\relax
\LoadClass{article}
\def\fullname#1{\gdef\@fullname{#1}}
%
\ifdefined\@fullname
\def\myTable{%
    \begin{tabular}{ll}
    Some & Text\\
    \@fullname & Text
    \end{tabular}%
}
\else
    \def\myTable{Why not defined?!}
\fi
\end{filecontents*}

\documentclass{myClass} \begin{document} \fullname{Defined} \myTable \end{document}

1 Answers1

3

As the OP structured it, the \ifdefined test was being performed as the class was loading. Instead, it should be performed during the document phase. I do that here by including the test in the definition of \myTable.

EDIT: I also changed the \else condition of \MyTable to actually print out the "warning", rather than merely to define it.

\begin{filecontents*}[overwrite]{myClass.cls}
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{myClass}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions\relax
\LoadClass{article}
\def\fullname#1{\gdef\@fullname{#1}}
%
\newcommand\myTable{%
 \ifdefined\@fullname
    \begin{tabular}{ll}
    Some & Text\\
    \@fullname & Text
    \end{tabular}%
 \else
    Why not defined?!
 \fi
}
\end{filecontents*}

\documentclass{myClass} \begin{document} \fullname{Defined} \myTable \end{document}

enter image description here