| 1 |
% !TEX root = texblend-doc.tex |
| 2 |
% !TEX TS-program = lualatex |
| 3 |
|
| 4 |
\section{Introduction} |
| 5 |
This tool compiles individual files that are included as parts of larger documents. |
| 6 |
It utilizes the preamble of the main document but disregards all other included files. |
| 7 |
|
| 8 |
The main purpose is to allow fast compilation of particular chapters or sections, |
| 9 |
eliminating the need to recompile the entire document. |
| 10 |
This facilitates an efficient way to check for formatting or syntax errors in |
| 11 |
the particular part of the document being worked on. |
| 12 |
|
| 13 |
\section{Structure of \TeX\ Files} |
| 14 |
|
| 15 |
The basic usage is as follows: consider a main document that includes files for |
| 16 |
individual chapters, named for example \texttt{main.tex}: |
| 17 |
|
| 18 |
|
| 19 |
\begin{verbatim} |
| 20 |
\documentclass{article} |
| 21 |
\author{John Doe} |
| 22 |
\title{Sample Document} |
| 23 |
\usepackage{upquote} |
| 24 |
\usepackage{microtype} |
| 25 |
\usepackage{hyperref} |
| 26 |
\begin{document} |
| 27 |
\maketitle |
| 28 |
\tableofcontents |
| 29 |
\input{intro} |
| 30 |
\input{usage} |
| 31 |
\end{document} |
| 32 |
\end{verbatim} |
| 33 |
|
| 34 |
We can compile this document to obtain a PDF file containing the text of all |
| 35 |
chapters. However, by using \TeX Blend, we can generate separate PDFs for each |
| 36 |
chapter. The advantage is that all commands defined in the packages used in the |
| 37 |
main document will be available. |
| 38 |
|
| 39 |
In the included files, we can use special directives that indicate the main |
| 40 |
file and the engine to be used for compilation. Similar directives are employed |
| 41 |
by various \TeX\ editors, such as \TeX Shop or \TeX Works. |
| 42 |
|
| 43 |
For instance, a file like \texttt{intro.tex}, which is included in the main document, |
| 44 |
might look like this: |
| 45 |
|
| 46 |
\begin{verbatim} |
| 47 |
% !TEX root = main.tex |
| 48 |
% !TEX TS-program = lualatex |
| 49 |
|
| 50 |
\section{Introduction} |
| 51 |
This tool compiles individual files that are included |
| 52 |
as parts of larger documents. |
| 53 |
\end{verbatim} |
| 54 |
|
| 55 |
Notice the comments at the beginning of the file. These are |
| 56 |
directives, indicating the main document and the engine to be used for |
| 57 |
compilation. Many \TeX\ editors support these directives, and we utilize them in |
| 58 |
\TeX Blend to effectively control the compilation process too. |
| 59 |
|
| 60 |
These directives follow a specific format, requiring placement at the beginning |
| 61 |
of the file and commencing with a percentage sign. Subsequently, there is a |
| 62 |
space followed by either the marker \texttt{!TEX} or \texttt{!TeX}, |
| 63 |
both of which are recognized formats. |
| 64 |
The next element is the property name with an optional \texttt{TS-} prefix |
| 65 |
(in line with the TeX Shop editor), followed by an equals sign and, finally, the |
| 66 |
value. |
| 67 |
|
| 68 |
Two crucial properties are \texttt{root}, indicating the name of the main file, and |
| 69 |
\texttt{program}, through which we can select the program for compiling the document. |
| 70 |
However, it is possible to specify additional properties, which can then be |
| 71 |
utilized in template documents. |
| 72 |
|
| 73 |
\subsection{Placement of the Main Document and Templates} |
| 74 |
\label{sec:placement} |
| 75 |
|
| 76 |
You can specify the full path to the main document in the \verb|root| property. |
| 77 |
\TeX Blend can also be used to compile documents using a universal template. |
| 78 |
The path to this template can be specified in full or can leverage the directory |
| 79 |
structure of TeX by placing it in a directory recognized by the KPSE library. |
| 80 |
This directory is typically designated for user packages, commonly found at |
| 81 |
\verb|~/texmf/tex/latex|, although it may vary on different systems. |
| 82 |
You can identify its location on your system using the command: |
| 83 |
|
| 84 |
\begin{verbatim} |
| 85 |
$ kpsewhich --var-value TEXMFHOME |
| 86 |
\end{verbatim} |
| 87 |
|
| 88 |
This command typically outputs a path similar to this: \texttt{/home/username/texmf}. |
| 89 |
If this directory does not exist, create it. Further, within this directory, |
| 90 |
create the subdirectories \texttt{tex/latex/templates}: |
| 91 |
|
| 92 |
\begin{verbatim} |
| 93 |
$ mkdir -p ~/texmf/tex/latex/templates |
| 94 |
\end{verbatim} |
| 95 |
|
| 96 |
You can then place your templates in this directory. |
| 97 |
To test the availability of the template, run the following command: |
| 98 |
|
| 99 |
\begin{verbatim} |
| 100 |
$ kpsewhich templatename.tex |
| 101 |
\end{verbatim} |
| 102 |
|
| 103 |
It should print path of the template document. |
| 104 |
|
| 105 |
\subsection{Custom Variables in Templates}\label{sec:variables} |
| 106 |
|
| 107 |
As templates are intended to be universal across various projects, it is |
| 108 |
possible to incorporate variables into them. These variables can be populated |
| 109 |
from properties in the directives, such as the document title. |
| 110 |
|
| 111 |
To include variables for expansion in the template, you can use the notation |
| 112 |
\verb|{{variableName}}|. For example, to set the document title, you can use |
| 113 |
\texttt{\textbackslash title\{\{\{title\}\}\}}. The double curly braces around |
| 114 |
the variable will be replaced with its value, while the third pair of curly braces will remain in the |
| 115 |
document. |
| 116 |
|
| 117 |
Say that you have a following template saved in \url{~/texmf/tex/latex/templates/mytemplate.tex}: |
| 118 |
|
| 119 |
\begin{verbatim} |
| 120 |
\documentclass{article} |
| 121 |
\title{{{title}}} |
| 122 |
\author{Michal} |
| 123 |
\usepackage{microtype} |
| 124 |
\begin{document} |
| 125 |
\end{document} |
| 126 |
\end{verbatim} |
| 127 |
|
| 128 |
|
| 129 |
A document that utilizes this template may look like the following: |
| 130 |
|
| 131 |
\begin{verbatim} |
| 132 |
% !TEX root = mytemplate.tex |
| 133 |
% !TEX title = hello world |
| 134 |
\maketitle |
| 135 |
\end{verbatim} |
| 136 |
|
| 137 |
|
| 138 |
This produces a following document with variables expanded: |
| 139 |
|
| 140 |
\begin{verbatim} |
| 141 |
\documentclass{article} |
| 142 |
\title{hello world} |
| 143 |
\author{Michal} |
| 144 |
\usepackage{microtype} |
| 145 |
\begin{document} |
| 146 |
% !TEX root = mytemplate.tex |
| 147 |
% !TEX title = hello world |
| 148 |
\maketitle |
| 149 |
\end{document} |
| 150 |
\end{verbatim} |
| 151 |
|
| 152 |
You can require expansion of variables using the \verb|--expand| command line option. |
| 153 |
|