(courtesy of Google)
logo for The PracTeX Journal TUG logo

The online journal of the TeX Users Group
ISSN 1556-6994


About The PracTeX Journal
Archives of The PracTeX Journal

Next issue
Winter 2011


Editorial board

       Table of Contents

Issue 2011, Number 1    [Published 2011-09-19]

Ask Nelly

Contents

Page numbers in bibliography

Dear Nelly,

A number of books incorporate into their bibliography items a list of one or more pages on which the given reference is cited in that book. For example, the book The Analysis of Variance, by H. Scheffe, contains this entry in the bibliography:

 G. Birkhoff and S. MacLane (1953), A Survey of Modern Algebra, Macmillan, 
 New York. [371, 380, 387]

The three numbers in brackets indicate the pages on which Scheffe cites Birkhoff and MacLane. Scheffe did this for every entry.

Is there a simple way (or any way) to do this in LaTeX? I've looked at http://tug.ctan.org and also at the documentation for makebst.tex, but don't see this issue discussed.

This is of course a useful feature for readers of a book, but it is also useful for someone (like me) writing a book in LaTeX, to track easily where I myself have used a citation.

Sincerely, Jay


Dear Jay,

The package backref from the hyperref suite does exactly what you need. Just adding

 \usepackage{backref}

to the preamble of your LaTeX document will load this package. Once loaded, it will create a list of page numbers on which each bibliographic item is cited, and it will print those as part of each entry in your bibliography.

The default behaviour of backref is to list page numbers, but it can also be made to list section numbers instead, by loading it thusly:

 \usepackage[backref]{backref}

whereas the default behaviour is equivalent to

 \usepackage[backpageref]{backref}

and in documents that are to be used electronically, the listed page or section numbers can be made into hyperlinks.

There are a few caveats:

  • If your document uses a thebibliography environment be sure to leave empty lines or a \par between entries in your bibliographic database. If you don't, backref may behave oddly
 \begin{thebibliography}  % separate \bibitem's when using backref
 \bibitem ...
 
 \bibitem ...
 
 \bibitem ...
 \end{thebibliography}
  • Make sure to perform an extra run of latex when compiling your document, since the insertion of the page numbers by backref may very well change page breaks in the back matter of your document
  • The package backref is not compatible with every bibliographic package CTAN has to offer. natbib is recommended.

I hope this answers your question.

Kind regards,

Yuri (on behalf of Nelly)

Teacher vs student course materials

Dear Nelly: When I write course materials for my students, I often create a student version of the syllabus, as well as a version for me and my assistants that contains additional material, such as answers to exercises. I do, however, find that maintaining two documents with mostly identical content is not only tedious, but also rather error-prone. Surely there is a better way to do this? I've searched CTAN in vain, so I've set my hopes on you...

Answer: Thank you for your trust! There is indeed a better way!

By using the package comment you can do this as follows:

  • In the preamble of your LaTeX document add
 \usepackage{comment}
 
 \includecomment{teacher}  % use this to make a document *with* teacher materials
 % \excludecomment{teacher}  % use this to make a document without teacher materials
  • In the body of your document use, for example,
 What is the circumference of the circle?
 \begin{teacher}
   The answer is $2\pi r$.
 \end{teacher}
 ...
 How much of the cheese did the mouse eat?
 \begin{teacher}
   The answer is $\frac78$.
 \end{teacher}

If you typeset your document now it will include the answers to both questions.

To make a document without the answers, change the two preamble lines above to

 % \includecomment{teacher}  % use this to make a document *with* teacher materials
 \excludecomment{teacher}  % use this to make a document without teacher materials

and typeset again.

For an example of this method, see the article by Lenore Horner in this issue. In the file Sample test she uses six variables to make different versions of the document --- see halfway down this file where she uses

 %create annotated and unannotated output from this file by changing include <-> exclude
 \excludecomment{topics}
 \includecomment{questions}
 ...

Advanced refinements

If you operate from the command line, you can use the same method shown above, and automate this as follows:

  • To make a teacher version do
 latex '\AtBeginDocument{\includecomment{teacher}}\input{syllabus}'
  • To make a version without teacher material do
 latex '\AtBeginDocument{\excludecomment{teacher}}\input{syllabus}'

where syllabus is the name of your source file, syllabus.tex.

If you are on Linux, UNIX, or Mac OS X, you can additionally create a Makefile as follows:

 student:
     latex '\AtBeginDocument{\excludecomment{teacher}}\input{syllabus}'
     
 teacher:
     latex '\AtBeginDocument{\includecomment{teacher}}\input{syllabus}'

This way you can typeset the student version by giving the command make student and the teacher version by issuing the command make teacher.


The above question was answered by Yuri Robbers, a member of the editorial board of this journal. He can be reached at pracjourn at tug dot org.


Sponsors:   logo for the TeX Users Group   logo for Personal TeX, Inc.    Be a sponsor!

Web site Generated December 25, 2012 (wiki); TUG home page; search; contact webmaster.