0

I want to write a new class based on the article class for student home-works that needs a modified title page.

Is it possible to create new macros like \title{} and \author{} that can be used in the modified \maketitle code (e.g. \tutor{} and \dueDate{}) without editing the latex.ltx file?

In the question How to make a new command similar to \author the class that is worked on is memoir.cls while I'm trying to modify the article.cls. Furthermore the best solution given is by adding new information to \author macro and not on how to add new macros that are ready to use in the preamble.

Al_Fh
  • 452
  • see https://tex.stackexchange.com/questions/58506/how-to-make-a-new-command-similar-to-author – user185220 Apr 09 '19 at 12:11
  • They are using the memoir class there while I'm trying to do this by modifying the article.cls. – Al_Fh Apr 09 '19 at 12:12
  • Also they don't really answer the question. And in the comments it is hinted that information can be added to the \author macro but not how to create a new one – Al_Fh Apr 09 '19 at 12:14
  • Yes that is possible and you should indeed not modify latex.ltx at all. It will probably come down to copying the relevant bits from article.cls/latex.ltx and elsewhere and adding the redefinition to your custom class. – moewe Apr 09 '19 at 12:21
  • The linked answer shows how to define a command analogous to \author, namely \director: \newcommand{\director}[1]{\gdef\@director{#1}}% \newcommand{\@director}{\@latex@warning@no@line{No \noexpand\director given}}. You can now use \@director in your title formatting. – moewe Apr 09 '19 at 12:23

1 Answers1

2

In latex.ltx, there are two lines related to \author:

\def\author#1{\gdef\@author{#1}}
\def\@author{\@latex@warning@no@line{No \noexpand\author given}}

Then you can always have

\documentclass{article}
\makeatletter
\def\tutor#1{\gdef\@tutor{#1}}
\def\@tutor{\@latex@warning@no@line{No \noexpand\tutor given}}
\makeatother
\begin{document}
\tutor{Al Fh}
\makeatletter\@tutor\makeatother
\end{document}

Now customize your \maketitle with this command \@tutor, like

\documentclass{article}
\usepackage{array}
\makeatletter
\def\tutor#1{\gdef\@tutor{#1}}
\def\@tutor{\@latex@warning@no@line{No \noexpand\tutor given}}
\renewcommand\maketitle{%
\begin{center}
\textbf{\Huge\@title}\\[2em]
{\large\begin{tabular}{>{\bfseries}ll}
    Author: & \@author\\
    Tutor: & \@tutor\\
    Date: & \@date
\end{tabular}}
\end{center}\par\vspace{2em}}
\usepackage{lipsum}
\begin{document}
\title{My document}
\author{Your student}
\tutor{Al Fh}
\date{\today}
\maketitle
\lipsum[1]
\end{document}
  • So in the end I have to define \tutor after the begin{document} label and not before it? – Al_Fh Apr 09 '19 at 12:29
  • @Al_Fh No. You can put \tutor in the preamble if you like. I prefer putting it inside. –  Apr 09 '19 at 12:30