4

I am attempting to define a macro that can be used to specify the names of committee members for a thesis/dissertation. I would like to allow the user to specify this command multiple times to add multiple committee members, as can be done in the mitthesis class file.

Looking at the mitthesis class file I got the idea to use a box to combine the calls to the macro. The way they do it is:

% since there can be more than one supervisor,
% we build the appropriate boxes for the titlepage and
% the abstractpage as the user makes multiple calls
% to \supervisor
\newbox\@titlesupervisor    \newbox\@abstractsupervisor

\def\supervisor#1#2{\setbox\@titlesupervisor\vbox
  {\unvbox\@titlesupervisor \vskip 10pt% plus 1fil minus 1fil
  \def\baselinestretch{1}\large
  \signature{Certified by}{#1 \\ #2 \\ Thesis Supervisor}}
  \setbox\@abstractsupervisor\vbox{\unvbox\@abstractsupervisor
  \vskip\baselineskip \def\baselinestretch{1}\@normalsize 
  \par\noindent Thesis Supervisor: #1 \\ Title: #2}}

From what I've read we could do something similar with a save box so I tried something like this:

% We need to allow for multiple calls to committee
% Therefore start building the committee section of the title page
% Each call to committee should first specify the name as arg 1, and  
% then the degree as arg 2
% for instance \committee{John Doe}{Ph.D.}
\newsavebox\@committeebox
\def\committee#1#2{%
    \sbox{\@committeebox}{%
        \usebox{\@committeebox}\\%
        \bfseries
        #1, #2%
    }%
}

but for some reason this only displays the first committee member that is added.

I tested the idea by adding a

\sbox{\@committeebox}{test}

before the \def in the above example (after the \newsavebox) which works somewhat by adding 'test' to the output before the first specified committee member, although it doesn't move things to a new line like I thought it should (I get testJane Doe, Ph.D. like this but it still doesn't display the other specified committee member.

Can somebody see what is going wrong here or give me a reason this will not work? Obviously I could just use what mitthesis does but I am asking this to try and get a better understanding of the way things are going on.

As a mwe you could have

\documentclass{sample}

\committee{Jane Doe}{MS}
\committee{John Doe}{Ph.D.}

\begin{document}

  \maketitle

 \end{document}

as your tex file and

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{sample}[2016/01/29 Sample]

\DeclareOption*{%
    \ClassWarning{sample}{No options permitted}%
}

\ProcessOptions\relax
\LoadClass{report}

\def\maketitle{%
    \begin{center}
        \usebox{\@committeebox}
    \end{center}
}

as your sample.cls file.

Andrew
  • 361
  • Are you after a recursive (cumulative) definition of a macro? And the mwe should have sample as document class, not test ;-) –  Feb 01 '16 at 19:49
  • I guess so @Christian. I'm not entirely sure whether this would be defined as recursive or not. Thanks for the catch of the mismatch between the name of the class file and the provides class command. I will fix it now. – Andrew Feb 01 '16 at 19:55

1 Answers1

3

I don't understand why this is constructed inside a box as its not necessary. Moreover, I obtain all committee members' names when I use your example, except that they're packed next to one another. This stems from the fact that you're not boxing content in a \vbox the way mitthesis does.

I'd suggest not boxing content but rather accumulate them in a macro as-is, and set them at a later point with the necessary definitions. Here is such an implementation:

enter image description here

\documentclass{article}

% We need to allow for multiple calls to committee
% Therefore start building the committee section of the title page
% Each call to committee should first specify the name as arg 1, and  
% then the degree as arg 2
% for instance \committee{John Doe}{Ph.D.}
\newcommand\committeemembers{}% This willl store committee members
\makeatletter
\newcommand\committee[2]{% Add another committee member to the list
  \g@addto@macro\committeemembers{\nextcommitteemember #1, #2}%
}
\makeatother

\newcommand{\nextcommitteemember}{}% Just a placeholder
\newcommand{\printcommittee}[1][c]{{% Print the list of committee members
  % http://tex.stackexchange.com/a/89187/5764
  \renewcommand{\nextcommitteemember}{\gdef\nextcommitteemember{\tabularnewline}}%
  \bfseries% Committee member formatting
  \begin{tabular}{#1}
    \committeemembers
  \end{tabular}
}}
\committee{Jane Doe}{MSc}
\committee{John Doe}{PhD}
\committee{Who Cares}{BSc}

\begin{document}

\begin{center}
  \printcommittee[l]
  \qquad
  \printcommittee
  \qquad
  \printcommittee[r]
\end{center}

\end{document}
Werner
  • 603,163
  • Ah ok. The only reason i was using a box was because of how mitthesis does it. I guess the main issue is that I still don't fully understand boxes. Also, it is odd that the code "worked" (at least somewhat) for you as is. When I replaced your code with my code in the .cls file and ran the example latex document it worked for me, but it definitely did not work using my old code. Perhaps the other committee member was just being pushed off the page or something. One question @Werner. Can you either explain or point to a good source on how the line \g@addto@macro... works? – Andrew Feb 01 '16 at 20:17
  • 1
    @Andrew: "\g@addto@macro: Globally add to the end of a macro" See section 68.1 Hooks (p 461) of source2e. etoolbox provides similar wrappers in the form of \apptocmd for appending (and also \pretocmd for prepending) content to an existing macro. – Werner Feb 01 '16 at 20:24
  • Ok, so essentially that entire line says that whenever \committee is called it adds to the macro \committeemembers \nextcommitteemember #1, #2 where \nextcommitteemember simply provides a new table line and #1/#2 were the arguments passed to \committee. That makes sense and will be very useful in the future. Thanks for the explanation. – Andrew Feb 01 '16 at 20:32
  • @Andrew: Correct. I've used a trick to make the first \newcommitteemember do nothing but redefine itself to be a "new table line". That also helps occasionally. – Werner Feb 01 '16 at 20:33