我遇到了一个奇怪的难题,无法解决。除了通常包含的软件包外,我还添加了三个额外的软件包:
tikz
-- 用于状态图mdwtab
以及syntax
上下文无关文法
当我将这三个包放在一起时,LaTex 不允许我编译,我不知道为什么。如果我简单地删除其中一个,一切都会正常。以下是我在同时包含这两个包时收到的错误消息:
ERROR: Argument of \XC@definec@lor has an extra }.
--- TeX said ---
<inserted text>
\par
l.32 \node[state,initial,accepting] (q_0)
{$q_0$};
--- HELP ---
From the .log file...
I've run across a `}' that doesn't seem to match anything.
For example, `\def\a#1{...}' and `\a}' would produce
this error. If you simply proceed now, the `\par' that
I've just inserted will cause me to report a runaway
argument that might be the root of the problem. But if
your `}' was spurious, just type `2' and it will go away.
下面显示了一个包含两个包的简单示例。我一注释掉这两个包mdwtab
,syntax
所有东西就编译好了。
\documentclass[10pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage{amsmath,amsthm,amssymb}
\usepackage{graphicx,ctable,booktabs}
\usepackage{verbatim}
\usepackage{tikz}
\usetikzlibrary{automata,positioning}
\usepackage{mdwtab}
\usepackage{syntax}
% ----------------------------------------------------------------------------------------------------------------------------------------------
% Commands
%-----------------------------------------------------------------------------------------------------------------------------------------------
\newcommand{\justif}[2]{&{#1}&\text{#2}}
\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\R}{\mathbb{R}}
\begin{document}
\section*{Pushdown Automata}
\begin{grammar}\centering
<S> $\rightarrow$ 0S1 | $\epsilon$
\end{grammar}
\begin{center}
\begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid,auto]
\node[state,initial,accepting] (q_0) {$q_0$};
\node[state] (q_1) [right=of q_0] {$q_1$};
\node[state] (q_2) [below=of q_1] {$q_2$};
\node[state,accepting] (q_3) [left=of q_2] {$q_3$};
\path[->]
(q_0) edge node {$\epsilon,\epsilon \to \$$} (q_1)
(q_1) edge [loop above] node {$0,\epsilon\to 0$} ()
edge node {$1,0\to\epsilon$} (q_2)
(q_2) edge [loop right] node {$1,0\to\epsilon$} ()
edge node {$\epsilon,\$\to\epsilon$} (q_3);
\end{tikzpicture}
\end{center}
\end{document}
- 这里的问题是什么?我该如何编译它以便可以获得我的 pdf?
谢谢大家的帮助!
答案1
该syntax
包使下划线字符处于活动状态,以便下划线可以在数学模式之外使用(始终是一种危险的策略)。因此,问题是由于您的节点标签中有下划线造成的。解决此问题的最简单方法是撤消对环境syntax
中的下划线所做的欺骗。这可以使用包的功能tikzpicture
轻松完成。(我还使您的示例更加简洁。)\AtBeginEnvironment
etoolbox
\documentclass[10pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage{tikz}
%
\usetikzlibrary{
automata
,positioning}
\usepackage{syntax}
\usepackage{etoolbox}
\AtBeginEnvironment{tikzpicture}{\catcode`\_=8}
\begin{document}
\section*{Pushdown Automata}
\begin{grammar}\centering
<S> $\rightarrow$ 0S1 | $\epsilon$
\end{grammar}
\begin{center}
\begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid,auto]
\node[state,initial,accepting] (q_0) {$q_0$};
\node[state] (q_1) [right=of q_0] {$q_1$};
\node[state] (q_2) [below=of q_1] {$q_2$};
\node[state,accepting] (q_3) [left=of q_2] {$q_3$};
\path[->]
(q_0) edge node {$\epsilon,\epsilon \to \$$} (q_1)
(q_1) edge [loop above] node {$0,\epsilon\to 0$} ()
edge node {$1,0\to\epsilon$} (q_2)
(q_2) edge [loop right] node {$1,0\to\epsilon$} ()
edge node {$\epsilon,\$\to\epsilon$} (q_3);
\end{tikzpicture}
\end{center}
\end{document}