0

LaTeX cmd: Verbatim-like command '\checkboxYesNo' illegal in argument.

I get the above message when I tried to migrate away from using tabu & xstring combination to tabularray & native LaTeX3 combination for creating a requirements table. I use \checkboxYesNo to determine if the state of some checkboxes that are embedded into the table. This macro is embedded in a larger one, as it gets called 4 times per call to the larger one. I have attached a MWE with comments on what to comment out to make it work correctly. If I switch in the old \checkboxYesNoOld function, it will work with the new tabularray package.

I am not sure how to embed a macro inside a second one where inner macro makes decision based on the inputs being fed to it. I read through some of the other previous answers but I just cannot wrap my head around this issue.

\documentclass{article}
\usepackage{tikz}
\usepackage{tabu}  
\usepackage{booktabs}
\usepackage{tabularray} % Replaces 'tabu', 'tabularx', & 'multirow'
\UseTblrLibrary{booktabs} % Used by 'tabularray' to load packages for internal use
\usepackage{xstring} % Needed for "checkboxYesNoOld" command

\newcommand{\checkYes}{% \begin{tikzpicture}[scale=1, line width=1.0pt]% \draw ( 0, 0) -- + ( 0, 1.5ex) -- + ( 1.5ex, 1.5ex) -- + ( 1.5ex, 0) -- cycle

( 0.3ex,  0.3ex) -- +
( 0.9ex,  0.9ex)

( 0.3ex,  1.2ex) -- + 
( 0.9ex, -0.9ex);

\end{tikzpicture}% }

% Creates Unchecked Checkbox \newcommand{\checkNo}{% \begin{tikzpicture}[scale=1, line width=1.0pt]% \draw ( 0, 0) -- + ( 0, 1.5ex) -- + ( 1.5ex, 1.5ex) -- + ( 1.5ex, 0) -- cycle; \end{tikzpicture}% }

\ExplSyntaxOn \NewDocumentCommand{\checkboxYesNo}{vv} { \prg_generate_conditional_variant:Nnn \str_if_in:nn {ee} { TF, T, F } \str_if_in:eeTF { \str_foldcase:n { #2 } } { \str_foldcase:n { #1 } } {\checkYes} {\checkNo} } \ExplSyntaxOff

\newcommand{\checkboxYesNoOld}[2]{ %% #1--Find This; #2--Search This List %% Outputs a Checked or Unchecked box \lowercase{\def\myList{#2}}% \lowercase{\def\findMe{#1}}% \IfSubStr{\myList}{\findMe}{\checkYes}{\checkNo}% % \IfSubStr{\myList}{\findMe}{Yes \findMe - \myList}{No \findMe - \myList}% }

\newcommand{\reqUserOld}[6]{% \begin{tabu} to 0.99\textwidth{p{60pt} *{3}{p{1pt} X[2,l] } p{1pt} X[3,l] } \toprule {\small \textbf{Req Name}} & \multicolumn{8}{l}{\textbf{#2}} \ \cmidrule(r){1-1} \cmidrule(l){2-9} {\small Req ID} & \multicolumn{8}{l}{#1} \ \cmidrule(r){1-1} \cmidrule(l){2-9} {\small Requirement} & \multicolumn{8}{l}{#3} \ \cmidrule(r){1-1} \cmidrule(l){2-9} {\small Remarks} & \multicolumn{8}{l}{#4} \ \cmidrule(r){1-1} \cmidrule(l){2-9} {\small Parent} & \multicolumn{8}{l}{#5} \ \cmidrule(r){1-1} \cmidrule(l){2-9} {\small Verification} &

%%%% Use this for "correct" output %{\small \checkYes} & {\small Test} & %{\small \checkNo} & {\small Analysis} & %{\small \checkNo} & {\small Inspection} & %{\small \checkYes} & {\small Review-of-Design} \

%%%% This may cause a different error. {\small \checkboxYesNoOld{t}{#6}} & {\small Test} & {\small \checkboxYesNoOld{a}{#6}} & {\small Analysis} & {\small \checkboxYesNoOld{i}{#6}} & {\small Inspection} & {\small \checkboxYesNoOld{r}{#6}} & {\small Review-of-Design} \

\bottomrule
\tabuphantomline

\end{tabu} }

\newcommand{\reqUser}[6]{% \begin{tblr}{ width = 0.99\textwidth, colspec = {t{60pt} *{3}{t{1pt} X[2,l] } t{1pt} X[3,l]} }

\toprule
{\small \textbf{Req Name}} & \SetCell[r=1,c=8]{l}{\textbf{#2}} \\

\cmidrule[r]{1-1} \cmidrule[l]{2-9}
{\small Req ID}       & \SetCell[r=1,c=8]{l}{#1} \\
\cmidrule[r]{1-1} \cmidrule[l]{2-9}
{\small Requirement}  & \SetCell[r=1,c=8]{l}{#3} \\
\cmidrule[r]{1-1} \cmidrule[l]{2-9}
{\small Remarks}      & \SetCell[r=1,c=8]{l}{#4} \\
\cmidrule[r]{1-1} \cmidrule[l]{2-9}
{\small Parent}       & \SetCell[r=1,c=8]{l}{#5} \\
\cmidrule[r]{1-1} \cmidrule[l]{2-9}

{\small Verification} &  
{\small \checkboxYesNoOld{t}{#6}} & {\small Test} & 
{\small \checkboxYesNoOld{a}{#6}} & {\small Analysis} & 
{\small \checkboxYesNoOld{i}{#6}} & {\small Inspection} & 
{\small \checkboxYesNoOld{r}{#6}} & {\small Review-of-Design}  
\bottomrule

\end{tblr} % ! So the \checkboxYesNo command is causing the table to be super tall }

\begin{document}

% This produces the desired results under the old tabu/xstring system \reqUserOld{M-03}{Req Name 3}{A description}{Some remarks}{The Parent Requirement}{tr}

%% Use this for "error" output (The verbatim command '\checkboxYesNo' cannot be used inside) %\reqUser{M-03}{Req Name 3}{A description}{Some remarks}{The Parent Requirement}{tr}

\end{document}

Nebabon
  • 115
  • 1
    You can't grab verbatim material inside arguments: it's not clear why you are trying that with the expl3 solution but using classical argument handling with your older one – Joseph Wright May 18 '22 at 12:55
  • Well, catcode is a complex topic in TeX. For simplicity, just assume you can't (it's too simple and limiting though. If you want to try to learn serious TeX programming try package writing - Where do I start LaTeX programming? - TeX - LaTeX Stack Exchange) – user202729 May 18 '22 at 13:13
  • Actually... in this case it appears you just need to define the largest one to grab argument verbatim, then pass it to normal inner ones. Nevertheless you never show where you want to try using the argument so we can't tell (there's no example of argument that requires verbatim in your document) – user202729 May 18 '22 at 13:15
  • You should move your \prg_generate_conditional_variant:Nnn outside of your macro definition. This doesn't need to run everytime you call your macro, just use it once in your preamble. And like other's already said, instead of v v as argument specifier in your \NewDocumentCommand, use m m instead and everything should work as you expect. – Skillmon May 18 '22 at 14:55
  • And if every cell in your table should be \small, it might be a good idea to use \small outside the table instead of in every cell (and if a single cell shouldn't be small you could use \normalsize there). – Skillmon May 18 '22 at 14:57
  • Also, in your tikzpictures you could use \draw (0,0) rectangle (1.5ex, 1.5ex); instead of your cycle-construct to draw the box. – Skillmon May 18 '22 at 15:02

1 Answers1

2

The following does include a few corrections:

  • using mm instead of vv as arguments
  • only generate the variants of \str_if_in:nnTF once
  • using rectangle in your tikzpicture
  • move the box drawing to another macro (reduced code duplication for your \checkYes/\checkNo)
  • specify \small for the entire first column
  • use only two columns instead of 9 and joining the last 8 in every but the last row
  • there was a \\ missing before the \bottomrule
\documentclass{article}
\usepackage{tikz}
\usepackage{tabu}  
\usepackage{booktabs}
\usepackage{tabularray} % Replaces 'tabu', 'tabularx', & 'multirow'
\UseTblrLibrary{booktabs} % Used by 'tabularray' to load packages for internal use
\usepackage{xstring} % Needed for "checkboxYesNoOld" command

\newcommand\checkboxBox[1] {% \begin{tikzpicture}[scale=1, line width=1.0pt] \draw (0,0) rectangle (1.5ex, 1.5ex) #1; \end{tikzpicture}% } \newcommand{\checkYes}{% \checkboxBox {% ( 0.3ex, 0.3ex) -- + ( 0.9ex, 0.9ex) ( 0.3ex, 1.2ex) -- + ( 0.9ex, -0.9ex) }% }

% Creates Unchecked Checkbox \newcommand{\checkNo}{\checkboxBox{}}

\ExplSyntaxOn \prg_generate_conditional_variant:Nnn \str_if_in:nn {ee} { TF, T, F } \NewDocumentCommand{\checkboxYesNo}{mm} { \str_if_in:eeTF { \str_foldcase:n { #2 } } { \str_foldcase:n { #1 } } {\checkYes} {\checkNo} } \ExplSyntaxOff

\newcommand{\checkboxYesNoOld}[2]{ %% #1--Find This; #2--Search This List %% Outputs a Checked or Unchecked box \lowercase{\def\myList{#2}}% \lowercase{\def\findMe{#1}}% \IfSubStr{\myList}{\findMe}{\checkYes}{\checkNo}% % \IfSubStr{\myList}{\findMe}{Yes \findMe - \myList}{No \findMe - \myList}% }

\newcommand{\reqUserOld}[6]{% \begingroup \small \begin{tabu} to 0.99\textwidth{p{60pt} *{3}{p{1pt} X[2,l] } p{1pt} X[3,l] } \toprule {\small \textbf{Req Name}} & \multicolumn{8}{l}{\textbf{#2}} \ \cmidrule(r){1-1} \cmidrule(l){2-9} {\small Req ID} & \multicolumn{8}{l}{#1} \ \cmidrule(r){1-1} \cmidrule(l){2-9} {\small Requirement} & \multicolumn{8}{l}{#3} \ \cmidrule(r){1-1} \cmidrule(l){2-9} {\small Remarks} & \multicolumn{8}{l}{#4} \ \cmidrule(r){1-1} \cmidrule(l){2-9} {\small Parent} & \multicolumn{8}{l}{#5} \ \cmidrule(r){1-1} \cmidrule(l){2-9} {\small Verification} &

%%%% Use this for "correct" output %{\small \checkYes} & {\small Test} & %{\small \checkNo} & {\small Analysis} & %{\small \checkNo} & {\small Inspection} & %{\small \checkYes} & {\small Review-of-Design} \

%%%% This may cause a different error. {\small \checkboxYesNoOld{t}{#6}} & {\small Test} & {\small \checkboxYesNoOld{a}{#6}} & {\small Analysis} & {\small \checkboxYesNoOld{i}{#6}} & {\small Inspection} & {\small \checkboxYesNoOld{r}{#6}} & {\small Review-of-Design} \

\bottomrule
\tabuphantomline

\end{tabu} \endgroup }

\newcommand{\reqUser}[6]{% \begin{tblr}{ width = 0.99\textwidth, colspec = {>{\small}h{60pt} X} }

\toprule
\textbf{Req Name} & \textbf{#2} \\

\cmidrule[r]{1-1} \cmidrule[l]{2-2}
Req ID       & #1 \\
\cmidrule[r]{1-1} \cmidrule[l]{2-2}
Requirement  & #3 \\
\cmidrule[r]{1-1} \cmidrule[l]{2-2}
Remarks      & #4 \\
\cmidrule[r]{1-1} \cmidrule[l]{2-2}
Parent       & #5 \\
\cmidrule[r]{1-1} \cmidrule[l]{2-2}

Verification &
  \small
  \checkboxYesNoOld{t}{#6} Test \hfill
  \checkboxYesNoOld{a}{#6} Analysis \hfill
  \checkboxYesNoOld{i}{#6} Inspection \hfill
  \checkboxYesNoOld{r}{#6} Review-of-Design \\
\bottomrule

\end{tblr} % ! So the \checkboxYesNo command is causing the table to be super tall }

\begin{document}

% This produces the desired results under the old tabu/xstring system \noindent \reqUserOld{M-03}{Req Name 3}{A description}{Some remarks}{The Parent Requirement}{tr}

%% Use this for "error" output (The verbatim command '\checkboxYesNo' cannot be used inside) \noindent \reqUser{M-03}{Req Name 3}{A description}{Some remarks}{The Parent Requirement}{tr}

\end{document}

enter image description here

Skillmon
  • 60,462
  • Asides from answering all my questions, you managed to answer a question about \hfill I didn't know I had. – Nebabon May 18 '22 at 22:24