• Home   /  
  • Archive by category "1"

Backmatter Bibliography Latex

In large projects, such as books, keeping parts of your document in several .tex files makes the task of correcting errors and making further changes easier. It's simpler to locate a specific word or element in a short file. For this purpose this article explains how to manage big projects.

[edit]Introduction

Below is an example of a book whose sections and user-defined commands are stored in separate files.

As you see, the example is a book with three chapters and several sections in a neat main file that pulls external files to generate the final document. The command in the book document class is used for the first pages of the document, the page numbering style is set to Roman numerals by this command; the command resets the page numbering and changes the style to Arabic, disables the chapter numbering (suitable for the bibliography and appendices).

In the subsequent sections each part will be more clearly explained.

  Open an example of the import package in ShareLaTeX

[edit]Preamble in a separate file

If the preamble of your document has many user-defined commands or term definitions for the glossary, you can put it in a separate file. The right way is to create a file with the .sty extension. Let's see an example:

All the commands in this file could have been put in the preamble, but the main file would have become confusing because of this large amount of code, and to locate the actual body of the document in such large file would be a cumbersome task.

This file could also be put in a normal .tex file and imported with the command (see the next section), but a .sty file prevents possible errors if the file is accidentally imported more than once.

Notice that the first line of the example is


this means that we have to import this package as example in the main file, i.e. with the command


as shown in the introduction.

Note: A .sty file is far more flexible, it can be used to define your own macros and optional parameters can be passed, see Writing your own package.

  Open an example of the import package in ShareLaTeX

[edit]Importing files

The standard tool to insert a latex file into another are and (see below), but these are prone to errors if nested file importing is needed. For this reason the recommended option is the package import.

First, add this line to the preamble of your document:


Then use . The first parameter inside braces is the directory where the file is located, it can be relative to the current working directory or absolute. The second parameter is the name of the file to be imported

There is also available the command that has the same syntax, but if used in one of the files that are imported in the main file, the path will be relative to that sub-file. For instance, below is the contents of the file "section1-1.tex" that was imported in the previous example:

As you see, this file imports a pgf plot file called "plot1.tex" that creates a 3d plot. This file is imported by

from the "img" folder, contained in the folder "sections".


If were used instead, the path img/ would be relative to the main file, instead of the folder "sections" where "section1-1.tex" is saved.

  Open an example of the import package in ShareLaTeX

[edit]Inputting and including files

Short description of the commands input and include.

command

Use this command in the document body to insert the contents of another file named . LaTeX won't start a new page before processing the material in . allows you to nest commands, in files that are already being inputted by the root file.

command

Use this command in the document body to insert the contents of another file named . LaTeX will start a new page before processing the material input from . Make sure not to include the extension in the filename, as this will stop the file from being input (the extension can optionally be included with and ). It is not possible to nest commands.

  Open an example of the import package in ShareLaTeX

[edit]Further reading

For more information see:

\documentclass[a4paper,11pt]{book}\usepackage{import}\usepackage{example}   \usepackage{makeidx}\makeindex   \begin{document}   \frontmatter\import{./}{title.tex}   \clearpage\thispagestyle{empty}   \tableofcontents   \mainmatter\chapter{First chapter}\import{sections/}{section1-1.tex}\import{sections/}{section1-2.tex}   \chapter{Additional chapter}\import{sections/}{section2-1.tex}   \chapter{Last chapter}\import{sections/}{section3-1.tex}   \backmatter   \import{./}{bibliography.tex}   \end{document}
\ProvidesPackage{example}   \usepackage{amsmath}\usepackage{amsfonts}\usepackage{amssymb}\usepackage[latin1]{inputenc}\usepackage[spanish, english]{babel}\usepackage{graphicx}\usepackage{blindtext}\usepackage{textcomp}\usepackage{pgfplots}   \pgfplotsset{width=10cm,compat=1.9}   %Header styles\usepackage{fancyhdr}\setlength{\headheight}{15pt}\pagestyle{fancy}\renewcommand{\chaptermark}[1]{\markboth{#1}{}}\renewcommand{\sectionmark}[1]{\markright{#1}{}}\fancyhf{}\fancyhead[LE,RO]{\thepage}\fancyhead[RE]{\textbf{\textit{\nouppercase{\leftmark}}}}\fancyhead[LO]{\textbf{\textit{\nouppercase{\rightmark}}}}\fancypagestyle{plain}{%\fancyhf{}% remove everything\renewcommand{\headrulewidth}{0pt}% remove lines as well\renewcommand{\footrulewidth}{0pt}}   %makes available the commands \proof, \qedsymbol and \theoremstyle\usepackage{amsthm}   %Ruler\newcommand{\HRule}{\rule{\linewidth}{0.5mm}}   %Lemma definition and lemma counter\newtheorem{lemma}{Lemma}[section]   %Definition counter\theoremstyle{definition}\newtheorem{definition}{Definition}[section]   %Corolary counter\newtheorem{corolary}{Corolary}[section]   %Commands for naturals, integers, topology, hull, Ball, Disc, Dimension, boundary and a few more\newcommand{\E}{{\mathcal{E}}}\newcommand{\F}{{\mathcal{F}}} ...   %Example environment\theoremstyle{remark}\newtheorem{examle}{Example}   %Example counter\newcommand{\reiniciar}{\setcounter{example}{0}}
\chapter{First chapter}\import{sections/}{section1-1.tex}\import{sections/}{section1-2.tex}
\section{First section}   Below is a simple 3d plot   \begin{figure}[h]\centering\subimport{img/}{plot1.tex}\caption{Caption}\label{fig:my_label}\end{figure}   [...]
\subimport{img/}{plot1.tex}

Introduction

I used LaTeX to layout my report, as it provides beautiful mathematics and a powerful way of handling references. Along the way I learned quite a lot about using it effectively, which might be of help to other people writing a thesis, so hence this page.

I found a lot by Googling and reading tutorials, and the the compulsory read for anyone starting with LaTeX is The Not So Short Introduction to LaTeX. It takes you through the first steps, but also provides in-depth tips.

I use the MiKTeX installation and my LaTeX editor of choice is TeXnicCenter. I further have GhostScript installed, which allows me to use .eps images.

Main document file

The main document file describes the structure of the document, and links to separate files containing the actual content of the report. The following code is found sequentially in the document.

Document type

My thesis was laid out as a book, on A4 paper, with the equations set to float to the left.

\documentclass[a4paper,fleqn]{book}

Packages

The options in LaTeX can be added and/or extended by means of packages. I use quite a long list, and I will explain the relevant ones.

\usepackage{graphicx,amsfonts,psfrag,fancyhdr,layout,appendix,subfigure} \usepackage[sectionbib]{natbib} \usepackage{chapterbib}
graphicx
essential for adding images to you document.
amsfonts
includes a list of mathematical symbols and styles. Useful if you are using equations a lot.
psfrag
I use eps files for my pictures, and with this package I can replace text in those images. This allows me to have the same font size and type in both images and text.
fancyhdr
this package allows control over the headers and footers for documents with class book. The use is non-trivial, but powerful results are possible.
layout
simple package, which prints an overview of all the margins on the page when you insert .
appendix
allows more detailed control over the appendices.
subfigure
extremely useful package which allows you to put multiple figures (and tables!) in a figure environment, so that you can refer to them individually, e.g. Figure 5(a).
natbib
powerful extension for controlling your references. The package has a lot of options, and in this case I use the option, as I wanted to have multiple bibliographies in my document, and they should be labelled as section, and not as chapters.
chapterbib
package which controls the multiple bibliographies for the document. This has important consequences for the document though, as I will explain later. To get this working, you first need to run BibTeX for each of the chapters for which you want to have the bibliography, followed by compiling the entire document.

Margins

The default for the book documentclass is that the margins differ on the even/odd pages. I prefer equal margins, and thus explictly set them. For determining the correct values I used the option.

% Set equal margins on book style \setlength{\oddsidemargin}{53pt} \setlength{\evensidemargin}{53pt} \setlength{\marginparwidth}{57pt} \setlength{\footskip}{30pt}

Fancy Headers

Using fancy headers is rather tricky and cumbersome, but the results are nice. I will walk through the pieces of code throughout the document. What is important to know are the commands such as . The stand for Odd and Even pages, and for Left or Right side of the page.

% Redefine plain page style \fancypagestyle{plain}{ \fancyhf{} \renewcommand{\headrulewidth}{0pt} \fancyfoot[LE,RO]{\thepage} }

Redefining the plain page style such that it has no horizontal line at the top, nothing in the page headers, and it has the pagenumbers always on the outside of the pages ().

% Code for creating empty pages % No headers on empty pages before new chapter \makeatletter \def\cleardoublepage{\clearpage\if@twoside \ifodd\c@page\else \hbox{} \thispagestyle{plain} \newpage \if@twocolumn\hbox{}\newpage\fi\fi\fi} \makeatother \clearpage{\pagestyle{plain}\cleardoublepage}

With the book style a new chapter always starts on an odd page. If the previous page is empty, the above code ensures that it is of .

% Define pagestyle \pagestyle{fancy} \fancyhf{} \renewcommand{\chaptermark}[1]{\markboth{ \emph{#1}}{}} \fancyhead[LO]{} \fancyhead[RE]{\leftmark} \fancyfoot[LE,RO]{\thepage}

The fancy page style is first defined here, but it will be changed and augmented throughout the document.

The code describes that the page numbers, , should be in the footer and always on the outer edge of the pages.

On even pages, the Chapter name should be shown on the right and in italics. The latter is achieved by redefining , and using . The position of the chapter name will be changed after the front matter.

Paragraph formatting

I prefer the Dutch style of paragraph formatting, with no indents, and with whitespace separating the paragraphs.

% Dutch style of paragraph formatting, i.e. no indents. \setlength{\parskip}{1.3ex plus 0.2ex minus 0.2ex} \setlength{\parindent}{0pt}

Table of Content

I prefer a smaller TOC with less details.

% Less detailed TOC \setcounter{tocdepth}{1}

Document start

% Document starts here \begin{document}

The book style divides the document into three parts, for Preface, Summary, etc. which have Roman numeral for page numbers, for the main content with Arabic numerals, for the Appendices and for the Bibliography.

Front matter

\frontmatter \include{msc_titlepage} \include{msc_preface} \include{msc_summary} % Remove parskip for toc \setlength{\parskip}{0ex plus 0.5ex minus 0.2ex} \tableofcontents % Dutch style of paragraph formatting, i.e. no indents. \setlength{\parskip}{1.3ex plus 0.2ex minus 0.2ex}

The various parts of the document are d, which makes sure they start on an odd page. Also, the paragraph formatting is changed so that there is no for the TOC.

Main matter

\mainmatter % Adjustments headers \fancyhead[LO]{\leftmark} \fancyhead[RE]{\emph{Chapter \thechapter}} \include{msc_introduction} \include{msc_paper1} \include{msc_paper2} \input{msc_conclusion} \newpage \pagestyle{plain} \addcontentsline{toc}{chapter}{Bibliography} \bibliographystyle{elsart-harv-ms} \bibliography{finalreportrefs} \newpage

The fancy headers are adjusted again. This time, the odd pages will have the chapter name on the left, and the even pages will have Chapter X on the right. This way both texts will be towards the inner margin of the book, and it will look as if it were one sentence.

All chapters are d, except the conclusion. The reason why this is done is tricky to understand and has to do with the use of the package. That package requires the use of to create individual bibliographies per chapter. However, if there are references in your chapter, but you do not want a separate bibliography, you must use , as is the case with the conclusions in this example.

I had two full bilbiographies in my report, one before the Appendices, and one after, as the report would be handed in as two individual booklets. The makes sure that the Bibliography is placed in the TOC as a chapter.

Appendix

\appendix \noappendicestocpagenum \addappheadtotoc % Adjustments headers \pagestyle{fancy} \fancyhead[LO]{\leftmark} \fancyhead[RE]{\emph{Appendix \thechapter}} \renewcommand{\headrulewidth}{0.5pt} \input{msc_appendix_equilibrium} \input{msc_appendix_comparison} \input{msc_appendix_matlab} \input{msc_appendix_prototype_v2} \input{msc_appendix_examples} \input{msc_appendix_future}

The adds a separating entry to the TOC, saying Appendices. The option then makes sure that there is no pagenumber after that line.

The fancy headers are adjusted again, to now say Appendix X, and the horizontal line is redefined as it was erased by the use of the pagestyle just prior to the appendices.

Note that all appendices use as they contain references, but do not need an individual bibliography.

Backmatter

\backmatter \nocite{calladine1991,connelly1999,pellegrino1990,calladine1978,calladine1992} % Adjustments headers \pagestyle{plain} \addcontentsline{toc}{chapter}{Bibliography} \bibliographystyle{elsart-harv-ms} \bibliography{finalreportrefs}

The is used to add entries to the Bibliography, which had not been cited in the text. It is used to add some references which provide background information.

Le Fin

\end{document}

Various LaTeX tips

Citing

I use the NatBib package for citing, and it has useful features. An important aspect is the difference between and .

\citep{pellegrino1986} \citet{pellegrino1986} \citep[e.g.][p.p. 220]{coxeter} would result, when using the harvard citation style, in Pellegrino 1986 (Pellegrino, 1986) (e.g. Coxeter, 1989, p.p. 220)

Subtables

In some occasions it is desirable to have various subtables, with one common table number. That can be done using the package.

\begin{table} \caption{Caption for total table} \centering \subtable[Caption for table 1]{ \begin{tabular}{ccc} \end{tabular} \label{tab:firsttable} } \qquad\qquad \subtable[Caption for table 2]{ \begin{tabular}{ccc} \end{tabular} \label{tab:secondtable} } \end{table}

If you refer to the second table with it will give you something like Table 5(b).

psfrag

I use eps images throughout the report. As a consequence one cannot use the pdflatex package, as it cannot handle eps images. Therefore you have to first convert to PostScript and then to PDF, using GhostScript. A benefit of using eps is that you can use to replace text in the image by the default LaTeX fonttype and fontsize.

\begin{figure}[p] \centering \psfrag{v1}{$\mathbf{v}_1$} \psfrag{v2}{$\mathbf{v}_2$} \psfrag{v3}{$\mathbf{v}_3$} \psfrag{origin}{origin} \includegraphics[width=0.45\textwidth]{images/conus.eps} \caption{A conic intersected by a plane generates a conic section.} \label{fig:conus} \end{figure}

Removing whitespace

When using abbreviations such as i.e. the last period can be interpreted as a period for the end of a sentence, and as a result the space can be quite large and ugly. There is a way to prevent that.

i.e.\ rest of text here

Correct page number for Bibliography in TOC

When you insert a bibliography into your thesis, for example like this:

\addcontentsline{toc}{chapter}{Bibliography} \bibliographystyle{elsart-harv-ms} \bibliography{finalreportrefs}

you may notice that the page counter for the Bibliography in the Table of Contents, is two pages off! Fortunately the solution is easy: prior to , use the command and the numbering will now be ok.

© Mark Schenk 2005 — 2009.

One thought on “Backmatter Bibliography Latex

Leave a comment

L'indirizzo email non verrĂ  pubblicato. I campi obbligatori sono contrassegnati *