5

# Update 2015-03-19 Better Answer Found

This question is part of a trail of questions. The goal mine was to use this list inside of a tikz node, but I removed that from previous questions in the interest of keeping it simple. Along the way, I ran into problems with post-processing and tikz. So, for those interested, here is a quick list for reference:

For making a macro that can handle post-parsing-inputted list items, see:

Related Question for making a macro that can handle post-parsing-inputted list items, see:


Update 2015-03-12 LOOKING FOR BETTER ANSWER

This question, although I have accepted an answer, was never answered to my satisfaction, because the answer was no, it is not possible to insert a list from aux into a tikz node due to @gobble munching up the final } during the first run. Perhaps in the future, someone will arrive at another conclusion. I can only hope for this...

Question

This is an extension of another question because the answer to the other question, while correctly answering the question, fails to address the problem of a custom \maketitle command using tikz:

How can I loop thru a list of inputs that come after \maketitle, yet use that list as part of the \maketitle command?

Problem

Code typesets unreliably. It will typeset correctly until you make one typo, then it will result it:

Argument of \@gobble has an extra }.


Problem Clarified UPDATED 2015-03-18

The problem lies in the \tikz \node {\manuallanguages};, which does not produce a satisfactory output. As expained above,

  1. when using @gobble, the }is "gobbled", which is essential for tikz to parse the code.

  2. Leaving out @gobble means having a strange comma separating an empty item in the beginning of the list. (HOWEVER, note the \kern0pt provided by David Carlisle's answer which solves this problem.

Super Minimalistic Code based on David Carlisle's answer.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\makeatletter
\let\@title\@empty
\let\@subtitle\@empty
\newcommand\subtitle[1]{%
  \gdef\@subtitle{#1}}
\newcommand{\manuallanguages}{} % initialization
\newcommand{\inputlanguagefile}[3]{%
%  #1 is unneeded for this minimal example
%  #2 is used elsewhere and unneeded for this minimal example
  \protected@write\@auxout{}{\string\used@language{#1}}
}%
\newcommand{\language@sep}{\ifnum\lastnodetype=12 \else, \fi}% list separator (does not use unless >1 item)
\newcommand{\used@language}[1]{%
  \g@addto@macro\manuallanguages{\language@sep{#1}}% add items to list
}%
\makeatother
\begin{document}
    \tikz[overlay,remember picture]\node [color=red,draw,dashed,inner sep=1cm,font=\bfseries] at (current page.center) {\kern0pt \manuallanguages};
  \inputlanguagefile{En}{English}{en} %<- En added to list
  \inputlanguagefile{Da}{Dansk}{da} %<- Da added to list
  \inputlanguagefile{De}{Deutsch}{de} %<- Da added to list
\end{document}

Attempt

The following code based on egreg's answer to the original question.

It seems unreliable: after just making one mistake and typesetting, it no longer compiles. I get Argument of \@gobble has an extra }. It probably has something to do with tikz, because when I put the #1 and #2 variables of \maketitle into nodes, that is when I ran into problems. Because it sometimes typeset even under those conditions, I am not really sure what the issue is.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,positioning}
\makeatletter 
\newcommand{\manuallanguages}{\@gobble} % initialization
\newcommand{\inputlanguagefile}[3]{%
  \input{#3}% File to input
  %#2 is used elsewhere and unneeded for this minimal example
  \@namedef{language@#1}{#1}% Creates new command language@En for example (if I understand correctly)
  \protected@write\@auxout{}{\string\used@language{}#1}% Calls \used@language command to generate list saved as string to aux
}
\AtEndDocument{\let\used@language\@gobble}% What is this doing?
\newcommand{\language@sep}{, }% list separator (does not use unless >1 item)
\newcommand{\used@language}[1]{%
  \g@addto@macro\manuallanguages{\language@sep{#1}}% add items to list
}
\makeatother

\renewcommand{\maketitle}[2]{%
\begin{tikzpicture}[overlay,remember picture]
\node [font=\Huge] (title) at ($ (current page.north)!.25!(current page.south) $) {#1};
\node [font=\Large, below=of title] (subtitle) {#2};
\end{tikzpicture}
%#1
%#2
\thispagestyle{empty}
\setcounter{page}{0}
\clearpage
}

\begin{document}

\maketitle[\manuallanguages]{User Manuals}

\inputlanguagefile{En}{English}{./en.tex}
\inputlanguagefile{Da}{Dansk}{./da.tex}
\inputlanguagefile{Da}{Deutsch}{./de.tex}

\end{document}
  • \language@sep is not defined to take an argument... Why did you eliminate the \format@language...? I'm just trying to understand your code. (And egreg's.) – cfr Mar 8 '15 at 21:34
  • \language@sep is set to the delimiter ", ". As far as "not being defined to take an argument", I am not sure how to answer that. Any new command can/must be set to something. I eliminated \format@language, because I do not use the mapping (e.g. {da}{Dansk}) and have no need to select one of those two as in the original code from @egreg. – Jonathan Komar Mar 9 '15 at 6:48
  • See my answer for the syntax of \newcommand. Anyway, it is just a point about the syntax:\language@sep{}#1 would be less confusing. Also \inputlanguagefile{En}{English}{en} rather than \inputlanguagefile{En}{English}{./en.tex} is probably better. – cfr Mar 9 '15 at 13:02
  • I do something not completely dissimilar to this but use PGF keys to handle the argument. That is, the command sets the value of the key which gets passed to the tikzpicture environment. I'm not sure if that's why, but I've not had any problems doing it that way. (Mine is titles of a customised section command rather than \maketitle but I can't see why that would matter.) – cfr Mar 9 '15 at 13:10
  • Duly noted, thanks! Tell that to @egreg :-p I just copied his code. :) – Jonathan Komar Mar 9 '15 at 13:37
4
+50

I'm not sure I understand the question or the problem with the current answer, but this is a version which doesn't initialise the list to \@gobble which appeared to be the main objection.

\documentclass{article}
\usepackage{tikz,lipsum}
\usetikzlibrary{calc,positioning}
\makeatletter
\let\@title\@empty
\let\@subtitle\@empty
\newcommand\subtitle[1]{%
  \gdef\@subtitle{#1}}
\renewcommand\maketitle{%
  \begin{titlepage}%
    \begin{tikzpicture}[overlay,remember picture]
      \node [font=\Huge] (title) at ($ (current page.north)!.25!(current page.south) $) {\@title};
      \node [font=\Large, below=of title] (subtitle) {\kern0pt \@subtitle{}};
    \end{tikzpicture}
  \end{titlepage}%
}
\newcommand{\manuallanguages}{} % initialization
\newcommand{\inputlanguagefile}[3]{%
  \input{#3}% File to input
  %#2 is used elsewhere and unneeded for this minimal example
  \protected@write\@auxout{}{\string\used@language{#1}}% Calls \used@language command to generate list saved as string to aux
}

\newcommand{\language@sep}{\ifnum\lastnodetype=12 \else, \fi}% list separator (does not use unless >1 item)
\newcommand{\used@language}[1]{%
  \g@addto@macro\manuallanguages{\language@sep{#1}}% add items to list
}
\makeatother
\begin{filecontents}{de.tex}
  \title{de}
  \subtitle{Gebrauchsanweisung}
  \maketitle
  \section{Test}
  \lipsum[50]
\end{filecontents}
\begin{filecontents}{da.tex}
  \title{da}
  \subtitle{Brugsanvisning}
  \maketitle
  \section{Test}
  \lipsum[50]
\end{filecontents}
\begin{filecontents}{en.tex}
  \title{en}
  \subtitle{User Manual}
  \maketitle
  \section{Test}
  \lipsum[50]
\end{filecontents}

\begin{document}

  \title{User Manuals}
  \subtitle{\manuallanguages}
  \maketitle

  \inputlanguagefile{En}{English}{en}
  \inputlanguagefile{Da}{Dansk}{da}
  \inputlanguagefile{Da}{Deutsch}{de}

\end{document}
  • (+1) But I think the objection to my answer is that I've changed the syntax of the command \maketitle[]{} (or \mymacro[]{} or...) and that my code didn't work with that syntax. But, to be honest, I was rather confused by this and am not sure I understand the objection either. – cfr Mar 18 '15 at 0:48
  • @DavidCarlisle See my latest edits using your code. I tried to remove extraneous things from the code. Hopefully that clarifies the issue once and for all. Cfr is right in pointing out that the main issue is \mymacro[]{}, but that is only partially correct. Satisfying this question requires a robust answer that can fit any macro (that is correct), but the real issue is putting the output of the aux into the tikz node. The title of this question makes this pretty clear I think. Surprisingly, perhaps due to an unsatisfactory or verbose MWE on my part, the issue was not properly conveyed. – Jonathan Komar Mar 18 '15 at 19:02
  • @macmadness86 there's nothing clear about the question to be honest, the aux file (by the time it is read) is just a list of definitions like a package file or the document itself, there is nothing special about aux file processing as far as I can see. Similarly the tikz node seems irrelevant to the question as far as I understand it, you are just typesetting a list without an initial comma, but it could be in a tikz node or a minipage or just in a paragraph on the main page, tikz doesn't seem to be relevant in any way, unless I misunderstand? – David Carlisle Mar 18 '15 at 20:38
  • @DavidCarlisle Why is tikz relevant? I added a few links to other related questions. The other two answers were not compatible with tikz nodes. I needed to narrow down the problem by asking sequential questions (because I did not completely understand the problem myself). Finally, tikz is relevant simply due to the question's title. In summary, I ended up with @gobble and Werner's etoolbox solution. egreg's @gobble did not work with tikz. Werner's etoolbox solution did not post-process list items entered after the macro call. – Jonathan Komar Mar 19 '15 at 13:01
  • @macmadness86 it doesn't really matter but tikz really isn't related to any of the solutions working or not. You are just setting up some tikz decoration then typesetting a paragraph of text inside a node, all of the solutions would apply (or not) to any paragraph setting whether or not it is in a tikz node. – David Carlisle Mar 19 '15 at 14:49
7

EDIT

Unlike the original code, this does not produce a compilation error when first typeset. Nor does it rely on the titling package.

I define \subtitle{} and \@subtitle to handle the subtitles. titlepage is used within a redefined \maketitle to create the actual title pages. Since we redefine \maketitle, we can issue \maketitle, \title etc. multiple times. We can also access the titles and subtitles using \@title and \@subtitle. These are used within the titlepage environment to pass the current values into the tikzpicture.

The result:

user manuals

The code:

\documentclass{article}
\usepackage{tikz,lipsum}
\usetikzlibrary{calc,positioning}
\makeatletter
\let\@title\@empty
\let\@subtitle\@empty
\newcommand\subtitle[1]{%
  \gdef\@subtitle{#1}}
\renewcommand\maketitle{%
  \begin{titlepage}%
    \begin{tikzpicture}[overlay,remember picture]
      \node [font=\Huge] (title) at ($ (current page.north)!.25!(current page.south) $) {\@title};
      \node [font=\Large, below=of title] (subtitle) {\@subtitle{}};
    \end{tikzpicture}
  \end{titlepage}%
}
\newcommand{\manuallanguages}{\@gobble} % initialization
\newcommand{\inputlanguagefile}[3]{%
  \input{#3}% File to input
  %#2 is used elsewhere and unneeded for this minimal example
  \protected@write\@auxout{}{\string\used@language{#1}}% Calls \used@language command to generate list saved as string to aux
}
\AtEndDocument{\let\used@language\@gobble}% What is this doing?
\newcommand{\language@sep}{, }% list separator (does not use unless >1 item)
\newcommand{\used@language}[1]{%
  \g@addto@macro\manuallanguages{\language@sep{#1}}% add items to list
}
\makeatother
\begin{filecontents}{de.tex}
  \title{de}
  \subtitle{Gebrauchsanweisung}
  \maketitle
  \section{Test}
  \lipsum[50]
\end{filecontents}
\begin{filecontents}{da.tex}
  \title{da}
  \subtitle{Brugsanvisning}
  \maketitle
  \section{Test}
  \lipsum[50]
\end{filecontents}
\begin{filecontents}{en.tex}
  \title{en}
  \subtitle{User Manual}
  \maketitle
  \section{Test}
  \lipsum[50]
\end{filecontents}

\begin{document}

  \title{User Manuals}
  \subtitle{\manuallanguages}
  \maketitle

  \inputlanguagefile{En}{English}{en}
  \inputlanguagefile{Da}{Dansk}{da}
  \inputlanguagefile{Da}{Deutsch}{de}

\end{document}

Note that this follows, as far as I could figure, your intentions but since the syntax in different questions didn't always match, I've had to guess and I'm not sure I'm right. However, it should just be a question of e.g. reversing the arguments given to \title{} and \subtitle{} or whatever. I had to use code from different questions because you did not post a complete example here.

  • I tried running this and I immediately got the same error as before: line 56 ! Argument of \@gobble has an extra }.<inserted text>\par\maketitle which leads me to believe that the code I posted should work. (but wait, I ran it a second time and it suddenly worked) The example I posted is only missing the file contents for the inputs, which can be found on the linked question. tex.stackexchange.com/questions/231195/… – Jonathan Komar Mar 10 '15 at 7:09
  • Is there any way to have the command look like this: \maketitle[subtitle]{title}? The reason for that is to have it work with any command, not just maketitle-specific. – Jonathan Komar Mar 10 '15 at 7:51
  • +1 for explanation of .aux. \maketitle can be redefined without any problems. The kind of documents I am working with are far more complex than any standard latex style. \maketitle is effectively not even used in my documents (just in name). This is what I meant about any command. It could be called \commandB[subtitle]{title} for lack of creativity. I do need \manuallanguages in the node, which is what this question is addressing (not about creating a title page with \maketitle). I was not sure if I should accept your answer because of this. – Jonathan Komar Mar 10 '15 at 21:19
  • Is the problem that the list is empty on the first run when inside a node? is \let\thesubtitle\@empty the important ingredient? Maybe you could expand your answer for the sake of learning. It would be a great help! (I should also mention that I am not using the titling package, rather a simple redefining of \maketitle using \renewcommand as demonstrated in my code) – Jonathan Komar Mar 10 '15 at 21:30
  • 1
    @macmadness86 OK. The current version eliminates both the first-run compilation error and the dependency on the titling package. The problem is not that the list is empty but the list consists of \@gobble which gobbles a single argument. After the first run, the thing gobbled is the first comma (which you don't want). On the first run, however, there is nothing for it to gobble except the end of the TiKZ node. In the current version, it is given something to gobble on the first run, {}, which is innocuous on subsequent runs (I think). – cfr Mar 11 '15 at 0:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.