Since I am not experienced with writing
clsso it may be a very simple question and is a duplicate but I cannot use the exact word to express it.
Here is what I want to achieve in this cls:
- There are two commands,
\authorandinstructor(this is defined in cls), each taking an argument. - Normally, they can be set separately.
- However, if
\authoror\instructoris empty (i.e.\author{},\instructor{}) or\authoror\instructoris not defined by the user, they should use a fallback,\@authorwill be\@instructoror\@instructorbe assigned\@authoraccording to which one is missing. - If both are missed, maybe just do nothing.
This is a MnWE. It compiles with error. (Strangely, with my full cls, it compiles fine but the \if statement does not seem right and the result is wrong.)
\RequirePackage{filecontents}
\begin{filecontents*}{myclass.cls}
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{myclass}
\LoadClass{article}
\let\@instructor\@empty
\newcommand{\instructor}[1]{\gdef\@instructor{#1}}
\newcommand{\test}{\@instructor}
\makeatletter
\if\@instructor\@empty
\def\@instructor\@author % author is the instructor (if not specified)
\else
\if\@author\@empty
\def\@author\@instructor % instructor is the author (if not specified)
\fi
\fi
\makeatother
\end{filecontents*}
\documentclass{myclass}
\author{Author Name}
% \instructor{Instructor Name}
\instructor{}
\begin{document}
\test{}
\end{document}
\ifxnot\if(in both cases) and\letnot\defyou can not do\def\something\somethingelset needs braces – David Carlisle Mar 19 '22 at 08:05