24

I'm preparing a new template for our students' projects based on memoir. All this projects are supervised (directed) by one or more professors so I would like to declare a command like \author but called \director.

This way the student can declare \director{My professor} and the template will place and format the name.

I would like to be like \author and not just a simple \newcommand because it can include affiliation, several names, etc.

I don't know where is \author declared, where should I look?

lockstep
  • 250,273
Ignasi
  • 136,588
  • 1
    Be specific over the placement of the new \director location. It's easy to find where \author is defined/declared (in memoir.cls) – Werner Jun 04 '12 at 15:53
  • How about \let\author\director? This will make the command \director inherit/receive all properties of the \author command -- how ever the latter command is set up. – Mico Jun 04 '12 at 16:53
  • 2
    then \director{foo} will overwrite the author setting. –  Jun 04 '12 at 17:03
  • @Werner Previous to my question I looked for \author and \@author definitions in memoir.cls. \author appears in lines 2493 and 2525 but there is no definition there. And \@author is used in \maketitle (lines 2449-2465). Looking there more carefully I've understood how to declare and insert a \director command into \maketitle. – Ignasi Jun 04 '12 at 17:16

2 Answers2

20

As mentioned, \author and \@author are defined in latex.ltx, but memoir adds some extra flair to them (for example, allowing multiple authors via \and and properly setting them). The following minimal example adds \director to the mix:

enter image description here

\documentclass{memoir}% http://ctan.org/pkg/memoir
\makeatletter
\newcommand{\director}[1]{\gdef\@director{#1}}%
\newcommand{\@director}{\@latex@warning@no@line{No \noexpand\director given}}
\addtoiargdef{\director}{%
  \begingroup\let\footnote\@gobble}{%
  \begingroup
    \renewcommand{\thanks}[1]{}
    \renewcommand{\and}{\unskip, }
    \renewcommand{\andnext}{\unskip, }
    \renewcommand{\thanksmark}[1]{}
    \renewcommand{\thanksgap}[1]{}
    \protected@xdef\thedirector{#1}
  \endgroup\endgroup}
\newcommand{\predirector}[1]{\def\@bspredirector{#1}}
\newcommand{\postdirector}[1]{\def\@bspostdirector{#1}}
\renewcommand{\maketitlehookc}{%
  {\@bspredirector \@director \@bspostdirector}%
}
\predirector{\begin{center}
  \large \lineskip .5em%
  \begin{tabular}[t]{c}}
\postdirector{\end{tabular}\par\end{center}}
\makeatother
\title{A Title}
\author{An Author \and Another Author}
\director{My Director \and My other Director}
\date{\today}
\begin{document}
\maketitle
\end{document}

The process is a duplication of the components of \author and inserts the \director below the \author inside \@maketitle using the hooks provided. That is, \@maketitle has a hook:

  • \maketitlehooka before \title;
  • \maketitlehookb before \author;
  • \maketitlehookc before \date; and
  • \maketitlehookd after \date.

I've redefined \maketitlehookc to now be/contain \director and it is formatted in the same way \author is (centered and \large).

jub0bs
  • 58,916
Werner
  • 603,163
  • Can this be used in an article? How? I tried to change memoir with article but it won't work. – 71GA Sep 30 '13 at 09:36
  • How can I do the same thing in a report class document? – Kajsa Dec 10 '16 at 17:53
  • @Kajsa: You want exactly the same in report? – Werner Dec 10 '16 at 18:09
  • @Werner: I am building my own \maketitle in a customized report class and I want to add a \supervisor option that will work as \author and only be shown if a supervisor is set. – Kajsa Dec 10 '16 at 18:14
  • @Kajsa: Here is a simple way to insert a \supervisor: Code. It's simple because it assumes a specific order of the title commands: \supervisor after \author, and appends the supervisor content to the \@author macro which is set during \maketitle. This code also works with/without titlepage option. Alternatively, this code uses etoolbox to patch \@maketitle and insert \@supervisor directly: Code. Therefore, order of usage doesn't matter. Update required for non-titlepage usage. – Werner Dec 10 '16 at 19:04
  • @Werner: Thank you. But for some reason the \ifcsname does not seem to work. If I do not define \supervisor the document does not compile. Do you have any suggestions? – Kajsa Dec 10 '16 at 19:25
  • @Kajsa: What are you compiling with? Perhaps you could post some code that I can work with. Alternatively, ask a follow-up question here. – Werner Dec 10 '16 at 19:42
  • @Werner: I have tried TeXMaker PDFLaTeX and LaTeX. It gives the error undefined control sequence. Here's a minimum example Code. – Kajsa Dec 10 '16 at 19:53
  • @Kajsa: There's no need to \patchcmd{\maketitle} when you're just going to redefine \maketitle immediately after it. Here's some code that compiles fine on my end: Code – Werner Dec 10 '16 at 19:58
13

author is defined in latex.ltx

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

you can load the file under Linux with

gedit `kpsewhich latex.ltx`  

However, memoir has some more definitions of authors. Have a look into the file memoir.cls and search for author. In the title the macro \@author is used and set to \relax after the title.