# Split a document into several files: Missing \begin{document}

I'm wanting to split a document into several files as follows and as shows the attached picture:

main file main.tex is in principal folder.

In each chapter file I input 2 files namely header.tex and structure.tex

So for example, in chap1_langFormels.tex file, I have the following file organization:

\input{../header}

\chapter{Introduction}

text

\chapter{Languages}

text

\end{document}


Here is header.tex source code:

\documentclass[11pt]{book}
\input{../structure}
%\usepackage[paperwidth=16cm, paperheight=24cm]{geometry}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}

%\usepackage{qtree}
\usepackage[activate={true,nocompatibility},final,tracking=true,kerning=true,spacing=true,factor=1100,stretch=10,shrink=10]{microtype}
\usepackage{multicol}

\usepackage{makecell}
\usepackage{tabularx}
\usepackage{listings}
\usepackage{ragged2e}
\newcolumntype{R}{>{\RaggedLeft}X}

\usepackage{xcolor}
%\usepackage{hyperref}

\newcolumntype{L}[1]{>{\RaggedRight}X} % new

\definecolor{light-gray}{gray}{0.9}
\newcommand{\code}[1]{\colorbox{light-gray}{\texttt{#1}}}
\DeclareMathAlphabet\mathsf{OT1}{lcmss}{m}{n}

\setlength{\unitlength}{1cm}    %% Unité

\hypersetup{pdftitle={Title},pdfauthor={Author}} % Uncomment and fill out to include PDF metadata for the author and title of the book

\begin{document}

\newpage
~\vfill

\pagestyle{empty} % Disable headers and footers for the following pages

\tableofcontents

\cleardoublepage % Forces the first chapter to start on an odd page so it's on the right side of the book

\pagestyle{fancy} % Enable headers and footers again


Structure.tex file code is here.

I'm having the following error message:

pdflatex chap1_langFormels.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017/Debian) (preloaded format=pdflatex)
restricted \write18 enabled.
entering extended mode
(./chap1_langFormels.tex
LaTeX2e <2017-04-15>
Babel <3.18> and hyphenation patterns for 84 language(s) loaded.

! LaTeX Error: Missing \begin{document}.

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

l.16 \usepackage
{multicol}
?


The entire chap1_langFormels.log file content is here.

Same problem happens for /principal/main.tex file. Thank you for any help.

Edit

I have just tried the following: in chap1_langFormels.tex file when I comment the line inputing structure.tex, there is no longer error. The compilation goes fine. When I uncomment this same line structure.tex in chap1_langFormels.tex file, I get the same error message Missing \begin{document}and showing the same \usepackage{multicol} line as previous. After that I copied the content of header.tex and structure.tex directly into chap1_langFormels.tex to have only one file. After compilation, I got the same error message Missing \begin{document} and showing the same \usepackage{multicol} line as previous. So it look like if this line \usepackage{multicol} in header.tex is in conflict with something in structure.tex.

• the log you show does not match the input you show, it shows chap1_langFormels.tex being onput and then (without any more files being input) \usepackage being seen on line 16. Jan 28 at 8:45
• @DavidCarlisle I have edited the question to add the full log output. Jan 28 at 9:18
• I don't in general follow external links, I did that time but that is still a truncated file and does not show the error at all, try to cut down your example remove all packages not needed to show the problem, then show the log (or at least theterminal outout) in teh question, the log currently showing in the question is not helping anyone answer. Jan 28 at 9:23
• \usepackage {multicol} being seen on line 16 is line 16 of header.tex file Jan 28 at 9:34
• sorry we try to help but we need some clues. multicol is not on line 16 of the file shown here, the log file shown here does not show header.tex being included and the log file at the external link shows header.tex being included but is incomplete and shows no error. Jan 28 at 9:39

Taking your structure.tex and deleting lines while keeping the error produces a more reasonable test document

\documentclass[11pt]{book}

\usepackage{microtype} % Slightly tweak font spacing for aesthetics

\usepackage[activate={true,nocompatibility},final,tracking=true,kerning=true,spacing=true,factor=1100,stretch=10,shrink=10]{microtype}
\usepackage{multicol}

\begin{document}

\end{document}


The second call to microtype generates the error (showing whatever is on the following line, that happens to be multicol here) That looks like a bug in microtype but as you can not load a package twice, just deleting the second call would also work.

The terminal output that matches this test file is

L3 programming layer <2022-01-21>
(/usr/local/texlive/2021/texmf-dist/tex/latex/base/book.cls
Document Class: book 2021/10/04 v1.4n Standard LaTeX document class
(/usr/local/texlive/2021/texmf-dist/tex/latex/base/bk11.clo))
(/usr/local/texlive/2021/texmf-dist/tex/latex/microtype/microtype.sty
(/usr/local/texlive/2021/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/local/texlive/2021/texmf-dist/tex/latex/etoolbox/etoolbox.sty)
(/usr/local/texlive/2021/texmf-dist/tex/latex/microtype/microtype-pdftex.def)
(/usr/local/texlive/2021/texmf-dist/tex/latex/microtype/microtype.cfg))

! LaTeX Error: Missing \begin{document}.

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

l.10 \usepackage
{multicol}
?


Actually the microtypepackage isn't at fault here that combination on a second call to the package (which should give an option clash error) gives a missing begin document error with any package. Investigating...

\documentclass[11pt]{book}

\usepackage{indentfirst} % Slightly tweak font spacing for aesthetics

%\tracingall
\usepackage[activate={}]{indentfirst}

\begin{document}

\end{document}

• same here (probably should have reported it back then...) Jan 28 at 14:41
• @Robert ah thanks, Joseph and I are looking, not sure if we can change the option handler here or at least document this, Jan 28 at 14:49
• Thank you @DavidCarlisle for your assistance. Since your first answer I applied your proposition and a new error pop out. So I was trying to get rid of that error in vain. The code has evolve. I have had certain packages twice. Should I open a new discussion to post the new code of my 3 files? Jan 28 at 15:09
• @cProg feel free to ask a new question but please (as in the answers here) try to make more reasponable test files, it would not have taken you long to do as I did before posting, delete everything that you could delete while still making the error so ending up with a simple one-file test file of a few lines. You did not need three files here. Jan 28 at 15:18