LaTeX3 逐字命令在参数中不合法

LaTeX3 逐字命令在参数中不合法

LaTeX cmd:参数中类似逐字的命令“\checkboxYesNo”非法。

当我尝试从使用tabu&xstring组合迁移到tabularray& 本机LaTeX3组合来创建需求表时,我收到了上述消息。我用它\checkboxYesNo来确定嵌入到表中的某些复选框的状态。此宏嵌入在更大的宏中,因为每次调用更大的宏时都会调用 4 次。我附上了一个 MWE,其中包含有关注释掉哪些内容以使其正常工作的注释。如果我切换到旧的\checkboxYesNoOld,它将与新tabularray包一起工作。

我不确定如何将一个宏嵌入第二个宏中,让内部宏根据输入做出决策。我阅读了其他一些以前的答案,但我就是无法理解这个问题。

\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}

答案1

下面确实包含了一些更正:

  • 使用mm而不是vv作为参数
  • 仅生成变体\str_if_in:nnTF仅生成一次
  • 使用rectangle在你的tikzpicture
  • 将框绘图移动到另一个宏(减少代码重复)\checkYes/的代码重复\checkNo
  • 指定\small整个第一列
  • 只使用两列而不是九列,并将除最后一行之外的每一行的最后 8 列连接起来
  • 之前有一个\\失踪\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}

在此处输入图片描述

相关内容