图书类中的编译问题

图书类中的编译问题

\include{}我正在写一本书,我使用和命令将其拆分成几个文件\includeonly{}。章节“章节Thomae”具有 Thomae 的功能这里

如果我使用\includeonly{}命令(就像下面的代码) 一切都好。没有一章有问题

\documentclass{book}
\includeonly{chapter1} % or chapter2 or chapter3 or chapterThomae etc
\begin{document}
\include{chapter1}
\include{chapter2}
\include{chapter3}
\include{chapterThomae}
%etc
\end{document}

如果我禁用\includeonly{}命令(拥有整本书 -参见下面的代码我明白了错误报告

\documentclass{book}
 %\includeonly{chapter1}
\begin{document}
\include{chapter1}
\include{chapter2}
\include{chapter3}
\include{chapterThomae}
%etc
\end{document}

pdf 视图(和 pdf 文件)也被删除。

pdfview 显示

我认为包含 Thomae 函数的章节出了问题。如果我禁用此章节(就像下面的代码)一切又恢复正常了。

\documentclass{book}
 %\includeonly{chapter1}
\begin{document}
\include{chapter1}
\include{chapter2}
\include{chapter3}
 %\include{chapterThomae}
%etc
\end{document}

有什么问题?我该如何解决?

附言:如果标题不正确,我很抱歉。我甚至无法想象问题出在哪里,所以我找不到合适的标题

答案1

这里有一个误解:你可以\documentclass{}一个 TeX 文档中不能有两个命令

请参阅我根据您给出的代码创建的以下 MWE(该包filecontents仅用于在一个 MWE 中拥有三个 tex 代码;这仅用于此处的测试目的,您当然可以使用原始代码):

\RequirePackage{filecontents}
\begin{filecontents}{\jobname-chapter1.tex}
\chapter{Chapter One}

Text for chapter one ...
\end{filecontents}

\begin{filecontents}{\jobname-chapterThomae.tex}
\documentclass{article}
\usepackage{tikz}

\makeatletter
\pgfmathdeclarefunction*{gcd}{2}{%
  \begingroup
    \pgfmathcontinuelooptrue
    \pgfmath@xa=#1pt\relax % <-
    \pgfmath@xb=#2pt\relax % <-
    \ifdim\pgfmath@xa=0pt\relax
      \pgfmathcontinueloopfalse
      \pgfmath@xa=\pgfmath@xb
    \fi
    \ifdim\pgfmath@xb=0pt\relax
      \pgfmathcontinueloopfalse
      \pgfmath@xb=\pgfmath@xa
    \fi
    \ifdim\pgfmath@xa<0pt\relax
      \pgfmath@xa=-\pgfmath@xa
    \fi
    \ifdim\pgfmath@xb<0pt\relax
      \pgfmath@xb=-\pgfmath@xb
    \fi
    \loop
      \ifpgfmathcontinueloop
      \ifdim\pgfmath@xa=\pgfmath@xb
        \pgfmathcontinueloopfalse
      \else
        \ifdim\pgfmath@xa>\pgfmath@xb
          \advance\pgfmath@xa by-\pgfmath@xb\relax
        \else
          \advance\pgfmath@xb by-\pgfmath@xa\relax
        \fi
      \fi
    \repeat
    \pgfmathparse{int(\pgfmath@xa)}%
    \pgfmath@smuggleone\pgfmathresult
  \endgroup}
\makeatother

\begin{document}
\begin{center}
    \begin{tikzpicture}[scale=8]
    \draw [-stealth] (-0.1,0) -- (1.1,0);
    \draw [-stealth] (0,-0.1) -- (0,0.6);
    \foreach \X in {1,...,7}
    {\ifnum\X=1
        \else
        \draw (0.02,1/\X) -- (-0.02,1/\X) node[left,xshift={(-(1+pow(-1,\X)))*3pt}]{$\frac{1}{\X}$};
        \fi
    }
    \foreach \X [evaluate=\X as \Ymax using {int(\X-1)}]in {95,94,...,2}%Το μέγεθος του πρώτου όρου καθορίζει το πλήθος των κουκκίδων, άρα και την απόσταση του «τριγώνου» από τον χ'χ.
    {\foreach \Y in {1,...,\Ymax}
        {\ifnum\X<6
            \draw (\Y/\X,0.02) -- (\Y/\X,-0.02) node[below,fill=white]{$\frac{\Y}{\X}$};
            \else
            \draw[ultra thin] (\Y/\X,0.01) -- (\Y/\X,-0.01);
            \fi
            \pgfmathtruncatemacro{\TST}{gcd(\X,\Y)}
            \ifnum\TST=1
            \fill ({\Y/\X},1/\X) circle(0.05pt); %μέγεθος κουκκίδων
            \fi
        }
    }
    \foreach \X in {0,1,...,80}
    {\fill (\X/80,0) circle(0.05pt); } %μέγεθος κουκκίδων
    \end{tikzpicture}
\end{center}
\end{document}
\end{filecontents}


\documentclass{book}

%\includeonly{\jobname-chapter1} % or chapter2 or chapter3 or chapterThomae etc
\begin{document}
\include{\jobname-chapter1}
\include{\jobname-chapterThomae}
\end{document}

将此代码复制到mwe.tex计算机的新目录中,并使用 进行编译pdflatex mwe.tex。然后您将看到以下错误消息(以及更多其他消息):

 (mwe-chapter1.tex
Chapter 1.
) [1



{C:/Users/User/AppData/Local/MiKTeX/2.9/pdftex/config/pdftex.map}]
\openout2 = `mwe-chapterThomae.aux'.

 (mwe-chapterThomae.tex

! LaTeX Error: Can be used only in preamble.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.5 \documentclass
                  {article}
Your command was ignored.
Type  I <command> <return>  to replace it with another command,
or  <return>  to continue without it.

错误消息! LaTeX Error: Can be used only in preamble.告诉您,您无法\documentclass{article像对那样调用文档的 tex 代码\include{\jobname-chapterThomae},因为此文件包含第二次命令调用\documentclass...

现在让我们重新编写上面给出的 MWE \documentclass,并在文件中删除 、\begin{document)和,并将调用和更正代码移到代码的正确前导中。请注意,文件现在以 开头:\end{document)\jobname-chapterThomae.textikz\jobname-chapterThomae.tex\begin{center}

\RequirePackage{filecontents}
\begin{filecontents}{\jobname-chapter1.tex}
\chapter{Chapter One}

Text for chapter one ...
\end{filecontents}

\begin{filecontents}{\jobname-chapterThomae.tex}
\begin{center}
    \begin{tikzpicture}[scale=8]
    \draw [-stealth] (-0.1,0) -- (1.1,0);
    \draw [-stealth] (0,-0.1) -- (0,0.6);
    \foreach \X in {1,...,7}
    {\ifnum\X=1
        \else
        \draw (0.02,1/\X) -- (-0.02,1/\X) node[left,xshift={(-(1+pow(-1,\X)))*3pt}]{$\frac{1}{\X}$};
        \fi
    }
    \foreach \X [evaluate=\X as \Ymax using {int(\X-1)}]in {95,94,...,2}%Το μέγεθος του πρώτου όρου καθορίζει το πλήθος των κουκκίδων, άρα και την απόσταση του «τριγώνου» από τον χ'χ.
    {\foreach \Y in {1,...,\Ymax}
        {\ifnum\X<6
            \draw (\Y/\X,0.02) -- (\Y/\X,-0.02) node[below,fill=white]{$\frac{\Y}{\X}$};
            \else
            \draw[ultra thin] (\Y/\X,0.01) -- (\Y/\X,-0.01);
            \fi
            \pgfmathtruncatemacro{\TST}{gcd(\X,\Y)}
            \ifnum\TST=1
            \fill ({\Y/\X},1/\X) circle(0.05pt); %??????? ?????????
            \fi
        }
    }
    \foreach \X in {0,1,...,80}
    {\fill (\X/80,0) circle(0.05pt); } %??????? ?????????
    \end{tikzpicture}
\end{center}
\end{filecontents}


\documentclass{book}

\usepackage{tikz} % <===================================================

\makeatletter% <========================================================
\pgfmathdeclarefunction*{gcd}{2}{%
  \begingroup
    \pgfmathcontinuelooptrue
    \pgfmath@xa=#1pt\relax % <-
    \pgfmath@xb=#2pt\relax % <-
    \ifdim\pgfmath@xa=0pt\relax
      \pgfmathcontinueloopfalse
      \pgfmath@xa=\pgfmath@xb
    \fi
    \ifdim\pgfmath@xb=0pt\relax
      \pgfmathcontinueloopfalse
      \pgfmath@xb=\pgfmath@xa
    \fi
    \ifdim\pgfmath@xa<0pt\relax
      \pgfmath@xa=-\pgfmath@xa
    \fi
    \ifdim\pgfmath@xb<0pt\relax
      \pgfmath@xb=-\pgfmath@xb
    \fi
    \loop
      \ifpgfmathcontinueloop
      \ifdim\pgfmath@xa=\pgfmath@xb
        \pgfmathcontinueloopfalse
      \else
        \ifdim\pgfmath@xa>\pgfmath@xb
          \advance\pgfmath@xa by-\pgfmath@xb\relax
        \else
          \advance\pgfmath@xb by-\pgfmath@xa\relax
        \fi
      \fi
    \repeat
    \pgfmathparse{int(\pgfmath@xa)}%
    \pgfmath@smuggleone\pgfmathresult
  \endgroup}
\makeatother % <========================================================

%\includeonly{\jobname-chapter1} % or chapter2 or chapter3 or chapterThomae etc
\begin{document}
\include{\jobname-chapter1}
\include{\jobname-chapterThomae}
\end{document}

现在它可以编译了,没有错误和两个警告(好的,由...引起filecontents!),结果如下:

生成的 pdf 没有错误

相关内容