LaTeX Boilerplate is for those starting a project or more experienced users who want an organized structure to their documents. All code (e.g. \newcommand, pgfkeys) and packages included are commented. The boilerplate contains examples for common tasks: figures, tables, BibTeX, index, new commands (including some using pgfkeys), and more.
A GitHub repository can be found at: LaTeX Boilerplate. I briefly explain the layout; installation and usage can be found in the repository readme.
For those who want to dive right in, the git repository (includes a readme):
LaTeX_Boilerplate
Intro
Creating a LaTeX project from scratch can be a headache, a lot of time is wasted figuring out the basic code and styles LaTeX needs to happily typeset your document. Also, unifying formatting for chapters, figures, etc. is not obvious to the beginner. In addition, large projects can become unwieldy and bogged down when the entire text is located in one file. And making sure that when you add or remove citations things don't go haywire can be a pain if not done properly.
Luckily, LaTeX includes solutions to all of these problems: functions to standardized common formatting, an include feature to manage sections sensibly, BibTeX for citation management, and other useful features. I have compiled a skeleton LaTeX project (a boilerplate) that allows the beginner (or even more advance user) to start a project quickly and with the proper groundwork. HTML5 Boilerplate is a great example of this sort of thing.
The ever useful pandoc should be downloaded. I included some batch files that can be used to convert common file formats into something a LaTeX compiler can read, e.g. you might want to take HTML files and turned them into LaTeX, as I do with my short stories. Bash scripts are forthcoming.
Main
The main project file is laid out to include packages, header/footer, and new commands first. This is followed by changing the font size to an appropriate amount (I use 12pt text with 15pt line spacing, see The Elements of Typographic Style). The title page is included along with thanks and a table of contents. The different sections, chapters, figures, and tables are included in separate .tex files to make project management easier.
References (bibtex) and index (makeidx) are included last under the appendix. Examples for their usage are sprinkled throughout the example figures and chapters.
Building the project has been made independent of specific editors by including batch (build.bat) and bash (build.sh) scripts to automatically build and clean-up the directory afterwards (e.g. removing .aux files), assuming you install some LaTeX distribution with pdflatex, xelatex, makeidx and bibtex that are included in the system PATH and callable via the command line.
- %_______PREAMBLE_______
- %Include packages
- %Include packages
- %Get macro commands
- %Meta information to put in PDF
- \hypersetup{pdfauthor={Author},pdftitle={Title},pdfsubject={Space},pdfkeywords={Space}}
- %_______DOCUMENT_______
- \begin{document}
- %Change font size and line spacing
- %12pt font with 15pt spacing default
- \fontsize{12}{15}\leading{15pt}
- %_______TITLE_______
- \begin{titlepage}
- \lbptitle{Title}{Subtitle}{Author}{}
- \end{titlepage}
- \pagenumbering{roman}
- %_______MISC_______
- %Copyright and Thanks
- %_______TABLE_OF_CONTENTS_______
- %Change to 1,2,3...
- \pagenumbering{arabic}
- %_______MAIN_TEXT_______
- %Part of book
- \lbppart{Part I}{Subtitle}
- %Include section page
- %Include introduction
- \include{chapters/chapter2}
- %The end section page
- \lbpendsection{End of Preview}{We've only just begun\dots}
- %_______APPENDIX_______
- %Input will insert to code directly, no new page
- \input{chapters/figures}
- %_______BIBLIOGRAPHY_______
- %_______INDEX_______
- %_______
- \end{document}
BibTeX
One main advantage of LaTeX over Word or other processors is the bibliography feature. Using a plain-text file, one can add and comment all their references for a particular project. Because the default setting for bibtex is to include only references you actually cite, this allows you to build a library of references that you can call upon for different projects and not have to worry about improper citations.
The default style in the project is to number, subscript, and order (e.g. when you have multiple citations, will appears as 1-3,10 instead of 10,1,3,2) the citations. This style can easily be changed by altering \usepackage[numbers,super,sort&compress]{natbib} in \common\packages.tex.
An example entry is seen below, most bibtex citations can be automatically obtained from the web on a publication's website or on search engines like Google Scholar or Pubmed (using TeXMed).
More information cab be found at BibTeX.
- Lorem impsum \citep{Febre:2005}
- @book{Febre:2005,
- author = {Alain Fabre},
- title = {Diccionario etnolingüístico y guía bibliográfica de los pueblos indígenas sudamericanos},
- publisher = {Geoprojects},
- volume = {},
- number = {},
- series = {},
- address = {Beirut, Lebanon},
- edition = {},
- year = {2005},
- month = {},
- isbn = {},
- note = {\url{butler.cc.tut.fi/~fabre/BookInternetVersio/Dic=Tupi.pdf}},
- }
Index
The index feature allows the easiest way to track particular words or concepts the reader might want to find throughout the text. It is automatically alphabetized and the index itself can be customized by renewing the environment (example included in \common\codes.tex).
I created the command \lbpindex{}{} to allow a standard input for all indexed words and concepts so if the package or layout changes, I don't have to change every command throughout a project. Subentries can be created using \index{entry!subentry}. More information can be found at LaTeX indexing with an example index found at the end of project.pdf in the git repository.
- \clearpage
- \addcontentsline{toc}{chapter}{Index}
- \printindex
- Lorem ipsum \index{Lorem ipsum}{} dolor sit...
- We start with the Algonquin and then discuss the \lbpindex{Cahokia}{}...
Functions
Next, pgfkeys is used together with \newcommand to help get around the nine argument limit of \newcommand. This allows us to make standard formatting for a multi-figure panel, as seen below.
This is accomplished by loading a set of keys (see \pgfkeys) that map input variables in the \multifig[var=something] command to variables \newcommand can use (e.g. \figvar).
- %Example of multi-panel figure
- \multifig[
- label=11,
- capTitle=Early native American staples,
- capDes={(a) Pueblo bonito was an.... (b) Located in Peru. (c) The different type of game hunted in the Americas. (d) The cenote, which were seen as sacred by the Maya.}
- ]{fig}{images/pueblobonito.jpg}{fig}{images/chavin.jpg}{fig}{images/nagame.jpg}{fig}{images/cenote.jpg}
- %_______Multi_Panel_Figure_______
- %Keys loaded when pgfkeys is called
- \pgfkeys{
- %Call with \pgfkeys{/family, #1}
- %Define a family directory to avoid name-clashes
- /multifig/.is family, /multifig,
- %key/.estore in = \newVariable
- label/.estore in = \mfigLabel,
- capTitle/.estore in = \mfigCapTitle,
- capDes/.estore in = \mfigCapDesc,
- }
- %Create a new figure command
- %command looks like \multifig[key=val,...]{panelTitle}{imageLocation}..
- %example:
- %First arg ([key=val,...]) passed to pgfkeys, get new variables back, circumvent the 9 argument rule for \newcommand
- \pgfkeys{/multifig, #1}
- \begin{figure*}[ht!]
- \begin{center}
- \subfloat[#2]{\includegraphics[width=3.0in]{#3}}
- \subfloat[#4]{\includegraphics[width=3.0in]{#5}} \\
- \subfloat[#6]{\includegraphics[width=3.0in]{#7}}
- \subfloat[#8]{\includegraphics[width=3.0in]{#9}}
- \captionsetup{labelformat=empty}
- \label{fig:\mfigLabel}
- \end{center}
- \end{figure*}
- }
Conclusion
The main thrust for the project was to provide myself an evolving standard for LaTeX documents, as starting from scratch or trying to remember which project had the most up-to-date working skeleton was inefficient. However, sharing the project will hopefully allow others to gain use from it and induce me to keep it updated and well organized. In the future, I plan to flesh out the project to include more working examples and clean-up the code to make it more consistent and better commented. As the project evolves, I'll post more.