我跑
pdflatex -interaction nonstopmode -halt-on-error -file-line-error test.tex
注意到我的文件第 75 行有一些错误
/Users/masi/Dropbox/bin/test.tex:75: ==> Fatal error occurred, no output
PDF file produced!
运行不带参数的命令时没有出现这样的错误。
第 75 行所示的文件
\documentclass{article}
\usepackage{rotating}
\usepackage{pdfpages}
\usepackage{verbatim}
\usepackage{amsmath, amsfonts, amssymb, textcomp, mathtools, xparse}
\usepackage[T4, OT1]{fontenc}
\usepackage{graphicx}
\graphicspath{{/Users/masi/Dropbox/Physiology/images/}}
% Animations cannot be included here
% \addmediapath{ {/Users/masi/Dropbox/Physiology/animations/} }
\usepackage{newunicodechar}
\usepackage{multirow}
\DeclarePairedDelimiter{\abs}{\lvert}{\rvert}
\DeclarePairedDelimiter{\norm}{\lVert}{\rVert}
\usepackage{color}
\usepackage{hyperref}
\usepackage{media9} % animations swf
\usepackage{Tabbing}
\usepackage{doi, natbib}
\hypersetup{
colorlinks=true,
linkcolor=blue,
citecolor=blue,
allcolors=blue
}
\usepackage[affil-it]{authblk}
\usepackage{import}
\usepackage{color}
\usepackage[normalem]{ulem}
\usepackage{titling} % Two titles in one document
% \DeclarePairedDelimiter{\abs}{\lvert}{\rvert} % This requires amsmath, I think
%%%%%%%%%%%%%%%%%%%%%%%%%%% Question and Answer %%%%%%%%%%%%%%%%%
\usepackage[framemethod=tikz]{mdframed}
\mdfdefinestyle{ans}{
linecolor=cyan,
backgroundcolor=yellow!20,
frametitlebackgroundcolor=green!40,
frametitlerule=true
}
\newcounter{question}[section]%
\setcounter{question}{0}
\newenvironment{question}[1]{%
\refstepcounter{question}%
\begin{mdframed}[style=ans,frametitle={Question: #1}]
}{%
\end{mdframed}%
}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%% Smaller things
\newtheorem{case}{Case logic}
\mdfdefinestyle{que}{
linecolor=cyan,
backgroundcolor=cyan!20,
}
\surroundwithmdframed[style=que]{case}
\newtheorem{sidenote}{Sidenote}
\mdfdefinestyle{que}{
linecolor=cyan,
backgroundcolor=cyan!20,
}
\surroundwithmdframed[style=que]{sidenote}
\newtheorem{citation}{Citation}
\mdfdefinestyle{que}{ % TODO Line 75, refers to error here
linecolor=cyan,
backgroundcolor=yellow!20,
}
\surroundwithmdframed[style=que]{citation}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newtheorem{theorem}{Theorem}
\newtheorem{proposition}[theorem]{Proposition}
\newenvironment{definition}[1][Definition]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}] \emph}{\end{trivlist}}
\providecommand{\keywords}[1]{\textbf{Keywords:} #1}
%%%%%%%%%%%%%%%%%%%%%%%%% Counter Section %%%%%%%%%%%%%%%%%%%%%%
\makeatletter
\def\@part[#1]#2{%
\ifnum \c@secnumdepth >\m@ne
\refstepcounter{part}%
\fi
\addcontentsline{toc}{part}{#1}%
{\parindent \z@ \raggedright
\interlinepenalty \@M
\normalfont
\LARGE \bfseries #2%
\markboth{}{}\par}%
\nobreak
\vskip 3ex
\@afterheading}
\@addtoreset{section}{part}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
Lorem ipsun.
\end{document}
您能看出第 75 行有什么错误吗?
答案1
除了 David 的回答之外,还要说明为什么编译器在第 75 行而不是第 74 行停止,这才是真正的原因。
首先,这是 LaTeX 在文件中写入有关引用的注释\citation
时内部使用的命令:.aux
\cite
% latex.ltx, line 6118:
\let\citation\@gobble
它被定义为对其参数不执行任何操作,因为其目的是在读取文件时向 BibTeX 传递一条消息.aux
。
foo
其次,如果命令已经存在,则无法定义环境\foo
,因为
\newenvironment{foo}{...}{...}
通过定义\foo
和来工作\endfoo
。所以你的
\newtheorem{citation}{Citation}
会产生错误,因为它的工作包括做一些相当于
\newenvironment{citation}
尽管是内部形式;实际上,LaTeX 确实如此\expandafter\ifdefinable\csname citation\endcsname
,这解释了错误消息。然而它确实如此后寻找[
(可能的尾随可选参数)。
这会导致编译器占用空格,直到找到第一个不存在的标记,[
或者如果找到一个标记则停止[
。因此,在搜索标记的过程中,TeX 将转到第 75 行。在这种情况下,行尾就像一个空格。
对此我们无能为力。错误消息中的行号只能是 TeX 意识到有错误时激活的行号,并且是在查找之后,最终开始处理时出现的\newtheorem
(实际上\@ynthm
,但这几乎无关紧要)。
故事的寓意是:行号可以提供帮助,但错误信息才是最具参考价值的部分。
如果输入的是
\newtheorem{citation}{Citation}\relax
因为\relax
停止查找[
。是否应该\relax
在每个\newtheorem
语句后添加?不,只需查看错误消息(如果发生),在本例中为
! LaTeX Error: Command \citation already defined.
Or name \end... illegal, see p.192 of the manual.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
这确实表明了真正的问题。
答案2
运行 MWE 时会显示该行有错误,
! LaTeX Error: Command \citation already defined.
Or name \end... illegal, see p.192 of the manual.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.75 \mdfdefinestyle
{que}{ % TODO Line 75, refers to error here
?
假设日志中也有同样的错误?
所以其实是之前的那行
\newtheorem{citation}{Citation}
声明一个citation
已在此上下文中定义的环境。