# it it possible to compile a single tex file to pdf

I am now using \include to connect each single .tex as a whole book. Now I just want to compile one of the section of the book as a single pdf, is there any way to do this? I am already tried pandoc like this:

pandoc jenkins-kubernetes.tex --pdf-engine=xelatex -o jenkins.pdf


but the output of the pdf with a bad formats and did not support chinese words. is there any better way to archive this? I am reference the tex file like this:

\section{Chaos}

\input{chapter-2020-04/chaos/flutter/enterprise.tex}
\input{chapter-2020-04/chaos/http/self-sign-certificate.tex}
\input{chapter-2020-04/chaos/http/auto-update-certificate.tex}
\input{chapter-2020-04/chaos/http/cert-problem.tex}

• If the included files are one.tex, two.tex, three.tex, etc., and you include them via \incude{one}, \include{two}, etc., you can compile one or more of these, for example, using \includeonly{one,three}, \includeonly{two}, etc.
– Ivan
Apr 1, 2021 at 15:24

With the subfiles package you create subfiles for each chapter of the book an then compile every subfile independently, until is error free. Each subfile is self-sufficient: it will automatically use the preamble in the main file.

The debugging is much faster, because using \input or \include the errors messages many times point to the wrong line number. Also, it will not be necessary to compile it twice, since it is not necessary to generate a table of contents.

There are four possible cases to test how it works:

To begin put main.tex in a brand new directory. Create inside a subdirectory chapters and put chap1.tex and chap2.tex in there.

(1) Compile main.tex commenting both \subfile{./chapters/chap1} and \subfile{./chapters/chap2} from main.tex

It will generate main.pdf with the title, the TOC and the chapter "Introduction", as expected, after two compiles.

(2) Compile chap1.tex keeping commented \subfile{./chapters/chap1} and \subfile{./chapters/chap2} in main.tex

It will generate chap1.pdf in the chapters directory, using main.tex preamble. Get a similar result compiling chap2.tex

There will be no Title, TOC or Introduction, so it will be faster to compile. In the real life you use this capability to debug both files. The error messages will point to the right lines of the code.

(3) Run main.tex, now un-commenting \subfile{./chapters/chap1} and \subfile{./chapters/chap2}

It will run twice (because of the TOC) and will generate main.pdf in the root directory, complete with title page, table of contents and all the chapters.

(4 Delete files from the root directory except main.tex and compile chap1.tex.

It will run twice, as before, and will generate main.pdf in the root directory, complete with title page, table of contents and all the chapters, as in (3).

This is main.tex of a book prototype:

%% main.tex in its own directory

\documentclass[12pt,a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{graphicx}
\usepackage[left=2.00cm, right=2.00cm, top=2.00cm, bottom=2.00cm]{geometry}

\usepackage{kantlipsum} % dummy text

\author{The Author}
\title{The BooK Title}
\begin{document}

\maketitle

\tableofcontents

\chapter*{Introduction}
0. \kant[1-6]

\subfile{./chapters/chap1}  % chapter #1 file in  root/chapters directory

\subfile{./chapters/chap2} %chapter #2 file in  root/chapters directory

\end{document}


This is the chap1.tex file

 %% chap1.tex in "chapters" directory  will compile using main.tex preamble

\documentclass[../main.tex]{subfiles}

\begin{document}
\chapter{One}
1. \kant[2-7]

\end{document}


and this the chap2.tex file

%% chap2.tex in "chapters" directory  will compile using main.tex preamble

\documentclass[../main.tex]{subfiles}

\begin{document}
\chapter{Two}
2. \kant[7-8]
\end{document