改进 tikz-error 消息

改进 tikz-error 消息

这道题是关于使用时查找编译错误的原因tikz

考虑文件compiles.texcompiles-not1.texcompiles-not2.tex。那么很明显无法编译,因为尚未分配compiles-not1.tex名称。文件无法编译,因为名称 后面有一个空格。但是,从错误消息中很难看出这一点。Ccompiles-not2.tex\draw (A) -- (A -| B );B

是否可以调整生成的错误消息,以便tikztikz某种方式标记代码和名称?我的意思是,在示例中,错误消息! Package pgf Error: No shape named 'B ' is known.可能更有帮助,因为名称中的空格B\␣B带有尾随空格)与消息的分隔更清晰。

文件compiles.tex编译没有错误。

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
    \node (A) {A};
    \node[above right of=A] (B) {B};
    \draw (A) -- (A -| B);
\end{tikzpicture}
\end{document}

编译时compiles-not1.tex生成! Package pgf Error: No shape named C is known.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
    \node (A) {A};
    \node[above right of=A] (B) {B};
    \draw (A) -- (A -| C);
\end{tikzpicture}
\end{document}

compiles-not2.tex生成! Package pgf Error: No shape named B is known.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
    \node (A) {A};
    \node[above right of=A] (B) {B};
    \draw (A) -- (A -| B );
\end{tikzpicture}
\end{document}

答案1

我认为在 SourceForge 上提出关于此问题的功能请求可能会有所帮助 (https://sourceforge.net/p/pgf/feature-requests/?source=navbar),但似乎可以通过修补宏来实现这一点。

\documentclass{article}
\usepackage{tikz}
\usepackage{etoolbox}
\patchcmd{\pgfpointanchor}{No shape named #1 is known}{No shape named '#1' is known}{}{}
\begin{document}
\begin{tikzpicture}
    \node (A) {A};
    \node[above right of=A] (B) {B};
    \draw (A) -- (A -| B );
\end{tikzpicture}
\end{document}

这将引发错误

! Package pgf Error: No shape named 'B ' is known.

See the pgf package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.9     \draw (A) -- (A -| B )
                              ;
? 

相关内容