TeX Live 2020 从 2018 更新后出现的问题

TeX Live 2020 从 2018 更新后出现的问题

以下命令在 TeX Live 2018 上运行良好,但在更新到 TeX Live 2020 后,出现此错误。我找不到问题所在:

! Missing \endcsname inserted.
<to be read again> 
                   \OT1\j 
l.85     <Prix >{,,5,7.5}[$\times\dots$]
                                        
?
\documentclass{standalone}
\usepackage{tikz,xparse}

\pgfkeys{/tikz/.cd,
    % hauteur des lignes
    BLS/.store in=\BLS,
    BLS=1.1*\baselineskip,
    % largeur étiquette
    TDP etq width/.store in=\TDPew,
    TDP etq width=3em,
    % largeur cases
    TDP case width/.store in=\TDPcw,
    TDP case width=3em,
    }

    \tikzset{%
        % style général des cases
        TDPnode/.style={outer sep=0pt,inner sep=1pt,
            minimum height=\BLS,draw,text depth=2pt},
        % style des étiquettes de ligne
        TDPetq/.style={TDPnode,anchor=north east,fill=gray,
            minimum width=\TDPew + 9pt,align=left,
            text width=\TDPew},
        % style des cases
        TDPcas/.style={TDPnode,anchor=west,minimum width=\TDPcw},
        % style de la flèche
        TDPfle/.style={>=stealth,semithick}
    }


\NewDocumentCommand{\TDP}
    {
    o       % fleche gauche
    d<>     % etq 
    m       % liste 1ere ligne separateur "," 
    d<>     % etq ;
    m       % liste 2sde ligne separateur ","
    o       % fleche droite
    }
    {%
    
    \IfValueTF{#2}{%
    % On traite l'etiquette
    \node[TDPetq] (A0) at (0,\BLS)  {\strut#2} ; }{
    \coordinate (A0) at (0,\BLS) ;}
    
    % traite la liste
    \foreach \x [count=\i from 0, count=\j from 1] in {#3} {%
        \node[TDPcas] (A\j) at (A\i.east) {\strut\x} ;
        }
    \node[TDPcas,draw=none] (AF) at (A\j.west) {} ;
    
    \IfValueTF{#4}{%
    % On traite l'etiquette
    \node[TDPetq] (B0) at (0,0) {\strut#4} ;}{
    \coordinate (B0) at (0,0) ;}

    % traite la liste
    \foreach \x [count=\i from 0, count=\j from 1] in {#5} {%
        \node[TDPcas] (B\j) at (B\i.east) {\strut\x} ;
        }
    \node[TDPcas,draw=none] (BF) at (B\j.west) {} ;

    \IfValueTF{#1}{% fleche de gauche
        \draw[TDPfle,<-] ([xshift=-2pt]A0.west)
        arc (90:270:{.6*\BLS} and 0.5*\BLS)
        node[midway,left=-2pt] {#1};
    }{3}

    \IfValueTF{#6}{% fleche de droite
        \draw[TDPfle,->] ([xshift=2pt]AF.east)
        arc (90:-90:{.6*\BLS} and 0.5*\BLS)
        node[midway,right=-2pt] {#6};
    }{}
}


\begin{document}

\begin{tikzpicture}[%
    TDP etq width=2cm,baseline={(0,0)},
    every node/.style={text depth=2pt}]
    
    \TDP[$\dots\times$]<Masse (kg)>{0.5,1,2,}%
    <Prix >{,,5,7.5}[$\times\dots$]
        
\end{tikzpicture}

\end{document}

答案1

这是一个有意改变Z 因为否则你通常会丢失无点的 i 和 j 字符,因为\i\j经常用作循环变量\foreach

要在循环结束后使用循环中的最后一项,您可以\xdef\lastj{\j}在内部添加\foreach,然后在外部使用\lastj

在此处输入图片描述

\documentclass{standalone}
\usepackage{tikz,xparse}

\pgfkeys{/tikz/.cd,
    % hauteur des lignes
    BLS/.store in=\BLS,
    BLS=1.1*\baselineskip,
    % largeur étiquette
    TDP etq width/.store in=\TDPew,
    TDP etq width=3em,
    % largeur cases
    TDP case width/.store in=\TDPcw,
    TDP case width=3em,
    }

    \tikzset{%
        % style général des cases
        TDPnode/.style={outer sep=0pt,inner sep=1pt,
            minimum height=\BLS,draw,text depth=2pt},
        % style des étiquettes de ligne
        TDPetq/.style={TDPnode,anchor=north east,fill=gray,
            minimum width=\TDPew + 9pt,align=left,
            text width=\TDPew},
        % style des cases
        TDPcas/.style={TDPnode,anchor=west,minimum width=\TDPcw},
        % style de la flèche
        TDPfle/.style={>=stealth,semithick}
    }


\NewDocumentCommand{\TDP}
    {
    o       % fleche gauche
    d<>     % etq 
    m       % liste 1ere ligne separateur "," 
    d<>     % etq ;
    m       % liste 2sde ligne separateur ","
    o       % fleche droite
    }
    {%
    
    \IfValueTF{#2}{%
    % On traite l'etiquette
    \node[TDPetq] (A0) at (0,\BLS)  {\strut#2} ; }{
    \coordinate (A0) at (0,\BLS) ;}
    
    % traite la liste
    \foreach \x [count=\i from 0, count=\j from 1] in {#3} {%
        \node[TDPcas] (A\j) at (A\i.east) {\strut\x} ;
        \xdef\lastj{\j} % define here
        }
    \node[TDPcas,draw=none] (AF) at (A\lastj.west) {} ; % use \lastj outside
    
    \IfValueTF{#4}{%
    % On traite l'etiquette
    \node[TDPetq] (B0) at (0,0) {\strut#4} ;}{
    \coordinate (B0) at (0,0) ;}

    % traite la liste
    \foreach \x [count=\i from 0, count=\j from 1] in {#5} {%
        \node[TDPcas] (B\j) at (B\i.east) {\strut\x} ;
        \xdef\lastj{\j} % define here
        }
    \node[TDPcas,draw=none] (BF) at (B\lastj.west) {} ; % use \lastj outside

    \IfValueTF{#1}{% fleche de gauche
        \draw[TDPfle,<-] ([xshift=-2pt]A0.west)
        arc (90:270:{.6*\BLS} and 0.5*\BLS)
        node[midway,left=-2pt] {#1};
    }{3}

    \IfValueTF{#6}{% fleche de droite
        \draw[TDPfle,->] ([xshift=2pt]AF.east)
        arc (90:-90:{.6*\BLS} and 0.5*\BLS)
        node[midway,right=-2pt] {#6};
    }{}
}


\begin{document}

\begin{tikzpicture}[%
    TDP etq width=2cm,baseline={(0,0)},
    every node/.style={text depth=2pt}]
    
    \TDP[$\dots\times$]<Masse (kg)>{0.5,1,2,}%
    <Prix >{,,5,7.5}[$\times\dots$]
        
\end{tikzpicture}

\end{document}

答案2

这个答案解释了导致问题的 pgf 更改之一。但是,还有另一个更改允许您将计数偷运出组:\pgfutil@pushmacro\pgfutil@popmacro。虽然我不确定是否要使用\i\j作为计数器,但您可以使用上述宏将宏偷运出循环foreach。这些技巧可以更广泛地用于将您需要的任何内容从由生成的本地组中导出\foreach

\documentclass{standalone}
\usepackage{tikz,xparse}
\makeatletter
\newcommand\pgfpush[1]{\pgfutil@pushmacro#1}
\newcommand\pgfpop[1]{\pgfutil@popmacro#1}
\makeatother

\pgfkeys{/tikz/.cd,
    % hauteur des lignes
    BLS/.store in=\BLS,
    BLS=1.1*\baselineskip,
    % largeur etiquette
    TDP etq width/.store in=\TDPew,
    TDP etq width=3em,
    % largeur cases
    TDP case width/.store in=\TDPcw,
    TDP case width=3em,
    }

    \tikzset{%
        % style general des cases
        TDPnode/.style={outer sep=0pt,inner sep=1pt,
            minimum height=\BLS,draw,text depth=2pt},
        % style des etiquettes de ligne
        TDPetq/.style={TDPnode,anchor=north east,fill=gray,
            minimum width=\TDPew + 9pt,align=left,
            text width=\TDPew},
        % style des cases
        TDPcas/.style={TDPnode,anchor=west,minimum width=\TDPcw},
        % style de la fleche
        TDPfle/.style={>=stealth,semithick}
    }


\NewDocumentCommand{\TDP}%
    {
    o       % fleche gauche
    d<>     % etq 
    m       % liste 1ere ligne separateur "," 
    d<>     % etq ;
    m       % liste 2sde ligne separateur ","
    o       % fleche droite
    }
    {%
    %
    \IfValueTF{#2}{%
    % On traite l'etiquette
    \node[TDPetq] (A0) at (0,\BLS)  {\strut#2} ; }{
    \coordinate (A0) at (0,\BLS) ;}
%     %
%     % traite la liste
    \foreach \x [count=\i from 0, count=\j from 1] in {#3} {%
        \node[TDPcas] (A\j) at (A\i.east) {\strut\x} ;
        \pgfpush\j
        }
    \pgfpop\j   
    \node[TDPcas,draw=none] (AF) at (A\j.west) {} ;
%   %   
    \IfValueTF{#4}{%
    % On traite l'etiquette
    \node[TDPetq] (B0) at (0,0) {\strut#4} ;}{
    \coordinate (B0) at (0,0) ;}
    % traite la liste
    \foreach \x [count=\i from 0, count=\j from 1] in {#5} {%
        \node[TDPcas] (B\j) at (B\i.east) {\strut\x} ;
        \pgfpush\j
        }
    \pgfpop\j       
    \node[TDPcas,draw=none] (BF) at (B\j.west) {} ;
    \IfValueTF{#1}{% fleche de gauche
        \draw[TDPfle,<-] ([xshift=-2pt]A0.west)
        arc (90:270:{.6*\BLS} and 0.5*\BLS)
        node[midway,left=-2pt] {#1};
    }{3}
    \IfValueTF{#6}{% fleche de droite
        \draw[TDPfle,->] ([xshift=2pt]AF.east)
        arc (90:-90:{.6*\BLS} and 0.5*\BLS)
        node[midway,right=-2pt] {#6};
    }{}
}

\begin{document}
\begin{tikzpicture}[%
    TDP etq width=2cm,baseline={(0,0)},
    every node/.style={text depth=2pt}]
    
    \TDP[$\dots\times$]<Masse (kg)>{0.5,1,2,}%
    <Prix >{,,5,7.5}[$\times\dots$]      
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容