I have a certain table to which I would like to add lines by a command.

One way I can get to this looks like this:

 #1 & #2 & #3 \tabularnewline

and the table

\begin{tabularx}{\unitlength}{ X X X }

First & Second & Third \tabularnewline

which is ok for simple tables, but when the situation gets more involved I would like to be able to separate the initialization of the row from the placing of the table.

By more involved I mean that the command will take possibly a large number of variable, some of which numbers. Meanwhile the table shall reside amidst other code for the page, somewhere. Ideally, I have a neat .tex file where I list all my definition and either save them to a easy name that I then add in the table (so that I also don't lose an idea of the content of the table, which I would if I were to, say, use \input{my_list_of_rows.tex} altought this might be a solution.

I imagined something like saving the resulting row from the command in a more succintly named variable and have a separate sheet for it.

An example would be:

row_complex = \arow{this}{is}{a}{nastyyyy}{$\mathcal{C}$ row}
row_real    = \arow{this}{is}{a}{less nasty}{$\mathcal{R}$ow}

with the table taking

\begin{tabularx}{\unitlength}{ ... }

Is it possible and how would one do such a thing? Or, what are other standard way of dealing with this kind of situation?

  • 1
    I don't understand what you mean by a "more involved" situation; "[separating] the initialization of the row from the placing in the table." Can you elaborate?
    – Werner
    May 25, 2016 at 23:05
  • Can you also complete your code so that it can be compiled? If your code is completed 'in the obvious way', it certainly will not work because the macro name you have chosen is not allowed. (If you are using expl3 syntax to do this, then you are abusing it badly and should please stop doing it in public. What you do in private is up to you. ;) )
    – cfr
    May 25, 2016 at 23:17
  • Ehm..I do not abuse syntax either in private or in public. I am badly new to making latex doing more complicated than basic command. I have read around stuff like \def and macros might be on the lines of what I am looking for, but honestly I don't even know where the documentation on this features should be (which is the con of how "we" teach ourselves latex).
    – Three Diag
    May 25, 2016 at 23:25
  • @ThreeDiag I thought it unlikely that was the reason, but I wasn't sure so it seemed worth pointing out. Because you you did say your code was OK for simple cases, but unless you are changing cat codes, it can't possibly work because those are not legal macro names.
    – cfr
    May 26, 2016 at 0:03

1 Answer 1


Basic option would be my_rows.tex with

\rowdef{row_complex}{\arow{this}{is}{a}{nastyyyy}{$\mathcal{C}$ row}}
\rowdef{row_real}{\arow{this}{is}{a}{less nasty}{$\mathcal{R}$ow}}

Then adding in the preamble

\newcommand*\rowdef[1]{\expandafter\def\csname row@#1\endcsname}
\newcommand*\rowuse[1]{\csname row@#1\endcsname}

with the table taking

  • By the way, \arow has five arguments…
    – Manuel
    May 25, 2016 at 23:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .