GeneralAppend argument

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
Moander
Posts: 1
Joined: Mon Dec 15, 2008 10:41 am

Append argument

Post by Moander »

I am software developer that are trying to set together a document class for our standardised project specifications.

The idea is that the most common information that always should be available should be required by the document class so instead of writing

Code: Select all

\begin{document}
Projectname: X
Projectmanager: Y
\end{document}
we will write

Code: Select all

\projectname{X}
\projectmanager{Y}
\printProjectInfo
I have to admit that it took me a while to figure out that you could store data by doing

Code: Select all

\newcommand{\projectmanager}[1]{\renewcommand{\projectmanager}{#1}}
My current problem is that I can't figure out how I can append data to a variabel.

Lets say I want to have a list of all dependencies. I should preferably store them by doing something like

Code: Select all

\addDependency{Name}{Short Reason}
\addDependency{Name}{Short Reason}
\printDependencies
sort of like the table of content command. Unfortunately I can't figure out how I should do it.

Does anyone know of a short tutorial or a book that shows how you can do something like this?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

daleif
Posts: 199
Joined: Wed Nov 19, 2008 12:46 am

Re: Append argument

Post by daleif »

you could use a tokenlist, though it is not that easy to understand the use of it.

See tex by topic (free book)
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Append argument

Post by Juanjo »

Perhaps the following code may be of some help:

Code: Select all

\documentclass[a4paper]{article}

\makeatletter
\newcommand{\projectname}[1]{\gdef\@projectname{#1}}
\newcommand{\projectmanager}[1]{\gdef\@projectmanager{#1}}
\newcommand{\printprojectinfo}{%
  \begin{center} 
     {\Large\scshape Project name: \@projectname} \\[2ex] 
     {\large\sffamily Project manager: \@projectmanager}
  \end{center}\vspace{5ex}}
\makeatother

\newtoks\dependencies 
\dependencies={\noindent\textbf{Dependencies}:\begin{description}}
\newcommand\AppendToks[1]{\toks0={#1}%
   \edef\Act{\noexpand\dependencies ={\the\dependencies \the\toks0}}\global\Act}
\newcommand\addDependency[2]{\AppendToks{\item[#1] #2}}    
\newcommand\printdependencies{\AppendToks{\end{description}}\the\dependencies}

\begin{document}

\projectname{A test of some \LaTeX{} code}
\projectmanager{The LaTeX-Community Team}
\printprojectinfo

\addDependency{\TeX\ system}{Without a \TeX\ system, nothing can be tested.}
\addDependency{Books}{It is convenient to read \emph{\TeX\ by Topic}, by Victor Eijkhout.
  It provides a good background.}
\addDependency{Forums}{Useful for solving doubts and get help from \LaTeX\ enthusiasts.}

\printdependencies

\end{document}
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
Post Reply