缺少 \begin{document} - LaTeX 错误

缺少 \begin{document} - LaTeX 错误

我正在为《应用晶体学杂志》制作一个模板,示例可用这里(请参阅附录 D)。不幸的是,我遇到了问题标题中提到的错误。我按照这个回答解决错误却没有任何成功。下面您可以看到一个最小工作示例。在这里您可以找到.cls文件

%------------------------------------------------------------------------------
% Template file for the submission of papers to IUCr journals in LaTeX2e
% using the iucr document class
% Copyright 1999-2003 International Union of Crystallography
% Version 1.2 (11 December 2002)
%------------------------------------------------------------------------------
\documentclass{iucr} % DO NOT DELETE THIS LINE
%-------------------------------------------------------------------------
% Information about the type of paper
%-------------------------------------------------------------------------
\paperprodcode{a000000} % Replace with production code if known
\paperref{xx9999} % Replace xx9999 with reference code if known
\papertype{FA} % Indicate type of article
% FA - research papers (full article)
% SC - short communications
% FC - fast communications
% LA - lead article
% TR - topical review
% XL - crystallization papers
% (Following categories rarely in LaTeX)
% AA - abstracts
% AD - addenda and errata
% AI - inorganic compounds
% AM - metal-organic compounds
% AO - organic compounds
% BC - books received
% BR - book reviews
% BI - biography
% CA - cif applications
% CD - crystal data
% CE - current events
% CI - inorganic compounds
% CL - calendar of events
% CM - metal-organic compounds
% CN - cryocrystallography papers
% CO - organic compounds
% CP - computer programs
% CR - crystallographers
% CS - scientific comment
% ED - editorial
% EI - inorganic compounds
% EM - metal-organic compounds
% EO - organic compounds
% FI - inorganic compounds
% FM - metal-organic compounds
% FO - organic compounds
% IP - issue preface
% IU - iucr
% LE - letters to the editor
% LN - laboratory notes
% ME - forthcoming meetings/short courses
% MR - meeting reports
% NN - notes and news
% NP - new commercial products
% OB - obituaries
% PA - computer program abstracts
% RI - reference information
% SG - structural genomics papers
% SI - short format inorganic compounds
% SM - short format metal-organic compounds
% SO - short format organic compounds
% SP - short structural papers
% SR - software reviews
% TE - teaching and education
\paperlang{english} % Can be english, french, german or russian
%-------------------------------------------------------------------------
% Information about journal to which submitted
%-------------------------------------------------------------------------
\journalcode{J} % Indicate the journal to which submitted
% A - Acta Crystallographica Section A
% B - Acta Crystallographica Section B
% C - Acta Crystallographica Section C
% D - Acta Crystallographica Section D
% E - Acta Crystallographica Section E
% J - Journal of Applied Crystallography
% S - Journal of Synchrotron Radiation
%--------------------------------------------------------------------
% The following entries will be changed as required by editorial staff
%--------------------------------------------------------------------
\journalyr{2003}
\journaliss{1}
\journalvol{59}
\journalfirstpage{000}
\journallastpage{000}
\journalreceived{0 XXXXXXX 0000}
\journalaccepted{0 XXXXXXX 0000}
\journalonline{0 XXXXXXX 0000}


% \let\proof\relax
% \let\endproof\relax
% \usepackage{amsthm}



\begin{document} 

%-------------------------------------------------------------------------
% The introductory (header) part of the paper
%-------------------------------------------------------------------------
% The title of the paper. Use \shorttitle to indicate an abbreviated title
% for use in running heads (you will need to uncomment it).
\title{Title of Paper}
%\shorttitle{Short Title}
% Authors’ names and addresses. Use \cauthor for the main (contact) author.
% Use \author for all other authors. Use \aff for authors’ affiliations.
% Use lower-case letters in square brackets to link authors to their
% affiliations; if there is only one affiliation address, remove the [a].
\cauthor[a]{Forename}{Surname}{email}{address if different from \aff}
\author[b]{Forename}{Surname}
\aff[a]{First affiliation address \country{England}}
\aff[b]{Second affiliation address}
% Use \shortauthor to indicate an abbreviated author list for use in
% running heads (you will need to uncomment it).
%\shortauthor{Soape, Author and Doe}
% Use \vita if required to give biographical details (for authors of
% invited review papers only). Uncomment it.
%\vita{Author’s biography}
% Keywords (required for Journal of Synchrotron Radiation only)
% Use the \keyword macro for each word or phrase, e.g.
% \keyword{X-ray diffraction}\keyword{muscle}
%\keyword{keyword}
% PDB and NDB reference codes for structures referenced in the article and
% deposited with the Protein Data Bank and Nucleic Acids Database (Acta
% Crystallographica Section D). Repeat for each separate structure e.g
% \PDBref[dethiobiotin synthetase]{1byi} \NDBref[d(G$_4$CGC$_4$)]{ad0002}
%\PDBref[optional name]{refcode}
%\NDBref[optional name]{refcode}
\maketitle % DO NOT DELETE THIS LINE
\begin{synopsis}
Supply a synopsis of the paper for inclusion in the Table of Contents.
\end{synopsis}
\begin{abstract}
Abstract goes here.
\end{abstract}
%-------------------------------------------------------------------------
% The main body of the paper
%-------------------------------------------------------------------------
% Now enter the text of the document in multiple \section’s, \subsection’s
% and \subsubsection’s as required.
\section{Section title}

Text text text text text text text text text text text text text text
text text text text text text text.
\subsection{Title}
Text text text text text text text text text text text text text text
text text text text text text text.

\subsubsection{Title}
Text text text text text text text text text text text text text text
text text text text text text text.
% Appendices appear after the main body of the text. They are prefixed by
% a single \appendix declaration, and are then structured just like the
% body text.
\appendix
\section{Appendix title}
Text text text text text text text text text text text text text text
text text text text text text text.
\subsection{Title}
Text text text text text text text text text text text text text text
text text text text text text text.
\subsubsection{Title}
Text text text text text text text text text text text text text text
text text text text text text text.
%-------------------------------------------------------------------------
% The back matter of the paper - acknowledgements and references
%-------------------------------------------------------------------------
% Acknowledgements come after the appendices
\ack{Acknowledgements}
% References are at the end of the document, between \begin{references}
% and \end{references} tags. Each reference is in a \reference entry.

\begin{references}
\reference{Author, A. \& Author, B. (1984). \emph{Journal} \textbf{Vol},
first page--last page.}
\end{references}
%-------------------------------------------------------------------------
% TABLES AND FIGURES SHOULD BE INSERTED AFTER THE MAIN BODY OF THE TEXT
%-------------------------------------------------------------------------
% Simple tables should use the tabular environment according to this
% model
\begin{table}
\caption{Caption to table}
\begin{tabular}{llcr} % Alignment for each cell: l=left, c=center, r=right
HEADING & FOR & EACH & COLUMN \\
\hline
entry & entry & entry & entry \\
entry & entry & entry & entry \\
entry & entry & entry & entry \\
\end{tabular}
\end{table}
% Postscript figures can be included with multiple figure blocks
\begin{figure}
\caption{Caption describing figure.}
\includegraphics{main_gui.eps}
\end{figure}

\end{document} 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

答案1

完整信息如下

! LaTeX Error: Missing \begin{document}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.7364   \RHUBARB
                 % % hack - see above

这条令人反感的语句前面有一条评论,翻译过来就是“我们知道这是错的”......

% The next line is rather mysterious. For some reason the way in which \_ is
% set up requires that it be instantiated in some hidden way like this:
% undoubtedly a subtle bug, but this provides a workaround for current
% dictionaries
\gdef\RHUBARB{\smash{$\phantom{\_}$}}%
  \RHUBARB% % hack - see above

如果你删除或注释掉以下行

\RHUBARB% % hack - see above

然后它运行就不会出错了。

答案2

错误原因是奇怪的行

\gdef\RHUBARB{\smash{$\phantom{\_}$}}%
  \RHUBARB% % hack - see above

但我可以说为什么它过去不会引发错误。2018 年,一些 LaTeX 内核命令进行了修改,以确保它们始终在 LR 模式(TeXspeak 中的水平模式)下处理:其中包括\smash

之前,\smash只是\hbox向主垂直列表贡献了一个,所以它没有触发Missing \begin{document}错误。

另一方面,删除\RHUBARB并不能真正解决问题:使用 TeX Live 2017 运行文档会产生

在此处输入图片描述

注释掉该\RHUBARB行并使用 TeX Live 2021 运行,结果如下

在此处输入图片描述

我认为这不能算是好的输出。

除了明显错误的章节标题外,我们还可以注意到另一个方面:第一条规则后缺少一些垂直空间。“附录 A”的令人惊讶的排版可以通过\appendix在源代码之前添加一个空行来解决:这是由于类使用了\vspace\baselineskip而不是\vskip\baselineskip或者更好的是\par\vspace{\baselineskip}

你可以通过改变来恢复空间

\gdef\RHUBARB{\smash{$\phantom{\_}$}}%
  \RHUBARB% % hack - see above

进入

\gdef\RHUBARB{\hbox{\smash{$\phantom{\_}$}}}%
  \RHUBARB% % hack - see above

因此神秘的黑客攻击方式与以前相同。

章节标题的错误排版已通过注释掉第 1326 行来纠正iucr.cls

    \thesection.\ #1\par%
    %\vskip-\baselineskip%
    \vskip4pt minus 4pt}%

现在输出符合预期

在此处输入图片描述

相关内容