# Department of Computer Science and Technology

 Contents

# Preparing Tripos exam questions in LaTeX

The Computer Science Tripos examiners greatly appreciate if any exam questions submitted by assessors are provided not only on paper, but also as LaTeX source files.

## LaTeX templates

We have prepared for each question setter (assessor) an individual exam pack, which is a directory filled with the necessary LaTeX class file, an individual Makefile, and a template file for each of the Tripos questions that have been assigned to a question setter. These packs are available both unpacked, as well as *.tar.gz packages (aimed at Unix/Linux/macOS users) and *.zip packages (aimed at Windows users):

There are two versions of each exampack available:

• The exampack-*.tar.gz package is for Unix/Linux/macOS users who have GNU Make available. It includes a Makefile that produces PDFs of both the question and solution-notes from a single source file. Just run “make” to rebuild all PDFs as required. (On macOS, if you don't have “make” available, run “xcode-select --install” to install it.)
• The exampack-*.zip package is for Windows users, or others who do not have (or do not wish to use) GNU Make. Instead of a Makefile, it contains a *-solutions.tex wrapper file for each question.

Changes for 2019:

• The question filenames no longer contain the initials of the question setter (too much hassle to update if question setters change in the last minute).
• The solution notes and exam-pack filenames now show the question setter's CRSId instead of just their initials.
• Addition of \usepackage[utf8]{inputenc} (to reduce the risk of character set accidents)

Please read the documentation for the tripos document class, at least the brief section “Use by Tripos question setters”.

When you hand in your questions on a USB stick, please include only

• the question files (20??-p??-q??.{tex,pdf})
• associated figures (20??-p??-q??-*.*, see below for details)
• the solution PDFs (20??-p??-q??*-solutions.pdf)

Do not modify the provided tripos.cls file.

Each question has an individual LaTeX source file following the naming convention

2019-p04-q08.tex = 2019 Paper 4 Question 8


Do not forget to include marks (using the “\fullmarks” macro), solution notes (using the “answer” environment), and associated syllabus keywords (using the “\topics” macro). See the tripos class documentation for details.

Image filenames: If your question file loads any image files, please give each image file the same name prefix as your question file has. For example, the image files that come with 2019-p04-q08.tex might be called

  2019-p04-q08-fig1.fig
2019-p04-q08-fig1.pdf
2019-p04-q08-fig1.pdftex
2019-p04-q08-fig2.fig
2019-p04-q08-fig2.pdf


The idea is that all question and image files can nicely coexist in a single directory with all others, and will appear there in a useful sorting order.

For examiners: there is also exampack-20??_papers, with all files needed for formatting papers and signoff sheets.

## Prerequisites

You obviously need LaTeX installed on your computer, preferably in form of a common TeX distribution such as such as TeX Live for Linux, MacTeX for macOS, or MikTeX for Windows. TeX Live comes included with many Linux distributions.

On some distributions, the TeX environment comes modularized into many different subpackages that can be installed optionally, and you may have to install a few additional ones to have available all prerequisite files to the tripos class.

On Ubuntu Linux 16.04:

sudo apt-get install pgf texlive-latex-extra texlive-math-extra


On Ubuntu Linux 18.04:

sudo apt-get install texlive-latex-extra texlive-science


## Including graphics files

If you want to include some graphics file into a question or its solution notes:

• Please prepare your figure in one of the graphics formats that "pdflatex" can include: PDF (for drawings), PNG (for screenshots) or JPEG (for photos).
• Please make sure that the names of your graphics files start with the same prefix as the question file in which you include them (see above).
• The tripos class loads by default the graphicx package for you, so you can use its facilities to include images, e.g.
\includegraphics[width=0.8\linewidth]{2019-p04-q08-fig1.pdf}


(You may want to place that into the “center” or “quote” environment.)

• Please also provide to the examiners any human-editable source files that you used to produce your graphics. This way, they get archived along with the question and are available if you ever want to modify a figure.

### Xfig

A popular choice of drawing program for use with pdflatex is xfig, as its “pdftex” export format provides an easy means to generate graphics that use LaTeX for any text labels, leading to a consistent use of fonts.

On Ubuntu Linux, you can install xfig with the command

sudo apt-get install xfig transfig


### Any graphics package (pgf, xy, etc.)

You can use any LaTeX graphics package that you like to produce your figure, but you cannot load additional packages inside your question file. Instead, if you want to use a package not already included by default, you can produce your figure as a separate PDF file from a separate LaTeX source file, and then merely include the resulting PDF from your question file. This way, the examiners will usually not have to learn how to install whatever exotic drawing package you fancy this year.

The preview package provides a convenient way to produce PDF figures with a correct bounding box for easy embedding.

Example: create for each of your figures a separate LaTeX file (say 2019-p04-q08-fig1.tex) of the following form:

\documentclass[ownpackages]{tripos}
\usepackage{your-favourite-graphics-package}
\usepackage[active,tightpage]{preview}
\begin{document}
\begin{preview}
\end{preview}
\end{document}


Then include the resulting PDF in your question file with

\includegraphics{2019-p04-q08-fig1.pdf}


## Security considerations

The University's examiner's guide has some guidance on security requirements for exam questions and papers:

You should observe absolute confidentiality in the drafting of question papers. Word processors and printers used for the preparation of question papers must be secure from unauthorised access and if at all possible should not be connected to a network. Copies of draft or final question papers and marking schemes should be stored in a secure, locked filing cabinet and preferably in a room that is not accessed by students.

In the Computer Laboratory, we certainly advise strongly against storing plaintext exam questions and their drafts on the departmental filer.

The encfs encrypted filesystem package for Linux allows you to work comfortably with files that are only stored in encrypted form on disks or file servers. More information ...

On Ubuntu Linux, you can install encfs with the command

sudo apt-get install encfs


## The tripos document class

The tripos document class file was developed by Markus Kuhn in 2012 to help with typesetting Computer Science Tripos papers at the Computer Laboratory using pdflatex:

It is also used by some lecturers to typeset their MPhil test papers at the Computer Laboratory. This document class was carefully designed to maintain visual compatibility with how Computer Science Tripos papers have been typeset since the early 1990s at the Computer Laboratory. (Should other departments be interested in using it as well, its design was meant to be flexible enough to easily accommodate this.)

## Examples

Example files showing how to typeset an individual question and associated solution notes:

## Archive

We maintain a departmental online archive of all past exam questions since 1993. Easy read-only access to the archived sources of all past exam questions is available on the departmental filer under

/anfs/www/tripospapers

Since the LaTeX source files also contain solution notes, access to them is restricted for exam questions younger than two years, which is the embargo period for solution notes set by the Teaching Management Committee.

After the exams, pagemaster will archive the source code of all exam questions and solution notes on the departmental filer in a Subversion repository located under

/usr/groups/wwwsvn/repositories/tripos-papers/

The README.txt file there explains the detailed repository arrangements and provides instructions on how to add the archive of another year.

You can use one of the following Subversion commands to checkout your own working copy of the full archive:

svn checkout svn+ssh:[Javascript required]/tripos-papers/all exams
write access for authorized users
svn checkout file:///usr/groups/wwwsvn/repositories/tripos-papers/all exams

If you are only interested in a particular year, replace in the above URLs “all” with the year, e.g.

svn checkout svn+ssh://slogin.cl.cam.ac.uk/usr/groups/wwwsvn/repositories/tripos-papers/2014 exams-2014


## Formatting practice papers

Some Directors of Studies prepare practice papers for their students, using selected exam questions from past years. The tripos.cls package makes this very easy for post-2011 questions. Just prepare a paper file that inputs the question files that you would like to use. The following example-practicepaper.tex file shows this:

\documentclass{tripos}
\begin{document}
\begin{paper}[CSTpartIB,year=2015,paper=3,renumberquestions=true,
day=Wednesday 13 May,time=4.30,endtime=6.00,
subtitle={Practice paper for John Doe}]
\maketitle
\input{2012-p03-q05-djg}
\input{2013-p03-q03-am}
\input{2014-p03-q08-acr}
\input{2014-p03-q01-fms}
\input{2012-p03-q02-fms}
\input{2013-p03-q04-tgg}
\input{2014-p03-q04-tgg}
\input{2012-p03-q08-de}
\input{2013-p03-q09-rja}
\end{paper}
\end{document}



Setting the option renumberquestions=true makes sure that questions are renumbered continuously, rather than appear under their original number. You can also use the options day, time, endtime, and subtitle to adjust what appears on the cover page of your paper. See the tripos.cls documentation for more information on how to format entire papers.

Place tripos.cls into the same directory.

On a CL-managed Linux machine, you can set the following environment variable in the shell, to make sure pdflatex automatically finds the listed questions in the exam question archive:

export TEXINPUTS=.::/anfs/www/tripospapers//


## Formatting MPhil/Part III module tests

The tripos class can also be used to typeset papers or cover sheets for tests in masters modules.

## FAQs

### Why do {\it italics} and {\bf bold} not work?

The commands \it, \bf, \rm, \sl, \sc, \sf, \tt, \cal are plainTeX font-selection commands that are not part of LaTeX. While article.cls does still contain a backwards-compatibility hack to make some of these old commands work, they are not widely documented, do not fit in well with the modern LaTeX font mechanics, do not give access to all available font styles, and admin staff handling your exam files may not have seen them in their LaTeX course or textbook.

LaTeX equivalents include

 {\it italics} → \emph{italics}, \textit{italics} or {\itshape italics} {\bf bold} → \textbf{bold} or {\bfseries bold} {\tt code} → \texttt{code}, \verb+code+ or {\ttfamily code} {\sl text} → \textsl{text} or {\slshape text} {\sc text} → \textsc{text} or {\scshape text} {\sf text} → \textsf{text} or {\slfamily text} ${\rm max}$ → $\mathrm{max}$ or $\text{max}$ ${\bf max}$ → $\mathbf{max}$ ${\tt max}$ → $\mathtt{max}$ ${\cal Z}$ → $\mathcal{Z}$

See Lamport's LaTeX reference manual, section C.7.8 (p. 191) and section C.15.1 (p. 225–226) for other font-style commands, and page 228 for an explanation of why not to use the old ones any more.

### Can we include listings.sty?

The listings.sty package is not loaded by tripos.cls because it has caused font problems. It also is a rather huge and complex package that seems no longer maintained. Most question setters who include source code use the “verbatim” or “alltt” environments. The latter permits the use of mathematical notation, e.g. $$a\sp{2}\sb{i}$$.

An external pretty-printer that outputs LaTeX source might also be an option (e.g., LGrind, Pygments). See also the section above on how to use any graphics package.

### Can I use LyX with tripos.cls?

Using LyX is neither recommended nor supported. But if you are very determined to do so, the following information might help:

• In LyX, go to Document > Settings > Language > Encoding and select there “Other: "Language Default (no inputenc)"”. Otherwise tripos.cls will complain about LyX having added “\usepackage[latin9]{inputenc}” at the start of the file.
• There is an experimental LyX layout file at /homes/mgk25/.lyx/layouts/tripos.layout, which adjusts some of the visual appearance of the question in LyX towards what it will look like when typeset. It is far from perfect, due to limitations of LyX.