如何使用带有语法和下划线的 tkz-graph?

如何使用带有语法和下划线的 tkz-graph?

下面的文档编译时没有错误。但是,如果我取消注释任何注释行,就会出现错误(我将其粘贴在最后)。有什么技巧可以避免此错误吗?

\documentclass{article}
\usepackage[utf8]{inputenc}
%\usepackage{syntax}
%\usepackage{underscore}
\usepackage{tkz-graph}


\begin{document}

\begin{tikzpicture}
  \SetGraphUnit{1}
  \SetVertexMath
  \Vertex{q_1}
\end{tikzpicture}

\end{document}

错误:

ERROR: Use of \tikz@fig@scan@name doesn't match its definition.

--- TeX said ---
\pgfutil@ifnextchar ...1\def \pgfutil@reserved@a {
                                                  #2}\def \pgfutil@reserved@...
l.48    \Vertex[x=1.5, y=0]{q_2}

--- HELP ---
It's probably one of the picture-drawing commands, and you have used
the wrong syntax for specifying an argument. If it's \@array that
doesn't match its definition, then there is something wrong in an
@-expression in the argument of an array or tabular
environment---perhaps a fragile command that is not \protect'ed.

答案1

假设您不需要syntaxunderscore中的功能tikzpicture,您可以恢复类别代码:

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{tkz-graph}
\usepackage{syntax}
\usepackage{underscore}

% directly setting \catcode`\_=8 doesn't work
\newcommand\restoreuscatcode{\catcode`\_=8 }
\tikzset{every picture/.prefix style={execute at begin picture=\restoreuscatcode}}

\begin{document}

\begin{tikzpicture}
  \SetGraphUnit{1}
  \SetVertexMath
  \Vertex{q_1}
\end{tikzpicture}

\end{document}

答案2

一种解决方案是使用顶点的标签字段,q_1如下所示:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{syntax}
\usepackage{underscore}
\usepackage{tkz-graph}

\begin{document}

\begin{tikzpicture}
  \SetGraphUnit{1}
  \SetVertexMath
  \Vertex[L=q_1]{q1}
\end{tikzpicture}

\end{document}

相关内容