1

I'm trying to typeset a SRS document, and I'd like to create custom macros for integrating elements in a table.

That is, what I want to do is to specify requirements for a software this way:

\SrsReqTableStart
\SrsReqAdd{%
        code=A001,
        desc=Gestione stati lavorazione, 
        prior=5
    }
\SrsReqTableEnd

The problem is that when combining key-value arguments with table rows, after the first ampersand & character it stops recognizing custom commands.

To make myself clearer, this code defines the macros:

\newcommand{\SrsReqTableStart}{
\vspace{10pt}
\begin{tabular}{ l l l l l }
    ID & Nome & Prior. & Sforzo \\
\hline
}

\newcommand{\SrsReqTableEnd}{
\end{tabular}
}

\pgfkeys{
 /srsreq/.is family, /srsreq,
 code/.estore in = \srsReqCode,
 desc/.estore in = \srsReqDesc,
 prior/.estore in = \srsReqPrior,
}
\newcommand{\SrsReqAdd}[1]{
\pgfkeys{/srsreq, #1}%
    \hyperref[\srsReqCode]{\srsReqCode} \srsReqDesc   &%
    \tabularnewline
}

And it works this way, but when I write some command (text works) after the & character, it throws an error.

\hyperref[\srsReqCode]{\srsReqCode}  & \srsReqDesc %

Tried already researching, changing commands and key/value packages. Nothing changed this situation.

Thanks

2
  • 1
    Welcome to TeX.SX! Such snippets of code are useful, but a full example from \documentclass to \end{document} would be even better.
    – egreg
    Commented Apr 23, 2017 at 10:07
  • Thanks, actually I think I might have figured it out, I'll post a solution or more details asap
    – Mc128k
    Commented Apr 23, 2017 at 10:23

1 Answer 1

1

Solved by changing the code and with a small hack, I redefine the variables at every row, otherwise they just get the default values. It seems to work, so I'll post this as an answer if anybody needs this.

It works with default values too.

My SRS Functional Requirements table is now defined like this:

\SrsReqTableStart
    \SrsReqAdd[code=RF-CL-01,effort=8 ,prior=  ]{Requirement 1}
    \SrsReqAdd[code=RF-CL-02,effort=  ,prior=5 ]{Requirement 2}
    \SrsReqAdd[code=RF-CL-02,effort=10,prior=5 ]{Requirement 3}
\SrsReqTableEnd

It prints out a table, but arguments are specified independently from the table structure (more flexible for future changes).

In the preamble, import the package:

\usepackage{xkeyval} % Key/value coding

The SRS commands are defined:

\newcommand{\SrsReqTableStart}{
    \vspace{10pt}
    \begin{tabular}{ l l l l l }
        ID & Name & Prior. & Effort \\
    \hline
}
\newcommand{\SrsReqTableEnd}{
    \end{tabular}
}

Every row is defined by this command:

\makeatletter % Override @ meaning
\newlength{\pb@width}
\define@key{SrsReqAdd}{code}{\def\pb@code{#1}}
\define@key{SrsReqAdd}{effort}{\def\pb@effort{#1}}
\define@key{SrsReqAdd}{prior}{\def\pb@prior{#1}}
\setkeys{SrsReqAdd}{code=?,effort=?,prior=?} % Defaults
\newcommand{\SrsReqAdd}[2][]{
    \setkeys{SrsReqAdd}{#1} % Set new keys
    \hyperref[\pb@code]{\pb@code} &%
    #2 &% 
    \setkeys{SrsReqAdd}{#1} \pb@prior &%
    \setkeys{SrsReqAdd}{#1} \pb@effort \tabularnewline%
}
\makeatother % End override

Note the Defaults section. This is the cleanest code I could make, thanks to the answer here by Werner.

Opinions welcome

You must log in to answer this question.

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