I tried to create my custom class for lab reports, which needs to have a tabular on the titlepage which contains the dates on that I gave the report to my assistant for correction. In order to make things for the user as easy as possible I wanted to appear the dates and text automatically when they are defined by a command like \firsthandin{2017-01-06}
. As I need to define \firsthandin
, my thought was that it is useless to check whether this macro is defined, it is of course; but rather whether the argument is empty or differs from the default value. So I tried using \ifmtarg
from ifmtarg.sty
. Here is what I have so far:
protokoll.cls
\ProvidesClass{protokoll}[2017/01/05 v1.0]
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{scrartcl}}
\ProcessOptions
\LoadClass[a4paper,fontsize=11pt,oneside]{scrartcl}
%=====================================================
\RequirePackage[utf8]{inputenc}
\RequirePackage{ifmtarg}
%=====================================================
\newcommand{\@firsthandin}{}
\newcommand{\firsthandin}[1]{\renewcommand{\@firsthandin}{#1}}
\newcommand{\@secondhandin}{Unknown}
\newcommand{\secondhandin}[1]{\renewcommand{\@secondhandin}{#1}}
\renewcommand{\maketitle}{
\begin{titlepage}
\begin{table}
\centering
\begin{tabular}{ll}
\ifmtarg{\@firsthandin}{}{First date} & \ifmtarg{\@firsthandin{}{\@firsthandin} \\
Second date & \@secondhandin \\
\end{tabular}
\end{table}
\end{titlepage}
}
The second line is just to check whether there is another mistake regarding the variables.
I also tried changing the first line of the tabular to \ifmtarg{\@firsthandin}{}{First date & \@firsthandin \\}
but this produces the same errors.
mwe_protokoll.tex
\documentclass{protokoll}
\firsthandin{05.01.2017}
\begin{document}
\maketitle
\end{document}
I get errors about Misplaced \cr
which is according to @DavidCarlisle (What does Misplaced \cr in latex error mean) used in the definition of \\
, so I guess \ifmtarg
messes up with the linebreaks of the tabular. Any ideas how to solve this?
(It is not important whether an empty space or "really nothing" is given out)
\@ifmtarg
, but there is another issue with\noalign
, I supposeetoolbox
its macro examination macros are much more power full. Plus it is meant to he used in user space (aka no @ in macro names)\@ifmtarg
is not in user space here, it's class code (but I agree with you about the possibly easieretoolbox
approach)@
was actually the problem...quite easy and a quite stupid mistake from me. But thanks for your eagle eyes. I will accept your answer as you solved my problem but I think I will use theetoolbox
method because it is even easier.\edef
part in the version I posted.