Ceci est une ancienne révision du document !
Let’s take a look at what we have covered so far in this series about Latex (see table below).
There are seventeen pieces of information about using Latex. (This one makes eighteen.) Assume we want to put all of them together to make a small book, a quick introduction to some of the major features of Latex. At two or three pages each, we should generate a PDF of about fifty to sixty pages. This is a task that Latex is much better at than word processors. I have written a few books using word processors. I wish I had known Latex at the time. If you wish to write several chapters, there are two obvious ways to do that in a word processor. The first is to put all of your work in one large file. That gets very unwieldy to navigate and will get painfully slow to edit, especially if your work includes anything other than text. Any graphics or tables will slow down editing work.
The second way is to put each chapter or each section in its own file. If you do that, keeping page numbering consistent and correct is a major chore. If you use Styles in a word processor (which you should), keeping the styles consistent from chapter to chapter can be painful. I know the major word processors have something like a “master document” that will pull all the individual files together. My experience is the master document method combines the weaknesses of both of the above methods, without generating any significant benefits. If you write a text and require references, endnotes, etc., these are difficult to manage with word processors' master files.
Latex uses what is a master document approach. Unlike word processors it works. You will learn how it works if you follow along with what I do this time.
Obviously what I do in this article will not generate a fifty page PDF. However I hope you will learn the techniques needed to build multiple chapter (section) output using Latex.
To start with, we will need at least some of the eighteen articles from the previous issues. What is needed is each article in plain text, in an ASCII file which is what tex files are. Since some of the articles include graphics, it would be best to have each article in its own folder. The “root” file will be called latexbk.tex, and will sit in a folder that also contains eighteen sub-folders: fcm167, fcm168, etc. In the folder for each issue will be a file called fcm###.tex plus any graphics that are part of that issue (next page, top right for the code).
… and so on, for all seventeen of the articles that Eric and I have written. Of course we expect to write more about Latex in the future. Whatever method used to put all of the code from the seventeen articles into one document needs to accept a monthly addition. As it turns out, Latex makes combining “chapters” into a “book” a very simple job.
Note I have copied only the Latex document code from these two articles. I did that to keep this article a reasonable size. Any tex file or any plain text file that can be converted to a tex file can easily be included in a larger document. There are two tasks we need to do to generate a large document from several small ones, while still maintaining the small ones as independent files. The first step is to make a “master” file. The second is to remove all the elements from the individual files that make them independent files. Neither task is difficult. However the second step will be repetitious since it has to be done on every small file.
The master file contains the overall instructions for the book. It has everything from \documentclass[]{} down to \begindocument{} and it also has the \enddocument{} code.
\documentclass[a4paper]{article} \title{Your First Book} \author{Your Name} \begin{document} … \end{document}
When we are finished, it will also contain all of the \usepackage instructions in all of your small files. Simply copy and paste any \usepackage instructions to the master file before commenting them. The top of your master document might look like this when you are finished.
\documentclass[letterpaper,11pt]{book} %preamble (this is a comment) \usepackage[utf8]{inputenc} \author{Your Name} (optional) \title{Your Title} (optional) \date{January 2022} (optional) \usepackage{graphicx, geometry, amsfonts, fancyhdr, xcolor, setspace, hyperref, cite, enumerate} \begin{document} \frontmatter (optional) \maketitle (No title? Remove this code) \tableofcontents (No table of contents - remove) \mainmatter (optional)
Note: If you are going to copy and paste this code into your Latex IDE, remove the items in parentheses (round brackets) or comment out all lines that have parentheses or there will be errors when compiling.
A series of “include” statements replace the text which would appear in any regular Tex document.
\include{fcm167}
No need to use the tex file extension. Latex will assume the file is a tex file type. If you have compiled the small documents individually, you may have already put the tex file and all of its compiled parts (aux, log, out, pdf, etc.) into separate folders. Simply put the name of the subfolder into the include statement:
\include{fcm167/fcm167}
Add as many include statements as needed so your book is complete. If you need any “back matter“ for your book then put those instructions after the last include statement. Then close the file.
\backmatter % bibliography, glossary and index would go here. \include{appendix} \bibliography{bibliography} \end{document}
If you compile your book now you will get at least one major error. It will stop the compilation until you correct it. This is the second step, the step that is repetitive since it has to be done in every small file. You have to make sure any instructions that are in the master file do not compile or do not appear in the small files. You have two choices. You can remove the duplicates or you can comment them out. I strongly suggest the second – comment out the instructions that are no longer needed. That will allow you to compile the small files individually without having to remember what is needed to make them complete Latex files again.
Remember to copy and paste any usepackage[]{} statements from the small files into the master file before you make them comments. You can see a line of packages in the sample document.
\usepackage{graphicx, geometry, amsfonts, fancyhdr, xcolor, setspace, hyperref, cite, enumerate}
These packages are not needed in every small file but at least one of the small documents requires one (or more) of these packages. If all of them are not included in a usepackage instruction the final book will not look as it should.
Now your small documents will start with any chapter or section title and possibly a label so you can use cross references from one or more of the other small files in the book.
\chapter{Chapter 1}\label{chap01}
If you are writing fiction, you probably do not need the label instruction since it is unlikely you are going to have cross references. In non-fiction, cross references are often used to link one part of a document to another part.
The sample code for the master file with the Tex code from FCM-167 and FCM-168 generates a six-page PDF. The first page is the title, then a blank page so the Table of Contents can start on a right-hand page. (I used documentclass = book.) Then there is another blank page so the contents can start on a right-hand page. The one line of text from FCM-167 is on physical page 5 (page 1 in the book) and the text from FCM-168 is on physical page 6.
If I change the documentclass to article, both the frontmatter and mainmatter instructions have to be removed or commented. Once that is done, the article compiles to three pages. The title and Table of Contents appear on page 1, the text from FCM-167 on page 2, and FCM-168 on page 3. (Find out what happens if you leave frontmatter and mainmatter commented and change to documentclass = book.)
Here is the Table of Contents for a more complete set of includes from other Latex articles.
That is it for this issue. Keep working with Latex and your favourite IDE, or try another IDE.