8

Situation

I have to make a cover template for a document. At the end of the page, I have to add the revision number with other useful info like this example:

\begin{tabular}{lccl}
    Revision 0 & 06-11-2014 & Initial Release & John Smith \\
    Revision 1 & 06-12-2014 & Changed something & Joe Blow \\
    ...
\end{tabular}

Objective

In the TEX document, the user would have to add their revision like this:

\AddRevision{06-11-2014}{Initial Release}{John Smith}
\AddRevision{06-12-2014}{Changed something}{Joe Blow}
...
\createFrontPage

When generating the PDF, this should automatically generate the tabular above. Note that the revision's number is automatically increase by 1 at each AddRevision.

What I have tried

I'm not familiar with Latex macros, so this is what I have for the moment. I just don't know if I'm close to the solution or if I'm doing totally wrong. Here's the code in my CLS file:

\newCounter{RowCounter}
\def\AddRev#1,#2,#3{\RevDate{#1}, \RevDesc{#2}, \RevAuthor{#3} \stepCounter{RowCounter}}

\newCounter{i}
\newcommand{\RevisionRows}
{
    \forloop{i}{0}{\value{i} < \value{RowCounter}}
    {
        Revision \arabic{i} & \RevDate & \RevDesc & \RevAuthor \\
    }
}    

\newcommand{\createFrontPage}
{
   % some stuff
   \begin{tabular}{lccl}
       \RevisionRows    
   \end{tabular}
}

Questions

Is my objective possible ? If yes, What am I doing wrong ? What's the best and clean solution ? Any suggestions are welcome.

Thanks a lot for your help.

5

Here is one way:

enter image description here

Notes:

I would recommend you put everything prior to the first \AddRevision in a separate package and have the users add the revisions before \begin{document}.

References:

Code:

\documentclass{article}

%% https://tex.stackexchange.com/questions/175568/build-tabular-content-via-foreach
\newcommand*{\MyTempTableTokens}{}%
\makeatletter
    \newtoks\@tabtoks
    %%% assignments to \@tabtoks must be global, because they are done in \foreach
    \newcommand\AddTableTokens[1]{\global\@tabtoks\expandafter{\the\@tabtoks#1}}
    \newcommand\eAddTableTokens[1]{%
      \protected@edef\MyTempTableTokens{#1}%
      \expandafter\AddTableTokens\expandafter{\MyTempTableTokens}%
    }
    %%% variable should always be operated on always locally or always globally
    \newcommand*\ResetTableTokens{\global\@tabtoks{}}
    \newcommand*\PrintTableTokens{\the\@tabtoks}
\makeatother



\newcounter{RowCounter}
\newcommand{\AddRevision}[3]{%
    \stepcounter{RowCounter}%
    \eAddTableTokens{Revision \arabic{RowCounter} & #1 & #2 & #3 \\}%
}%

\newcommand{\createFrontPage}{%
   % some stuff
   \begin{tabular}{lccl}
       \PrintTableTokens    
   \end{tabular}%
   \clearpage
}

\AtBeginDocument{%
    \createFrontPage%
}%

%-----------------------------------------------------------


\AddRevision{06-11-2014}{Initial Release}{John Smith}
\AddRevision{06-12-2014}{Changed something}{Joe Blow}

\begin{document}

     main document here

\end{document}

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.