3

I am writing a book and I split it in to several files using \include{} and \includeonly{} commands. The chapter "chapterThomae" has the Thomae's function from here.

If I use the \includeonly{} command (like the code below) everything is OK. No one chapter has any problem.

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

If I disable \includeonly{} command (to have the whole book - see the code below) I get this error report.

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

Also the pdf-view (and the pdf file) is deleted.

pdfview display

I think something goes wrong with the chapter that includes Thomae's function. If I disable this chapter (like the code below) everything is OK again.

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

What is the problem? How can I fix it?

PS: I am sorry if the title is not correct. I cannot even imagine what is the problem, so I couldn't find a proper title.

perror
  • 754
  • 1
  • 8
  • 21
  • 2
    there are no errors in the log file that you show. Ther eis a warning from fanchdr that you need to increase \headheight and a warning that you are typesetting some text in cmr that does not have the characters but no errors – David Carlisle Jul 18 '19 at 19:37
  • @DavidCarlisle , something goes wrong, because the pdf-view and the pdf-file deleted when I disable \includeonly{} command (see the edited post). – Kώστας Κούδας Jul 18 '19 at 19:52
  • 1
    Add the used code for hapterThomae.tex in your question. In your linked version there is for example an \end{document} included, that would cause an error ... – Mensch Jul 18 '19 at 19:59
  • This (https://pastebin.com/jdSfBFbN) is the code of the Thomae's function in chapterThomae. But, as I said, alone the chapterThomae has no problems. I can compile it alone without problems. Also, if I delete only the code of the Thomae's function (not all the chapter) I have no problems. I have problems only if I include all chapters and the Thomae's function code. – Kώστας Κούδας Jul 18 '19 at 20:42

1 Answers1

3

There is a missunderstanding here: You can not have two commands \documentclass{} in one TeX document.

Please see the following MWE I created from your given codes (package filecontents is only used to have three tex code in one MWE; this is only for testing purpose here, you can use your original codes of course):

\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}

Copy this code to mwe.tex in a new directory of your computer and compile it with pdflatex mwe.tex. Then you will see the following error messages (and others more):

 (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.

The error message ! LaTeX Error: Can be used only in preamble. tells you that you can not call \documentclass{article in your tex code for the document as you did with \include{\jobname-chapterThomae}, because this file contains that second call of command \documentclass ...

Now let us rework the given MWE above and delete \documentclass, \begin{document) and \end{document) in your file \jobname-chapterThomae.tex and move the call for tikz and the correcting code into the correct preamble of your code. Please see that file \jobname-chapterThomae.tex starts now with \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}

Now it compiles without errors and two warnings (okay, resulting from filecontents!) to the following result:

resulting pdf with no errors

Mensch
  • 65,388
  • sorry... I misunderstood your question. I thought that you wanted Thomae' function in a version that could be compiled. This is the chapterThomae (https://pastebin.com/60vawsn2). I would like to mention that this version (only chapterThomae https://pastebin.com/DU8drNdt) of main book and this (chapterLight with chapterThomae https://pastebin.com/stUqf4Eh) can compile. Those (whole book https://pastebin.com/uqhqqdZL and chapterNormal with chapterThomae https://pastebin.com/NK6qvsm0) have the problem. – Kώστας Κούδας Jul 19 '19 at 18:15
  • @KώσταςΚούδας Well, then please take my given mwe as an example and create based on my mwe an new mwe resulting in your error. That means we need to see the code of that part of your book causing the error. And please show us the english error message you got in your log file (an greek error message does not help me, I can not speak greek). – Mensch Jul 19 '19 at 18:32
  • thanks for your answer! The error message is this (https://pastebin.com/QZSQ7xiN). I include it in the question. The image was only to show that I truly have problem. I thought that your mwe was solving an other problem (including two commands \documentclass{} in one TeX document). I 'll try it in a few minutes (I 'm not in my pc now). – Kώστας Κούδας Jul 19 '19 at 18:57
  • 1
    @KώσταςΚούδας Sorry, but your linked log file is not complete and does not contain any error message as I can see, only several warnings. Please believe me, we need an complete, compilable tex code resulting in your errors. Only then we have not to guess what you are doing and can play with it on our own computers to find the culprit ... And please name the errors you got, show us only the complete error message in your question! – Mensch Jul 19 '19 at 19:13
  • I 'm sorry. I can't specify yet what is the problem to make a mwe for this. I 'll try again tomorrow. Thank's for your patience... – Kώστας Κούδας Jul 19 '19 at 22:29
  • 1
    @KώσταςΚούδας Do you have any news for us? – Mensch Jul 24 '19 at 15:38
  • I have done for many hours (until right now!!!) anything I could, and I couldn't manage to define the problem. So I decided to give it up for a while, as I have limited time, to write this book. So I have deleted Thomae's function and everything seems OK now. Thanks for your help!!! – Kώστας Κούδας Jul 25 '19 at 08:21