Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am writing a class file. I am defining a variable for my custom \maketitle like so:

\newcommand*{\comment}[1]{\def\commentname{#1}}
\comment{}

I want to be able to write a list of comments like so:

\comment{
    Comment1: this is a comment.

    Comment2: this is also a comment.

    etc.
}

Then I would like my \maketitle to form a table with each of the comments in a separate row. The table should preferably have a dynamic number of rows so that added comments increase the size of the table.

Is this possible?!

share|improve this question

1 Answer 1

up vote 4 down vote accepted

I would use a different input syntax with each comment as a separate command rather than split paragraphs:

enter image description here

\documentclass{article}

\newcounter{comment}
\def\comments{}
\makeatletter
\newcommand\comment[1]{%
\stepcounter{comment}%
\def\tmp##1{\g@addto@macro\comments{Comment ##1 & #1\\}}%
\expandafter\tmp\expandafter{\the\c@comment}}

\makeatother

\begin{document}

\comment{first thing}

\comment {second thing}

\comment {a very very liong third thing}




\begin{tabular}{|l|c|}
\comments
\end{tabular}

\end{document}

Or if you want explicit comment labels rather than a counter, it is a bit easier enter image description here

\documentclass{article}

\newcounter{comment}
\def\comments{}
\makeatletter
\newcommand\comment[2]{%
\g@addto@macro\comments{Comment #1 & #2\\}}

\makeatother

\begin{document}


\comment{com 1}{first thing}

\comment{com B}{second thing}

\comment{comment three}{a very very liong third thing}




\begin{tabular}{|l|c|}
\comments
\end{tabular}

\end{document}
share|improve this answer
1  
Expanding \thecomment only once is not sufficient. An \edef is needed. Or a preposterous number of \expandafters. –  egreg Jul 10 '12 at 15:50
    
Thanks, fixed... –  David Carlisle Jul 10 '12 at 16:15
    
this looks like it is just what I want. Any chance you could explain the comment command though? Would it be simple to add another argument to the comment which would be a version number, showing up in a different row of the table - instead of a simple counter? –  Ferguzz Jul 10 '12 at 16:34
    
i am trying just something like this: \def\comments{} \makeatletter \newcommand{\comment}[2]{% \g@addto@macro\comments{#1 & #2\\}} \makeatother but with no luck. i don't really understand the g@addto@macro line –  Ferguzz Jul 10 '12 at 16:43
    
That looks like it should work: I updated my answer –  David Carlisle Jul 10 '12 at 16:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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