Addcontentsline Toc Section Bibliography Generator

One of the immense strengths of LaTeX is its capability to cross-reference through information it places in auxiliary files. Done properly, this feature permits one to extract, insert, move and modify large and small chunks of the document around without having to manually renumber cross-references, it is all done automatically.

Table of contents

One of the easiest things to do is to insert a table of contents into a document simply by placing the LaTeX command \tableofcontents at the desired location in the document; see .

The first time this is LaTeX'ed the table will not appear because the information is being stored in the associated file. Subsequent LaTeX'ing will typeset the table of contents.

The package may be used to insert a Table of Contents of just the current chapter or Part in a book or report. Very useful to help map out the parts of the dissertation for a reader. See the scheme laid out in the skeleton file .

Footnotes

Unlike most publishers, LaTeX easily handles footnotes with contemptuous ease. Just use the \footnote{some-text} command with one argument being the text of the footnote. As seen in , this will typeset a numerical flag at the location of the footnote command and will place the footnote text at the bottom of the page.

Labels and references

Somewhat more sophisticated are references to equations and sections. First one has to label them as in \section{...} \label{sec-name} or in \begin{equation} ... \label{eq-name} \end{equation} which associates a string such as '' with the number of the section, and a string such as '' with the number of the equation. See .

Having created the labels, you refer to the objects using the command as seen in . You may use the command to typeset a symbol for 'section' and 'subsection'. You must put parentheses around the equation number in its reference.

One also labels and refers to chapters, subsections, subsubsections, tables, figures, and enumerated lists.

Avoid unhelpful and easy to misinterpret phrases such as "we will do", "from the above equation" and "in the figure below": instead use precise cross-references such as "section \ref{} does", "using equation (\ref{})", and "Figure \ref{} plots", respectively.

Drafts and electronic reading

When drafting a document, you often lose track of labels. Further, you want to read the document comfortably on screen rather than printing it. These desires are solved by two packages.

First, in the preamble will cause names of labels to also appear in a (draft) printed document for your ready reference.

Second, in the preamble will cause the document to be typeset with A5 paper size which is great for electronic reading. See and the next section where we also incorporate hypertext links.

Cross-reference into enumerated lists

Also ensure you cross-reference to enumerated lists, instead of coding the numbers by hand. Such cross-references are best done with . For example, this package empowers you to do the following in typesetting an algorithm. \begin{enumerate}[ref=Step~\theenumi] \item\label{s1} Proceed to \ref{s2}. \item\label{s2} Go to \ref{s1}. \end{enumerate} To get typeset
  1. Proceed to Step 2.
  2. Go to Step 1.
In mathematics we often want to cross-reference to parts of assumptions, theorems, and so on. Do this, given that assumptions use the theorem counter, with LaTeX such as \begin{assumption} \label{ass} Assume the following. \begin{enumerate} [ref=Assumption~\thetheorem.\theenumi] \item\label{a1} This is \ref{a1}, \item\label{a2} and this is \ref{a2} \end{enumerate} \end{assumption} To get typeset something like
Assumption 3. Assume the following.
  1. This is Assumption 3.1,
  2. and this is Assumption 3.2

Hypertext linking

A feature of LaTeX is the ability to automatically insert hypertext links within a document:
  • the command puts in a clickable link to the referred object;
  • the command automatically inserts a target;
  • table of contents, footnotes, citations, etc all generate appropriate hyperlinks,
The hyperref package is wonderful, try it. To get this feature just insert the command at the end of the preamble (e.g., ).

Warning:  the files generated with and without hyperref may be incompatible, so delete the current file before using hyperref.

Clever cross-referencing

The package enhances LaTeX's cross-referencing by determining the format of cross-references automatically according to the 'type' of cross-reference (whether to equation, section, theorem, and so on). After invoking the and packages, I recommend you include in the preamble (e.g., )

\usepackage[capitalise,nameinlink ,noabbrev]{cleveref} \crefname{equation}{}{} \crefname{enumi}{}{} All definitions must be after the above.

Then use for all your cross-references, except at the start of a sentence where you should use . The result is that each such cross-reference expands as in the following, with each cross-reference being a hyperlink.

LaTeX codeTypeset example
Figure 1
Theorem 2
Definition 3
(4)
Figures 1 and 2
Theorem 2 and Definition 3
(4) to (6)

You might ask why I do not recommend the automatic name 'equation' when cross-referencing an equation? The reason is that for best comprehension by readers, mostly we need to refer to an 'equation' by a more informative synonym such as "system (1)", "PDE (2)", "bound (3)", "approximation (4)", "inequality (5)", "transform (6)", and so on. It is not practical to code such informative synonyms automatically, we have to write them explicitly.

Similarly for an enumerated list: the default 'Item' name generated by is also functionally useless. Instead use via .

Warning: does not work with ; use instead.

Bibliography

A bibliography is handled as a sort of enumerated list with labels.

The following list like environment

\begin{thebibliography}{99} \bibitem{bib-name1} article-description1 \bibitem{bib-name2} article-description2 ... \end{thebibliography} typesets the bibliography with the heading References and associates the labels, the strings such as '', with the description of the article or reference. See the end of .

Hint: if you want the entry "References" to appear in the table-of-contents then put the line at the start of thebibliography environment (use instead for reports or books).

Achieve citations in the text to the bibliography items by the command

\cite{bib-name} This typesets the number of the bibitem in square brackets as seen in .

Generally put a non-breaking space before the cite command as in

Mandelbrot~\cite{Mandel}...

The actual citation has no meaning

Avoid the odius perversion, that somehow has spread throughout modern writing, of using citations in your sentences in the form "in [2]" or "by [3]". The bracketed number of a citation is just a pointer to more information. The bracketed number must not be part of the meaning of the sentence.
  • Bad ""
  • Good ""
  • Bad ""
  • Good ""
The meaning of your sentences must be independent of whether the bracketed citation appears or not.

BibTeX et al.

The basic bibliography environment is fine for your first project report. However, in time you develop enough so that you want to keep one central database of all your references which you then access via the command in any document you prepare.
  • First you prepare your database, say , consisting of records such as @article{Roberts94a, author = {A. J. Roberts}, journal = {Australasian Science}, month = apr, title = {The importance of beings fractal}, year = 1994, pages = 23, } or @article{Roberts95b, author = {A. J. Roberts and A. Cronin}, journal = {Physica A}, pages = {867--878}, title = {Unbiased estimation of multi-fractal dimensions of finite data sets}, volume = 233, year = 1996, } The program appears good for preparing and maintaining such a database; although I use BibDesk on a Macintosh.
  • Then whenever you prepare a document, include the commands \bibliographystyle{plain} \bibliography{ajr} instead of thebibliography environment. Use as normal within the document.
  • Lastly, after running LaTeX, execute the program bibtex (it will look in the file to determine what references are needed) which creates a file that later runs of LaTeX will read to form the bibliography. This sounds complicated, but it is all worth it.
There are also publicly available databases of files covering specialist areas of research compiled by interested people. For example there is one for dynamical systems.

Some people use a Harvard style

Many people need to know how to use a Harvard style of citations. The one big advantage of Harvard style is that the citations are mostly invariant: "Smith (1987)" means the same (mostly) in each article that a reader reads; whereas "Smith [13]" means different things in different articles; and lastly, "[13]" is completely meaningless to a reader.

In LaTeX, obtain a Harvard style of citations as follows, with the same format for the data files, and very similar commands in the document.

  • In the preamble put (get it from a CTAN site if your system does not have the package).
  • In the place you want the bibliography put then as before but now using the AGSM bibtex style instead of the default plain style.
  • Then to get the following citations use the given command
    • "Roberts & Cronin (1996)" use ;
    • "(Roberts & Cronin, 1996)" use ;
    • this form also typesets an afterword, for example, for "(Roberts & Cronin, 1996, p.15)" use ;
    • for three or more authors will typeset "Roberts et al. (1996)" which is good, but the convention is that the first time a three author work is cited the three authors ought to be explicitly given so then use to get "Roberts, Cronin & Another (1996)" the first time you site the work.
  • Finally, the default style for URLs in natbib is very ugly. So in the preamble after and , include the statement
The hyperref package works with natbib and agsm.

As for the bracketed citation style, the parenthetical form is just a pointer to more information and must not contribute to the meaning of the sentence. Also avoid physically impossible statements such as ; instead use .

Collaboration with BibTeX

In your first use of LaTeX you will probably be working on your own, in which case ignore this subsection. But as soon as you start to collaborate on writing, then come back and read this: collaboration with BibTeX is only reasonable with the following which merges from all the collaborators the relevant bib entries from their database into the common database .

  • Ensure your system has the script or ---it comes with most LaTeX systems.
  • Say three people are collaborating: you are Alice with collaborators Bob and Eve, and you each have separate bib files say , and , respectively. Then, in your LaTeX source, say , include a line for each collaborator of the following form, \bibliography{bibexport,alice} %\bibliography{bibexport,bob} %\bibliography{bibexport,eve}
  • Execute LaTeX on the source (which records in the bibfiles to use).
  • Execute (usually via a terminal application) which merges into the local file the necessary bib information from itself (first) and (second). Ignore warnings about duplicated bib entries.
  • Execute to get the new file generated, and away you go as usual.
  • When your collaborators want to merge in information from their personal bibfiles, and respectively, then they uncomment the bibliography line for themselves, comment out the other bibliography lines, and then proceed as above.
  • One can even choose the bibliography command automatically by lines in the source such as \IfFileExists{alice.sty} {\bibliography{bibexport,alice}}{} \IfFileExists{bob.sty} {\bibliography{bibexport,bob}}{} \IfFileExists{eve.sty} {\bibliography{bibexport,eve}}{} provided each individual has a personal style file implementing their personal preferences for style!

Gather bibliographic data via Zoterro

To find articles, one often searches the internet: use "Google Scholar" rather than just Google or other web search engine (as they are too indiscriminant).

Once found on the internet, mostly it is good to use Zoterro (a plugin to browsers) to download the article and the bibliographic information (despite occasional failure). Then a richt-click to "Export Item(s)..." saves bibliographic info in a *.bib file: edit and merge with your own database.

BibLaTeX?

This is a new more powerful and flexible method for citations from data: to be incorporated soon.

Divide and conquer large documents

Large documents, especially dissertations and books, can be a pain to deal with just because of their size. LaTeX gives a facility to split the source, the file, into manageable sized chunks to make editing easier and to speed typesetting by only doing that chunk of interest at any one time.
  • Establish the main file, as in , of the form \documentclass{article} \begin{document} \include{frac25a} \include{frac25b} \include{frac25c} \end{document} with as many divisions as there are logical chunks in your document.
  • Then put all your normal LaTeX text and commands in the corresponding files. Here I have broken the input file into:
  • Typeset the main file and all appears as normal (except pagebreaks are enforced between the included files).
  • To typeset only one of the chunks, say the first section, just insert the command \includeonly{frac25b} in the preamble as you see commented out in .

Appendices

Often large documents have one or more appendices. If so just insert the command immediately before the first appendix, then use chapter and/or sectioning commands as before. The first chapter or section after will become Appendix A, the second will be Appendix B, etc.

Summary

Cross-referencing is important in professional documents. Cross-referencing is absolutely vital in research as you must `plug' your work into the world's knowledge base, and must connect information across pages and sections within your own work. LaTeX provides incredibly easy tools to do this.

chapterbib | References following each Chapter

Postby JensL » Sat Dec 13, 2008 12:07 pm

Hi there,

I am trying to compile a thesis in LaTeX and I need to put in References after each chapter. I have spend hours trying to get chapterbib to work, but I can't get it right.

Can anyone give a good example how to solve this problem? My current structure, cleaned of the formatting code, is this:


This is the main document called "Thesis.tex". The three individual chapters are stored in separate sub-folders, following a suggestion from someone on this list. An example for thesis-chapter1 is:

and the bibliography for this chapter is in thesis-chapter1.bib, which looks like this:

and is also stored in the sub-folder. Accordingly, there is a thesis-chapter2.bib in sub-folder "chapter2", and a thesis-chapter3.bib in sub-folder "chapter3".

For a test, I set up chapter 2 identical to chapter 1, but citing
, which is the only reference in thesis-chapter2.bib.
In chapter 3, I want to cite by \cite{awe}, which is the only reference in "thesis-chapter3.bib".

A number of web pages suggest that you need to compile as follows

But it doesn't work, and I can't make any sense out of the error messages I get:

Can anyone give a detailed example of how to use chapterbib properly to obtain a bibliography at the end of each chapter?
There are a few comments on this topics on the web, but I can't get it to work.

Any help is greatly appreciated.
  1. \documentclass[phd,tocprelim]{CU}
  2. \usepackage[sectionbib]{chapterbib}
  3. %\bibliographystyle{plain}
  4. %\bibliographystyle{IEEEbib}
  5. \include{chapter1/thesis-chapter1}
  6. \include{chapter2/thesis-chapter2}
  7. \include{chapter3/thesis-chapter3}
  1. The text for Section 1 goes here, without brackets.
  2. test \cite{Brakenridge1994}
  3. \bibliographystyle{plain}
  4. \bibliography{chapter1/thesis-chapter1}
  1. @article{Brakenridge1994,
  2. Author = {Brakenridge, G.B. and Knox, J.C. and Paylor II, E.D. and Magiligan, F.},
  3. Title = {Radar Remote Sensing Aids Study of the Great Flood of 1993},
  1. A level-1 auxiliary file: chapter2/thesis-chapter2.aux
  2. Illegal, another \bibstyle command---line 8 of file chapter2/thesis-chapter2.aux
  3. I'm skipping whatever remains of this command
  4. Illegal, another \bibdata command---line 9 of file chapter2/thesis-chapter2.aux
  5. : {chapter2/thesis-chapter2}
  6. I'm skipping whatever remains of this command
  7. A level-1 auxiliary file: chapter3/thesis-chapter3.aux
  8. Illegal, another \bibstyle command---line 8 of file chapter3/thesis-chapter3.aux
  9. I'm skipping whatever remains of this command
  10. Illegal, another \bibdata command---line 9 of file chapter3/thesis-chapter3.aux
  11. : {chapter3/thesis-chapter3}
  12. I'm skipping whatever remains of this command
  13. Database file #1: chapter1/thesis-chapter1.bib
  14. Warning--I dind't find a database entry for "Barber1996"
Last edited by JensL on Sat Dec 13, 2008 1:52 pm, edited 1 time in total.

One thought on “Addcontentsline Toc Section Bibliography Generator

Leave a Reply

Your email address will not be published. Required fields are marked *