GeneralErrors from addcontentsline when calling it on macro contents containing macros themselves

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
User avatar
Bozack
Posts: 117
Joined: Wed Feb 06, 2008 4:21 pm

Errors from addcontentsline when calling it on macro contents containing macros themselves

Post by Bozack »

I'm working on putting together a class for my thesis, using a bunch of user-defined macros and such for layout and semi-automatic layout. Currently, I have a "database"-esque system where I add publications, which can then be automatically output in a list-of-publications, and have automatically generated front-pages for each of the publications included in the end of the thesis.

I simply add a publication to the "database" by running a command \definepublication{name}{header}{title}{authorlist}{journal} (simplified for the MWE here) defined by

Code: Select all

\newcommand\definepublication[5]{%   \definepublication{name}{header}{title}{authorlist}{journal}
  \expandafter\def\csname #1header\endcsname{#2}      % #2 header
  \expandafter\def\csname #1title\endcsname{#3}       % #3 title
  \expandafter\def\csname #1authorlist\endcsname{#4}  % #4 authorlist
  \expandafter\def\csname #1journal\endcsname{#5}     % #5 journal
}
Now, I have this working up to a point. My problem comes when I want the front-pages for each of the publications added to the table of contents. I want to simply add a line with \addcontentsline{toc}{section}{\hspace{-1.6em}<publication-header>}, where <publication-header> would be automatically input during calling the macro to insert the front-page. (I have to use \addcontentsline instead of just letting \chapter{} handle it, since I want a specific layout in the ToC - details of which are irrelevant here.)

So far, I have a macro using ifthenelse from the ifthen package to call back to the "database" and output whatever information is wanted (this is also simplified for the MWE),

Code: Select all

\newcommand{\publicationlist}[2]{%  \publicationlist{name}{what-you-want-out}
  % Get the information for the named publication 
  \def\pubheader{\csname #1header\endcsname}
  \def\pubtitle{\csname #1title\endcsname}
  \def\pubauthors{\csname #1authorlist\endcsname}
  \def\pubjournal{\csname #1journal\endcsname}
  
  % Output what is needed in the form that it should have
  \ifthenelse{ \equal{#2}{header} }%
    { \pubheader }{}%
  \ifthenelse{ \equal{#2}{text} }%
    { \section*{\pubjournal} \pubauthors \\[2.5mm] ``\pubtitle'' }{}%
}
and I have a macro that will create the front-page for the publication inclusion,

Code: Select all

\newcommand{\publicationfrontpage}[1]{%  \publicationfrontpage{name}
  \def\pubchaptername{\publicationlist{#1}{header}}%
  \chapter*{\pubchaptername}
  \addcontentsline{toc}{section}{\hspace{-1.6em}\pubchaptername} 
  \publicationlist{#1}{text}
}
Then I can have a simple document like

Code: Select all

\documentclass{extbook}
\usepackage{ifthen}
<... macros ...>
\begin{document}
\tableofcontents
\definepublication{testarticle}{Publication IV}{title-of-article}{all-of-the-authors}{Journal-name}
\publicationfrontpage{testarticle}
\end{document}
which will call all of these functions and automatically create the front-page for that given publication.

Now the problem is that the \addcontentsline macro creates a ton of error messages at compile, but if I replace the \pubchaptername in there with simple text, or even \testarticleheader (which is technically what the \def\pubchaptername{\publicationlist{#1}{header}} calls in the case of that particular publication), there are no errors.

Is there something about expansion that I do not understand, or does this go deeper? Thank you so much if you read through all of this and might have a suggestion! :)



I have attached a full MWE where this error shows up - to make it easier to test on other systems:
MWE.tex
(1.75 KiB) Downloaded 225 times
OS, LaTeX-system, editor: Arch Linux 64bit, TeXlive, Kile | Windows 10 Professional 64bit, MikTeX 4.9, TeXnicCenter 2.02 64bit

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
Post Reply