LaTeX forum ⇒ 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.
User avatar
Bozack
Posts: 115
Joined: Wed Feb 06, 2008 4:21 pm
Location: Nørrebro, Copenhagen, Denmark
Contact:

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

Postby Bozack » Tue Sep 19, 2017 1:11 am

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

  1. \newcommand\definepublication[5]{% \definepublication{name}{header}{title}{authorlist}{journal}
  2. \expandafter\def\csname #1header\endcsname{#2} % #2 header
  3. \expandafter\def\csname #1title\endcsname{#3} % #3 title
  4. \expandafter\def\csname #1authorlist\endcsname{#4} % #4 authorlist
  5. \expandafter\def\csname #1journal\endcsname{#5} % #5 journal
  6. }

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),

  1. \newcommand{\publicationlist}[2]{% \publicationlist{name}{what-you-want-out}
  2. % Get the information for the named publication
  3. \def\pubheader{\csname #1header\endcsname}
  4. \def\pubtitle{\csname #1title\endcsname}
  5. \def\pubauthors{\csname #1authorlist\endcsname}
  6. \def\pubjournal{\csname #1journal\endcsname}
  7.  
  8. % Output what is needed in the form that it should have
  9. \ifthenelse{ \equal{#2}{header} }%
  10. { \pubheader }{}%
  11. \ifthenelse{ \equal{#2}{text} }%
  12. { \section*{\pubjournal} \pubauthors \\[2.5mm] ``\pubtitle'' }{}%
  13. }

and I have a macro that will create the front-page for the publication inclusion,

  1. \newcommand{\publicationfrontpage}[1]{% \publicationfrontpage{name}
  2. \def\pubchaptername{\publicationlist{#1}{header}}%
  3. \chapter*{\pubchaptername}
  4. \addcontentsline{toc}{section}{\hspace{-1.6em}\pubchaptername}
  5. \publicationlist{#1}{text}
  6. }

Then I can have a simple document like
  1. \documentclass{extbook}
  2. \usepackage{ifthen}
  3. <... macros ...>
  4. \begin{document}
  5. \tableofcontents
  6. \definepublication{testarticle}{Publication IV}{title-of-article}{all-of-the-authors}{Journal-name}
  7. \publicationfrontpage{testarticle}
  8. \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 4 times
OS, LaTeX-system, editor: Arch Linux 64bit, TeXlive, Kile | Windows 7 Professional 64bit, MikTeX 2.9, TeXnicCenter 2.0 beta 1 64bit

Return to “General”

Who is online

Users browsing this forum: Bing [Bot] and 10 guests