report writing and digital typographystudentnet.cs.manchester.ac.uk/ugt/comp10120/labscripts/101lab3...

51
COMP10120 Lab Session 3 Report writing and Digital Typography Contents 3.1 Introduction ................... 10 3.2 Getting started ................. 10 Exercise 1: A closer look ........ 10 Exercise 2: A larger example ..... 14 3.3 Common formatting features ......... 24 3.3.1 Enumerated and bulleted lists .... 24 3.3.2 Changing the appearance of text . . . 24 3.3.3 Cross referencing ............ 25 3.3.4 Figures and pictures .......... 26 Exercise 3: Including images ..... 28 Exercise 4: A reflection on your studies 28 October 16, 2018 8

Upload: others

Post on 25-May-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Lab Session3

Report writing andDigital Typography

Contents31 Introduction 1032 Getting started 10

Exercise 1 A closer look 10Exercise 2 A larger example 14

33 Common formatting features 24331 Enumerated and bulleted lists 24332 Changing the appearance of text 24333 Cross referencing 25334 Figures and pictures 26

Exercise 3 Including images 28Exercise 4 A reflection on your studies 28

October 16 2018 8

COMP10120 Report writing and Digital Typography

34 Typesetting Mathematics 30341 A longer piece of mathematics 34

Exercise 5 Formatting mathematics 3635 Curriculum vitaie 37

Exercise 6 Curriculum vitae 3736 Some optional extras 38

Exercise 7 Exploring more LATEX fea-tures (optional but easy) 38Exercise 8 A neat directory listing(optional more challenging) 39Exercise 9 A cleaning rota (optionaleven more challenging) 40

361 Marking Scheme 4037 Next steps 41

371 Acknowledgements 42372 License 42

38 Background 42381 Pronunciation 43382 Why LATEX 44383 Some history printing mathematics 46384 To WYSIWYG or not to WYSIWYG 48385 Style and content 52386 The right tool for the right job 54387 Summing up 54388 Fire And Ice 55389 Search Terms 563810 Acknowledgements 56

9

COMP10120 Report writing and Digital Typography

These notes are available online atstudentnetcsmanchesteracukugtCOMP10120labscripts101lab3pdf

31 Introduction

LATEX is a document preparation system that is funda-mentally different to anything that you are likely to haveseen before Itrsquos used worldwide by publishers aca-demics and scientists and it happens to be very goodfor writing CVs too

32 Getting started

Please complete all the exercises in thislab in your COMP10120ex3 directory Whenyou have completed as much as youare going to do you should run submitand (when next in the School) labprint

Exercise 1 A closer look

Fire up your favourite editor enter the following text(itrsquos important that you enter it exactly as it is below fornow) and then save it as a file called fire-and-icetex

10

COMP10120 Report writing and Digital Typography

(in case yoursquore wondering itrsquos the first line from a shortpoem called lsquoFire and Icersquo by American poet RobertFrost (R Frost 1924) the whole poem is on the PoetryFoundation website if yoursquore interested)

documentclass[a4paper]articlebegindocumentSome say the world will end in fireenddocument

Next run the command pdflatex fire-and-icetex(for now itrsquos sufficient to say that pdflatex invokesLATEX to create a PDF file as the output the full story isa bit more complicated)

LATEX will process your file and print out a surpris-ingly large amount of text into the shell window as itdoes so If all is well the last two lines printed out willbe something like

Output written on fire-and-icepdf (1 page 11853 bytes)Transcript written on fire-and-icelog

after which LATEX will return you to the command promptIf yoursquove made a mistake typing in the file LATEX willstop part way through processing your work and dis-play an error (possibly quite an obscure one) and showa lsquorsquo prompt The best thing to do at this stage is to

11

COMP10120 Report writing and Digital Typography

press ltctrlgtd or x to tell LATEX to give up trying toprocess your file Then fix the mistake and try again

If you now list the directory contents you shouldsee that a file fire-and-icepdf has been created (alongwith two other files fire-and-iceaux and fire-and-icelog

both of which we will ignore for now) Use one of thePDF readers (such as evince

evince

) to look at the contentsof fire-and-icepdf Admittedly itrsquos not the most ex-citing result if everything has worked properly so faryou should see a single-page document with the wordslsquoSome say the world will end in firersquo a little way downfrom the top of the page1

But now look more closely A lot more closely reallyzoom in See anything interesting

Even for this very short document LATEX has taken afairly sophisticated typographical decision on your be-half and ligated (which is typography-speak for lsquojoinedrsquo)the lsquofrsquo and the lsquoirsquo in the word lsquofirersquo the spacing betweenthe characters has been subtly altered so that the dotabove the lsquoirsquo and the blob on the end of the curvy bit(the lsquoarc of the stemrsquo if wersquore being formal) on the topof the lsquofrsquo join together to form a single shape calleda ligature Why Because having two blobs side by

1If you have been carried away with the sheer excitement and joy of learningto use LATEX and improvised the text rather than typing the first line of lsquoFire andIcersquo as requested please go back and change it now it really is important thatyou use exactly that text Really it is Thatrsquos better Thanks

12

COMP10120 Report writing and Digital Typography

side simply looks a bit clumsy as you can see in Fig-ure 31 To make this decision LATEX has had to knowa lot about the fonts being used (not all lsquofrsquos in all fontshave a blobby end not all lsquoirsquos in all fonts have a rounddot that would merge nicely with the blobby bit on theend of an lsquofrsquo and so on) Therersquos a reasonable chancethat yoursquove never heard of ligated characters beforemdashit is after all a fairly specialist thing And there arehundreds of other obscure but important lsquorulesrsquo of ty-pography that go to make professionally typeset doc-uments look good2 Individually they might not beobvious or hugely important but collectively and sub-liminally they make the difference between somethingthat looks just-about-acceptable (like most things writ-ten using wordprocessors) and things that stand out aslooking really professional (you might want to remem-ber this when it comes to putting your CV together)

But thatrsquos enough about the typography of the wordlsquofirersquo for now Letrsquos put together something more sub-stantial

2Look up lsquokerningrsquo lsquocombining charactersrsquo and lsquoserifrsquo on Wikipedia forstarters And if yoursquore really keen Donald Knuthrsquos fascinating and compen-dious book lsquoDigital Typographyrsquo (D Knuth 1999) has an entire chapter dedi-cated to the joys of the letter lsquoSrsquo Probably best not to bring this subject up at thepub though or at parties Unless they are very specialist parties

13

COMP10120 Report writing and Digital Typography

Figure 31The word lsquofirersquo typeset by (a) Microsoft Word 2011 withoutligated characters and (b) by LATEX showing the ligation ofthe characters lsquofrsquo and lsquoirsquo

Exercise 2 A larger example

Create yourself a new file called sectionstex by copy-ing fire-and-icetex In sectionstex replace the lineof poetry by copying and pasting the text from Figure32 (which contains the first three paragraphs of Dick-ensrsquo novel lsquoBleak Housersquo (C Dickens 1852))

Edit the text to make sure that there is a blank linebetween each of the three paragraphs (itrsquos not enoughthat each paragraph starts on a new line of its ownthere has to be an empty line in between them) Thatrsquoshow paragraphs are distinguished in LATEX (in fact itdoesnrsquot matter how many blank lines you put as longas there is at least one for the most part LATEX ignoresspare whitespace) After the lsquoBleak Housersquo text typea paragraph of gibberish by randomly hitting keys onthe keyboard and putting spaces in to make lsquowordsrsquo inthe text file You should end up with something like thefollowing but about three times as long (donrsquot cut andpaste this from here itrsquos important that you actually

14

COMP10120 Report writing and Digital Typography

London Michaelmas term lately over and theLord Chancellor sitting in Lincolnrsquos Inn HallImplacable November weather As much mud inthe streets as if the waters had but newly retiredfrom the face of the earth and it would not bewonderful to meet a Megalosaurus forty feetlong or so waddling like an elephantine lizardup Holborn Hill Smoke lowering down fromchimney-pots making a soft black drizzle withflakes of soot in it as big as full-grownsnowflakesndashgone into mourning one mightimagine for the death of the sun Dogsundistinguishable in mire Horses scarcelybetter splashed to their very blinkers Footpassengers jostling one anotherrsquos umbrellas in ageneral infection of ill temper and losing theirfoot-hold at street-corners where tens ofthousands of other foot passengers have beenslipping and sliding since the day broke (if thisday ever broke) adding new deposits to the crustupon crust of mud sticking at those pointstenaciously to the pavement and accumulatingat compound interest

Fog everywhere Fog up the river where it flowsamong green aits and meadows fog down theriver where it rolls defiled among the tiers ofshipping and the waterside pollutions of a great(and dirty) city Fog on the Essex marshes fogon the Kentish heights Fog creeping into thecabooses of collier-brigs fog lying out on theyards and hovering in the rigging of great shipsfog drooping on the gunwales of barges andsmall boats Fog in the eyes and throats ofancient Greenwich pensioners wheezing by thefiresides of their wards fog in the stem and bowlof the afternoon pipe of the wrathful skipperdown in his close cabin fog cruelly pinching thetoes and fingers of his shivering little rsquoprenticeboy on deck Chance people on the bridgespeeping over the parapets into a nether sky offog with fog all round them as if they were upin a balloon and hanging in the misty clouds

Gas looming through the fog in divers places inthe streets much as the sun may from thespongey fields be seen to loom by husbandmanand ploughboy Most of the shops lighted twohours before their timemdashas the gas seems toknow for it has a haggard and unwilling look

Figure 32Some sample text from the opening of the Dickensrsquo novellsquoBleak Housersquo (C Dickens 1852)

15

COMP10120 Report writing and Digital Typography

create some unique gibberish yourself)

Oisjdf oqweqwe oi soijs hbweo kbsd oijsdfoijqwknpiouh iusbdfspb sifuhygwqeb usgweijfblimqwoq oieuerwefwiu aokqjw uioshiufdsqiqks odfubfi psdiweneq

Be careful at this stage to only include letters (upper-case and lowercase) commas full-stops and perhapsnumbers in your gibberish text if you use any othersymbols you may upset LATEX

Next go to the website wwwlipsumcom and fol-low the instructions to generate yourself three para-graphs of whatrsquos called Lorem Ipsum text Copy andpaste that text into your LATEX document too (donrsquot worryabout what it means at this stage) again making surethat you have a blank line between the paragraphs

Run pdflatex and look at the resulting sectionspdfAgain at first glance therersquos nothing hugely excitinggoing on here the text from your tex file has beenassembled into a (probably) two page PDF documentBut in fact quite a few things have happened

bull The blank lines that separate the paragraphs inyour source file are gone and instead LATEX hasindented the first line of each paragraph Therersquosnothing profound here about the decision to in-dent paragraphs rather than (say) to leave a gap

16

COMP10120 Report writing and Digital Typography

between them (so called block paragraphs) itrsquosjust LATEXrsquos default paragraph style and can bechanged easily enough3

bull There are page numbers at the bottom of each page(except page 1) This is a very sensible default al-lowing you in meetings to ask people to lsquoturn topage 4rsquo and so on (itrsquos a bit odd and a source ofsome annoyance that most wordprocessors donrsquotdo this by default too) But you can easily switchpage numbers off change their style or move themelsewhere if you need to

bull The text is fully justified so that itrsquos flush on boththe left and right hand edges

bull Certain words that fall at the end of lines havebeen hyphenated even if they werenrsquot originallysplit by hyphens in the source text

These last two points about justification and hyphen-ation might seem utterly trivial but getting these fac-tors right turns out to be an important part of mak-ing readable documents readability is not just aboutwhich font you choose but about how the charactersand spaces are distributed on each line Itrsquos something

3Though apparently there is some evidence in M A Tinker 1963 that in-dented paragraphs increase readability

17

COMP10120 Report writing and Digital Typography

that you will have seen happen so often in profession-ally typeset materials that yoursquoll have taken it for grantedand you may not have spotted that it doesnrsquot happenin quite the same way when you use a wordproces-sor The principle behind justifying text seems easyenough at first glance you simply have to take any lsquoleftoverrsquo space that would be at the end of a line and re-distribute it between the words in some way to lsquospacethem outrsquo a bit more so that they take up all the avail-able horizontal room But it turns out to be much harderthan it seems and all the simple ways you might thinkof for doing this on a per-line basis give results thatare visually quite unsatisfactory with nasty patternsmade up of neighbouring whitespace appearing in thelayout and ruining everything The added complica-tion here is that to do the optimum job of shuffling thewords round on their lines you really need the flex-ibility of being able to hyphenate words to give youextra space on lines that would otherwise be tightlypacked with characters But if you hyphenate wordsbadly by breaking them in inappropriate places or doit too often then that makes the text hard to read tooItrsquos all deeply inconvenient and inter-related The bestsolution to this aesthetic conundrum so far was devel-oped by Knuth and Plass 1981 and later improved byFrank Liang during his PhD research (F M Liang1983) and itrsquos a technique that tries to optimise the lay-

18

COMP10120 Report writing and Digital Typography

out of whole paragraphs rather than individual linesThe algorithm takes into account all manner of differ-ent things language-specific character patterns the num-ber of consecutive lines that end with hyphens the wordlsquotightnessrsquo on each line and many others The detailsdonrsquot really matter here but the really important in-sight is that you get better results by working on a big-ger chunk of the document (in this case a paragraph at atime) rather than trying to independently optimise lotsof small bits (say lines) and hoping that the result ofjoining them all together turns out nicely This idea ofoptimising things globally versus locally is somethingyoursquoll see many times throughout your Computer Sci-ence degree watch out for it in all the algorithms courses

This highlights a fundamental difference betweenthe WYSIWYG paradigm and the way that documentsare produced using LATEX As wersquove seen small changesdown at the level of individual characters can have fairlylarge knock-on consequences for the optimal layout ofa document changing one letter for another affects thelength of a line which in turn affects the hyphenationoptions which then affects the length of a paragraphwhich means that the best place for a figure that was onpage 99 might now be on page 100 but that means thatall references to lsquopage 99rsquo now need a bit more room toaccount for the extra digit which means that the someline lengths have changed which means well you get

19

COMP10120 Report writing and Digital Typography

the idea Itrsquos more complicated than it first seems LATEXgets to see the whole of your document at once and cantherefore make decisions about how best to hyphen-ate lines position figures or whatever else it likes beforeit shows you the results so it can make solutions thatare optimal for the whole document as well as lookingat details such as ligated characters Wordprocessorscanrsquot afford to do this since it would be deeply distract-ing if every time you typed a character the whole lay-out of the document flapped around in front of youreyes Wordprocessors can only sensibly make little op-timisations at a local (probably per-line level) Itrsquos notthat wordprocessors are rubbish or that the people thatprogrammed them were lazy itrsquos a fundamentally dif-ferent way of working and knowing the pros and consof the different approaches will help you pick the righttool for the job

You may have noticed that actual text in your doc-ument (and in fact this one) takes up a (perhaps) sur-prisingly narrow horizontal region of the page Thislast lsquofeaturersquo might seem odd at first but it illustratesanother important typographical point that you maynever have thought of before reading long lines of textis hard because your eyes find it hard to move in acompletely straight line as they scan from left to rightSo the longer the line of words the more you have towork to keep your eyes from accidentally drifting up or

20

COMP10120 Report writing and Digital Typography

down onto a neighbouring line (perhaps yoursquove expe-rienced the phenomenon of accidentally re-reading thesame line over and over as your eyes get tired) It maynever have occurred to you but most books have rela-tively short lines of text and those that use large pagesoften split text into several columns so that individuallines are kept relatively short The widely trusted booklsquoThe Elements of Typographic Stylersquo (R Bringhurst1992) makes the following assertion

lsquoAnything from 45 to 75 characters is widely-regarded as a satisfactory length of line for a single-column page set in a serifed text face in a text sizeThe 66-character line (counting both letters andspaces) is widely regarded as idealrsquo

LATEX knows about this issue so made a sensible de-fault decision for you You may have noticed that thereis a subtle difference in appearance of this chapter fromprevious ones the lines are shorter and paragraphs areindented We wanted to use the default LATEX layoutfor this chapter but changed it for earlier chapters inan effort to save paper

Therersquos one last unusual thing to note your para-graph of gibberish text in between the real words fromBleak House and the Lorem Ipsum almost certainly standsout and looks really quite odd (it might even have con-fused LATEXrsquos hyphenation rules enough to have ended

21

COMP10120 Report writing and Digital Typography

up with one or more lines sticking out proud of theright hand margin) Let your eyes relax so that yourvision blurs for a moment you can still probably spotthat the gibberish paragraph looks out of place Itrsquosquite likely that you even found creating the gibber-ish unexpectedly hard The interesting thing here isthat as humans we spend so much time reading andwriting lsquoproperrsquo natural language that we become at-tuned to the patterns of letters words and the underly-ing lsquorhythmrsquo of our written language that its very hardto artificially reproduce something that looks plausiblethe frequency of the letters you chose by randomly hit-ting keys and the length and patterns of the words youput in place most likely donrsquot match the natural pat-terns of real languages so they just look plain wrongCuriously the Lorem Ipsum text that you got from thewebsite probably doesnrsquot look so bad in spite of it notbeing made up of real words But thatrsquos not surprisingsince Lorem Ipsum is specifically created to be used asa placeholder for real text when typesetting While thewords are meaningless Latin-like things their lengthand the distribution of characters and word lengths arechosen to mimic patterns in real language

Next letrsquos give our document some structure by di-viding it up into sections On the line before BleakHouse starts add the command

22

COMP10120 Report writing and Digital Typography

sectionBleak House

making sure it appears on a line of its own Then justbefore your paragraph of gibberish put a similar in-struction (again on its own line) and then create a finalsection before the Lorem Ipsum Rerun pdflatex andlook at the results You should see the section headingsappear in the appropriate places in the PDF automati-cally having been given section numbers Experimentby adding in a couple of sub-sections towards the endof the document using the subsection commandwhich like the section command above takes as aparameter some text contained in curly brackets

Now at the top of your document after the begindocumentline and before the command defining the first sectionadd the following two commands each on their ownline

tableofcontentsnewpage

Re-run pdflatex twice and check that the effect is whatyoursquod expect You need to process the source twice be-cause on the first run LATEX gathers and stores informa-tion about what to put in the table of contents and onlycreates it on the second run

23

COMP10120 Report writing and Digital Typography

33 Common formatting features

Before we give you some more exercises to do here is abrief introduction to some commonly used features ofLATEX

331 Enumerated and bulleted lists

Creating bulleted or numbered lists in LATEX is straight-forward and is done like this

beginenumerateitem My first itemitem My second itemitem The last thing on my listendenumerate

You must make sure that you both begin and end yourlist and that each item is terminated by a newline Chang-ing enumerate to itemize gives you a bulleted ratherthan numbered list (note the American spelling of lsquoitem-izersquo)

332 Changing the appearance of text

Text can be typeset in bold font using the textbfin italics using textitand in a fixed-width fontusing texttt as in the example below

24

COMP10120 Report writing and Digital Typography

Some textttsay the textbfworld will end in textitfire

which is typeset as

Some say the world will end in fire

333 Cross referencing

LATEX allows you to cross-reference almost anything inthe document which includes sections sub-sections andfigures To use the cross-referencing feature you simplyinsert the command

labelmymarker

at the point in the document you want to refer to andthen use the command

refmymarker

when you want to use the reference Obviously youreplace the text mymarkerwith something more mean-ingful An important tip here is to call the marker some-thing that refers to the content of that part of the doc-ument and to avoid the temptation to use numbers(so donrsquot call your marker section1 instead call itintroduction if you reorder your document itrsquos stilllikely to be the introduction but it may no longer beSection 1) For example

25

COMP10120 Report writing and Digital Typography

sectionReflection on Welcome WeeklabelwelcomeweekI spent most of welcome week getting to know my wayaround campus I should have made more effort to joinsocieties I think I must remember to get to theStudentsrsquo Union and take a look around there

subsectionThings I enjoyedEverything so far has been wonderful with the caveat Imentioned in Section refwelcomeweek

subsectionThings I didnrsquot enjoyIrsquove discovered that I donrsquot like soggy chips

The really useful thing about cross-referencing in LATEXis that yoursquoll get warnings when you compile your doc-ument if cross-references are undefined or used incor-rectly This means you donrsquot have to manually checkevery reference in your document to make sure itrsquos stillright You do however have to run LATEX twice forsimilar reasons to those given above

334 Figures and pictures

Including figures and pictures in your document is easyYou do it like this

beginfigure

26

COMP10120 Report writing and Digital Typography

Figure 33Some men possibly Dutch looking at cheeses

centerlineincludegraphics[width=10cm]imagesmen-and-cheesejpgcaptionSome men possibly Dutch looking at cheeseslabelfiguremenandcheesesendfigure

which is the code we used to create Figure 38 You canprobably see whatrsquos happening The command includegraphicsgets your image which can be PDF PNG JPG GIF orPostScript The beginfigureendfigurecode lsquowrapsrsquo up whatever picture yoursquore including andallows LATEX to treat it as an unbreakable floating thingthat it will position for you as best it can in the docu-ment while maintaining an overall nice typographicallayout This floating of figures can sometimes result inthe figure ending up in a place you didnrsquot expect but inmost cases LATEX will make the most sensible choice Itrsquos

27

COMP10120 Report writing and Digital Typography

possible to employ finer control over figure placementbut thatrsquos beyond the scope of this introduction

The includegraphics command is not built into core LATEX but is in an additional package whichneeds to be explicitly loaded We load this package byusing the command usepackagegraphicx in thedocument preamble ie after the documentclasscommand but before begindocument There arehundreds of such packages that extend LATEXrsquos func-tionality the lab scripts you are reading now use over30 of them

Exercise 3 Including images

Create a document imagetex that contains some text(maybe from rsquoLorem Ipsumrsquo) together with a figurecontaining an image of your choice perhaps the oneyou made in Intro Lab 2 like Steversquos Mr Noodle Thereshould also be a reference to the figure in the text Youshould first use the program convert

convert

(check its manpage) to create a PDF version of the image

Exercise 4 A reflection on your studies

Your first proper LATEX document will be a very briefreflection on your studies so far

Write a hand-crafted LATEX document called courses-reflectiontex

28

COMP10120 Report writing and Digital Typography

(exact name as usual please otherwise submitwill notwork) It will have the following structure

1 A table of contents

2 A brief paragraph saying what the document isabout

3 A section appropriately titled for one of your courseunits containing

bull a brief paragraph saying what the unit is about

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the most about the unit

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the least about the unit

A repeat of item 3 for each other unit you are study-ing These sections should appear in alphabeticalorder by course code (eg COMP10120)

After completing and successfully compiling and view-ing your document you should spell-check it as fol-lows

ispell courses-reflectiontex

29

COMP10120 Report writing and Digital Typography

Once you are completely satisfied with it produce ahard copy ready for marking

34 Typesetting Mathematics

Earlier we saw this formula

x =minusbplusmn

radicb2 minus 4ac

2aIt looks nice doesnrsquot it To tell LATEX to display thisyou have to type a bit of magic but itrsquos easily-learnedmagic To create such a formula in a WYSIWYG edi-tor there is also magic involved but it usually involvesa lot of mouse-clicking and remembering special keycombinations like rsquocontrol-thisrsquo and rsquoalt-thatrsquo In LATEXit doesnrsquot You simply type this

[ x = frac-b pm sqrtb^2-4ac2a ]

You can probably work out how most of this createsthe formula but it wonrsquot be obvious that the [ and ]symbols that enclose the formula mean lsquotypeset this asa displayed formula giving it some vertical space fromthe surrounding textrsquo If wersquod used ( and ) insteadto enclose the formula it would appear in-line like thisx = minusbplusmn

radicb2minus4ac2a It still looks very nice and observe

how itrsquos automatically been resized to fit and that the

30

COMP10120 Report writing and Digital Typography

lines of text have had their spacing changed a bit Thisall looks simple but the implementation inside LATEXand TEX is complex It involves parsing the descrip-tion of the formula to create a corresponding tree datastructure which is then recursively walked to workout the horizontal and vertical typographical spacingsneeded Yoursquoll meet these ideas in COMP11120 andCOMP26120 Algorithms and Imperative Programming

Herersquos another example taken from COMP27112Computer Graphics (itrsquos a lsquosimplersquo local illuminationmodel incorporating ambient diffuse and specular re-flection by multiple lights)

I = kaIa +

Msumi=1

Ipidprimei[kd(N middot Li) + ks(Ri middot V )n]

We write this in LATEX as follows

[ I = k_a I_a + sum_i=1^M fracI_p_idrsquo_i [ k_d(hatN cdot hatL_i)+ k_s(hatR_i cdot hatV)^n] ]

Try to match the LATEX commands with the formula dis-played above Yoursquoll see lots of curly brackets and thisexample illustrates their two uses in LATEX The firstis to provide an argument to a command for exam-ple hatN means lsquoapply the hat command to N rsquowhich creates N the vector N with a little hat on

31

COMP10120 Report writing and Digital Typography

The second use of curly brackets is to group thingstogether to avoid ambiguities In the example you cansee sum_i=1^M which creates a summation signand its lower and upper limits

sumMi=1 We wrap the

lower bound i=1 in curly brackets to group it into anindivisible unit If we were to omit the brackets writ-ing sum_i=1^M LATEX would then produce

sumi = 1M

which is not at all what we want (even LATEX canrsquot al-ways know what we really want)

One final example If we tell LATEX

[ T_1 = left[beginarraycccccos theta amp -sin theta amp 0 amp delta sin theta amp cos theta amp 0 amp epsilon 0 amp 0 amp 1 amp eta alpha amp beta amp gamma amp 1endarrayright] ]

wersquoll get a splendid matrix which expresses a particu-lar 3D geometrical transformation (Donrsquot worry if youdonrsquot recognise this yoursquoll be introduced to matrix no-tation in the latter part of COMP11120 MathematicalTechniques for Computer Science For now you can justtreat it as some mysterious maths)

32

COMP10120 Report writing and Digital Typography

T1 =

cos θ minus sin θ 0 δ

sin θ cos θ 0 ε

0 0 1 η

α β γ 1

In the LATEX code left[means lsquobig opening square

bracket pleasersquo ccccmeans lsquoan array with 4 columnsplease with the items in each column centredrsquo ampmeanslsquostart a new columnrsquo and means lsquostart a new rowrsquoYoursquoll notice that LATEX knows about greek letters itknows about most standard maths symbols too andalso the ways theyrsquore usually used

There are some symbols that you might need (forexample therefore which produces the usual threedots symbol there4) that are not part of standard LATEX Manysuch symbols are provided by the amssymb package ofsymbols compiled by the American Mathematical Soci-ety Details of the many symbols provided by this pack-age can be found online at

mirrormathkuedutex-archivefontsamsfontsdocamssymbpdf

To use these extra symbols you need to have usepackageamssymbin the document preamble

33

COMP10120 Report writing and Digital Typography

341 A longer piece of mathematics

We conclude this section with an example of a longerpiece of mathematics that shows how you might type-set a complete mathematical argument rather than asingle formula The example is Euclidrsquos proof of thefact that

radic2 is irrational Itrsquos an argument that has been

covered in COMP11120 and is an example of proof bycontradiction It starts by making the assumption thatit is not the case that

radic2 is irrational in other words that

we can find integers p and q withradic2 = pq

We can assume without losing anything that p andq have no common factors (Why)

radic2 = pq

qradic2 = p

2q2 = p2

This means that p2 is even from which we can also de-duce that p is even (Why)

This means that p = 2k for some k so

2q2 = (2k)2

there4 2q2 = 4k2

so q2 = 2k2

But this means that q2 and hence q is even Since p andq are both even we have a contradiction to our initialassumption so no such p and q exist

The way this is formatted is shown here

34

COMP10120 Report writing and Digital Typography

It starts by making the assumption that it is emphnot the casethat $sqrt2$ is irrational in other words that we can findintegers $p$ and $q$ with $sqrt2 = pq$

We can assume without losing anything that $p$ and $q$ haveemphno common factors (Why)

[beginarraylcl

sqrt2 amp = amp pq qsqrt2 amp = amp p 2q^2 amp = amp p^2

endarray]

This means that $p^2$ is even from which we can also deduce that $p$is even (Why)

This means that $p = 2k$ for some $k$ so ldots[beginarrayllcl

amp 2q^2 amp = amp (2k)^2 therefore amp 2q^2 amp = amp 4k^2 textso amp q^2 amp = amp 2k^2

endarray]

But this means that $q^2$ and hence $q$ is even Since $p$ and $q$are both even we have a contradiction to our initial assumptionso no such $p$ and $q$ exist

Notice the use of the array environment for gettingthings lined up You can find much more informationabout this on the web

LATEX really shines at typesetting mathematics and

35

COMP10120 Report writing and Digital Typography

it would take pages and pages to describe all the fea-tures Have a look at

enwikibooksorgwikiLaTeXMathematics

for a flavour

Exercise 5 Formatting mathematics

Now for an exercise that involves some mathematicsPlease create a file f-wtex which typesets the follow-ing piece of text and mathematics

There are many positive integer solutions tothe equation

x2 + y2 = z2

which can be rewritten as

z =radicx2 + y2

For example (3 4 5) or (5 12 13) Such solu-tions are called Pythagorean triples

However for higher powers the situation isvery different and we have-

Theorem Fermat-WilesFor all natural numbers n ge 3 there are no

36

COMP10120 Report writing and Digital Typography

integers x y z satisfying the equation

xn + yn = zn

35 Curriculum vitaie

There are several scenarios where using LATEX ratherthan other word processing software can be useful

bull typesetting mathematics yoursquove just read about

bull writing a technical document

bull your final year project peport

bull writing an article you want to get published

bull writing a Curriculum vitae CV

Wersquoll now look at CVrsquos briefly

Exercise 6 Curriculum vitae

Creating a professional document is especially impor-tant when you write your CV because how your CVlooks (not just the content) will determine if you are in-vited to interview for job you are applying for Thatcould be a summer internship next year a year long

37

COMP10120 Report writing and Digital Typography

placement after your second year or graduate positionafter you leave University

As well using a text-editor and compiling files fromthe command line other tools are available for editingLATEXWe will look at one of these overleafcom

Create a basic CV which describes you your edu-cation (including University) and any experience youhave or interesting projects that you may have doneYou can do this using httpsoverleafcom andchoosing the ready-made templates at httpswwwoverleafcomgallerytaggedcv

As you progress through University it is a good ideato keep your CV up to date and get feedback from asmany people as you can There will be opportunities todebug your CV later (See httpgitiomycv if youare interested) but yoursquoll need a ldquobeta releaserdquo (version10) of your CV to get started The best time to start thisprocess is now

36 Some optional extras

Exercise 7 Exploring more LATEX features (op-tional but easy)

This exercise reinforces some of the things yoursquove donealready but also introduces some features of LATEX that

38

COMP10120 Report writing and Digital Typography

will be new to you It is labelled as optional because itisnrsquot marked but we would recommend that you all tryit

Take a copy of the file optinfocoursesCOMP10120ex3latex-introtexand follow the instructions it contains You should readit before you process it with LATEX

Exercise 8 A neat directory listing (optionalmore challenging)

The fact that LATEX source files are just text makes it easyto have them generated by a program You are going toexploit this and use LATEX to produce a neat documentcontaining a listing of the files in any directory

Find how to create tables in LATEX tables using thetabular environment Make a LATEX document by handthat uses a table to neatly show the information aboutthe files in some (small) directory (as produced by ls

-l) Write a shell script called neat-ls that takes anargument which is the path name of a directory andproduces a LATEX document containing the above tablefor the given directory The script could also process theLATEX and display the resulting pdf file Finally find outabout the longtable package and change your script touse that instead

39

COMP10120 Report writing and Digital Typography

Exercise 9 A cleaning rota (optional evenmore challenging)

Now you will write a shell script called make-rota thatgenerates a house cleaning rota (Very handy for nextyear ) This is a table with columns such as KitchenBathroom and Lounge The rows will be weeks in theyear labelled with a date (eg always a Sunday) Theidea is that house mates can write their initials in theboxes promising to clean the corresponding room inthat particular week Start by making a sample tableby hand

Your script should take a single argument which isthe date of the first day of the first row eg102013(the US format for 20 Oct 13) The result will be a docu-ment that contains as many rows as fit on a single page(find out by experimenting)

The dates of each row should be generated from thefirst See the manual page for date to figure out howyou can generate a date that is a number of weeks anddays later than an existing one

361 Marking Scheme

You can view a copy of the marking scheme used bysubmit and labprint at

40

COMP10120 Report writing and Digital Typography

studentnetcsmanchesteracukugtlpmsphpunit=COMP10120ampex=ex3xml

37 Next steps

LATEX is a very powerful tool and it does take a littlegetting used to But itrsquos not as scary as it might initiallyseem and you should find that it doesnrsquot take long tolearn the common commands and techniques to makeyour documents well-structured and readable As youbecome more comfortable with the basics and under-stand the principles of typesetting finding out how todo more complex and sophisticated things is easymdashthere are hundreds of tutorials on the web

Donrsquot get carried away though and use the featuresjudiciously just because yoursquove found a cool new com-mand doesnrsquot mean that you should use it just to showoff your LATEX skills content and structure always trumpstypographic twiddlings4

4For example footnotes like this are for some reason a really tempting fea-ture to use in LATEX and in this document we have abused them mercilessly toillustrate a point Footnotes were originally a means for mechanical typeset-ters to insert comments corrections or additions to existing documents withouthaving to adjust the layout of a whole page and of course in digital typographythis is no longer necessary They can justifiably be used for citations (though itrsquosnot common to do so these days) and URLs if you donrsquot want these intrudinginto the body of your text And in some very very rare cases they can be usedas an aside to the main flow of the text (which is what has been done in this doc-ument) But this should be used sparingly If something is important to sayput it in the main body of your text If itrsquos not then perhaps you should thinkabout leaving it out completely or find some other way of including it Asking

41

COMP10120 Report writing and Digital Typography

371 Acknowledgements

Figure 38 is from the Wikipedia article on cheese

372 License

The text of this exercise is licensed under the terms ofthe Creative Commons Attribution 20 Generic (CC BY30) License

38 Background

What follows is additional contextual information aroundLATEX

LATEX was originally written by Leslie LamportW anAmerican computer scientist now working at MicrosoftResearch although its development has long been takenover by a world-wide LATEX community Itrsquos actuallybuilt on top of another system called TEX a computertypesetting system designed by one of the worldrsquos mostinfluential Computer Scientists Donald KnuthW of Stan-ford University Knuth has said that he designed TEX

the reader to look down at the bottom of a page to find out whether somethingis important or not is irritating and as yoursquove probably found out already oftenmeans you lose track of your reading position They also give the impressionthat the author isnrsquot clear about whether something is important or not whichis never good And long footnotes like this onemdashwhile LATEX will typeset themperfectly wellmdashare just plain silly Best avoid

42

COMP10120 Report writing and Digital Typography

for lsquothe creation of beautiful booksmdashand especially forbooks that contain a lot of mathematicsrsquo(D Knuth1984) Figure 34 shows what these eminent men looklike

So whatrsquos the purpose of LATEX Itrsquos purely a layerof software to make TEX easier to use in everyday sit-uations This is a good idea because although TEX isamazingly powerful it operates at a very low-level whichmakes it hard for non-expert users

Figure 34Don Knuth and Leslie Lamport

381 Pronunciation

The name TEX is intended by its creator to be pronouncedwith the final consonant as in the word loch or the nameBach but English speakers often pronounce it like thefirst syllable of technical The first syllable of LATEX is

43

COMP10120 Report writing and Digital Typography

pronounced as in rsquolayrsquo5

382 Why LATEX

Before we go any further why do we think LATEX is im-portant for youmdasha Computer Science studentmdashto knowabout Here are some reasons in no particular order

bull LATEX and TEX are superb examples of ComputerScience in action TEX was designed by Knuth fromfirst principlesmdashin other words from scratch TEXis actually a programming language and LATEX isa set of functions defined in the TEX language TheTEX lsquocompilerrsquo is written in WEBW a mixture ofdocumentation written in TeX and a PascalW sub-set in order to ensure portability it reads a TEXprogram and outputs documents TEX is completelyself-contained and designed to be portable to anycomputer architecture For example it implementsits own stackW and heapW (with garbage collectionW)and it does fixed-precision arithmeticW donrsquot worryif these terms donrsquot make much sense to you at themoment they soon will

5The Greek prefix lsquotexrsquo means lsquoartrsquo as well as lsquotechnologyrsquo so itrsquos a very nicelychosen name for a piece of software that produces such beautiful output Knuthexplained (D Knuth 1984) that one should lsquopronounce the X of TeX as a Greekchi not as an lsquoxrsquo so that TeX rhymes with the word blecchhhrsquo Wersquore not toosure that helps much unless you are confident in your pronunciation of theword lsquoblecchhrsquo Maybe itrsquos an American thing

44

COMP10120 Report writing and Digital Typography

bull LATEX is a new interesting way for you to thinkabout preparing documents

bull LATEX has a practical advantage for the writer inthat it helps you think more about what you wantto write rather than worrying about how it looks

bull LATEX is a powerful tool for professional scientificdocumentation and as a Computer Scientist youshould know about it

bull LATEX files are just plain text so can easily be cre-ated programatically For example the slides usedfor COMP16120 are generated automatically fromthe source of Johnrsquos book both are typeset usingLATEX The program labprint also produces itsoutput using LATEX using information drawn fromXMLW configuration files and ARCADE

bull Using LATEX is actually quite satisfying and thequality of its output may surprise you

In this lab session you are going to write severalshort documents using LATEX You could also write briefnotes in your logbook about how LATEX works and whatcommands you used inside the source of your docu-ments

45

COMP10120 Report writing and Digital Typography

383 Some history printing mathematics

Mathematics is hard to print on paper and on the Web(many websites resort to GIF or JPG images of mathsformulae which usually look horrible MathMLW pro-vides another approach but it is not yet widely used)

In the days before computers books and newspa-pers were printed with movable typeW made from lotsof little blocks of metal each with letters numbers andsymbols standing in relief which when inked left animpression on the paper (see Figure 35) The job ofthe printer (the printer here of course being a personnot a bit of electronics) was to gather together all theblocks in the right order between two horizontal stripsof wood to create a line of the document and then toassemble all those lines from top to bottom of a pageThus the term type settingW an incredible task whenyou think about it In the printerrsquos workshop by theway the blocks of metal were stored between jobs inwooden boxes called cases Letters like a b and c werestored in one case letters like A B and C were storedin a case sitting on top of that So a lower case and anupper case These terms may ring a bell

As technology progressed machines controlled bytypewriters would mechanically juggle the blocks intothe right order This conceptual model is the basis onwhich TEX operates Only now the metal blocks are

46

COMP10120 Report writing and Digital Typography

Figure 35On the left a piece of cast movable type in the Garamondfont On the right a case of cast metal type pieces andtypeset matter in a composing stick The text reads lsquoThequick brown fox jumps over the lazy dog and feels as if hewere in the seventh heaven of typography together with Her-mann Zapf the most famous artist of thersquo This document istypeset in a font called Palatino created by Hermann ZapfYou may have also seen rsquoZapf Dingbatsrsquo in the font lists ofvarious desktop applications Now you know why

little pieces of data arranged into data structuresThe one thing that traditional printers hated was

dealing with the typesetting of mathematics and theywould charge extra to do it It was incredibly fiddly toget the equations looking right they had to squeeze inextra bits of metal horizontally and vertically

When computers entered the printing world attemptsto print mathematics were limited by the printing tech-nology available It took a long time to reach the pointwhere computers could typeset mathematics beautifullyand that was the outstanding achievement of Knuthrsquos

47

COMP10120 Report writing and Digital Typography

TEXLetrsquos look at a quick example of the quality you get

from LATEX with a very simple formula that yoursquoll recog-nise

x =minusbplusmn

radicb2 minus 4ac

2aWersquoll revisit how LATEX typesets mathematics in Section 34

384 To WYSIWYG or not to WYSIWYG

Up until now you have probably used wordprocessingapplications such as Microsoft Word to create essaysletters and other (probably fairly short) documents Youmost likely know that the majority of modern wordprocessors use a paradigm called WYSIWYG or WhatYou See Is What You Get which means that you canmodify the visual style of the document yoursquore work-ing on by selecting the relevant bits and then choos-ing different attributes such as font size or colour usinga GUI In many ways this seems like such a sensibleand obvious way of doing things that you might bewondering why it even has a special name The rea-son is a historical one in the early days of comput-ing long before graphical window managers becamethe norm and when all you could display on screenwas fixed-width ASCII text in whatever the systemrsquos

48

COMP10120 Report writing and Digital Typography

default font was wordprocessors (eg Figure 36) onlyallowed you to format documents by using special se-quences of characters to cause particular effects Butthese effects were only visible when the document wasprinted So if you wanted a word to appear in boldtext in the wordprocessor you might write somethinglike [bold]hello world[bold] what you saw onscreen was not a direct reflection of what appeared onthe printed page If yoursquove written any HTML how-ever this process of marking up text may be familiarsee for example Figure 37 As computers moved todisplays able to draw things other than raw charac-ters on screen wordprocessors became capable of us-ing multiple fonts and styles as well as graphics anda new generation of applications appeared where whatyou saw on screen was an accurate reflection of how itwould appear when printed what you see (on screen)is what you get (on paper)

The huge advantage of WYSIWYG is that itrsquos reallyeasy to understand whatrsquos going on and most peoplecan create reasonably nicely formatted documents withrelatively little effort For short informal documentsone-off letters memos and such WYSIWYG works quitenicely But if yoursquove ever tried writing anything muchlonger or that includes images and tables you mayhave already started to see where the paradigm breaksdown For example if you write lsquoFigure 38 on page

49

COMP10120 Report writing and Digital Typography

Figure 36A screenshot of Wordperfect 51 running in Microsoft DOScirca 1989

51 shows a picture of some men looking at cheesersquo butthen later on edit your document to include some moretext at the start and a new picture of a some broccoli(as in Figure 39) yoursquod have to search through yourreport to find all mentions of lsquoFigure 38rsquo and lsquopage 51rsquoand manually update them to reflect the new number-ing This might be fine if you have two figures and fivepages but for a hundred-page report containing lots ofpictures you can see how this becomes tedious and er-ror prone very quickly

50

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 2: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

34 Typesetting Mathematics 30341 A longer piece of mathematics 34

Exercise 5 Formatting mathematics 3635 Curriculum vitaie 37

Exercise 6 Curriculum vitae 3736 Some optional extras 38

Exercise 7 Exploring more LATEX fea-tures (optional but easy) 38Exercise 8 A neat directory listing(optional more challenging) 39Exercise 9 A cleaning rota (optionaleven more challenging) 40

361 Marking Scheme 4037 Next steps 41

371 Acknowledgements 42372 License 42

38 Background 42381 Pronunciation 43382 Why LATEX 44383 Some history printing mathematics 46384 To WYSIWYG or not to WYSIWYG 48385 Style and content 52386 The right tool for the right job 54387 Summing up 54388 Fire And Ice 55389 Search Terms 563810 Acknowledgements 56

9

COMP10120 Report writing and Digital Typography

These notes are available online atstudentnetcsmanchesteracukugtCOMP10120labscripts101lab3pdf

31 Introduction

LATEX is a document preparation system that is funda-mentally different to anything that you are likely to haveseen before Itrsquos used worldwide by publishers aca-demics and scientists and it happens to be very goodfor writing CVs too

32 Getting started

Please complete all the exercises in thislab in your COMP10120ex3 directory Whenyou have completed as much as youare going to do you should run submitand (when next in the School) labprint

Exercise 1 A closer look

Fire up your favourite editor enter the following text(itrsquos important that you enter it exactly as it is below fornow) and then save it as a file called fire-and-icetex

10

COMP10120 Report writing and Digital Typography

(in case yoursquore wondering itrsquos the first line from a shortpoem called lsquoFire and Icersquo by American poet RobertFrost (R Frost 1924) the whole poem is on the PoetryFoundation website if yoursquore interested)

documentclass[a4paper]articlebegindocumentSome say the world will end in fireenddocument

Next run the command pdflatex fire-and-icetex(for now itrsquos sufficient to say that pdflatex invokesLATEX to create a PDF file as the output the full story isa bit more complicated)

LATEX will process your file and print out a surpris-ingly large amount of text into the shell window as itdoes so If all is well the last two lines printed out willbe something like

Output written on fire-and-icepdf (1 page 11853 bytes)Transcript written on fire-and-icelog

after which LATEX will return you to the command promptIf yoursquove made a mistake typing in the file LATEX willstop part way through processing your work and dis-play an error (possibly quite an obscure one) and showa lsquorsquo prompt The best thing to do at this stage is to

11

COMP10120 Report writing and Digital Typography

press ltctrlgtd or x to tell LATEX to give up trying toprocess your file Then fix the mistake and try again

If you now list the directory contents you shouldsee that a file fire-and-icepdf has been created (alongwith two other files fire-and-iceaux and fire-and-icelog

both of which we will ignore for now) Use one of thePDF readers (such as evince

evince

) to look at the contentsof fire-and-icepdf Admittedly itrsquos not the most ex-citing result if everything has worked properly so faryou should see a single-page document with the wordslsquoSome say the world will end in firersquo a little way downfrom the top of the page1

But now look more closely A lot more closely reallyzoom in See anything interesting

Even for this very short document LATEX has taken afairly sophisticated typographical decision on your be-half and ligated (which is typography-speak for lsquojoinedrsquo)the lsquofrsquo and the lsquoirsquo in the word lsquofirersquo the spacing betweenthe characters has been subtly altered so that the dotabove the lsquoirsquo and the blob on the end of the curvy bit(the lsquoarc of the stemrsquo if wersquore being formal) on the topof the lsquofrsquo join together to form a single shape calleda ligature Why Because having two blobs side by

1If you have been carried away with the sheer excitement and joy of learningto use LATEX and improvised the text rather than typing the first line of lsquoFire andIcersquo as requested please go back and change it now it really is important thatyou use exactly that text Really it is Thatrsquos better Thanks

12

COMP10120 Report writing and Digital Typography

side simply looks a bit clumsy as you can see in Fig-ure 31 To make this decision LATEX has had to knowa lot about the fonts being used (not all lsquofrsquos in all fontshave a blobby end not all lsquoirsquos in all fonts have a rounddot that would merge nicely with the blobby bit on theend of an lsquofrsquo and so on) Therersquos a reasonable chancethat yoursquove never heard of ligated characters beforemdashit is after all a fairly specialist thing And there arehundreds of other obscure but important lsquorulesrsquo of ty-pography that go to make professionally typeset doc-uments look good2 Individually they might not beobvious or hugely important but collectively and sub-liminally they make the difference between somethingthat looks just-about-acceptable (like most things writ-ten using wordprocessors) and things that stand out aslooking really professional (you might want to remem-ber this when it comes to putting your CV together)

But thatrsquos enough about the typography of the wordlsquofirersquo for now Letrsquos put together something more sub-stantial

2Look up lsquokerningrsquo lsquocombining charactersrsquo and lsquoserifrsquo on Wikipedia forstarters And if yoursquore really keen Donald Knuthrsquos fascinating and compen-dious book lsquoDigital Typographyrsquo (D Knuth 1999) has an entire chapter dedi-cated to the joys of the letter lsquoSrsquo Probably best not to bring this subject up at thepub though or at parties Unless they are very specialist parties

13

COMP10120 Report writing and Digital Typography

Figure 31The word lsquofirersquo typeset by (a) Microsoft Word 2011 withoutligated characters and (b) by LATEX showing the ligation ofthe characters lsquofrsquo and lsquoirsquo

Exercise 2 A larger example

Create yourself a new file called sectionstex by copy-ing fire-and-icetex In sectionstex replace the lineof poetry by copying and pasting the text from Figure32 (which contains the first three paragraphs of Dick-ensrsquo novel lsquoBleak Housersquo (C Dickens 1852))

Edit the text to make sure that there is a blank linebetween each of the three paragraphs (itrsquos not enoughthat each paragraph starts on a new line of its ownthere has to be an empty line in between them) Thatrsquoshow paragraphs are distinguished in LATEX (in fact itdoesnrsquot matter how many blank lines you put as longas there is at least one for the most part LATEX ignoresspare whitespace) After the lsquoBleak Housersquo text typea paragraph of gibberish by randomly hitting keys onthe keyboard and putting spaces in to make lsquowordsrsquo inthe text file You should end up with something like thefollowing but about three times as long (donrsquot cut andpaste this from here itrsquos important that you actually

14

COMP10120 Report writing and Digital Typography

London Michaelmas term lately over and theLord Chancellor sitting in Lincolnrsquos Inn HallImplacable November weather As much mud inthe streets as if the waters had but newly retiredfrom the face of the earth and it would not bewonderful to meet a Megalosaurus forty feetlong or so waddling like an elephantine lizardup Holborn Hill Smoke lowering down fromchimney-pots making a soft black drizzle withflakes of soot in it as big as full-grownsnowflakesndashgone into mourning one mightimagine for the death of the sun Dogsundistinguishable in mire Horses scarcelybetter splashed to their very blinkers Footpassengers jostling one anotherrsquos umbrellas in ageneral infection of ill temper and losing theirfoot-hold at street-corners where tens ofthousands of other foot passengers have beenslipping and sliding since the day broke (if thisday ever broke) adding new deposits to the crustupon crust of mud sticking at those pointstenaciously to the pavement and accumulatingat compound interest

Fog everywhere Fog up the river where it flowsamong green aits and meadows fog down theriver where it rolls defiled among the tiers ofshipping and the waterside pollutions of a great(and dirty) city Fog on the Essex marshes fogon the Kentish heights Fog creeping into thecabooses of collier-brigs fog lying out on theyards and hovering in the rigging of great shipsfog drooping on the gunwales of barges andsmall boats Fog in the eyes and throats ofancient Greenwich pensioners wheezing by thefiresides of their wards fog in the stem and bowlof the afternoon pipe of the wrathful skipperdown in his close cabin fog cruelly pinching thetoes and fingers of his shivering little rsquoprenticeboy on deck Chance people on the bridgespeeping over the parapets into a nether sky offog with fog all round them as if they were upin a balloon and hanging in the misty clouds

Gas looming through the fog in divers places inthe streets much as the sun may from thespongey fields be seen to loom by husbandmanand ploughboy Most of the shops lighted twohours before their timemdashas the gas seems toknow for it has a haggard and unwilling look

Figure 32Some sample text from the opening of the Dickensrsquo novellsquoBleak Housersquo (C Dickens 1852)

15

COMP10120 Report writing and Digital Typography

create some unique gibberish yourself)

Oisjdf oqweqwe oi soijs hbweo kbsd oijsdfoijqwknpiouh iusbdfspb sifuhygwqeb usgweijfblimqwoq oieuerwefwiu aokqjw uioshiufdsqiqks odfubfi psdiweneq

Be careful at this stage to only include letters (upper-case and lowercase) commas full-stops and perhapsnumbers in your gibberish text if you use any othersymbols you may upset LATEX

Next go to the website wwwlipsumcom and fol-low the instructions to generate yourself three para-graphs of whatrsquos called Lorem Ipsum text Copy andpaste that text into your LATEX document too (donrsquot worryabout what it means at this stage) again making surethat you have a blank line between the paragraphs

Run pdflatex and look at the resulting sectionspdfAgain at first glance therersquos nothing hugely excitinggoing on here the text from your tex file has beenassembled into a (probably) two page PDF documentBut in fact quite a few things have happened

bull The blank lines that separate the paragraphs inyour source file are gone and instead LATEX hasindented the first line of each paragraph Therersquosnothing profound here about the decision to in-dent paragraphs rather than (say) to leave a gap

16

COMP10120 Report writing and Digital Typography

between them (so called block paragraphs) itrsquosjust LATEXrsquos default paragraph style and can bechanged easily enough3

bull There are page numbers at the bottom of each page(except page 1) This is a very sensible default al-lowing you in meetings to ask people to lsquoturn topage 4rsquo and so on (itrsquos a bit odd and a source ofsome annoyance that most wordprocessors donrsquotdo this by default too) But you can easily switchpage numbers off change their style or move themelsewhere if you need to

bull The text is fully justified so that itrsquos flush on boththe left and right hand edges

bull Certain words that fall at the end of lines havebeen hyphenated even if they werenrsquot originallysplit by hyphens in the source text

These last two points about justification and hyphen-ation might seem utterly trivial but getting these fac-tors right turns out to be an important part of mak-ing readable documents readability is not just aboutwhich font you choose but about how the charactersand spaces are distributed on each line Itrsquos something

3Though apparently there is some evidence in M A Tinker 1963 that in-dented paragraphs increase readability

17

COMP10120 Report writing and Digital Typography

that you will have seen happen so often in profession-ally typeset materials that yoursquoll have taken it for grantedand you may not have spotted that it doesnrsquot happenin quite the same way when you use a wordproces-sor The principle behind justifying text seems easyenough at first glance you simply have to take any lsquoleftoverrsquo space that would be at the end of a line and re-distribute it between the words in some way to lsquospacethem outrsquo a bit more so that they take up all the avail-able horizontal room But it turns out to be much harderthan it seems and all the simple ways you might thinkof for doing this on a per-line basis give results thatare visually quite unsatisfactory with nasty patternsmade up of neighbouring whitespace appearing in thelayout and ruining everything The added complica-tion here is that to do the optimum job of shuffling thewords round on their lines you really need the flex-ibility of being able to hyphenate words to give youextra space on lines that would otherwise be tightlypacked with characters But if you hyphenate wordsbadly by breaking them in inappropriate places or doit too often then that makes the text hard to read tooItrsquos all deeply inconvenient and inter-related The bestsolution to this aesthetic conundrum so far was devel-oped by Knuth and Plass 1981 and later improved byFrank Liang during his PhD research (F M Liang1983) and itrsquos a technique that tries to optimise the lay-

18

COMP10120 Report writing and Digital Typography

out of whole paragraphs rather than individual linesThe algorithm takes into account all manner of differ-ent things language-specific character patterns the num-ber of consecutive lines that end with hyphens the wordlsquotightnessrsquo on each line and many others The detailsdonrsquot really matter here but the really important in-sight is that you get better results by working on a big-ger chunk of the document (in this case a paragraph at atime) rather than trying to independently optimise lotsof small bits (say lines) and hoping that the result ofjoining them all together turns out nicely This idea ofoptimising things globally versus locally is somethingyoursquoll see many times throughout your Computer Sci-ence degree watch out for it in all the algorithms courses

This highlights a fundamental difference betweenthe WYSIWYG paradigm and the way that documentsare produced using LATEX As wersquove seen small changesdown at the level of individual characters can have fairlylarge knock-on consequences for the optimal layout ofa document changing one letter for another affects thelength of a line which in turn affects the hyphenationoptions which then affects the length of a paragraphwhich means that the best place for a figure that was onpage 99 might now be on page 100 but that means thatall references to lsquopage 99rsquo now need a bit more room toaccount for the extra digit which means that the someline lengths have changed which means well you get

19

COMP10120 Report writing and Digital Typography

the idea Itrsquos more complicated than it first seems LATEXgets to see the whole of your document at once and cantherefore make decisions about how best to hyphen-ate lines position figures or whatever else it likes beforeit shows you the results so it can make solutions thatare optimal for the whole document as well as lookingat details such as ligated characters Wordprocessorscanrsquot afford to do this since it would be deeply distract-ing if every time you typed a character the whole lay-out of the document flapped around in front of youreyes Wordprocessors can only sensibly make little op-timisations at a local (probably per-line level) Itrsquos notthat wordprocessors are rubbish or that the people thatprogrammed them were lazy itrsquos a fundamentally dif-ferent way of working and knowing the pros and consof the different approaches will help you pick the righttool for the job

You may have noticed that actual text in your doc-ument (and in fact this one) takes up a (perhaps) sur-prisingly narrow horizontal region of the page Thislast lsquofeaturersquo might seem odd at first but it illustratesanother important typographical point that you maynever have thought of before reading long lines of textis hard because your eyes find it hard to move in acompletely straight line as they scan from left to rightSo the longer the line of words the more you have towork to keep your eyes from accidentally drifting up or

20

COMP10120 Report writing and Digital Typography

down onto a neighbouring line (perhaps yoursquove expe-rienced the phenomenon of accidentally re-reading thesame line over and over as your eyes get tired) It maynever have occurred to you but most books have rela-tively short lines of text and those that use large pagesoften split text into several columns so that individuallines are kept relatively short The widely trusted booklsquoThe Elements of Typographic Stylersquo (R Bringhurst1992) makes the following assertion

lsquoAnything from 45 to 75 characters is widely-regarded as a satisfactory length of line for a single-column page set in a serifed text face in a text sizeThe 66-character line (counting both letters andspaces) is widely regarded as idealrsquo

LATEX knows about this issue so made a sensible de-fault decision for you You may have noticed that thereis a subtle difference in appearance of this chapter fromprevious ones the lines are shorter and paragraphs areindented We wanted to use the default LATEX layoutfor this chapter but changed it for earlier chapters inan effort to save paper

Therersquos one last unusual thing to note your para-graph of gibberish text in between the real words fromBleak House and the Lorem Ipsum almost certainly standsout and looks really quite odd (it might even have con-fused LATEXrsquos hyphenation rules enough to have ended

21

COMP10120 Report writing and Digital Typography

up with one or more lines sticking out proud of theright hand margin) Let your eyes relax so that yourvision blurs for a moment you can still probably spotthat the gibberish paragraph looks out of place Itrsquosquite likely that you even found creating the gibber-ish unexpectedly hard The interesting thing here isthat as humans we spend so much time reading andwriting lsquoproperrsquo natural language that we become at-tuned to the patterns of letters words and the underly-ing lsquorhythmrsquo of our written language that its very hardto artificially reproduce something that looks plausiblethe frequency of the letters you chose by randomly hit-ting keys and the length and patterns of the words youput in place most likely donrsquot match the natural pat-terns of real languages so they just look plain wrongCuriously the Lorem Ipsum text that you got from thewebsite probably doesnrsquot look so bad in spite of it notbeing made up of real words But thatrsquos not surprisingsince Lorem Ipsum is specifically created to be used asa placeholder for real text when typesetting While thewords are meaningless Latin-like things their lengthand the distribution of characters and word lengths arechosen to mimic patterns in real language

Next letrsquos give our document some structure by di-viding it up into sections On the line before BleakHouse starts add the command

22

COMP10120 Report writing and Digital Typography

sectionBleak House

making sure it appears on a line of its own Then justbefore your paragraph of gibberish put a similar in-struction (again on its own line) and then create a finalsection before the Lorem Ipsum Rerun pdflatex andlook at the results You should see the section headingsappear in the appropriate places in the PDF automati-cally having been given section numbers Experimentby adding in a couple of sub-sections towards the endof the document using the subsection commandwhich like the section command above takes as aparameter some text contained in curly brackets

Now at the top of your document after the begindocumentline and before the command defining the first sectionadd the following two commands each on their ownline

tableofcontentsnewpage

Re-run pdflatex twice and check that the effect is whatyoursquod expect You need to process the source twice be-cause on the first run LATEX gathers and stores informa-tion about what to put in the table of contents and onlycreates it on the second run

23

COMP10120 Report writing and Digital Typography

33 Common formatting features

Before we give you some more exercises to do here is abrief introduction to some commonly used features ofLATEX

331 Enumerated and bulleted lists

Creating bulleted or numbered lists in LATEX is straight-forward and is done like this

beginenumerateitem My first itemitem My second itemitem The last thing on my listendenumerate

You must make sure that you both begin and end yourlist and that each item is terminated by a newline Chang-ing enumerate to itemize gives you a bulleted ratherthan numbered list (note the American spelling of lsquoitem-izersquo)

332 Changing the appearance of text

Text can be typeset in bold font using the textbfin italics using textitand in a fixed-width fontusing texttt as in the example below

24

COMP10120 Report writing and Digital Typography

Some textttsay the textbfworld will end in textitfire

which is typeset as

Some say the world will end in fire

333 Cross referencing

LATEX allows you to cross-reference almost anything inthe document which includes sections sub-sections andfigures To use the cross-referencing feature you simplyinsert the command

labelmymarker

at the point in the document you want to refer to andthen use the command

refmymarker

when you want to use the reference Obviously youreplace the text mymarkerwith something more mean-ingful An important tip here is to call the marker some-thing that refers to the content of that part of the doc-ument and to avoid the temptation to use numbers(so donrsquot call your marker section1 instead call itintroduction if you reorder your document itrsquos stilllikely to be the introduction but it may no longer beSection 1) For example

25

COMP10120 Report writing and Digital Typography

sectionReflection on Welcome WeeklabelwelcomeweekI spent most of welcome week getting to know my wayaround campus I should have made more effort to joinsocieties I think I must remember to get to theStudentsrsquo Union and take a look around there

subsectionThings I enjoyedEverything so far has been wonderful with the caveat Imentioned in Section refwelcomeweek

subsectionThings I didnrsquot enjoyIrsquove discovered that I donrsquot like soggy chips

The really useful thing about cross-referencing in LATEXis that yoursquoll get warnings when you compile your doc-ument if cross-references are undefined or used incor-rectly This means you donrsquot have to manually checkevery reference in your document to make sure itrsquos stillright You do however have to run LATEX twice forsimilar reasons to those given above

334 Figures and pictures

Including figures and pictures in your document is easyYou do it like this

beginfigure

26

COMP10120 Report writing and Digital Typography

Figure 33Some men possibly Dutch looking at cheeses

centerlineincludegraphics[width=10cm]imagesmen-and-cheesejpgcaptionSome men possibly Dutch looking at cheeseslabelfiguremenandcheesesendfigure

which is the code we used to create Figure 38 You canprobably see whatrsquos happening The command includegraphicsgets your image which can be PDF PNG JPG GIF orPostScript The beginfigureendfigurecode lsquowrapsrsquo up whatever picture yoursquore including andallows LATEX to treat it as an unbreakable floating thingthat it will position for you as best it can in the docu-ment while maintaining an overall nice typographicallayout This floating of figures can sometimes result inthe figure ending up in a place you didnrsquot expect but inmost cases LATEX will make the most sensible choice Itrsquos

27

COMP10120 Report writing and Digital Typography

possible to employ finer control over figure placementbut thatrsquos beyond the scope of this introduction

The includegraphics command is not built into core LATEX but is in an additional package whichneeds to be explicitly loaded We load this package byusing the command usepackagegraphicx in thedocument preamble ie after the documentclasscommand but before begindocument There arehundreds of such packages that extend LATEXrsquos func-tionality the lab scripts you are reading now use over30 of them

Exercise 3 Including images

Create a document imagetex that contains some text(maybe from rsquoLorem Ipsumrsquo) together with a figurecontaining an image of your choice perhaps the oneyou made in Intro Lab 2 like Steversquos Mr Noodle Thereshould also be a reference to the figure in the text Youshould first use the program convert

convert

(check its manpage) to create a PDF version of the image

Exercise 4 A reflection on your studies

Your first proper LATEX document will be a very briefreflection on your studies so far

Write a hand-crafted LATEX document called courses-reflectiontex

28

COMP10120 Report writing and Digital Typography

(exact name as usual please otherwise submitwill notwork) It will have the following structure

1 A table of contents

2 A brief paragraph saying what the document isabout

3 A section appropriately titled for one of your courseunits containing

bull a brief paragraph saying what the unit is about

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the most about the unit

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the least about the unit

A repeat of item 3 for each other unit you are study-ing These sections should appear in alphabeticalorder by course code (eg COMP10120)

After completing and successfully compiling and view-ing your document you should spell-check it as fol-lows

ispell courses-reflectiontex

29

COMP10120 Report writing and Digital Typography

Once you are completely satisfied with it produce ahard copy ready for marking

34 Typesetting Mathematics

Earlier we saw this formula

x =minusbplusmn

radicb2 minus 4ac

2aIt looks nice doesnrsquot it To tell LATEX to display thisyou have to type a bit of magic but itrsquos easily-learnedmagic To create such a formula in a WYSIWYG edi-tor there is also magic involved but it usually involvesa lot of mouse-clicking and remembering special keycombinations like rsquocontrol-thisrsquo and rsquoalt-thatrsquo In LATEXit doesnrsquot You simply type this

[ x = frac-b pm sqrtb^2-4ac2a ]

You can probably work out how most of this createsthe formula but it wonrsquot be obvious that the [ and ]symbols that enclose the formula mean lsquotypeset this asa displayed formula giving it some vertical space fromthe surrounding textrsquo If wersquod used ( and ) insteadto enclose the formula it would appear in-line like thisx = minusbplusmn

radicb2minus4ac2a It still looks very nice and observe

how itrsquos automatically been resized to fit and that the

30

COMP10120 Report writing and Digital Typography

lines of text have had their spacing changed a bit Thisall looks simple but the implementation inside LATEXand TEX is complex It involves parsing the descrip-tion of the formula to create a corresponding tree datastructure which is then recursively walked to workout the horizontal and vertical typographical spacingsneeded Yoursquoll meet these ideas in COMP11120 andCOMP26120 Algorithms and Imperative Programming

Herersquos another example taken from COMP27112Computer Graphics (itrsquos a lsquosimplersquo local illuminationmodel incorporating ambient diffuse and specular re-flection by multiple lights)

I = kaIa +

Msumi=1

Ipidprimei[kd(N middot Li) + ks(Ri middot V )n]

We write this in LATEX as follows

[ I = k_a I_a + sum_i=1^M fracI_p_idrsquo_i [ k_d(hatN cdot hatL_i)+ k_s(hatR_i cdot hatV)^n] ]

Try to match the LATEX commands with the formula dis-played above Yoursquoll see lots of curly brackets and thisexample illustrates their two uses in LATEX The firstis to provide an argument to a command for exam-ple hatN means lsquoapply the hat command to N rsquowhich creates N the vector N with a little hat on

31

COMP10120 Report writing and Digital Typography

The second use of curly brackets is to group thingstogether to avoid ambiguities In the example you cansee sum_i=1^M which creates a summation signand its lower and upper limits

sumMi=1 We wrap the

lower bound i=1 in curly brackets to group it into anindivisible unit If we were to omit the brackets writ-ing sum_i=1^M LATEX would then produce

sumi = 1M

which is not at all what we want (even LATEX canrsquot al-ways know what we really want)

One final example If we tell LATEX

[ T_1 = left[beginarraycccccos theta amp -sin theta amp 0 amp delta sin theta amp cos theta amp 0 amp epsilon 0 amp 0 amp 1 amp eta alpha amp beta amp gamma amp 1endarrayright] ]

wersquoll get a splendid matrix which expresses a particu-lar 3D geometrical transformation (Donrsquot worry if youdonrsquot recognise this yoursquoll be introduced to matrix no-tation in the latter part of COMP11120 MathematicalTechniques for Computer Science For now you can justtreat it as some mysterious maths)

32

COMP10120 Report writing and Digital Typography

T1 =

cos θ minus sin θ 0 δ

sin θ cos θ 0 ε

0 0 1 η

α β γ 1

In the LATEX code left[means lsquobig opening square

bracket pleasersquo ccccmeans lsquoan array with 4 columnsplease with the items in each column centredrsquo ampmeanslsquostart a new columnrsquo and means lsquostart a new rowrsquoYoursquoll notice that LATEX knows about greek letters itknows about most standard maths symbols too andalso the ways theyrsquore usually used

There are some symbols that you might need (forexample therefore which produces the usual threedots symbol there4) that are not part of standard LATEX Manysuch symbols are provided by the amssymb package ofsymbols compiled by the American Mathematical Soci-ety Details of the many symbols provided by this pack-age can be found online at

mirrormathkuedutex-archivefontsamsfontsdocamssymbpdf

To use these extra symbols you need to have usepackageamssymbin the document preamble

33

COMP10120 Report writing and Digital Typography

341 A longer piece of mathematics

We conclude this section with an example of a longerpiece of mathematics that shows how you might type-set a complete mathematical argument rather than asingle formula The example is Euclidrsquos proof of thefact that

radic2 is irrational Itrsquos an argument that has been

covered in COMP11120 and is an example of proof bycontradiction It starts by making the assumption thatit is not the case that

radic2 is irrational in other words that

we can find integers p and q withradic2 = pq

We can assume without losing anything that p andq have no common factors (Why)

radic2 = pq

qradic2 = p

2q2 = p2

This means that p2 is even from which we can also de-duce that p is even (Why)

This means that p = 2k for some k so

2q2 = (2k)2

there4 2q2 = 4k2

so q2 = 2k2

But this means that q2 and hence q is even Since p andq are both even we have a contradiction to our initialassumption so no such p and q exist

The way this is formatted is shown here

34

COMP10120 Report writing and Digital Typography

It starts by making the assumption that it is emphnot the casethat $sqrt2$ is irrational in other words that we can findintegers $p$ and $q$ with $sqrt2 = pq$

We can assume without losing anything that $p$ and $q$ haveemphno common factors (Why)

[beginarraylcl

sqrt2 amp = amp pq qsqrt2 amp = amp p 2q^2 amp = amp p^2

endarray]

This means that $p^2$ is even from which we can also deduce that $p$is even (Why)

This means that $p = 2k$ for some $k$ so ldots[beginarrayllcl

amp 2q^2 amp = amp (2k)^2 therefore amp 2q^2 amp = amp 4k^2 textso amp q^2 amp = amp 2k^2

endarray]

But this means that $q^2$ and hence $q$ is even Since $p$ and $q$are both even we have a contradiction to our initial assumptionso no such $p$ and $q$ exist

Notice the use of the array environment for gettingthings lined up You can find much more informationabout this on the web

LATEX really shines at typesetting mathematics and

35

COMP10120 Report writing and Digital Typography

it would take pages and pages to describe all the fea-tures Have a look at

enwikibooksorgwikiLaTeXMathematics

for a flavour

Exercise 5 Formatting mathematics

Now for an exercise that involves some mathematicsPlease create a file f-wtex which typesets the follow-ing piece of text and mathematics

There are many positive integer solutions tothe equation

x2 + y2 = z2

which can be rewritten as

z =radicx2 + y2

For example (3 4 5) or (5 12 13) Such solu-tions are called Pythagorean triples

However for higher powers the situation isvery different and we have-

Theorem Fermat-WilesFor all natural numbers n ge 3 there are no

36

COMP10120 Report writing and Digital Typography

integers x y z satisfying the equation

xn + yn = zn

35 Curriculum vitaie

There are several scenarios where using LATEX ratherthan other word processing software can be useful

bull typesetting mathematics yoursquove just read about

bull writing a technical document

bull your final year project peport

bull writing an article you want to get published

bull writing a Curriculum vitae CV

Wersquoll now look at CVrsquos briefly

Exercise 6 Curriculum vitae

Creating a professional document is especially impor-tant when you write your CV because how your CVlooks (not just the content) will determine if you are in-vited to interview for job you are applying for Thatcould be a summer internship next year a year long

37

COMP10120 Report writing and Digital Typography

placement after your second year or graduate positionafter you leave University

As well using a text-editor and compiling files fromthe command line other tools are available for editingLATEXWe will look at one of these overleafcom

Create a basic CV which describes you your edu-cation (including University) and any experience youhave or interesting projects that you may have doneYou can do this using httpsoverleafcom andchoosing the ready-made templates at httpswwwoverleafcomgallerytaggedcv

As you progress through University it is a good ideato keep your CV up to date and get feedback from asmany people as you can There will be opportunities todebug your CV later (See httpgitiomycv if youare interested) but yoursquoll need a ldquobeta releaserdquo (version10) of your CV to get started The best time to start thisprocess is now

36 Some optional extras

Exercise 7 Exploring more LATEX features (op-tional but easy)

This exercise reinforces some of the things yoursquove donealready but also introduces some features of LATEX that

38

COMP10120 Report writing and Digital Typography

will be new to you It is labelled as optional because itisnrsquot marked but we would recommend that you all tryit

Take a copy of the file optinfocoursesCOMP10120ex3latex-introtexand follow the instructions it contains You should readit before you process it with LATEX

Exercise 8 A neat directory listing (optionalmore challenging)

The fact that LATEX source files are just text makes it easyto have them generated by a program You are going toexploit this and use LATEX to produce a neat documentcontaining a listing of the files in any directory

Find how to create tables in LATEX tables using thetabular environment Make a LATEX document by handthat uses a table to neatly show the information aboutthe files in some (small) directory (as produced by ls

-l) Write a shell script called neat-ls that takes anargument which is the path name of a directory andproduces a LATEX document containing the above tablefor the given directory The script could also process theLATEX and display the resulting pdf file Finally find outabout the longtable package and change your script touse that instead

39

COMP10120 Report writing and Digital Typography

Exercise 9 A cleaning rota (optional evenmore challenging)

Now you will write a shell script called make-rota thatgenerates a house cleaning rota (Very handy for nextyear ) This is a table with columns such as KitchenBathroom and Lounge The rows will be weeks in theyear labelled with a date (eg always a Sunday) Theidea is that house mates can write their initials in theboxes promising to clean the corresponding room inthat particular week Start by making a sample tableby hand

Your script should take a single argument which isthe date of the first day of the first row eg102013(the US format for 20 Oct 13) The result will be a docu-ment that contains as many rows as fit on a single page(find out by experimenting)

The dates of each row should be generated from thefirst See the manual page for date to figure out howyou can generate a date that is a number of weeks anddays later than an existing one

361 Marking Scheme

You can view a copy of the marking scheme used bysubmit and labprint at

40

COMP10120 Report writing and Digital Typography

studentnetcsmanchesteracukugtlpmsphpunit=COMP10120ampex=ex3xml

37 Next steps

LATEX is a very powerful tool and it does take a littlegetting used to But itrsquos not as scary as it might initiallyseem and you should find that it doesnrsquot take long tolearn the common commands and techniques to makeyour documents well-structured and readable As youbecome more comfortable with the basics and under-stand the principles of typesetting finding out how todo more complex and sophisticated things is easymdashthere are hundreds of tutorials on the web

Donrsquot get carried away though and use the featuresjudiciously just because yoursquove found a cool new com-mand doesnrsquot mean that you should use it just to showoff your LATEX skills content and structure always trumpstypographic twiddlings4

4For example footnotes like this are for some reason a really tempting fea-ture to use in LATEX and in this document we have abused them mercilessly toillustrate a point Footnotes were originally a means for mechanical typeset-ters to insert comments corrections or additions to existing documents withouthaving to adjust the layout of a whole page and of course in digital typographythis is no longer necessary They can justifiably be used for citations (though itrsquosnot common to do so these days) and URLs if you donrsquot want these intrudinginto the body of your text And in some very very rare cases they can be usedas an aside to the main flow of the text (which is what has been done in this doc-ument) But this should be used sparingly If something is important to sayput it in the main body of your text If itrsquos not then perhaps you should thinkabout leaving it out completely or find some other way of including it Asking

41

COMP10120 Report writing and Digital Typography

371 Acknowledgements

Figure 38 is from the Wikipedia article on cheese

372 License

The text of this exercise is licensed under the terms ofthe Creative Commons Attribution 20 Generic (CC BY30) License

38 Background

What follows is additional contextual information aroundLATEX

LATEX was originally written by Leslie LamportW anAmerican computer scientist now working at MicrosoftResearch although its development has long been takenover by a world-wide LATEX community Itrsquos actuallybuilt on top of another system called TEX a computertypesetting system designed by one of the worldrsquos mostinfluential Computer Scientists Donald KnuthW of Stan-ford University Knuth has said that he designed TEX

the reader to look down at the bottom of a page to find out whether somethingis important or not is irritating and as yoursquove probably found out already oftenmeans you lose track of your reading position They also give the impressionthat the author isnrsquot clear about whether something is important or not whichis never good And long footnotes like this onemdashwhile LATEX will typeset themperfectly wellmdashare just plain silly Best avoid

42

COMP10120 Report writing and Digital Typography

for lsquothe creation of beautiful booksmdashand especially forbooks that contain a lot of mathematicsrsquo(D Knuth1984) Figure 34 shows what these eminent men looklike

So whatrsquos the purpose of LATEX Itrsquos purely a layerof software to make TEX easier to use in everyday sit-uations This is a good idea because although TEX isamazingly powerful it operates at a very low-level whichmakes it hard for non-expert users

Figure 34Don Knuth and Leslie Lamport

381 Pronunciation

The name TEX is intended by its creator to be pronouncedwith the final consonant as in the word loch or the nameBach but English speakers often pronounce it like thefirst syllable of technical The first syllable of LATEX is

43

COMP10120 Report writing and Digital Typography

pronounced as in rsquolayrsquo5

382 Why LATEX

Before we go any further why do we think LATEX is im-portant for youmdasha Computer Science studentmdashto knowabout Here are some reasons in no particular order

bull LATEX and TEX are superb examples of ComputerScience in action TEX was designed by Knuth fromfirst principlesmdashin other words from scratch TEXis actually a programming language and LATEX isa set of functions defined in the TEX language TheTEX lsquocompilerrsquo is written in WEBW a mixture ofdocumentation written in TeX and a PascalW sub-set in order to ensure portability it reads a TEXprogram and outputs documents TEX is completelyself-contained and designed to be portable to anycomputer architecture For example it implementsits own stackW and heapW (with garbage collectionW)and it does fixed-precision arithmeticW donrsquot worryif these terms donrsquot make much sense to you at themoment they soon will

5The Greek prefix lsquotexrsquo means lsquoartrsquo as well as lsquotechnologyrsquo so itrsquos a very nicelychosen name for a piece of software that produces such beautiful output Knuthexplained (D Knuth 1984) that one should lsquopronounce the X of TeX as a Greekchi not as an lsquoxrsquo so that TeX rhymes with the word blecchhhrsquo Wersquore not toosure that helps much unless you are confident in your pronunciation of theword lsquoblecchhrsquo Maybe itrsquos an American thing

44

COMP10120 Report writing and Digital Typography

bull LATEX is a new interesting way for you to thinkabout preparing documents

bull LATEX has a practical advantage for the writer inthat it helps you think more about what you wantto write rather than worrying about how it looks

bull LATEX is a powerful tool for professional scientificdocumentation and as a Computer Scientist youshould know about it

bull LATEX files are just plain text so can easily be cre-ated programatically For example the slides usedfor COMP16120 are generated automatically fromthe source of Johnrsquos book both are typeset usingLATEX The program labprint also produces itsoutput using LATEX using information drawn fromXMLW configuration files and ARCADE

bull Using LATEX is actually quite satisfying and thequality of its output may surprise you

In this lab session you are going to write severalshort documents using LATEX You could also write briefnotes in your logbook about how LATEX works and whatcommands you used inside the source of your docu-ments

45

COMP10120 Report writing and Digital Typography

383 Some history printing mathematics

Mathematics is hard to print on paper and on the Web(many websites resort to GIF or JPG images of mathsformulae which usually look horrible MathMLW pro-vides another approach but it is not yet widely used)

In the days before computers books and newspa-pers were printed with movable typeW made from lotsof little blocks of metal each with letters numbers andsymbols standing in relief which when inked left animpression on the paper (see Figure 35) The job ofthe printer (the printer here of course being a personnot a bit of electronics) was to gather together all theblocks in the right order between two horizontal stripsof wood to create a line of the document and then toassemble all those lines from top to bottom of a pageThus the term type settingW an incredible task whenyou think about it In the printerrsquos workshop by theway the blocks of metal were stored between jobs inwooden boxes called cases Letters like a b and c werestored in one case letters like A B and C were storedin a case sitting on top of that So a lower case and anupper case These terms may ring a bell

As technology progressed machines controlled bytypewriters would mechanically juggle the blocks intothe right order This conceptual model is the basis onwhich TEX operates Only now the metal blocks are

46

COMP10120 Report writing and Digital Typography

Figure 35On the left a piece of cast movable type in the Garamondfont On the right a case of cast metal type pieces andtypeset matter in a composing stick The text reads lsquoThequick brown fox jumps over the lazy dog and feels as if hewere in the seventh heaven of typography together with Her-mann Zapf the most famous artist of thersquo This document istypeset in a font called Palatino created by Hermann ZapfYou may have also seen rsquoZapf Dingbatsrsquo in the font lists ofvarious desktop applications Now you know why

little pieces of data arranged into data structuresThe one thing that traditional printers hated was

dealing with the typesetting of mathematics and theywould charge extra to do it It was incredibly fiddly toget the equations looking right they had to squeeze inextra bits of metal horizontally and vertically

When computers entered the printing world attemptsto print mathematics were limited by the printing tech-nology available It took a long time to reach the pointwhere computers could typeset mathematics beautifullyand that was the outstanding achievement of Knuthrsquos

47

COMP10120 Report writing and Digital Typography

TEXLetrsquos look at a quick example of the quality you get

from LATEX with a very simple formula that yoursquoll recog-nise

x =minusbplusmn

radicb2 minus 4ac

2aWersquoll revisit how LATEX typesets mathematics in Section 34

384 To WYSIWYG or not to WYSIWYG

Up until now you have probably used wordprocessingapplications such as Microsoft Word to create essaysletters and other (probably fairly short) documents Youmost likely know that the majority of modern wordprocessors use a paradigm called WYSIWYG or WhatYou See Is What You Get which means that you canmodify the visual style of the document yoursquore work-ing on by selecting the relevant bits and then choos-ing different attributes such as font size or colour usinga GUI In many ways this seems like such a sensibleand obvious way of doing things that you might bewondering why it even has a special name The rea-son is a historical one in the early days of comput-ing long before graphical window managers becamethe norm and when all you could display on screenwas fixed-width ASCII text in whatever the systemrsquos

48

COMP10120 Report writing and Digital Typography

default font was wordprocessors (eg Figure 36) onlyallowed you to format documents by using special se-quences of characters to cause particular effects Butthese effects were only visible when the document wasprinted So if you wanted a word to appear in boldtext in the wordprocessor you might write somethinglike [bold]hello world[bold] what you saw onscreen was not a direct reflection of what appeared onthe printed page If yoursquove written any HTML how-ever this process of marking up text may be familiarsee for example Figure 37 As computers moved todisplays able to draw things other than raw charac-ters on screen wordprocessors became capable of us-ing multiple fonts and styles as well as graphics anda new generation of applications appeared where whatyou saw on screen was an accurate reflection of how itwould appear when printed what you see (on screen)is what you get (on paper)

The huge advantage of WYSIWYG is that itrsquos reallyeasy to understand whatrsquos going on and most peoplecan create reasonably nicely formatted documents withrelatively little effort For short informal documentsone-off letters memos and such WYSIWYG works quitenicely But if yoursquove ever tried writing anything muchlonger or that includes images and tables you mayhave already started to see where the paradigm breaksdown For example if you write lsquoFigure 38 on page

49

COMP10120 Report writing and Digital Typography

Figure 36A screenshot of Wordperfect 51 running in Microsoft DOScirca 1989

51 shows a picture of some men looking at cheesersquo butthen later on edit your document to include some moretext at the start and a new picture of a some broccoli(as in Figure 39) yoursquod have to search through yourreport to find all mentions of lsquoFigure 38rsquo and lsquopage 51rsquoand manually update them to reflect the new number-ing This might be fine if you have two figures and fivepages but for a hundred-page report containing lots ofpictures you can see how this becomes tedious and er-ror prone very quickly

50

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 3: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

These notes are available online atstudentnetcsmanchesteracukugtCOMP10120labscripts101lab3pdf

31 Introduction

LATEX is a document preparation system that is funda-mentally different to anything that you are likely to haveseen before Itrsquos used worldwide by publishers aca-demics and scientists and it happens to be very goodfor writing CVs too

32 Getting started

Please complete all the exercises in thislab in your COMP10120ex3 directory Whenyou have completed as much as youare going to do you should run submitand (when next in the School) labprint

Exercise 1 A closer look

Fire up your favourite editor enter the following text(itrsquos important that you enter it exactly as it is below fornow) and then save it as a file called fire-and-icetex

10

COMP10120 Report writing and Digital Typography

(in case yoursquore wondering itrsquos the first line from a shortpoem called lsquoFire and Icersquo by American poet RobertFrost (R Frost 1924) the whole poem is on the PoetryFoundation website if yoursquore interested)

documentclass[a4paper]articlebegindocumentSome say the world will end in fireenddocument

Next run the command pdflatex fire-and-icetex(for now itrsquos sufficient to say that pdflatex invokesLATEX to create a PDF file as the output the full story isa bit more complicated)

LATEX will process your file and print out a surpris-ingly large amount of text into the shell window as itdoes so If all is well the last two lines printed out willbe something like

Output written on fire-and-icepdf (1 page 11853 bytes)Transcript written on fire-and-icelog

after which LATEX will return you to the command promptIf yoursquove made a mistake typing in the file LATEX willstop part way through processing your work and dis-play an error (possibly quite an obscure one) and showa lsquorsquo prompt The best thing to do at this stage is to

11

COMP10120 Report writing and Digital Typography

press ltctrlgtd or x to tell LATEX to give up trying toprocess your file Then fix the mistake and try again

If you now list the directory contents you shouldsee that a file fire-and-icepdf has been created (alongwith two other files fire-and-iceaux and fire-and-icelog

both of which we will ignore for now) Use one of thePDF readers (such as evince

evince

) to look at the contentsof fire-and-icepdf Admittedly itrsquos not the most ex-citing result if everything has worked properly so faryou should see a single-page document with the wordslsquoSome say the world will end in firersquo a little way downfrom the top of the page1

But now look more closely A lot more closely reallyzoom in See anything interesting

Even for this very short document LATEX has taken afairly sophisticated typographical decision on your be-half and ligated (which is typography-speak for lsquojoinedrsquo)the lsquofrsquo and the lsquoirsquo in the word lsquofirersquo the spacing betweenthe characters has been subtly altered so that the dotabove the lsquoirsquo and the blob on the end of the curvy bit(the lsquoarc of the stemrsquo if wersquore being formal) on the topof the lsquofrsquo join together to form a single shape calleda ligature Why Because having two blobs side by

1If you have been carried away with the sheer excitement and joy of learningto use LATEX and improvised the text rather than typing the first line of lsquoFire andIcersquo as requested please go back and change it now it really is important thatyou use exactly that text Really it is Thatrsquos better Thanks

12

COMP10120 Report writing and Digital Typography

side simply looks a bit clumsy as you can see in Fig-ure 31 To make this decision LATEX has had to knowa lot about the fonts being used (not all lsquofrsquos in all fontshave a blobby end not all lsquoirsquos in all fonts have a rounddot that would merge nicely with the blobby bit on theend of an lsquofrsquo and so on) Therersquos a reasonable chancethat yoursquove never heard of ligated characters beforemdashit is after all a fairly specialist thing And there arehundreds of other obscure but important lsquorulesrsquo of ty-pography that go to make professionally typeset doc-uments look good2 Individually they might not beobvious or hugely important but collectively and sub-liminally they make the difference between somethingthat looks just-about-acceptable (like most things writ-ten using wordprocessors) and things that stand out aslooking really professional (you might want to remem-ber this when it comes to putting your CV together)

But thatrsquos enough about the typography of the wordlsquofirersquo for now Letrsquos put together something more sub-stantial

2Look up lsquokerningrsquo lsquocombining charactersrsquo and lsquoserifrsquo on Wikipedia forstarters And if yoursquore really keen Donald Knuthrsquos fascinating and compen-dious book lsquoDigital Typographyrsquo (D Knuth 1999) has an entire chapter dedi-cated to the joys of the letter lsquoSrsquo Probably best not to bring this subject up at thepub though or at parties Unless they are very specialist parties

13

COMP10120 Report writing and Digital Typography

Figure 31The word lsquofirersquo typeset by (a) Microsoft Word 2011 withoutligated characters and (b) by LATEX showing the ligation ofthe characters lsquofrsquo and lsquoirsquo

Exercise 2 A larger example

Create yourself a new file called sectionstex by copy-ing fire-and-icetex In sectionstex replace the lineof poetry by copying and pasting the text from Figure32 (which contains the first three paragraphs of Dick-ensrsquo novel lsquoBleak Housersquo (C Dickens 1852))

Edit the text to make sure that there is a blank linebetween each of the three paragraphs (itrsquos not enoughthat each paragraph starts on a new line of its ownthere has to be an empty line in between them) Thatrsquoshow paragraphs are distinguished in LATEX (in fact itdoesnrsquot matter how many blank lines you put as longas there is at least one for the most part LATEX ignoresspare whitespace) After the lsquoBleak Housersquo text typea paragraph of gibberish by randomly hitting keys onthe keyboard and putting spaces in to make lsquowordsrsquo inthe text file You should end up with something like thefollowing but about three times as long (donrsquot cut andpaste this from here itrsquos important that you actually

14

COMP10120 Report writing and Digital Typography

London Michaelmas term lately over and theLord Chancellor sitting in Lincolnrsquos Inn HallImplacable November weather As much mud inthe streets as if the waters had but newly retiredfrom the face of the earth and it would not bewonderful to meet a Megalosaurus forty feetlong or so waddling like an elephantine lizardup Holborn Hill Smoke lowering down fromchimney-pots making a soft black drizzle withflakes of soot in it as big as full-grownsnowflakesndashgone into mourning one mightimagine for the death of the sun Dogsundistinguishable in mire Horses scarcelybetter splashed to their very blinkers Footpassengers jostling one anotherrsquos umbrellas in ageneral infection of ill temper and losing theirfoot-hold at street-corners where tens ofthousands of other foot passengers have beenslipping and sliding since the day broke (if thisday ever broke) adding new deposits to the crustupon crust of mud sticking at those pointstenaciously to the pavement and accumulatingat compound interest

Fog everywhere Fog up the river where it flowsamong green aits and meadows fog down theriver where it rolls defiled among the tiers ofshipping and the waterside pollutions of a great(and dirty) city Fog on the Essex marshes fogon the Kentish heights Fog creeping into thecabooses of collier-brigs fog lying out on theyards and hovering in the rigging of great shipsfog drooping on the gunwales of barges andsmall boats Fog in the eyes and throats ofancient Greenwich pensioners wheezing by thefiresides of their wards fog in the stem and bowlof the afternoon pipe of the wrathful skipperdown in his close cabin fog cruelly pinching thetoes and fingers of his shivering little rsquoprenticeboy on deck Chance people on the bridgespeeping over the parapets into a nether sky offog with fog all round them as if they were upin a balloon and hanging in the misty clouds

Gas looming through the fog in divers places inthe streets much as the sun may from thespongey fields be seen to loom by husbandmanand ploughboy Most of the shops lighted twohours before their timemdashas the gas seems toknow for it has a haggard and unwilling look

Figure 32Some sample text from the opening of the Dickensrsquo novellsquoBleak Housersquo (C Dickens 1852)

15

COMP10120 Report writing and Digital Typography

create some unique gibberish yourself)

Oisjdf oqweqwe oi soijs hbweo kbsd oijsdfoijqwknpiouh iusbdfspb sifuhygwqeb usgweijfblimqwoq oieuerwefwiu aokqjw uioshiufdsqiqks odfubfi psdiweneq

Be careful at this stage to only include letters (upper-case and lowercase) commas full-stops and perhapsnumbers in your gibberish text if you use any othersymbols you may upset LATEX

Next go to the website wwwlipsumcom and fol-low the instructions to generate yourself three para-graphs of whatrsquos called Lorem Ipsum text Copy andpaste that text into your LATEX document too (donrsquot worryabout what it means at this stage) again making surethat you have a blank line between the paragraphs

Run pdflatex and look at the resulting sectionspdfAgain at first glance therersquos nothing hugely excitinggoing on here the text from your tex file has beenassembled into a (probably) two page PDF documentBut in fact quite a few things have happened

bull The blank lines that separate the paragraphs inyour source file are gone and instead LATEX hasindented the first line of each paragraph Therersquosnothing profound here about the decision to in-dent paragraphs rather than (say) to leave a gap

16

COMP10120 Report writing and Digital Typography

between them (so called block paragraphs) itrsquosjust LATEXrsquos default paragraph style and can bechanged easily enough3

bull There are page numbers at the bottom of each page(except page 1) This is a very sensible default al-lowing you in meetings to ask people to lsquoturn topage 4rsquo and so on (itrsquos a bit odd and a source ofsome annoyance that most wordprocessors donrsquotdo this by default too) But you can easily switchpage numbers off change their style or move themelsewhere if you need to

bull The text is fully justified so that itrsquos flush on boththe left and right hand edges

bull Certain words that fall at the end of lines havebeen hyphenated even if they werenrsquot originallysplit by hyphens in the source text

These last two points about justification and hyphen-ation might seem utterly trivial but getting these fac-tors right turns out to be an important part of mak-ing readable documents readability is not just aboutwhich font you choose but about how the charactersand spaces are distributed on each line Itrsquos something

3Though apparently there is some evidence in M A Tinker 1963 that in-dented paragraphs increase readability

17

COMP10120 Report writing and Digital Typography

that you will have seen happen so often in profession-ally typeset materials that yoursquoll have taken it for grantedand you may not have spotted that it doesnrsquot happenin quite the same way when you use a wordproces-sor The principle behind justifying text seems easyenough at first glance you simply have to take any lsquoleftoverrsquo space that would be at the end of a line and re-distribute it between the words in some way to lsquospacethem outrsquo a bit more so that they take up all the avail-able horizontal room But it turns out to be much harderthan it seems and all the simple ways you might thinkof for doing this on a per-line basis give results thatare visually quite unsatisfactory with nasty patternsmade up of neighbouring whitespace appearing in thelayout and ruining everything The added complica-tion here is that to do the optimum job of shuffling thewords round on their lines you really need the flex-ibility of being able to hyphenate words to give youextra space on lines that would otherwise be tightlypacked with characters But if you hyphenate wordsbadly by breaking them in inappropriate places or doit too often then that makes the text hard to read tooItrsquos all deeply inconvenient and inter-related The bestsolution to this aesthetic conundrum so far was devel-oped by Knuth and Plass 1981 and later improved byFrank Liang during his PhD research (F M Liang1983) and itrsquos a technique that tries to optimise the lay-

18

COMP10120 Report writing and Digital Typography

out of whole paragraphs rather than individual linesThe algorithm takes into account all manner of differ-ent things language-specific character patterns the num-ber of consecutive lines that end with hyphens the wordlsquotightnessrsquo on each line and many others The detailsdonrsquot really matter here but the really important in-sight is that you get better results by working on a big-ger chunk of the document (in this case a paragraph at atime) rather than trying to independently optimise lotsof small bits (say lines) and hoping that the result ofjoining them all together turns out nicely This idea ofoptimising things globally versus locally is somethingyoursquoll see many times throughout your Computer Sci-ence degree watch out for it in all the algorithms courses

This highlights a fundamental difference betweenthe WYSIWYG paradigm and the way that documentsare produced using LATEX As wersquove seen small changesdown at the level of individual characters can have fairlylarge knock-on consequences for the optimal layout ofa document changing one letter for another affects thelength of a line which in turn affects the hyphenationoptions which then affects the length of a paragraphwhich means that the best place for a figure that was onpage 99 might now be on page 100 but that means thatall references to lsquopage 99rsquo now need a bit more room toaccount for the extra digit which means that the someline lengths have changed which means well you get

19

COMP10120 Report writing and Digital Typography

the idea Itrsquos more complicated than it first seems LATEXgets to see the whole of your document at once and cantherefore make decisions about how best to hyphen-ate lines position figures or whatever else it likes beforeit shows you the results so it can make solutions thatare optimal for the whole document as well as lookingat details such as ligated characters Wordprocessorscanrsquot afford to do this since it would be deeply distract-ing if every time you typed a character the whole lay-out of the document flapped around in front of youreyes Wordprocessors can only sensibly make little op-timisations at a local (probably per-line level) Itrsquos notthat wordprocessors are rubbish or that the people thatprogrammed them were lazy itrsquos a fundamentally dif-ferent way of working and knowing the pros and consof the different approaches will help you pick the righttool for the job

You may have noticed that actual text in your doc-ument (and in fact this one) takes up a (perhaps) sur-prisingly narrow horizontal region of the page Thislast lsquofeaturersquo might seem odd at first but it illustratesanother important typographical point that you maynever have thought of before reading long lines of textis hard because your eyes find it hard to move in acompletely straight line as they scan from left to rightSo the longer the line of words the more you have towork to keep your eyes from accidentally drifting up or

20

COMP10120 Report writing and Digital Typography

down onto a neighbouring line (perhaps yoursquove expe-rienced the phenomenon of accidentally re-reading thesame line over and over as your eyes get tired) It maynever have occurred to you but most books have rela-tively short lines of text and those that use large pagesoften split text into several columns so that individuallines are kept relatively short The widely trusted booklsquoThe Elements of Typographic Stylersquo (R Bringhurst1992) makes the following assertion

lsquoAnything from 45 to 75 characters is widely-regarded as a satisfactory length of line for a single-column page set in a serifed text face in a text sizeThe 66-character line (counting both letters andspaces) is widely regarded as idealrsquo

LATEX knows about this issue so made a sensible de-fault decision for you You may have noticed that thereis a subtle difference in appearance of this chapter fromprevious ones the lines are shorter and paragraphs areindented We wanted to use the default LATEX layoutfor this chapter but changed it for earlier chapters inan effort to save paper

Therersquos one last unusual thing to note your para-graph of gibberish text in between the real words fromBleak House and the Lorem Ipsum almost certainly standsout and looks really quite odd (it might even have con-fused LATEXrsquos hyphenation rules enough to have ended

21

COMP10120 Report writing and Digital Typography

up with one or more lines sticking out proud of theright hand margin) Let your eyes relax so that yourvision blurs for a moment you can still probably spotthat the gibberish paragraph looks out of place Itrsquosquite likely that you even found creating the gibber-ish unexpectedly hard The interesting thing here isthat as humans we spend so much time reading andwriting lsquoproperrsquo natural language that we become at-tuned to the patterns of letters words and the underly-ing lsquorhythmrsquo of our written language that its very hardto artificially reproduce something that looks plausiblethe frequency of the letters you chose by randomly hit-ting keys and the length and patterns of the words youput in place most likely donrsquot match the natural pat-terns of real languages so they just look plain wrongCuriously the Lorem Ipsum text that you got from thewebsite probably doesnrsquot look so bad in spite of it notbeing made up of real words But thatrsquos not surprisingsince Lorem Ipsum is specifically created to be used asa placeholder for real text when typesetting While thewords are meaningless Latin-like things their lengthand the distribution of characters and word lengths arechosen to mimic patterns in real language

Next letrsquos give our document some structure by di-viding it up into sections On the line before BleakHouse starts add the command

22

COMP10120 Report writing and Digital Typography

sectionBleak House

making sure it appears on a line of its own Then justbefore your paragraph of gibberish put a similar in-struction (again on its own line) and then create a finalsection before the Lorem Ipsum Rerun pdflatex andlook at the results You should see the section headingsappear in the appropriate places in the PDF automati-cally having been given section numbers Experimentby adding in a couple of sub-sections towards the endof the document using the subsection commandwhich like the section command above takes as aparameter some text contained in curly brackets

Now at the top of your document after the begindocumentline and before the command defining the first sectionadd the following two commands each on their ownline

tableofcontentsnewpage

Re-run pdflatex twice and check that the effect is whatyoursquod expect You need to process the source twice be-cause on the first run LATEX gathers and stores informa-tion about what to put in the table of contents and onlycreates it on the second run

23

COMP10120 Report writing and Digital Typography

33 Common formatting features

Before we give you some more exercises to do here is abrief introduction to some commonly used features ofLATEX

331 Enumerated and bulleted lists

Creating bulleted or numbered lists in LATEX is straight-forward and is done like this

beginenumerateitem My first itemitem My second itemitem The last thing on my listendenumerate

You must make sure that you both begin and end yourlist and that each item is terminated by a newline Chang-ing enumerate to itemize gives you a bulleted ratherthan numbered list (note the American spelling of lsquoitem-izersquo)

332 Changing the appearance of text

Text can be typeset in bold font using the textbfin italics using textitand in a fixed-width fontusing texttt as in the example below

24

COMP10120 Report writing and Digital Typography

Some textttsay the textbfworld will end in textitfire

which is typeset as

Some say the world will end in fire

333 Cross referencing

LATEX allows you to cross-reference almost anything inthe document which includes sections sub-sections andfigures To use the cross-referencing feature you simplyinsert the command

labelmymarker

at the point in the document you want to refer to andthen use the command

refmymarker

when you want to use the reference Obviously youreplace the text mymarkerwith something more mean-ingful An important tip here is to call the marker some-thing that refers to the content of that part of the doc-ument and to avoid the temptation to use numbers(so donrsquot call your marker section1 instead call itintroduction if you reorder your document itrsquos stilllikely to be the introduction but it may no longer beSection 1) For example

25

COMP10120 Report writing and Digital Typography

sectionReflection on Welcome WeeklabelwelcomeweekI spent most of welcome week getting to know my wayaround campus I should have made more effort to joinsocieties I think I must remember to get to theStudentsrsquo Union and take a look around there

subsectionThings I enjoyedEverything so far has been wonderful with the caveat Imentioned in Section refwelcomeweek

subsectionThings I didnrsquot enjoyIrsquove discovered that I donrsquot like soggy chips

The really useful thing about cross-referencing in LATEXis that yoursquoll get warnings when you compile your doc-ument if cross-references are undefined or used incor-rectly This means you donrsquot have to manually checkevery reference in your document to make sure itrsquos stillright You do however have to run LATEX twice forsimilar reasons to those given above

334 Figures and pictures

Including figures and pictures in your document is easyYou do it like this

beginfigure

26

COMP10120 Report writing and Digital Typography

Figure 33Some men possibly Dutch looking at cheeses

centerlineincludegraphics[width=10cm]imagesmen-and-cheesejpgcaptionSome men possibly Dutch looking at cheeseslabelfiguremenandcheesesendfigure

which is the code we used to create Figure 38 You canprobably see whatrsquos happening The command includegraphicsgets your image which can be PDF PNG JPG GIF orPostScript The beginfigureendfigurecode lsquowrapsrsquo up whatever picture yoursquore including andallows LATEX to treat it as an unbreakable floating thingthat it will position for you as best it can in the docu-ment while maintaining an overall nice typographicallayout This floating of figures can sometimes result inthe figure ending up in a place you didnrsquot expect but inmost cases LATEX will make the most sensible choice Itrsquos

27

COMP10120 Report writing and Digital Typography

possible to employ finer control over figure placementbut thatrsquos beyond the scope of this introduction

The includegraphics command is not built into core LATEX but is in an additional package whichneeds to be explicitly loaded We load this package byusing the command usepackagegraphicx in thedocument preamble ie after the documentclasscommand but before begindocument There arehundreds of such packages that extend LATEXrsquos func-tionality the lab scripts you are reading now use over30 of them

Exercise 3 Including images

Create a document imagetex that contains some text(maybe from rsquoLorem Ipsumrsquo) together with a figurecontaining an image of your choice perhaps the oneyou made in Intro Lab 2 like Steversquos Mr Noodle Thereshould also be a reference to the figure in the text Youshould first use the program convert

convert

(check its manpage) to create a PDF version of the image

Exercise 4 A reflection on your studies

Your first proper LATEX document will be a very briefreflection on your studies so far

Write a hand-crafted LATEX document called courses-reflectiontex

28

COMP10120 Report writing and Digital Typography

(exact name as usual please otherwise submitwill notwork) It will have the following structure

1 A table of contents

2 A brief paragraph saying what the document isabout

3 A section appropriately titled for one of your courseunits containing

bull a brief paragraph saying what the unit is about

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the most about the unit

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the least about the unit

A repeat of item 3 for each other unit you are study-ing These sections should appear in alphabeticalorder by course code (eg COMP10120)

After completing and successfully compiling and view-ing your document you should spell-check it as fol-lows

ispell courses-reflectiontex

29

COMP10120 Report writing and Digital Typography

Once you are completely satisfied with it produce ahard copy ready for marking

34 Typesetting Mathematics

Earlier we saw this formula

x =minusbplusmn

radicb2 minus 4ac

2aIt looks nice doesnrsquot it To tell LATEX to display thisyou have to type a bit of magic but itrsquos easily-learnedmagic To create such a formula in a WYSIWYG edi-tor there is also magic involved but it usually involvesa lot of mouse-clicking and remembering special keycombinations like rsquocontrol-thisrsquo and rsquoalt-thatrsquo In LATEXit doesnrsquot You simply type this

[ x = frac-b pm sqrtb^2-4ac2a ]

You can probably work out how most of this createsthe formula but it wonrsquot be obvious that the [ and ]symbols that enclose the formula mean lsquotypeset this asa displayed formula giving it some vertical space fromthe surrounding textrsquo If wersquod used ( and ) insteadto enclose the formula it would appear in-line like thisx = minusbplusmn

radicb2minus4ac2a It still looks very nice and observe

how itrsquos automatically been resized to fit and that the

30

COMP10120 Report writing and Digital Typography

lines of text have had their spacing changed a bit Thisall looks simple but the implementation inside LATEXand TEX is complex It involves parsing the descrip-tion of the formula to create a corresponding tree datastructure which is then recursively walked to workout the horizontal and vertical typographical spacingsneeded Yoursquoll meet these ideas in COMP11120 andCOMP26120 Algorithms and Imperative Programming

Herersquos another example taken from COMP27112Computer Graphics (itrsquos a lsquosimplersquo local illuminationmodel incorporating ambient diffuse and specular re-flection by multiple lights)

I = kaIa +

Msumi=1

Ipidprimei[kd(N middot Li) + ks(Ri middot V )n]

We write this in LATEX as follows

[ I = k_a I_a + sum_i=1^M fracI_p_idrsquo_i [ k_d(hatN cdot hatL_i)+ k_s(hatR_i cdot hatV)^n] ]

Try to match the LATEX commands with the formula dis-played above Yoursquoll see lots of curly brackets and thisexample illustrates their two uses in LATEX The firstis to provide an argument to a command for exam-ple hatN means lsquoapply the hat command to N rsquowhich creates N the vector N with a little hat on

31

COMP10120 Report writing and Digital Typography

The second use of curly brackets is to group thingstogether to avoid ambiguities In the example you cansee sum_i=1^M which creates a summation signand its lower and upper limits

sumMi=1 We wrap the

lower bound i=1 in curly brackets to group it into anindivisible unit If we were to omit the brackets writ-ing sum_i=1^M LATEX would then produce

sumi = 1M

which is not at all what we want (even LATEX canrsquot al-ways know what we really want)

One final example If we tell LATEX

[ T_1 = left[beginarraycccccos theta amp -sin theta amp 0 amp delta sin theta amp cos theta amp 0 amp epsilon 0 amp 0 amp 1 amp eta alpha amp beta amp gamma amp 1endarrayright] ]

wersquoll get a splendid matrix which expresses a particu-lar 3D geometrical transformation (Donrsquot worry if youdonrsquot recognise this yoursquoll be introduced to matrix no-tation in the latter part of COMP11120 MathematicalTechniques for Computer Science For now you can justtreat it as some mysterious maths)

32

COMP10120 Report writing and Digital Typography

T1 =

cos θ minus sin θ 0 δ

sin θ cos θ 0 ε

0 0 1 η

α β γ 1

In the LATEX code left[means lsquobig opening square

bracket pleasersquo ccccmeans lsquoan array with 4 columnsplease with the items in each column centredrsquo ampmeanslsquostart a new columnrsquo and means lsquostart a new rowrsquoYoursquoll notice that LATEX knows about greek letters itknows about most standard maths symbols too andalso the ways theyrsquore usually used

There are some symbols that you might need (forexample therefore which produces the usual threedots symbol there4) that are not part of standard LATEX Manysuch symbols are provided by the amssymb package ofsymbols compiled by the American Mathematical Soci-ety Details of the many symbols provided by this pack-age can be found online at

mirrormathkuedutex-archivefontsamsfontsdocamssymbpdf

To use these extra symbols you need to have usepackageamssymbin the document preamble

33

COMP10120 Report writing and Digital Typography

341 A longer piece of mathematics

We conclude this section with an example of a longerpiece of mathematics that shows how you might type-set a complete mathematical argument rather than asingle formula The example is Euclidrsquos proof of thefact that

radic2 is irrational Itrsquos an argument that has been

covered in COMP11120 and is an example of proof bycontradiction It starts by making the assumption thatit is not the case that

radic2 is irrational in other words that

we can find integers p and q withradic2 = pq

We can assume without losing anything that p andq have no common factors (Why)

radic2 = pq

qradic2 = p

2q2 = p2

This means that p2 is even from which we can also de-duce that p is even (Why)

This means that p = 2k for some k so

2q2 = (2k)2

there4 2q2 = 4k2

so q2 = 2k2

But this means that q2 and hence q is even Since p andq are both even we have a contradiction to our initialassumption so no such p and q exist

The way this is formatted is shown here

34

COMP10120 Report writing and Digital Typography

It starts by making the assumption that it is emphnot the casethat $sqrt2$ is irrational in other words that we can findintegers $p$ and $q$ with $sqrt2 = pq$

We can assume without losing anything that $p$ and $q$ haveemphno common factors (Why)

[beginarraylcl

sqrt2 amp = amp pq qsqrt2 amp = amp p 2q^2 amp = amp p^2

endarray]

This means that $p^2$ is even from which we can also deduce that $p$is even (Why)

This means that $p = 2k$ for some $k$ so ldots[beginarrayllcl

amp 2q^2 amp = amp (2k)^2 therefore amp 2q^2 amp = amp 4k^2 textso amp q^2 amp = amp 2k^2

endarray]

But this means that $q^2$ and hence $q$ is even Since $p$ and $q$are both even we have a contradiction to our initial assumptionso no such $p$ and $q$ exist

Notice the use of the array environment for gettingthings lined up You can find much more informationabout this on the web

LATEX really shines at typesetting mathematics and

35

COMP10120 Report writing and Digital Typography

it would take pages and pages to describe all the fea-tures Have a look at

enwikibooksorgwikiLaTeXMathematics

for a flavour

Exercise 5 Formatting mathematics

Now for an exercise that involves some mathematicsPlease create a file f-wtex which typesets the follow-ing piece of text and mathematics

There are many positive integer solutions tothe equation

x2 + y2 = z2

which can be rewritten as

z =radicx2 + y2

For example (3 4 5) or (5 12 13) Such solu-tions are called Pythagorean triples

However for higher powers the situation isvery different and we have-

Theorem Fermat-WilesFor all natural numbers n ge 3 there are no

36

COMP10120 Report writing and Digital Typography

integers x y z satisfying the equation

xn + yn = zn

35 Curriculum vitaie

There are several scenarios where using LATEX ratherthan other word processing software can be useful

bull typesetting mathematics yoursquove just read about

bull writing a technical document

bull your final year project peport

bull writing an article you want to get published

bull writing a Curriculum vitae CV

Wersquoll now look at CVrsquos briefly

Exercise 6 Curriculum vitae

Creating a professional document is especially impor-tant when you write your CV because how your CVlooks (not just the content) will determine if you are in-vited to interview for job you are applying for Thatcould be a summer internship next year a year long

37

COMP10120 Report writing and Digital Typography

placement after your second year or graduate positionafter you leave University

As well using a text-editor and compiling files fromthe command line other tools are available for editingLATEXWe will look at one of these overleafcom

Create a basic CV which describes you your edu-cation (including University) and any experience youhave or interesting projects that you may have doneYou can do this using httpsoverleafcom andchoosing the ready-made templates at httpswwwoverleafcomgallerytaggedcv

As you progress through University it is a good ideato keep your CV up to date and get feedback from asmany people as you can There will be opportunities todebug your CV later (See httpgitiomycv if youare interested) but yoursquoll need a ldquobeta releaserdquo (version10) of your CV to get started The best time to start thisprocess is now

36 Some optional extras

Exercise 7 Exploring more LATEX features (op-tional but easy)

This exercise reinforces some of the things yoursquove donealready but also introduces some features of LATEX that

38

COMP10120 Report writing and Digital Typography

will be new to you It is labelled as optional because itisnrsquot marked but we would recommend that you all tryit

Take a copy of the file optinfocoursesCOMP10120ex3latex-introtexand follow the instructions it contains You should readit before you process it with LATEX

Exercise 8 A neat directory listing (optionalmore challenging)

The fact that LATEX source files are just text makes it easyto have them generated by a program You are going toexploit this and use LATEX to produce a neat documentcontaining a listing of the files in any directory

Find how to create tables in LATEX tables using thetabular environment Make a LATEX document by handthat uses a table to neatly show the information aboutthe files in some (small) directory (as produced by ls

-l) Write a shell script called neat-ls that takes anargument which is the path name of a directory andproduces a LATEX document containing the above tablefor the given directory The script could also process theLATEX and display the resulting pdf file Finally find outabout the longtable package and change your script touse that instead

39

COMP10120 Report writing and Digital Typography

Exercise 9 A cleaning rota (optional evenmore challenging)

Now you will write a shell script called make-rota thatgenerates a house cleaning rota (Very handy for nextyear ) This is a table with columns such as KitchenBathroom and Lounge The rows will be weeks in theyear labelled with a date (eg always a Sunday) Theidea is that house mates can write their initials in theboxes promising to clean the corresponding room inthat particular week Start by making a sample tableby hand

Your script should take a single argument which isthe date of the first day of the first row eg102013(the US format for 20 Oct 13) The result will be a docu-ment that contains as many rows as fit on a single page(find out by experimenting)

The dates of each row should be generated from thefirst See the manual page for date to figure out howyou can generate a date that is a number of weeks anddays later than an existing one

361 Marking Scheme

You can view a copy of the marking scheme used bysubmit and labprint at

40

COMP10120 Report writing and Digital Typography

studentnetcsmanchesteracukugtlpmsphpunit=COMP10120ampex=ex3xml

37 Next steps

LATEX is a very powerful tool and it does take a littlegetting used to But itrsquos not as scary as it might initiallyseem and you should find that it doesnrsquot take long tolearn the common commands and techniques to makeyour documents well-structured and readable As youbecome more comfortable with the basics and under-stand the principles of typesetting finding out how todo more complex and sophisticated things is easymdashthere are hundreds of tutorials on the web

Donrsquot get carried away though and use the featuresjudiciously just because yoursquove found a cool new com-mand doesnrsquot mean that you should use it just to showoff your LATEX skills content and structure always trumpstypographic twiddlings4

4For example footnotes like this are for some reason a really tempting fea-ture to use in LATEX and in this document we have abused them mercilessly toillustrate a point Footnotes were originally a means for mechanical typeset-ters to insert comments corrections or additions to existing documents withouthaving to adjust the layout of a whole page and of course in digital typographythis is no longer necessary They can justifiably be used for citations (though itrsquosnot common to do so these days) and URLs if you donrsquot want these intrudinginto the body of your text And in some very very rare cases they can be usedas an aside to the main flow of the text (which is what has been done in this doc-ument) But this should be used sparingly If something is important to sayput it in the main body of your text If itrsquos not then perhaps you should thinkabout leaving it out completely or find some other way of including it Asking

41

COMP10120 Report writing and Digital Typography

371 Acknowledgements

Figure 38 is from the Wikipedia article on cheese

372 License

The text of this exercise is licensed under the terms ofthe Creative Commons Attribution 20 Generic (CC BY30) License

38 Background

What follows is additional contextual information aroundLATEX

LATEX was originally written by Leslie LamportW anAmerican computer scientist now working at MicrosoftResearch although its development has long been takenover by a world-wide LATEX community Itrsquos actuallybuilt on top of another system called TEX a computertypesetting system designed by one of the worldrsquos mostinfluential Computer Scientists Donald KnuthW of Stan-ford University Knuth has said that he designed TEX

the reader to look down at the bottom of a page to find out whether somethingis important or not is irritating and as yoursquove probably found out already oftenmeans you lose track of your reading position They also give the impressionthat the author isnrsquot clear about whether something is important or not whichis never good And long footnotes like this onemdashwhile LATEX will typeset themperfectly wellmdashare just plain silly Best avoid

42

COMP10120 Report writing and Digital Typography

for lsquothe creation of beautiful booksmdashand especially forbooks that contain a lot of mathematicsrsquo(D Knuth1984) Figure 34 shows what these eminent men looklike

So whatrsquos the purpose of LATEX Itrsquos purely a layerof software to make TEX easier to use in everyday sit-uations This is a good idea because although TEX isamazingly powerful it operates at a very low-level whichmakes it hard for non-expert users

Figure 34Don Knuth and Leslie Lamport

381 Pronunciation

The name TEX is intended by its creator to be pronouncedwith the final consonant as in the word loch or the nameBach but English speakers often pronounce it like thefirst syllable of technical The first syllable of LATEX is

43

COMP10120 Report writing and Digital Typography

pronounced as in rsquolayrsquo5

382 Why LATEX

Before we go any further why do we think LATEX is im-portant for youmdasha Computer Science studentmdashto knowabout Here are some reasons in no particular order

bull LATEX and TEX are superb examples of ComputerScience in action TEX was designed by Knuth fromfirst principlesmdashin other words from scratch TEXis actually a programming language and LATEX isa set of functions defined in the TEX language TheTEX lsquocompilerrsquo is written in WEBW a mixture ofdocumentation written in TeX and a PascalW sub-set in order to ensure portability it reads a TEXprogram and outputs documents TEX is completelyself-contained and designed to be portable to anycomputer architecture For example it implementsits own stackW and heapW (with garbage collectionW)and it does fixed-precision arithmeticW donrsquot worryif these terms donrsquot make much sense to you at themoment they soon will

5The Greek prefix lsquotexrsquo means lsquoartrsquo as well as lsquotechnologyrsquo so itrsquos a very nicelychosen name for a piece of software that produces such beautiful output Knuthexplained (D Knuth 1984) that one should lsquopronounce the X of TeX as a Greekchi not as an lsquoxrsquo so that TeX rhymes with the word blecchhhrsquo Wersquore not toosure that helps much unless you are confident in your pronunciation of theword lsquoblecchhrsquo Maybe itrsquos an American thing

44

COMP10120 Report writing and Digital Typography

bull LATEX is a new interesting way for you to thinkabout preparing documents

bull LATEX has a practical advantage for the writer inthat it helps you think more about what you wantto write rather than worrying about how it looks

bull LATEX is a powerful tool for professional scientificdocumentation and as a Computer Scientist youshould know about it

bull LATEX files are just plain text so can easily be cre-ated programatically For example the slides usedfor COMP16120 are generated automatically fromthe source of Johnrsquos book both are typeset usingLATEX The program labprint also produces itsoutput using LATEX using information drawn fromXMLW configuration files and ARCADE

bull Using LATEX is actually quite satisfying and thequality of its output may surprise you

In this lab session you are going to write severalshort documents using LATEX You could also write briefnotes in your logbook about how LATEX works and whatcommands you used inside the source of your docu-ments

45

COMP10120 Report writing and Digital Typography

383 Some history printing mathematics

Mathematics is hard to print on paper and on the Web(many websites resort to GIF or JPG images of mathsformulae which usually look horrible MathMLW pro-vides another approach but it is not yet widely used)

In the days before computers books and newspa-pers were printed with movable typeW made from lotsof little blocks of metal each with letters numbers andsymbols standing in relief which when inked left animpression on the paper (see Figure 35) The job ofthe printer (the printer here of course being a personnot a bit of electronics) was to gather together all theblocks in the right order between two horizontal stripsof wood to create a line of the document and then toassemble all those lines from top to bottom of a pageThus the term type settingW an incredible task whenyou think about it In the printerrsquos workshop by theway the blocks of metal were stored between jobs inwooden boxes called cases Letters like a b and c werestored in one case letters like A B and C were storedin a case sitting on top of that So a lower case and anupper case These terms may ring a bell

As technology progressed machines controlled bytypewriters would mechanically juggle the blocks intothe right order This conceptual model is the basis onwhich TEX operates Only now the metal blocks are

46

COMP10120 Report writing and Digital Typography

Figure 35On the left a piece of cast movable type in the Garamondfont On the right a case of cast metal type pieces andtypeset matter in a composing stick The text reads lsquoThequick brown fox jumps over the lazy dog and feels as if hewere in the seventh heaven of typography together with Her-mann Zapf the most famous artist of thersquo This document istypeset in a font called Palatino created by Hermann ZapfYou may have also seen rsquoZapf Dingbatsrsquo in the font lists ofvarious desktop applications Now you know why

little pieces of data arranged into data structuresThe one thing that traditional printers hated was

dealing with the typesetting of mathematics and theywould charge extra to do it It was incredibly fiddly toget the equations looking right they had to squeeze inextra bits of metal horizontally and vertically

When computers entered the printing world attemptsto print mathematics were limited by the printing tech-nology available It took a long time to reach the pointwhere computers could typeset mathematics beautifullyand that was the outstanding achievement of Knuthrsquos

47

COMP10120 Report writing and Digital Typography

TEXLetrsquos look at a quick example of the quality you get

from LATEX with a very simple formula that yoursquoll recog-nise

x =minusbplusmn

radicb2 minus 4ac

2aWersquoll revisit how LATEX typesets mathematics in Section 34

384 To WYSIWYG or not to WYSIWYG

Up until now you have probably used wordprocessingapplications such as Microsoft Word to create essaysletters and other (probably fairly short) documents Youmost likely know that the majority of modern wordprocessors use a paradigm called WYSIWYG or WhatYou See Is What You Get which means that you canmodify the visual style of the document yoursquore work-ing on by selecting the relevant bits and then choos-ing different attributes such as font size or colour usinga GUI In many ways this seems like such a sensibleand obvious way of doing things that you might bewondering why it even has a special name The rea-son is a historical one in the early days of comput-ing long before graphical window managers becamethe norm and when all you could display on screenwas fixed-width ASCII text in whatever the systemrsquos

48

COMP10120 Report writing and Digital Typography

default font was wordprocessors (eg Figure 36) onlyallowed you to format documents by using special se-quences of characters to cause particular effects Butthese effects were only visible when the document wasprinted So if you wanted a word to appear in boldtext in the wordprocessor you might write somethinglike [bold]hello world[bold] what you saw onscreen was not a direct reflection of what appeared onthe printed page If yoursquove written any HTML how-ever this process of marking up text may be familiarsee for example Figure 37 As computers moved todisplays able to draw things other than raw charac-ters on screen wordprocessors became capable of us-ing multiple fonts and styles as well as graphics anda new generation of applications appeared where whatyou saw on screen was an accurate reflection of how itwould appear when printed what you see (on screen)is what you get (on paper)

The huge advantage of WYSIWYG is that itrsquos reallyeasy to understand whatrsquos going on and most peoplecan create reasonably nicely formatted documents withrelatively little effort For short informal documentsone-off letters memos and such WYSIWYG works quitenicely But if yoursquove ever tried writing anything muchlonger or that includes images and tables you mayhave already started to see where the paradigm breaksdown For example if you write lsquoFigure 38 on page

49

COMP10120 Report writing and Digital Typography

Figure 36A screenshot of Wordperfect 51 running in Microsoft DOScirca 1989

51 shows a picture of some men looking at cheesersquo butthen later on edit your document to include some moretext at the start and a new picture of a some broccoli(as in Figure 39) yoursquod have to search through yourreport to find all mentions of lsquoFigure 38rsquo and lsquopage 51rsquoand manually update them to reflect the new number-ing This might be fine if you have two figures and fivepages but for a hundred-page report containing lots ofpictures you can see how this becomes tedious and er-ror prone very quickly

50

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 4: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

(in case yoursquore wondering itrsquos the first line from a shortpoem called lsquoFire and Icersquo by American poet RobertFrost (R Frost 1924) the whole poem is on the PoetryFoundation website if yoursquore interested)

documentclass[a4paper]articlebegindocumentSome say the world will end in fireenddocument

Next run the command pdflatex fire-and-icetex(for now itrsquos sufficient to say that pdflatex invokesLATEX to create a PDF file as the output the full story isa bit more complicated)

LATEX will process your file and print out a surpris-ingly large amount of text into the shell window as itdoes so If all is well the last two lines printed out willbe something like

Output written on fire-and-icepdf (1 page 11853 bytes)Transcript written on fire-and-icelog

after which LATEX will return you to the command promptIf yoursquove made a mistake typing in the file LATEX willstop part way through processing your work and dis-play an error (possibly quite an obscure one) and showa lsquorsquo prompt The best thing to do at this stage is to

11

COMP10120 Report writing and Digital Typography

press ltctrlgtd or x to tell LATEX to give up trying toprocess your file Then fix the mistake and try again

If you now list the directory contents you shouldsee that a file fire-and-icepdf has been created (alongwith two other files fire-and-iceaux and fire-and-icelog

both of which we will ignore for now) Use one of thePDF readers (such as evince

evince

) to look at the contentsof fire-and-icepdf Admittedly itrsquos not the most ex-citing result if everything has worked properly so faryou should see a single-page document with the wordslsquoSome say the world will end in firersquo a little way downfrom the top of the page1

But now look more closely A lot more closely reallyzoom in See anything interesting

Even for this very short document LATEX has taken afairly sophisticated typographical decision on your be-half and ligated (which is typography-speak for lsquojoinedrsquo)the lsquofrsquo and the lsquoirsquo in the word lsquofirersquo the spacing betweenthe characters has been subtly altered so that the dotabove the lsquoirsquo and the blob on the end of the curvy bit(the lsquoarc of the stemrsquo if wersquore being formal) on the topof the lsquofrsquo join together to form a single shape calleda ligature Why Because having two blobs side by

1If you have been carried away with the sheer excitement and joy of learningto use LATEX and improvised the text rather than typing the first line of lsquoFire andIcersquo as requested please go back and change it now it really is important thatyou use exactly that text Really it is Thatrsquos better Thanks

12

COMP10120 Report writing and Digital Typography

side simply looks a bit clumsy as you can see in Fig-ure 31 To make this decision LATEX has had to knowa lot about the fonts being used (not all lsquofrsquos in all fontshave a blobby end not all lsquoirsquos in all fonts have a rounddot that would merge nicely with the blobby bit on theend of an lsquofrsquo and so on) Therersquos a reasonable chancethat yoursquove never heard of ligated characters beforemdashit is after all a fairly specialist thing And there arehundreds of other obscure but important lsquorulesrsquo of ty-pography that go to make professionally typeset doc-uments look good2 Individually they might not beobvious or hugely important but collectively and sub-liminally they make the difference between somethingthat looks just-about-acceptable (like most things writ-ten using wordprocessors) and things that stand out aslooking really professional (you might want to remem-ber this when it comes to putting your CV together)

But thatrsquos enough about the typography of the wordlsquofirersquo for now Letrsquos put together something more sub-stantial

2Look up lsquokerningrsquo lsquocombining charactersrsquo and lsquoserifrsquo on Wikipedia forstarters And if yoursquore really keen Donald Knuthrsquos fascinating and compen-dious book lsquoDigital Typographyrsquo (D Knuth 1999) has an entire chapter dedi-cated to the joys of the letter lsquoSrsquo Probably best not to bring this subject up at thepub though or at parties Unless they are very specialist parties

13

COMP10120 Report writing and Digital Typography

Figure 31The word lsquofirersquo typeset by (a) Microsoft Word 2011 withoutligated characters and (b) by LATEX showing the ligation ofthe characters lsquofrsquo and lsquoirsquo

Exercise 2 A larger example

Create yourself a new file called sectionstex by copy-ing fire-and-icetex In sectionstex replace the lineof poetry by copying and pasting the text from Figure32 (which contains the first three paragraphs of Dick-ensrsquo novel lsquoBleak Housersquo (C Dickens 1852))

Edit the text to make sure that there is a blank linebetween each of the three paragraphs (itrsquos not enoughthat each paragraph starts on a new line of its ownthere has to be an empty line in between them) Thatrsquoshow paragraphs are distinguished in LATEX (in fact itdoesnrsquot matter how many blank lines you put as longas there is at least one for the most part LATEX ignoresspare whitespace) After the lsquoBleak Housersquo text typea paragraph of gibberish by randomly hitting keys onthe keyboard and putting spaces in to make lsquowordsrsquo inthe text file You should end up with something like thefollowing but about three times as long (donrsquot cut andpaste this from here itrsquos important that you actually

14

COMP10120 Report writing and Digital Typography

London Michaelmas term lately over and theLord Chancellor sitting in Lincolnrsquos Inn HallImplacable November weather As much mud inthe streets as if the waters had but newly retiredfrom the face of the earth and it would not bewonderful to meet a Megalosaurus forty feetlong or so waddling like an elephantine lizardup Holborn Hill Smoke lowering down fromchimney-pots making a soft black drizzle withflakes of soot in it as big as full-grownsnowflakesndashgone into mourning one mightimagine for the death of the sun Dogsundistinguishable in mire Horses scarcelybetter splashed to their very blinkers Footpassengers jostling one anotherrsquos umbrellas in ageneral infection of ill temper and losing theirfoot-hold at street-corners where tens ofthousands of other foot passengers have beenslipping and sliding since the day broke (if thisday ever broke) adding new deposits to the crustupon crust of mud sticking at those pointstenaciously to the pavement and accumulatingat compound interest

Fog everywhere Fog up the river where it flowsamong green aits and meadows fog down theriver where it rolls defiled among the tiers ofshipping and the waterside pollutions of a great(and dirty) city Fog on the Essex marshes fogon the Kentish heights Fog creeping into thecabooses of collier-brigs fog lying out on theyards and hovering in the rigging of great shipsfog drooping on the gunwales of barges andsmall boats Fog in the eyes and throats ofancient Greenwich pensioners wheezing by thefiresides of their wards fog in the stem and bowlof the afternoon pipe of the wrathful skipperdown in his close cabin fog cruelly pinching thetoes and fingers of his shivering little rsquoprenticeboy on deck Chance people on the bridgespeeping over the parapets into a nether sky offog with fog all round them as if they were upin a balloon and hanging in the misty clouds

Gas looming through the fog in divers places inthe streets much as the sun may from thespongey fields be seen to loom by husbandmanand ploughboy Most of the shops lighted twohours before their timemdashas the gas seems toknow for it has a haggard and unwilling look

Figure 32Some sample text from the opening of the Dickensrsquo novellsquoBleak Housersquo (C Dickens 1852)

15

COMP10120 Report writing and Digital Typography

create some unique gibberish yourself)

Oisjdf oqweqwe oi soijs hbweo kbsd oijsdfoijqwknpiouh iusbdfspb sifuhygwqeb usgweijfblimqwoq oieuerwefwiu aokqjw uioshiufdsqiqks odfubfi psdiweneq

Be careful at this stage to only include letters (upper-case and lowercase) commas full-stops and perhapsnumbers in your gibberish text if you use any othersymbols you may upset LATEX

Next go to the website wwwlipsumcom and fol-low the instructions to generate yourself three para-graphs of whatrsquos called Lorem Ipsum text Copy andpaste that text into your LATEX document too (donrsquot worryabout what it means at this stage) again making surethat you have a blank line between the paragraphs

Run pdflatex and look at the resulting sectionspdfAgain at first glance therersquos nothing hugely excitinggoing on here the text from your tex file has beenassembled into a (probably) two page PDF documentBut in fact quite a few things have happened

bull The blank lines that separate the paragraphs inyour source file are gone and instead LATEX hasindented the first line of each paragraph Therersquosnothing profound here about the decision to in-dent paragraphs rather than (say) to leave a gap

16

COMP10120 Report writing and Digital Typography

between them (so called block paragraphs) itrsquosjust LATEXrsquos default paragraph style and can bechanged easily enough3

bull There are page numbers at the bottom of each page(except page 1) This is a very sensible default al-lowing you in meetings to ask people to lsquoturn topage 4rsquo and so on (itrsquos a bit odd and a source ofsome annoyance that most wordprocessors donrsquotdo this by default too) But you can easily switchpage numbers off change their style or move themelsewhere if you need to

bull The text is fully justified so that itrsquos flush on boththe left and right hand edges

bull Certain words that fall at the end of lines havebeen hyphenated even if they werenrsquot originallysplit by hyphens in the source text

These last two points about justification and hyphen-ation might seem utterly trivial but getting these fac-tors right turns out to be an important part of mak-ing readable documents readability is not just aboutwhich font you choose but about how the charactersand spaces are distributed on each line Itrsquos something

3Though apparently there is some evidence in M A Tinker 1963 that in-dented paragraphs increase readability

17

COMP10120 Report writing and Digital Typography

that you will have seen happen so often in profession-ally typeset materials that yoursquoll have taken it for grantedand you may not have spotted that it doesnrsquot happenin quite the same way when you use a wordproces-sor The principle behind justifying text seems easyenough at first glance you simply have to take any lsquoleftoverrsquo space that would be at the end of a line and re-distribute it between the words in some way to lsquospacethem outrsquo a bit more so that they take up all the avail-able horizontal room But it turns out to be much harderthan it seems and all the simple ways you might thinkof for doing this on a per-line basis give results thatare visually quite unsatisfactory with nasty patternsmade up of neighbouring whitespace appearing in thelayout and ruining everything The added complica-tion here is that to do the optimum job of shuffling thewords round on their lines you really need the flex-ibility of being able to hyphenate words to give youextra space on lines that would otherwise be tightlypacked with characters But if you hyphenate wordsbadly by breaking them in inappropriate places or doit too often then that makes the text hard to read tooItrsquos all deeply inconvenient and inter-related The bestsolution to this aesthetic conundrum so far was devel-oped by Knuth and Plass 1981 and later improved byFrank Liang during his PhD research (F M Liang1983) and itrsquos a technique that tries to optimise the lay-

18

COMP10120 Report writing and Digital Typography

out of whole paragraphs rather than individual linesThe algorithm takes into account all manner of differ-ent things language-specific character patterns the num-ber of consecutive lines that end with hyphens the wordlsquotightnessrsquo on each line and many others The detailsdonrsquot really matter here but the really important in-sight is that you get better results by working on a big-ger chunk of the document (in this case a paragraph at atime) rather than trying to independently optimise lotsof small bits (say lines) and hoping that the result ofjoining them all together turns out nicely This idea ofoptimising things globally versus locally is somethingyoursquoll see many times throughout your Computer Sci-ence degree watch out for it in all the algorithms courses

This highlights a fundamental difference betweenthe WYSIWYG paradigm and the way that documentsare produced using LATEX As wersquove seen small changesdown at the level of individual characters can have fairlylarge knock-on consequences for the optimal layout ofa document changing one letter for another affects thelength of a line which in turn affects the hyphenationoptions which then affects the length of a paragraphwhich means that the best place for a figure that was onpage 99 might now be on page 100 but that means thatall references to lsquopage 99rsquo now need a bit more room toaccount for the extra digit which means that the someline lengths have changed which means well you get

19

COMP10120 Report writing and Digital Typography

the idea Itrsquos more complicated than it first seems LATEXgets to see the whole of your document at once and cantherefore make decisions about how best to hyphen-ate lines position figures or whatever else it likes beforeit shows you the results so it can make solutions thatare optimal for the whole document as well as lookingat details such as ligated characters Wordprocessorscanrsquot afford to do this since it would be deeply distract-ing if every time you typed a character the whole lay-out of the document flapped around in front of youreyes Wordprocessors can only sensibly make little op-timisations at a local (probably per-line level) Itrsquos notthat wordprocessors are rubbish or that the people thatprogrammed them were lazy itrsquos a fundamentally dif-ferent way of working and knowing the pros and consof the different approaches will help you pick the righttool for the job

You may have noticed that actual text in your doc-ument (and in fact this one) takes up a (perhaps) sur-prisingly narrow horizontal region of the page Thislast lsquofeaturersquo might seem odd at first but it illustratesanother important typographical point that you maynever have thought of before reading long lines of textis hard because your eyes find it hard to move in acompletely straight line as they scan from left to rightSo the longer the line of words the more you have towork to keep your eyes from accidentally drifting up or

20

COMP10120 Report writing and Digital Typography

down onto a neighbouring line (perhaps yoursquove expe-rienced the phenomenon of accidentally re-reading thesame line over and over as your eyes get tired) It maynever have occurred to you but most books have rela-tively short lines of text and those that use large pagesoften split text into several columns so that individuallines are kept relatively short The widely trusted booklsquoThe Elements of Typographic Stylersquo (R Bringhurst1992) makes the following assertion

lsquoAnything from 45 to 75 characters is widely-regarded as a satisfactory length of line for a single-column page set in a serifed text face in a text sizeThe 66-character line (counting both letters andspaces) is widely regarded as idealrsquo

LATEX knows about this issue so made a sensible de-fault decision for you You may have noticed that thereis a subtle difference in appearance of this chapter fromprevious ones the lines are shorter and paragraphs areindented We wanted to use the default LATEX layoutfor this chapter but changed it for earlier chapters inan effort to save paper

Therersquos one last unusual thing to note your para-graph of gibberish text in between the real words fromBleak House and the Lorem Ipsum almost certainly standsout and looks really quite odd (it might even have con-fused LATEXrsquos hyphenation rules enough to have ended

21

COMP10120 Report writing and Digital Typography

up with one or more lines sticking out proud of theright hand margin) Let your eyes relax so that yourvision blurs for a moment you can still probably spotthat the gibberish paragraph looks out of place Itrsquosquite likely that you even found creating the gibber-ish unexpectedly hard The interesting thing here isthat as humans we spend so much time reading andwriting lsquoproperrsquo natural language that we become at-tuned to the patterns of letters words and the underly-ing lsquorhythmrsquo of our written language that its very hardto artificially reproduce something that looks plausiblethe frequency of the letters you chose by randomly hit-ting keys and the length and patterns of the words youput in place most likely donrsquot match the natural pat-terns of real languages so they just look plain wrongCuriously the Lorem Ipsum text that you got from thewebsite probably doesnrsquot look so bad in spite of it notbeing made up of real words But thatrsquos not surprisingsince Lorem Ipsum is specifically created to be used asa placeholder for real text when typesetting While thewords are meaningless Latin-like things their lengthand the distribution of characters and word lengths arechosen to mimic patterns in real language

Next letrsquos give our document some structure by di-viding it up into sections On the line before BleakHouse starts add the command

22

COMP10120 Report writing and Digital Typography

sectionBleak House

making sure it appears on a line of its own Then justbefore your paragraph of gibberish put a similar in-struction (again on its own line) and then create a finalsection before the Lorem Ipsum Rerun pdflatex andlook at the results You should see the section headingsappear in the appropriate places in the PDF automati-cally having been given section numbers Experimentby adding in a couple of sub-sections towards the endof the document using the subsection commandwhich like the section command above takes as aparameter some text contained in curly brackets

Now at the top of your document after the begindocumentline and before the command defining the first sectionadd the following two commands each on their ownline

tableofcontentsnewpage

Re-run pdflatex twice and check that the effect is whatyoursquod expect You need to process the source twice be-cause on the first run LATEX gathers and stores informa-tion about what to put in the table of contents and onlycreates it on the second run

23

COMP10120 Report writing and Digital Typography

33 Common formatting features

Before we give you some more exercises to do here is abrief introduction to some commonly used features ofLATEX

331 Enumerated and bulleted lists

Creating bulleted or numbered lists in LATEX is straight-forward and is done like this

beginenumerateitem My first itemitem My second itemitem The last thing on my listendenumerate

You must make sure that you both begin and end yourlist and that each item is terminated by a newline Chang-ing enumerate to itemize gives you a bulleted ratherthan numbered list (note the American spelling of lsquoitem-izersquo)

332 Changing the appearance of text

Text can be typeset in bold font using the textbfin italics using textitand in a fixed-width fontusing texttt as in the example below

24

COMP10120 Report writing and Digital Typography

Some textttsay the textbfworld will end in textitfire

which is typeset as

Some say the world will end in fire

333 Cross referencing

LATEX allows you to cross-reference almost anything inthe document which includes sections sub-sections andfigures To use the cross-referencing feature you simplyinsert the command

labelmymarker

at the point in the document you want to refer to andthen use the command

refmymarker

when you want to use the reference Obviously youreplace the text mymarkerwith something more mean-ingful An important tip here is to call the marker some-thing that refers to the content of that part of the doc-ument and to avoid the temptation to use numbers(so donrsquot call your marker section1 instead call itintroduction if you reorder your document itrsquos stilllikely to be the introduction but it may no longer beSection 1) For example

25

COMP10120 Report writing and Digital Typography

sectionReflection on Welcome WeeklabelwelcomeweekI spent most of welcome week getting to know my wayaround campus I should have made more effort to joinsocieties I think I must remember to get to theStudentsrsquo Union and take a look around there

subsectionThings I enjoyedEverything so far has been wonderful with the caveat Imentioned in Section refwelcomeweek

subsectionThings I didnrsquot enjoyIrsquove discovered that I donrsquot like soggy chips

The really useful thing about cross-referencing in LATEXis that yoursquoll get warnings when you compile your doc-ument if cross-references are undefined or used incor-rectly This means you donrsquot have to manually checkevery reference in your document to make sure itrsquos stillright You do however have to run LATEX twice forsimilar reasons to those given above

334 Figures and pictures

Including figures and pictures in your document is easyYou do it like this

beginfigure

26

COMP10120 Report writing and Digital Typography

Figure 33Some men possibly Dutch looking at cheeses

centerlineincludegraphics[width=10cm]imagesmen-and-cheesejpgcaptionSome men possibly Dutch looking at cheeseslabelfiguremenandcheesesendfigure

which is the code we used to create Figure 38 You canprobably see whatrsquos happening The command includegraphicsgets your image which can be PDF PNG JPG GIF orPostScript The beginfigureendfigurecode lsquowrapsrsquo up whatever picture yoursquore including andallows LATEX to treat it as an unbreakable floating thingthat it will position for you as best it can in the docu-ment while maintaining an overall nice typographicallayout This floating of figures can sometimes result inthe figure ending up in a place you didnrsquot expect but inmost cases LATEX will make the most sensible choice Itrsquos

27

COMP10120 Report writing and Digital Typography

possible to employ finer control over figure placementbut thatrsquos beyond the scope of this introduction

The includegraphics command is not built into core LATEX but is in an additional package whichneeds to be explicitly loaded We load this package byusing the command usepackagegraphicx in thedocument preamble ie after the documentclasscommand but before begindocument There arehundreds of such packages that extend LATEXrsquos func-tionality the lab scripts you are reading now use over30 of them

Exercise 3 Including images

Create a document imagetex that contains some text(maybe from rsquoLorem Ipsumrsquo) together with a figurecontaining an image of your choice perhaps the oneyou made in Intro Lab 2 like Steversquos Mr Noodle Thereshould also be a reference to the figure in the text Youshould first use the program convert

convert

(check its manpage) to create a PDF version of the image

Exercise 4 A reflection on your studies

Your first proper LATEX document will be a very briefreflection on your studies so far

Write a hand-crafted LATEX document called courses-reflectiontex

28

COMP10120 Report writing and Digital Typography

(exact name as usual please otherwise submitwill notwork) It will have the following structure

1 A table of contents

2 A brief paragraph saying what the document isabout

3 A section appropriately titled for one of your courseunits containing

bull a brief paragraph saying what the unit is about

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the most about the unit

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the least about the unit

A repeat of item 3 for each other unit you are study-ing These sections should appear in alphabeticalorder by course code (eg COMP10120)

After completing and successfully compiling and view-ing your document you should spell-check it as fol-lows

ispell courses-reflectiontex

29

COMP10120 Report writing and Digital Typography

Once you are completely satisfied with it produce ahard copy ready for marking

34 Typesetting Mathematics

Earlier we saw this formula

x =minusbplusmn

radicb2 minus 4ac

2aIt looks nice doesnrsquot it To tell LATEX to display thisyou have to type a bit of magic but itrsquos easily-learnedmagic To create such a formula in a WYSIWYG edi-tor there is also magic involved but it usually involvesa lot of mouse-clicking and remembering special keycombinations like rsquocontrol-thisrsquo and rsquoalt-thatrsquo In LATEXit doesnrsquot You simply type this

[ x = frac-b pm sqrtb^2-4ac2a ]

You can probably work out how most of this createsthe formula but it wonrsquot be obvious that the [ and ]symbols that enclose the formula mean lsquotypeset this asa displayed formula giving it some vertical space fromthe surrounding textrsquo If wersquod used ( and ) insteadto enclose the formula it would appear in-line like thisx = minusbplusmn

radicb2minus4ac2a It still looks very nice and observe

how itrsquos automatically been resized to fit and that the

30

COMP10120 Report writing and Digital Typography

lines of text have had their spacing changed a bit Thisall looks simple but the implementation inside LATEXand TEX is complex It involves parsing the descrip-tion of the formula to create a corresponding tree datastructure which is then recursively walked to workout the horizontal and vertical typographical spacingsneeded Yoursquoll meet these ideas in COMP11120 andCOMP26120 Algorithms and Imperative Programming

Herersquos another example taken from COMP27112Computer Graphics (itrsquos a lsquosimplersquo local illuminationmodel incorporating ambient diffuse and specular re-flection by multiple lights)

I = kaIa +

Msumi=1

Ipidprimei[kd(N middot Li) + ks(Ri middot V )n]

We write this in LATEX as follows

[ I = k_a I_a + sum_i=1^M fracI_p_idrsquo_i [ k_d(hatN cdot hatL_i)+ k_s(hatR_i cdot hatV)^n] ]

Try to match the LATEX commands with the formula dis-played above Yoursquoll see lots of curly brackets and thisexample illustrates their two uses in LATEX The firstis to provide an argument to a command for exam-ple hatN means lsquoapply the hat command to N rsquowhich creates N the vector N with a little hat on

31

COMP10120 Report writing and Digital Typography

The second use of curly brackets is to group thingstogether to avoid ambiguities In the example you cansee sum_i=1^M which creates a summation signand its lower and upper limits

sumMi=1 We wrap the

lower bound i=1 in curly brackets to group it into anindivisible unit If we were to omit the brackets writ-ing sum_i=1^M LATEX would then produce

sumi = 1M

which is not at all what we want (even LATEX canrsquot al-ways know what we really want)

One final example If we tell LATEX

[ T_1 = left[beginarraycccccos theta amp -sin theta amp 0 amp delta sin theta amp cos theta amp 0 amp epsilon 0 amp 0 amp 1 amp eta alpha amp beta amp gamma amp 1endarrayright] ]

wersquoll get a splendid matrix which expresses a particu-lar 3D geometrical transformation (Donrsquot worry if youdonrsquot recognise this yoursquoll be introduced to matrix no-tation in the latter part of COMP11120 MathematicalTechniques for Computer Science For now you can justtreat it as some mysterious maths)

32

COMP10120 Report writing and Digital Typography

T1 =

cos θ minus sin θ 0 δ

sin θ cos θ 0 ε

0 0 1 η

α β γ 1

In the LATEX code left[means lsquobig opening square

bracket pleasersquo ccccmeans lsquoan array with 4 columnsplease with the items in each column centredrsquo ampmeanslsquostart a new columnrsquo and means lsquostart a new rowrsquoYoursquoll notice that LATEX knows about greek letters itknows about most standard maths symbols too andalso the ways theyrsquore usually used

There are some symbols that you might need (forexample therefore which produces the usual threedots symbol there4) that are not part of standard LATEX Manysuch symbols are provided by the amssymb package ofsymbols compiled by the American Mathematical Soci-ety Details of the many symbols provided by this pack-age can be found online at

mirrormathkuedutex-archivefontsamsfontsdocamssymbpdf

To use these extra symbols you need to have usepackageamssymbin the document preamble

33

COMP10120 Report writing and Digital Typography

341 A longer piece of mathematics

We conclude this section with an example of a longerpiece of mathematics that shows how you might type-set a complete mathematical argument rather than asingle formula The example is Euclidrsquos proof of thefact that

radic2 is irrational Itrsquos an argument that has been

covered in COMP11120 and is an example of proof bycontradiction It starts by making the assumption thatit is not the case that

radic2 is irrational in other words that

we can find integers p and q withradic2 = pq

We can assume without losing anything that p andq have no common factors (Why)

radic2 = pq

qradic2 = p

2q2 = p2

This means that p2 is even from which we can also de-duce that p is even (Why)

This means that p = 2k for some k so

2q2 = (2k)2

there4 2q2 = 4k2

so q2 = 2k2

But this means that q2 and hence q is even Since p andq are both even we have a contradiction to our initialassumption so no such p and q exist

The way this is formatted is shown here

34

COMP10120 Report writing and Digital Typography

It starts by making the assumption that it is emphnot the casethat $sqrt2$ is irrational in other words that we can findintegers $p$ and $q$ with $sqrt2 = pq$

We can assume without losing anything that $p$ and $q$ haveemphno common factors (Why)

[beginarraylcl

sqrt2 amp = amp pq qsqrt2 amp = amp p 2q^2 amp = amp p^2

endarray]

This means that $p^2$ is even from which we can also deduce that $p$is even (Why)

This means that $p = 2k$ for some $k$ so ldots[beginarrayllcl

amp 2q^2 amp = amp (2k)^2 therefore amp 2q^2 amp = amp 4k^2 textso amp q^2 amp = amp 2k^2

endarray]

But this means that $q^2$ and hence $q$ is even Since $p$ and $q$are both even we have a contradiction to our initial assumptionso no such $p$ and $q$ exist

Notice the use of the array environment for gettingthings lined up You can find much more informationabout this on the web

LATEX really shines at typesetting mathematics and

35

COMP10120 Report writing and Digital Typography

it would take pages and pages to describe all the fea-tures Have a look at

enwikibooksorgwikiLaTeXMathematics

for a flavour

Exercise 5 Formatting mathematics

Now for an exercise that involves some mathematicsPlease create a file f-wtex which typesets the follow-ing piece of text and mathematics

There are many positive integer solutions tothe equation

x2 + y2 = z2

which can be rewritten as

z =radicx2 + y2

For example (3 4 5) or (5 12 13) Such solu-tions are called Pythagorean triples

However for higher powers the situation isvery different and we have-

Theorem Fermat-WilesFor all natural numbers n ge 3 there are no

36

COMP10120 Report writing and Digital Typography

integers x y z satisfying the equation

xn + yn = zn

35 Curriculum vitaie

There are several scenarios where using LATEX ratherthan other word processing software can be useful

bull typesetting mathematics yoursquove just read about

bull writing a technical document

bull your final year project peport

bull writing an article you want to get published

bull writing a Curriculum vitae CV

Wersquoll now look at CVrsquos briefly

Exercise 6 Curriculum vitae

Creating a professional document is especially impor-tant when you write your CV because how your CVlooks (not just the content) will determine if you are in-vited to interview for job you are applying for Thatcould be a summer internship next year a year long

37

COMP10120 Report writing and Digital Typography

placement after your second year or graduate positionafter you leave University

As well using a text-editor and compiling files fromthe command line other tools are available for editingLATEXWe will look at one of these overleafcom

Create a basic CV which describes you your edu-cation (including University) and any experience youhave or interesting projects that you may have doneYou can do this using httpsoverleafcom andchoosing the ready-made templates at httpswwwoverleafcomgallerytaggedcv

As you progress through University it is a good ideato keep your CV up to date and get feedback from asmany people as you can There will be opportunities todebug your CV later (See httpgitiomycv if youare interested) but yoursquoll need a ldquobeta releaserdquo (version10) of your CV to get started The best time to start thisprocess is now

36 Some optional extras

Exercise 7 Exploring more LATEX features (op-tional but easy)

This exercise reinforces some of the things yoursquove donealready but also introduces some features of LATEX that

38

COMP10120 Report writing and Digital Typography

will be new to you It is labelled as optional because itisnrsquot marked but we would recommend that you all tryit

Take a copy of the file optinfocoursesCOMP10120ex3latex-introtexand follow the instructions it contains You should readit before you process it with LATEX

Exercise 8 A neat directory listing (optionalmore challenging)

The fact that LATEX source files are just text makes it easyto have them generated by a program You are going toexploit this and use LATEX to produce a neat documentcontaining a listing of the files in any directory

Find how to create tables in LATEX tables using thetabular environment Make a LATEX document by handthat uses a table to neatly show the information aboutthe files in some (small) directory (as produced by ls

-l) Write a shell script called neat-ls that takes anargument which is the path name of a directory andproduces a LATEX document containing the above tablefor the given directory The script could also process theLATEX and display the resulting pdf file Finally find outabout the longtable package and change your script touse that instead

39

COMP10120 Report writing and Digital Typography

Exercise 9 A cleaning rota (optional evenmore challenging)

Now you will write a shell script called make-rota thatgenerates a house cleaning rota (Very handy for nextyear ) This is a table with columns such as KitchenBathroom and Lounge The rows will be weeks in theyear labelled with a date (eg always a Sunday) Theidea is that house mates can write their initials in theboxes promising to clean the corresponding room inthat particular week Start by making a sample tableby hand

Your script should take a single argument which isthe date of the first day of the first row eg102013(the US format for 20 Oct 13) The result will be a docu-ment that contains as many rows as fit on a single page(find out by experimenting)

The dates of each row should be generated from thefirst See the manual page for date to figure out howyou can generate a date that is a number of weeks anddays later than an existing one

361 Marking Scheme

You can view a copy of the marking scheme used bysubmit and labprint at

40

COMP10120 Report writing and Digital Typography

studentnetcsmanchesteracukugtlpmsphpunit=COMP10120ampex=ex3xml

37 Next steps

LATEX is a very powerful tool and it does take a littlegetting used to But itrsquos not as scary as it might initiallyseem and you should find that it doesnrsquot take long tolearn the common commands and techniques to makeyour documents well-structured and readable As youbecome more comfortable with the basics and under-stand the principles of typesetting finding out how todo more complex and sophisticated things is easymdashthere are hundreds of tutorials on the web

Donrsquot get carried away though and use the featuresjudiciously just because yoursquove found a cool new com-mand doesnrsquot mean that you should use it just to showoff your LATEX skills content and structure always trumpstypographic twiddlings4

4For example footnotes like this are for some reason a really tempting fea-ture to use in LATEX and in this document we have abused them mercilessly toillustrate a point Footnotes were originally a means for mechanical typeset-ters to insert comments corrections or additions to existing documents withouthaving to adjust the layout of a whole page and of course in digital typographythis is no longer necessary They can justifiably be used for citations (though itrsquosnot common to do so these days) and URLs if you donrsquot want these intrudinginto the body of your text And in some very very rare cases they can be usedas an aside to the main flow of the text (which is what has been done in this doc-ument) But this should be used sparingly If something is important to sayput it in the main body of your text If itrsquos not then perhaps you should thinkabout leaving it out completely or find some other way of including it Asking

41

COMP10120 Report writing and Digital Typography

371 Acknowledgements

Figure 38 is from the Wikipedia article on cheese

372 License

The text of this exercise is licensed under the terms ofthe Creative Commons Attribution 20 Generic (CC BY30) License

38 Background

What follows is additional contextual information aroundLATEX

LATEX was originally written by Leslie LamportW anAmerican computer scientist now working at MicrosoftResearch although its development has long been takenover by a world-wide LATEX community Itrsquos actuallybuilt on top of another system called TEX a computertypesetting system designed by one of the worldrsquos mostinfluential Computer Scientists Donald KnuthW of Stan-ford University Knuth has said that he designed TEX

the reader to look down at the bottom of a page to find out whether somethingis important or not is irritating and as yoursquove probably found out already oftenmeans you lose track of your reading position They also give the impressionthat the author isnrsquot clear about whether something is important or not whichis never good And long footnotes like this onemdashwhile LATEX will typeset themperfectly wellmdashare just plain silly Best avoid

42

COMP10120 Report writing and Digital Typography

for lsquothe creation of beautiful booksmdashand especially forbooks that contain a lot of mathematicsrsquo(D Knuth1984) Figure 34 shows what these eminent men looklike

So whatrsquos the purpose of LATEX Itrsquos purely a layerof software to make TEX easier to use in everyday sit-uations This is a good idea because although TEX isamazingly powerful it operates at a very low-level whichmakes it hard for non-expert users

Figure 34Don Knuth and Leslie Lamport

381 Pronunciation

The name TEX is intended by its creator to be pronouncedwith the final consonant as in the word loch or the nameBach but English speakers often pronounce it like thefirst syllable of technical The first syllable of LATEX is

43

COMP10120 Report writing and Digital Typography

pronounced as in rsquolayrsquo5

382 Why LATEX

Before we go any further why do we think LATEX is im-portant for youmdasha Computer Science studentmdashto knowabout Here are some reasons in no particular order

bull LATEX and TEX are superb examples of ComputerScience in action TEX was designed by Knuth fromfirst principlesmdashin other words from scratch TEXis actually a programming language and LATEX isa set of functions defined in the TEX language TheTEX lsquocompilerrsquo is written in WEBW a mixture ofdocumentation written in TeX and a PascalW sub-set in order to ensure portability it reads a TEXprogram and outputs documents TEX is completelyself-contained and designed to be portable to anycomputer architecture For example it implementsits own stackW and heapW (with garbage collectionW)and it does fixed-precision arithmeticW donrsquot worryif these terms donrsquot make much sense to you at themoment they soon will

5The Greek prefix lsquotexrsquo means lsquoartrsquo as well as lsquotechnologyrsquo so itrsquos a very nicelychosen name for a piece of software that produces such beautiful output Knuthexplained (D Knuth 1984) that one should lsquopronounce the X of TeX as a Greekchi not as an lsquoxrsquo so that TeX rhymes with the word blecchhhrsquo Wersquore not toosure that helps much unless you are confident in your pronunciation of theword lsquoblecchhrsquo Maybe itrsquos an American thing

44

COMP10120 Report writing and Digital Typography

bull LATEX is a new interesting way for you to thinkabout preparing documents

bull LATEX has a practical advantage for the writer inthat it helps you think more about what you wantto write rather than worrying about how it looks

bull LATEX is a powerful tool for professional scientificdocumentation and as a Computer Scientist youshould know about it

bull LATEX files are just plain text so can easily be cre-ated programatically For example the slides usedfor COMP16120 are generated automatically fromthe source of Johnrsquos book both are typeset usingLATEX The program labprint also produces itsoutput using LATEX using information drawn fromXMLW configuration files and ARCADE

bull Using LATEX is actually quite satisfying and thequality of its output may surprise you

In this lab session you are going to write severalshort documents using LATEX You could also write briefnotes in your logbook about how LATEX works and whatcommands you used inside the source of your docu-ments

45

COMP10120 Report writing and Digital Typography

383 Some history printing mathematics

Mathematics is hard to print on paper and on the Web(many websites resort to GIF or JPG images of mathsformulae which usually look horrible MathMLW pro-vides another approach but it is not yet widely used)

In the days before computers books and newspa-pers were printed with movable typeW made from lotsof little blocks of metal each with letters numbers andsymbols standing in relief which when inked left animpression on the paper (see Figure 35) The job ofthe printer (the printer here of course being a personnot a bit of electronics) was to gather together all theblocks in the right order between two horizontal stripsof wood to create a line of the document and then toassemble all those lines from top to bottom of a pageThus the term type settingW an incredible task whenyou think about it In the printerrsquos workshop by theway the blocks of metal were stored between jobs inwooden boxes called cases Letters like a b and c werestored in one case letters like A B and C were storedin a case sitting on top of that So a lower case and anupper case These terms may ring a bell

As technology progressed machines controlled bytypewriters would mechanically juggle the blocks intothe right order This conceptual model is the basis onwhich TEX operates Only now the metal blocks are

46

COMP10120 Report writing and Digital Typography

Figure 35On the left a piece of cast movable type in the Garamondfont On the right a case of cast metal type pieces andtypeset matter in a composing stick The text reads lsquoThequick brown fox jumps over the lazy dog and feels as if hewere in the seventh heaven of typography together with Her-mann Zapf the most famous artist of thersquo This document istypeset in a font called Palatino created by Hermann ZapfYou may have also seen rsquoZapf Dingbatsrsquo in the font lists ofvarious desktop applications Now you know why

little pieces of data arranged into data structuresThe one thing that traditional printers hated was

dealing with the typesetting of mathematics and theywould charge extra to do it It was incredibly fiddly toget the equations looking right they had to squeeze inextra bits of metal horizontally and vertically

When computers entered the printing world attemptsto print mathematics were limited by the printing tech-nology available It took a long time to reach the pointwhere computers could typeset mathematics beautifullyand that was the outstanding achievement of Knuthrsquos

47

COMP10120 Report writing and Digital Typography

TEXLetrsquos look at a quick example of the quality you get

from LATEX with a very simple formula that yoursquoll recog-nise

x =minusbplusmn

radicb2 minus 4ac

2aWersquoll revisit how LATEX typesets mathematics in Section 34

384 To WYSIWYG or not to WYSIWYG

Up until now you have probably used wordprocessingapplications such as Microsoft Word to create essaysletters and other (probably fairly short) documents Youmost likely know that the majority of modern wordprocessors use a paradigm called WYSIWYG or WhatYou See Is What You Get which means that you canmodify the visual style of the document yoursquore work-ing on by selecting the relevant bits and then choos-ing different attributes such as font size or colour usinga GUI In many ways this seems like such a sensibleand obvious way of doing things that you might bewondering why it even has a special name The rea-son is a historical one in the early days of comput-ing long before graphical window managers becamethe norm and when all you could display on screenwas fixed-width ASCII text in whatever the systemrsquos

48

COMP10120 Report writing and Digital Typography

default font was wordprocessors (eg Figure 36) onlyallowed you to format documents by using special se-quences of characters to cause particular effects Butthese effects were only visible when the document wasprinted So if you wanted a word to appear in boldtext in the wordprocessor you might write somethinglike [bold]hello world[bold] what you saw onscreen was not a direct reflection of what appeared onthe printed page If yoursquove written any HTML how-ever this process of marking up text may be familiarsee for example Figure 37 As computers moved todisplays able to draw things other than raw charac-ters on screen wordprocessors became capable of us-ing multiple fonts and styles as well as graphics anda new generation of applications appeared where whatyou saw on screen was an accurate reflection of how itwould appear when printed what you see (on screen)is what you get (on paper)

The huge advantage of WYSIWYG is that itrsquos reallyeasy to understand whatrsquos going on and most peoplecan create reasonably nicely formatted documents withrelatively little effort For short informal documentsone-off letters memos and such WYSIWYG works quitenicely But if yoursquove ever tried writing anything muchlonger or that includes images and tables you mayhave already started to see where the paradigm breaksdown For example if you write lsquoFigure 38 on page

49

COMP10120 Report writing and Digital Typography

Figure 36A screenshot of Wordperfect 51 running in Microsoft DOScirca 1989

51 shows a picture of some men looking at cheesersquo butthen later on edit your document to include some moretext at the start and a new picture of a some broccoli(as in Figure 39) yoursquod have to search through yourreport to find all mentions of lsquoFigure 38rsquo and lsquopage 51rsquoand manually update them to reflect the new number-ing This might be fine if you have two figures and fivepages but for a hundred-page report containing lots ofpictures you can see how this becomes tedious and er-ror prone very quickly

50

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 5: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

press ltctrlgtd or x to tell LATEX to give up trying toprocess your file Then fix the mistake and try again

If you now list the directory contents you shouldsee that a file fire-and-icepdf has been created (alongwith two other files fire-and-iceaux and fire-and-icelog

both of which we will ignore for now) Use one of thePDF readers (such as evince

evince

) to look at the contentsof fire-and-icepdf Admittedly itrsquos not the most ex-citing result if everything has worked properly so faryou should see a single-page document with the wordslsquoSome say the world will end in firersquo a little way downfrom the top of the page1

But now look more closely A lot more closely reallyzoom in See anything interesting

Even for this very short document LATEX has taken afairly sophisticated typographical decision on your be-half and ligated (which is typography-speak for lsquojoinedrsquo)the lsquofrsquo and the lsquoirsquo in the word lsquofirersquo the spacing betweenthe characters has been subtly altered so that the dotabove the lsquoirsquo and the blob on the end of the curvy bit(the lsquoarc of the stemrsquo if wersquore being formal) on the topof the lsquofrsquo join together to form a single shape calleda ligature Why Because having two blobs side by

1If you have been carried away with the sheer excitement and joy of learningto use LATEX and improvised the text rather than typing the first line of lsquoFire andIcersquo as requested please go back and change it now it really is important thatyou use exactly that text Really it is Thatrsquos better Thanks

12

COMP10120 Report writing and Digital Typography

side simply looks a bit clumsy as you can see in Fig-ure 31 To make this decision LATEX has had to knowa lot about the fonts being used (not all lsquofrsquos in all fontshave a blobby end not all lsquoirsquos in all fonts have a rounddot that would merge nicely with the blobby bit on theend of an lsquofrsquo and so on) Therersquos a reasonable chancethat yoursquove never heard of ligated characters beforemdashit is after all a fairly specialist thing And there arehundreds of other obscure but important lsquorulesrsquo of ty-pography that go to make professionally typeset doc-uments look good2 Individually they might not beobvious or hugely important but collectively and sub-liminally they make the difference between somethingthat looks just-about-acceptable (like most things writ-ten using wordprocessors) and things that stand out aslooking really professional (you might want to remem-ber this when it comes to putting your CV together)

But thatrsquos enough about the typography of the wordlsquofirersquo for now Letrsquos put together something more sub-stantial

2Look up lsquokerningrsquo lsquocombining charactersrsquo and lsquoserifrsquo on Wikipedia forstarters And if yoursquore really keen Donald Knuthrsquos fascinating and compen-dious book lsquoDigital Typographyrsquo (D Knuth 1999) has an entire chapter dedi-cated to the joys of the letter lsquoSrsquo Probably best not to bring this subject up at thepub though or at parties Unless they are very specialist parties

13

COMP10120 Report writing and Digital Typography

Figure 31The word lsquofirersquo typeset by (a) Microsoft Word 2011 withoutligated characters and (b) by LATEX showing the ligation ofthe characters lsquofrsquo and lsquoirsquo

Exercise 2 A larger example

Create yourself a new file called sectionstex by copy-ing fire-and-icetex In sectionstex replace the lineof poetry by copying and pasting the text from Figure32 (which contains the first three paragraphs of Dick-ensrsquo novel lsquoBleak Housersquo (C Dickens 1852))

Edit the text to make sure that there is a blank linebetween each of the three paragraphs (itrsquos not enoughthat each paragraph starts on a new line of its ownthere has to be an empty line in between them) Thatrsquoshow paragraphs are distinguished in LATEX (in fact itdoesnrsquot matter how many blank lines you put as longas there is at least one for the most part LATEX ignoresspare whitespace) After the lsquoBleak Housersquo text typea paragraph of gibberish by randomly hitting keys onthe keyboard and putting spaces in to make lsquowordsrsquo inthe text file You should end up with something like thefollowing but about three times as long (donrsquot cut andpaste this from here itrsquos important that you actually

14

COMP10120 Report writing and Digital Typography

London Michaelmas term lately over and theLord Chancellor sitting in Lincolnrsquos Inn HallImplacable November weather As much mud inthe streets as if the waters had but newly retiredfrom the face of the earth and it would not bewonderful to meet a Megalosaurus forty feetlong or so waddling like an elephantine lizardup Holborn Hill Smoke lowering down fromchimney-pots making a soft black drizzle withflakes of soot in it as big as full-grownsnowflakesndashgone into mourning one mightimagine for the death of the sun Dogsundistinguishable in mire Horses scarcelybetter splashed to their very blinkers Footpassengers jostling one anotherrsquos umbrellas in ageneral infection of ill temper and losing theirfoot-hold at street-corners where tens ofthousands of other foot passengers have beenslipping and sliding since the day broke (if thisday ever broke) adding new deposits to the crustupon crust of mud sticking at those pointstenaciously to the pavement and accumulatingat compound interest

Fog everywhere Fog up the river where it flowsamong green aits and meadows fog down theriver where it rolls defiled among the tiers ofshipping and the waterside pollutions of a great(and dirty) city Fog on the Essex marshes fogon the Kentish heights Fog creeping into thecabooses of collier-brigs fog lying out on theyards and hovering in the rigging of great shipsfog drooping on the gunwales of barges andsmall boats Fog in the eyes and throats ofancient Greenwich pensioners wheezing by thefiresides of their wards fog in the stem and bowlof the afternoon pipe of the wrathful skipperdown in his close cabin fog cruelly pinching thetoes and fingers of his shivering little rsquoprenticeboy on deck Chance people on the bridgespeeping over the parapets into a nether sky offog with fog all round them as if they were upin a balloon and hanging in the misty clouds

Gas looming through the fog in divers places inthe streets much as the sun may from thespongey fields be seen to loom by husbandmanand ploughboy Most of the shops lighted twohours before their timemdashas the gas seems toknow for it has a haggard and unwilling look

Figure 32Some sample text from the opening of the Dickensrsquo novellsquoBleak Housersquo (C Dickens 1852)

15

COMP10120 Report writing and Digital Typography

create some unique gibberish yourself)

Oisjdf oqweqwe oi soijs hbweo kbsd oijsdfoijqwknpiouh iusbdfspb sifuhygwqeb usgweijfblimqwoq oieuerwefwiu aokqjw uioshiufdsqiqks odfubfi psdiweneq

Be careful at this stage to only include letters (upper-case and lowercase) commas full-stops and perhapsnumbers in your gibberish text if you use any othersymbols you may upset LATEX

Next go to the website wwwlipsumcom and fol-low the instructions to generate yourself three para-graphs of whatrsquos called Lorem Ipsum text Copy andpaste that text into your LATEX document too (donrsquot worryabout what it means at this stage) again making surethat you have a blank line between the paragraphs

Run pdflatex and look at the resulting sectionspdfAgain at first glance therersquos nothing hugely excitinggoing on here the text from your tex file has beenassembled into a (probably) two page PDF documentBut in fact quite a few things have happened

bull The blank lines that separate the paragraphs inyour source file are gone and instead LATEX hasindented the first line of each paragraph Therersquosnothing profound here about the decision to in-dent paragraphs rather than (say) to leave a gap

16

COMP10120 Report writing and Digital Typography

between them (so called block paragraphs) itrsquosjust LATEXrsquos default paragraph style and can bechanged easily enough3

bull There are page numbers at the bottom of each page(except page 1) This is a very sensible default al-lowing you in meetings to ask people to lsquoturn topage 4rsquo and so on (itrsquos a bit odd and a source ofsome annoyance that most wordprocessors donrsquotdo this by default too) But you can easily switchpage numbers off change their style or move themelsewhere if you need to

bull The text is fully justified so that itrsquos flush on boththe left and right hand edges

bull Certain words that fall at the end of lines havebeen hyphenated even if they werenrsquot originallysplit by hyphens in the source text

These last two points about justification and hyphen-ation might seem utterly trivial but getting these fac-tors right turns out to be an important part of mak-ing readable documents readability is not just aboutwhich font you choose but about how the charactersand spaces are distributed on each line Itrsquos something

3Though apparently there is some evidence in M A Tinker 1963 that in-dented paragraphs increase readability

17

COMP10120 Report writing and Digital Typography

that you will have seen happen so often in profession-ally typeset materials that yoursquoll have taken it for grantedand you may not have spotted that it doesnrsquot happenin quite the same way when you use a wordproces-sor The principle behind justifying text seems easyenough at first glance you simply have to take any lsquoleftoverrsquo space that would be at the end of a line and re-distribute it between the words in some way to lsquospacethem outrsquo a bit more so that they take up all the avail-able horizontal room But it turns out to be much harderthan it seems and all the simple ways you might thinkof for doing this on a per-line basis give results thatare visually quite unsatisfactory with nasty patternsmade up of neighbouring whitespace appearing in thelayout and ruining everything The added complica-tion here is that to do the optimum job of shuffling thewords round on their lines you really need the flex-ibility of being able to hyphenate words to give youextra space on lines that would otherwise be tightlypacked with characters But if you hyphenate wordsbadly by breaking them in inappropriate places or doit too often then that makes the text hard to read tooItrsquos all deeply inconvenient and inter-related The bestsolution to this aesthetic conundrum so far was devel-oped by Knuth and Plass 1981 and later improved byFrank Liang during his PhD research (F M Liang1983) and itrsquos a technique that tries to optimise the lay-

18

COMP10120 Report writing and Digital Typography

out of whole paragraphs rather than individual linesThe algorithm takes into account all manner of differ-ent things language-specific character patterns the num-ber of consecutive lines that end with hyphens the wordlsquotightnessrsquo on each line and many others The detailsdonrsquot really matter here but the really important in-sight is that you get better results by working on a big-ger chunk of the document (in this case a paragraph at atime) rather than trying to independently optimise lotsof small bits (say lines) and hoping that the result ofjoining them all together turns out nicely This idea ofoptimising things globally versus locally is somethingyoursquoll see many times throughout your Computer Sci-ence degree watch out for it in all the algorithms courses

This highlights a fundamental difference betweenthe WYSIWYG paradigm and the way that documentsare produced using LATEX As wersquove seen small changesdown at the level of individual characters can have fairlylarge knock-on consequences for the optimal layout ofa document changing one letter for another affects thelength of a line which in turn affects the hyphenationoptions which then affects the length of a paragraphwhich means that the best place for a figure that was onpage 99 might now be on page 100 but that means thatall references to lsquopage 99rsquo now need a bit more room toaccount for the extra digit which means that the someline lengths have changed which means well you get

19

COMP10120 Report writing and Digital Typography

the idea Itrsquos more complicated than it first seems LATEXgets to see the whole of your document at once and cantherefore make decisions about how best to hyphen-ate lines position figures or whatever else it likes beforeit shows you the results so it can make solutions thatare optimal for the whole document as well as lookingat details such as ligated characters Wordprocessorscanrsquot afford to do this since it would be deeply distract-ing if every time you typed a character the whole lay-out of the document flapped around in front of youreyes Wordprocessors can only sensibly make little op-timisations at a local (probably per-line level) Itrsquos notthat wordprocessors are rubbish or that the people thatprogrammed them were lazy itrsquos a fundamentally dif-ferent way of working and knowing the pros and consof the different approaches will help you pick the righttool for the job

You may have noticed that actual text in your doc-ument (and in fact this one) takes up a (perhaps) sur-prisingly narrow horizontal region of the page Thislast lsquofeaturersquo might seem odd at first but it illustratesanother important typographical point that you maynever have thought of before reading long lines of textis hard because your eyes find it hard to move in acompletely straight line as they scan from left to rightSo the longer the line of words the more you have towork to keep your eyes from accidentally drifting up or

20

COMP10120 Report writing and Digital Typography

down onto a neighbouring line (perhaps yoursquove expe-rienced the phenomenon of accidentally re-reading thesame line over and over as your eyes get tired) It maynever have occurred to you but most books have rela-tively short lines of text and those that use large pagesoften split text into several columns so that individuallines are kept relatively short The widely trusted booklsquoThe Elements of Typographic Stylersquo (R Bringhurst1992) makes the following assertion

lsquoAnything from 45 to 75 characters is widely-regarded as a satisfactory length of line for a single-column page set in a serifed text face in a text sizeThe 66-character line (counting both letters andspaces) is widely regarded as idealrsquo

LATEX knows about this issue so made a sensible de-fault decision for you You may have noticed that thereis a subtle difference in appearance of this chapter fromprevious ones the lines are shorter and paragraphs areindented We wanted to use the default LATEX layoutfor this chapter but changed it for earlier chapters inan effort to save paper

Therersquos one last unusual thing to note your para-graph of gibberish text in between the real words fromBleak House and the Lorem Ipsum almost certainly standsout and looks really quite odd (it might even have con-fused LATEXrsquos hyphenation rules enough to have ended

21

COMP10120 Report writing and Digital Typography

up with one or more lines sticking out proud of theright hand margin) Let your eyes relax so that yourvision blurs for a moment you can still probably spotthat the gibberish paragraph looks out of place Itrsquosquite likely that you even found creating the gibber-ish unexpectedly hard The interesting thing here isthat as humans we spend so much time reading andwriting lsquoproperrsquo natural language that we become at-tuned to the patterns of letters words and the underly-ing lsquorhythmrsquo of our written language that its very hardto artificially reproduce something that looks plausiblethe frequency of the letters you chose by randomly hit-ting keys and the length and patterns of the words youput in place most likely donrsquot match the natural pat-terns of real languages so they just look plain wrongCuriously the Lorem Ipsum text that you got from thewebsite probably doesnrsquot look so bad in spite of it notbeing made up of real words But thatrsquos not surprisingsince Lorem Ipsum is specifically created to be used asa placeholder for real text when typesetting While thewords are meaningless Latin-like things their lengthand the distribution of characters and word lengths arechosen to mimic patterns in real language

Next letrsquos give our document some structure by di-viding it up into sections On the line before BleakHouse starts add the command

22

COMP10120 Report writing and Digital Typography

sectionBleak House

making sure it appears on a line of its own Then justbefore your paragraph of gibberish put a similar in-struction (again on its own line) and then create a finalsection before the Lorem Ipsum Rerun pdflatex andlook at the results You should see the section headingsappear in the appropriate places in the PDF automati-cally having been given section numbers Experimentby adding in a couple of sub-sections towards the endof the document using the subsection commandwhich like the section command above takes as aparameter some text contained in curly brackets

Now at the top of your document after the begindocumentline and before the command defining the first sectionadd the following two commands each on their ownline

tableofcontentsnewpage

Re-run pdflatex twice and check that the effect is whatyoursquod expect You need to process the source twice be-cause on the first run LATEX gathers and stores informa-tion about what to put in the table of contents and onlycreates it on the second run

23

COMP10120 Report writing and Digital Typography

33 Common formatting features

Before we give you some more exercises to do here is abrief introduction to some commonly used features ofLATEX

331 Enumerated and bulleted lists

Creating bulleted or numbered lists in LATEX is straight-forward and is done like this

beginenumerateitem My first itemitem My second itemitem The last thing on my listendenumerate

You must make sure that you both begin and end yourlist and that each item is terminated by a newline Chang-ing enumerate to itemize gives you a bulleted ratherthan numbered list (note the American spelling of lsquoitem-izersquo)

332 Changing the appearance of text

Text can be typeset in bold font using the textbfin italics using textitand in a fixed-width fontusing texttt as in the example below

24

COMP10120 Report writing and Digital Typography

Some textttsay the textbfworld will end in textitfire

which is typeset as

Some say the world will end in fire

333 Cross referencing

LATEX allows you to cross-reference almost anything inthe document which includes sections sub-sections andfigures To use the cross-referencing feature you simplyinsert the command

labelmymarker

at the point in the document you want to refer to andthen use the command

refmymarker

when you want to use the reference Obviously youreplace the text mymarkerwith something more mean-ingful An important tip here is to call the marker some-thing that refers to the content of that part of the doc-ument and to avoid the temptation to use numbers(so donrsquot call your marker section1 instead call itintroduction if you reorder your document itrsquos stilllikely to be the introduction but it may no longer beSection 1) For example

25

COMP10120 Report writing and Digital Typography

sectionReflection on Welcome WeeklabelwelcomeweekI spent most of welcome week getting to know my wayaround campus I should have made more effort to joinsocieties I think I must remember to get to theStudentsrsquo Union and take a look around there

subsectionThings I enjoyedEverything so far has been wonderful with the caveat Imentioned in Section refwelcomeweek

subsectionThings I didnrsquot enjoyIrsquove discovered that I donrsquot like soggy chips

The really useful thing about cross-referencing in LATEXis that yoursquoll get warnings when you compile your doc-ument if cross-references are undefined or used incor-rectly This means you donrsquot have to manually checkevery reference in your document to make sure itrsquos stillright You do however have to run LATEX twice forsimilar reasons to those given above

334 Figures and pictures

Including figures and pictures in your document is easyYou do it like this

beginfigure

26

COMP10120 Report writing and Digital Typography

Figure 33Some men possibly Dutch looking at cheeses

centerlineincludegraphics[width=10cm]imagesmen-and-cheesejpgcaptionSome men possibly Dutch looking at cheeseslabelfiguremenandcheesesendfigure

which is the code we used to create Figure 38 You canprobably see whatrsquos happening The command includegraphicsgets your image which can be PDF PNG JPG GIF orPostScript The beginfigureendfigurecode lsquowrapsrsquo up whatever picture yoursquore including andallows LATEX to treat it as an unbreakable floating thingthat it will position for you as best it can in the docu-ment while maintaining an overall nice typographicallayout This floating of figures can sometimes result inthe figure ending up in a place you didnrsquot expect but inmost cases LATEX will make the most sensible choice Itrsquos

27

COMP10120 Report writing and Digital Typography

possible to employ finer control over figure placementbut thatrsquos beyond the scope of this introduction

The includegraphics command is not built into core LATEX but is in an additional package whichneeds to be explicitly loaded We load this package byusing the command usepackagegraphicx in thedocument preamble ie after the documentclasscommand but before begindocument There arehundreds of such packages that extend LATEXrsquos func-tionality the lab scripts you are reading now use over30 of them

Exercise 3 Including images

Create a document imagetex that contains some text(maybe from rsquoLorem Ipsumrsquo) together with a figurecontaining an image of your choice perhaps the oneyou made in Intro Lab 2 like Steversquos Mr Noodle Thereshould also be a reference to the figure in the text Youshould first use the program convert

convert

(check its manpage) to create a PDF version of the image

Exercise 4 A reflection on your studies

Your first proper LATEX document will be a very briefreflection on your studies so far

Write a hand-crafted LATEX document called courses-reflectiontex

28

COMP10120 Report writing and Digital Typography

(exact name as usual please otherwise submitwill notwork) It will have the following structure

1 A table of contents

2 A brief paragraph saying what the document isabout

3 A section appropriately titled for one of your courseunits containing

bull a brief paragraph saying what the unit is about

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the most about the unit

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the least about the unit

A repeat of item 3 for each other unit you are study-ing These sections should appear in alphabeticalorder by course code (eg COMP10120)

After completing and successfully compiling and view-ing your document you should spell-check it as fol-lows

ispell courses-reflectiontex

29

COMP10120 Report writing and Digital Typography

Once you are completely satisfied with it produce ahard copy ready for marking

34 Typesetting Mathematics

Earlier we saw this formula

x =minusbplusmn

radicb2 minus 4ac

2aIt looks nice doesnrsquot it To tell LATEX to display thisyou have to type a bit of magic but itrsquos easily-learnedmagic To create such a formula in a WYSIWYG edi-tor there is also magic involved but it usually involvesa lot of mouse-clicking and remembering special keycombinations like rsquocontrol-thisrsquo and rsquoalt-thatrsquo In LATEXit doesnrsquot You simply type this

[ x = frac-b pm sqrtb^2-4ac2a ]

You can probably work out how most of this createsthe formula but it wonrsquot be obvious that the [ and ]symbols that enclose the formula mean lsquotypeset this asa displayed formula giving it some vertical space fromthe surrounding textrsquo If wersquod used ( and ) insteadto enclose the formula it would appear in-line like thisx = minusbplusmn

radicb2minus4ac2a It still looks very nice and observe

how itrsquos automatically been resized to fit and that the

30

COMP10120 Report writing and Digital Typography

lines of text have had their spacing changed a bit Thisall looks simple but the implementation inside LATEXand TEX is complex It involves parsing the descrip-tion of the formula to create a corresponding tree datastructure which is then recursively walked to workout the horizontal and vertical typographical spacingsneeded Yoursquoll meet these ideas in COMP11120 andCOMP26120 Algorithms and Imperative Programming

Herersquos another example taken from COMP27112Computer Graphics (itrsquos a lsquosimplersquo local illuminationmodel incorporating ambient diffuse and specular re-flection by multiple lights)

I = kaIa +

Msumi=1

Ipidprimei[kd(N middot Li) + ks(Ri middot V )n]

We write this in LATEX as follows

[ I = k_a I_a + sum_i=1^M fracI_p_idrsquo_i [ k_d(hatN cdot hatL_i)+ k_s(hatR_i cdot hatV)^n] ]

Try to match the LATEX commands with the formula dis-played above Yoursquoll see lots of curly brackets and thisexample illustrates their two uses in LATEX The firstis to provide an argument to a command for exam-ple hatN means lsquoapply the hat command to N rsquowhich creates N the vector N with a little hat on

31

COMP10120 Report writing and Digital Typography

The second use of curly brackets is to group thingstogether to avoid ambiguities In the example you cansee sum_i=1^M which creates a summation signand its lower and upper limits

sumMi=1 We wrap the

lower bound i=1 in curly brackets to group it into anindivisible unit If we were to omit the brackets writ-ing sum_i=1^M LATEX would then produce

sumi = 1M

which is not at all what we want (even LATEX canrsquot al-ways know what we really want)

One final example If we tell LATEX

[ T_1 = left[beginarraycccccos theta amp -sin theta amp 0 amp delta sin theta amp cos theta amp 0 amp epsilon 0 amp 0 amp 1 amp eta alpha amp beta amp gamma amp 1endarrayright] ]

wersquoll get a splendid matrix which expresses a particu-lar 3D geometrical transformation (Donrsquot worry if youdonrsquot recognise this yoursquoll be introduced to matrix no-tation in the latter part of COMP11120 MathematicalTechniques for Computer Science For now you can justtreat it as some mysterious maths)

32

COMP10120 Report writing and Digital Typography

T1 =

cos θ minus sin θ 0 δ

sin θ cos θ 0 ε

0 0 1 η

α β γ 1

In the LATEX code left[means lsquobig opening square

bracket pleasersquo ccccmeans lsquoan array with 4 columnsplease with the items in each column centredrsquo ampmeanslsquostart a new columnrsquo and means lsquostart a new rowrsquoYoursquoll notice that LATEX knows about greek letters itknows about most standard maths symbols too andalso the ways theyrsquore usually used

There are some symbols that you might need (forexample therefore which produces the usual threedots symbol there4) that are not part of standard LATEX Manysuch symbols are provided by the amssymb package ofsymbols compiled by the American Mathematical Soci-ety Details of the many symbols provided by this pack-age can be found online at

mirrormathkuedutex-archivefontsamsfontsdocamssymbpdf

To use these extra symbols you need to have usepackageamssymbin the document preamble

33

COMP10120 Report writing and Digital Typography

341 A longer piece of mathematics

We conclude this section with an example of a longerpiece of mathematics that shows how you might type-set a complete mathematical argument rather than asingle formula The example is Euclidrsquos proof of thefact that

radic2 is irrational Itrsquos an argument that has been

covered in COMP11120 and is an example of proof bycontradiction It starts by making the assumption thatit is not the case that

radic2 is irrational in other words that

we can find integers p and q withradic2 = pq

We can assume without losing anything that p andq have no common factors (Why)

radic2 = pq

qradic2 = p

2q2 = p2

This means that p2 is even from which we can also de-duce that p is even (Why)

This means that p = 2k for some k so

2q2 = (2k)2

there4 2q2 = 4k2

so q2 = 2k2

But this means that q2 and hence q is even Since p andq are both even we have a contradiction to our initialassumption so no such p and q exist

The way this is formatted is shown here

34

COMP10120 Report writing and Digital Typography

It starts by making the assumption that it is emphnot the casethat $sqrt2$ is irrational in other words that we can findintegers $p$ and $q$ with $sqrt2 = pq$

We can assume without losing anything that $p$ and $q$ haveemphno common factors (Why)

[beginarraylcl

sqrt2 amp = amp pq qsqrt2 amp = amp p 2q^2 amp = amp p^2

endarray]

This means that $p^2$ is even from which we can also deduce that $p$is even (Why)

This means that $p = 2k$ for some $k$ so ldots[beginarrayllcl

amp 2q^2 amp = amp (2k)^2 therefore amp 2q^2 amp = amp 4k^2 textso amp q^2 amp = amp 2k^2

endarray]

But this means that $q^2$ and hence $q$ is even Since $p$ and $q$are both even we have a contradiction to our initial assumptionso no such $p$ and $q$ exist

Notice the use of the array environment for gettingthings lined up You can find much more informationabout this on the web

LATEX really shines at typesetting mathematics and

35

COMP10120 Report writing and Digital Typography

it would take pages and pages to describe all the fea-tures Have a look at

enwikibooksorgwikiLaTeXMathematics

for a flavour

Exercise 5 Formatting mathematics

Now for an exercise that involves some mathematicsPlease create a file f-wtex which typesets the follow-ing piece of text and mathematics

There are many positive integer solutions tothe equation

x2 + y2 = z2

which can be rewritten as

z =radicx2 + y2

For example (3 4 5) or (5 12 13) Such solu-tions are called Pythagorean triples

However for higher powers the situation isvery different and we have-

Theorem Fermat-WilesFor all natural numbers n ge 3 there are no

36

COMP10120 Report writing and Digital Typography

integers x y z satisfying the equation

xn + yn = zn

35 Curriculum vitaie

There are several scenarios where using LATEX ratherthan other word processing software can be useful

bull typesetting mathematics yoursquove just read about

bull writing a technical document

bull your final year project peport

bull writing an article you want to get published

bull writing a Curriculum vitae CV

Wersquoll now look at CVrsquos briefly

Exercise 6 Curriculum vitae

Creating a professional document is especially impor-tant when you write your CV because how your CVlooks (not just the content) will determine if you are in-vited to interview for job you are applying for Thatcould be a summer internship next year a year long

37

COMP10120 Report writing and Digital Typography

placement after your second year or graduate positionafter you leave University

As well using a text-editor and compiling files fromthe command line other tools are available for editingLATEXWe will look at one of these overleafcom

Create a basic CV which describes you your edu-cation (including University) and any experience youhave or interesting projects that you may have doneYou can do this using httpsoverleafcom andchoosing the ready-made templates at httpswwwoverleafcomgallerytaggedcv

As you progress through University it is a good ideato keep your CV up to date and get feedback from asmany people as you can There will be opportunities todebug your CV later (See httpgitiomycv if youare interested) but yoursquoll need a ldquobeta releaserdquo (version10) of your CV to get started The best time to start thisprocess is now

36 Some optional extras

Exercise 7 Exploring more LATEX features (op-tional but easy)

This exercise reinforces some of the things yoursquove donealready but also introduces some features of LATEX that

38

COMP10120 Report writing and Digital Typography

will be new to you It is labelled as optional because itisnrsquot marked but we would recommend that you all tryit

Take a copy of the file optinfocoursesCOMP10120ex3latex-introtexand follow the instructions it contains You should readit before you process it with LATEX

Exercise 8 A neat directory listing (optionalmore challenging)

The fact that LATEX source files are just text makes it easyto have them generated by a program You are going toexploit this and use LATEX to produce a neat documentcontaining a listing of the files in any directory

Find how to create tables in LATEX tables using thetabular environment Make a LATEX document by handthat uses a table to neatly show the information aboutthe files in some (small) directory (as produced by ls

-l) Write a shell script called neat-ls that takes anargument which is the path name of a directory andproduces a LATEX document containing the above tablefor the given directory The script could also process theLATEX and display the resulting pdf file Finally find outabout the longtable package and change your script touse that instead

39

COMP10120 Report writing and Digital Typography

Exercise 9 A cleaning rota (optional evenmore challenging)

Now you will write a shell script called make-rota thatgenerates a house cleaning rota (Very handy for nextyear ) This is a table with columns such as KitchenBathroom and Lounge The rows will be weeks in theyear labelled with a date (eg always a Sunday) Theidea is that house mates can write their initials in theboxes promising to clean the corresponding room inthat particular week Start by making a sample tableby hand

Your script should take a single argument which isthe date of the first day of the first row eg102013(the US format for 20 Oct 13) The result will be a docu-ment that contains as many rows as fit on a single page(find out by experimenting)

The dates of each row should be generated from thefirst See the manual page for date to figure out howyou can generate a date that is a number of weeks anddays later than an existing one

361 Marking Scheme

You can view a copy of the marking scheme used bysubmit and labprint at

40

COMP10120 Report writing and Digital Typography

studentnetcsmanchesteracukugtlpmsphpunit=COMP10120ampex=ex3xml

37 Next steps

LATEX is a very powerful tool and it does take a littlegetting used to But itrsquos not as scary as it might initiallyseem and you should find that it doesnrsquot take long tolearn the common commands and techniques to makeyour documents well-structured and readable As youbecome more comfortable with the basics and under-stand the principles of typesetting finding out how todo more complex and sophisticated things is easymdashthere are hundreds of tutorials on the web

Donrsquot get carried away though and use the featuresjudiciously just because yoursquove found a cool new com-mand doesnrsquot mean that you should use it just to showoff your LATEX skills content and structure always trumpstypographic twiddlings4

4For example footnotes like this are for some reason a really tempting fea-ture to use in LATEX and in this document we have abused them mercilessly toillustrate a point Footnotes were originally a means for mechanical typeset-ters to insert comments corrections or additions to existing documents withouthaving to adjust the layout of a whole page and of course in digital typographythis is no longer necessary They can justifiably be used for citations (though itrsquosnot common to do so these days) and URLs if you donrsquot want these intrudinginto the body of your text And in some very very rare cases they can be usedas an aside to the main flow of the text (which is what has been done in this doc-ument) But this should be used sparingly If something is important to sayput it in the main body of your text If itrsquos not then perhaps you should thinkabout leaving it out completely or find some other way of including it Asking

41

COMP10120 Report writing and Digital Typography

371 Acknowledgements

Figure 38 is from the Wikipedia article on cheese

372 License

The text of this exercise is licensed under the terms ofthe Creative Commons Attribution 20 Generic (CC BY30) License

38 Background

What follows is additional contextual information aroundLATEX

LATEX was originally written by Leslie LamportW anAmerican computer scientist now working at MicrosoftResearch although its development has long been takenover by a world-wide LATEX community Itrsquos actuallybuilt on top of another system called TEX a computertypesetting system designed by one of the worldrsquos mostinfluential Computer Scientists Donald KnuthW of Stan-ford University Knuth has said that he designed TEX

the reader to look down at the bottom of a page to find out whether somethingis important or not is irritating and as yoursquove probably found out already oftenmeans you lose track of your reading position They also give the impressionthat the author isnrsquot clear about whether something is important or not whichis never good And long footnotes like this onemdashwhile LATEX will typeset themperfectly wellmdashare just plain silly Best avoid

42

COMP10120 Report writing and Digital Typography

for lsquothe creation of beautiful booksmdashand especially forbooks that contain a lot of mathematicsrsquo(D Knuth1984) Figure 34 shows what these eminent men looklike

So whatrsquos the purpose of LATEX Itrsquos purely a layerof software to make TEX easier to use in everyday sit-uations This is a good idea because although TEX isamazingly powerful it operates at a very low-level whichmakes it hard for non-expert users

Figure 34Don Knuth and Leslie Lamport

381 Pronunciation

The name TEX is intended by its creator to be pronouncedwith the final consonant as in the word loch or the nameBach but English speakers often pronounce it like thefirst syllable of technical The first syllable of LATEX is

43

COMP10120 Report writing and Digital Typography

pronounced as in rsquolayrsquo5

382 Why LATEX

Before we go any further why do we think LATEX is im-portant for youmdasha Computer Science studentmdashto knowabout Here are some reasons in no particular order

bull LATEX and TEX are superb examples of ComputerScience in action TEX was designed by Knuth fromfirst principlesmdashin other words from scratch TEXis actually a programming language and LATEX isa set of functions defined in the TEX language TheTEX lsquocompilerrsquo is written in WEBW a mixture ofdocumentation written in TeX and a PascalW sub-set in order to ensure portability it reads a TEXprogram and outputs documents TEX is completelyself-contained and designed to be portable to anycomputer architecture For example it implementsits own stackW and heapW (with garbage collectionW)and it does fixed-precision arithmeticW donrsquot worryif these terms donrsquot make much sense to you at themoment they soon will

5The Greek prefix lsquotexrsquo means lsquoartrsquo as well as lsquotechnologyrsquo so itrsquos a very nicelychosen name for a piece of software that produces such beautiful output Knuthexplained (D Knuth 1984) that one should lsquopronounce the X of TeX as a Greekchi not as an lsquoxrsquo so that TeX rhymes with the word blecchhhrsquo Wersquore not toosure that helps much unless you are confident in your pronunciation of theword lsquoblecchhrsquo Maybe itrsquos an American thing

44

COMP10120 Report writing and Digital Typography

bull LATEX is a new interesting way for you to thinkabout preparing documents

bull LATEX has a practical advantage for the writer inthat it helps you think more about what you wantto write rather than worrying about how it looks

bull LATEX is a powerful tool for professional scientificdocumentation and as a Computer Scientist youshould know about it

bull LATEX files are just plain text so can easily be cre-ated programatically For example the slides usedfor COMP16120 are generated automatically fromthe source of Johnrsquos book both are typeset usingLATEX The program labprint also produces itsoutput using LATEX using information drawn fromXMLW configuration files and ARCADE

bull Using LATEX is actually quite satisfying and thequality of its output may surprise you

In this lab session you are going to write severalshort documents using LATEX You could also write briefnotes in your logbook about how LATEX works and whatcommands you used inside the source of your docu-ments

45

COMP10120 Report writing and Digital Typography

383 Some history printing mathematics

Mathematics is hard to print on paper and on the Web(many websites resort to GIF or JPG images of mathsformulae which usually look horrible MathMLW pro-vides another approach but it is not yet widely used)

In the days before computers books and newspa-pers were printed with movable typeW made from lotsof little blocks of metal each with letters numbers andsymbols standing in relief which when inked left animpression on the paper (see Figure 35) The job ofthe printer (the printer here of course being a personnot a bit of electronics) was to gather together all theblocks in the right order between two horizontal stripsof wood to create a line of the document and then toassemble all those lines from top to bottom of a pageThus the term type settingW an incredible task whenyou think about it In the printerrsquos workshop by theway the blocks of metal were stored between jobs inwooden boxes called cases Letters like a b and c werestored in one case letters like A B and C were storedin a case sitting on top of that So a lower case and anupper case These terms may ring a bell

As technology progressed machines controlled bytypewriters would mechanically juggle the blocks intothe right order This conceptual model is the basis onwhich TEX operates Only now the metal blocks are

46

COMP10120 Report writing and Digital Typography

Figure 35On the left a piece of cast movable type in the Garamondfont On the right a case of cast metal type pieces andtypeset matter in a composing stick The text reads lsquoThequick brown fox jumps over the lazy dog and feels as if hewere in the seventh heaven of typography together with Her-mann Zapf the most famous artist of thersquo This document istypeset in a font called Palatino created by Hermann ZapfYou may have also seen rsquoZapf Dingbatsrsquo in the font lists ofvarious desktop applications Now you know why

little pieces of data arranged into data structuresThe one thing that traditional printers hated was

dealing with the typesetting of mathematics and theywould charge extra to do it It was incredibly fiddly toget the equations looking right they had to squeeze inextra bits of metal horizontally and vertically

When computers entered the printing world attemptsto print mathematics were limited by the printing tech-nology available It took a long time to reach the pointwhere computers could typeset mathematics beautifullyand that was the outstanding achievement of Knuthrsquos

47

COMP10120 Report writing and Digital Typography

TEXLetrsquos look at a quick example of the quality you get

from LATEX with a very simple formula that yoursquoll recog-nise

x =minusbplusmn

radicb2 minus 4ac

2aWersquoll revisit how LATEX typesets mathematics in Section 34

384 To WYSIWYG or not to WYSIWYG

Up until now you have probably used wordprocessingapplications such as Microsoft Word to create essaysletters and other (probably fairly short) documents Youmost likely know that the majority of modern wordprocessors use a paradigm called WYSIWYG or WhatYou See Is What You Get which means that you canmodify the visual style of the document yoursquore work-ing on by selecting the relevant bits and then choos-ing different attributes such as font size or colour usinga GUI In many ways this seems like such a sensibleand obvious way of doing things that you might bewondering why it even has a special name The rea-son is a historical one in the early days of comput-ing long before graphical window managers becamethe norm and when all you could display on screenwas fixed-width ASCII text in whatever the systemrsquos

48

COMP10120 Report writing and Digital Typography

default font was wordprocessors (eg Figure 36) onlyallowed you to format documents by using special se-quences of characters to cause particular effects Butthese effects were only visible when the document wasprinted So if you wanted a word to appear in boldtext in the wordprocessor you might write somethinglike [bold]hello world[bold] what you saw onscreen was not a direct reflection of what appeared onthe printed page If yoursquove written any HTML how-ever this process of marking up text may be familiarsee for example Figure 37 As computers moved todisplays able to draw things other than raw charac-ters on screen wordprocessors became capable of us-ing multiple fonts and styles as well as graphics anda new generation of applications appeared where whatyou saw on screen was an accurate reflection of how itwould appear when printed what you see (on screen)is what you get (on paper)

The huge advantage of WYSIWYG is that itrsquos reallyeasy to understand whatrsquos going on and most peoplecan create reasonably nicely formatted documents withrelatively little effort For short informal documentsone-off letters memos and such WYSIWYG works quitenicely But if yoursquove ever tried writing anything muchlonger or that includes images and tables you mayhave already started to see where the paradigm breaksdown For example if you write lsquoFigure 38 on page

49

COMP10120 Report writing and Digital Typography

Figure 36A screenshot of Wordperfect 51 running in Microsoft DOScirca 1989

51 shows a picture of some men looking at cheesersquo butthen later on edit your document to include some moretext at the start and a new picture of a some broccoli(as in Figure 39) yoursquod have to search through yourreport to find all mentions of lsquoFigure 38rsquo and lsquopage 51rsquoand manually update them to reflect the new number-ing This might be fine if you have two figures and fivepages but for a hundred-page report containing lots ofpictures you can see how this becomes tedious and er-ror prone very quickly

50

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 6: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

side simply looks a bit clumsy as you can see in Fig-ure 31 To make this decision LATEX has had to knowa lot about the fonts being used (not all lsquofrsquos in all fontshave a blobby end not all lsquoirsquos in all fonts have a rounddot that would merge nicely with the blobby bit on theend of an lsquofrsquo and so on) Therersquos a reasonable chancethat yoursquove never heard of ligated characters beforemdashit is after all a fairly specialist thing And there arehundreds of other obscure but important lsquorulesrsquo of ty-pography that go to make professionally typeset doc-uments look good2 Individually they might not beobvious or hugely important but collectively and sub-liminally they make the difference between somethingthat looks just-about-acceptable (like most things writ-ten using wordprocessors) and things that stand out aslooking really professional (you might want to remem-ber this when it comes to putting your CV together)

But thatrsquos enough about the typography of the wordlsquofirersquo for now Letrsquos put together something more sub-stantial

2Look up lsquokerningrsquo lsquocombining charactersrsquo and lsquoserifrsquo on Wikipedia forstarters And if yoursquore really keen Donald Knuthrsquos fascinating and compen-dious book lsquoDigital Typographyrsquo (D Knuth 1999) has an entire chapter dedi-cated to the joys of the letter lsquoSrsquo Probably best not to bring this subject up at thepub though or at parties Unless they are very specialist parties

13

COMP10120 Report writing and Digital Typography

Figure 31The word lsquofirersquo typeset by (a) Microsoft Word 2011 withoutligated characters and (b) by LATEX showing the ligation ofthe characters lsquofrsquo and lsquoirsquo

Exercise 2 A larger example

Create yourself a new file called sectionstex by copy-ing fire-and-icetex In sectionstex replace the lineof poetry by copying and pasting the text from Figure32 (which contains the first three paragraphs of Dick-ensrsquo novel lsquoBleak Housersquo (C Dickens 1852))

Edit the text to make sure that there is a blank linebetween each of the three paragraphs (itrsquos not enoughthat each paragraph starts on a new line of its ownthere has to be an empty line in between them) Thatrsquoshow paragraphs are distinguished in LATEX (in fact itdoesnrsquot matter how many blank lines you put as longas there is at least one for the most part LATEX ignoresspare whitespace) After the lsquoBleak Housersquo text typea paragraph of gibberish by randomly hitting keys onthe keyboard and putting spaces in to make lsquowordsrsquo inthe text file You should end up with something like thefollowing but about three times as long (donrsquot cut andpaste this from here itrsquos important that you actually

14

COMP10120 Report writing and Digital Typography

London Michaelmas term lately over and theLord Chancellor sitting in Lincolnrsquos Inn HallImplacable November weather As much mud inthe streets as if the waters had but newly retiredfrom the face of the earth and it would not bewonderful to meet a Megalosaurus forty feetlong or so waddling like an elephantine lizardup Holborn Hill Smoke lowering down fromchimney-pots making a soft black drizzle withflakes of soot in it as big as full-grownsnowflakesndashgone into mourning one mightimagine for the death of the sun Dogsundistinguishable in mire Horses scarcelybetter splashed to their very blinkers Footpassengers jostling one anotherrsquos umbrellas in ageneral infection of ill temper and losing theirfoot-hold at street-corners where tens ofthousands of other foot passengers have beenslipping and sliding since the day broke (if thisday ever broke) adding new deposits to the crustupon crust of mud sticking at those pointstenaciously to the pavement and accumulatingat compound interest

Fog everywhere Fog up the river where it flowsamong green aits and meadows fog down theriver where it rolls defiled among the tiers ofshipping and the waterside pollutions of a great(and dirty) city Fog on the Essex marshes fogon the Kentish heights Fog creeping into thecabooses of collier-brigs fog lying out on theyards and hovering in the rigging of great shipsfog drooping on the gunwales of barges andsmall boats Fog in the eyes and throats ofancient Greenwich pensioners wheezing by thefiresides of their wards fog in the stem and bowlof the afternoon pipe of the wrathful skipperdown in his close cabin fog cruelly pinching thetoes and fingers of his shivering little rsquoprenticeboy on deck Chance people on the bridgespeeping over the parapets into a nether sky offog with fog all round them as if they were upin a balloon and hanging in the misty clouds

Gas looming through the fog in divers places inthe streets much as the sun may from thespongey fields be seen to loom by husbandmanand ploughboy Most of the shops lighted twohours before their timemdashas the gas seems toknow for it has a haggard and unwilling look

Figure 32Some sample text from the opening of the Dickensrsquo novellsquoBleak Housersquo (C Dickens 1852)

15

COMP10120 Report writing and Digital Typography

create some unique gibberish yourself)

Oisjdf oqweqwe oi soijs hbweo kbsd oijsdfoijqwknpiouh iusbdfspb sifuhygwqeb usgweijfblimqwoq oieuerwefwiu aokqjw uioshiufdsqiqks odfubfi psdiweneq

Be careful at this stage to only include letters (upper-case and lowercase) commas full-stops and perhapsnumbers in your gibberish text if you use any othersymbols you may upset LATEX

Next go to the website wwwlipsumcom and fol-low the instructions to generate yourself three para-graphs of whatrsquos called Lorem Ipsum text Copy andpaste that text into your LATEX document too (donrsquot worryabout what it means at this stage) again making surethat you have a blank line between the paragraphs

Run pdflatex and look at the resulting sectionspdfAgain at first glance therersquos nothing hugely excitinggoing on here the text from your tex file has beenassembled into a (probably) two page PDF documentBut in fact quite a few things have happened

bull The blank lines that separate the paragraphs inyour source file are gone and instead LATEX hasindented the first line of each paragraph Therersquosnothing profound here about the decision to in-dent paragraphs rather than (say) to leave a gap

16

COMP10120 Report writing and Digital Typography

between them (so called block paragraphs) itrsquosjust LATEXrsquos default paragraph style and can bechanged easily enough3

bull There are page numbers at the bottom of each page(except page 1) This is a very sensible default al-lowing you in meetings to ask people to lsquoturn topage 4rsquo and so on (itrsquos a bit odd and a source ofsome annoyance that most wordprocessors donrsquotdo this by default too) But you can easily switchpage numbers off change their style or move themelsewhere if you need to

bull The text is fully justified so that itrsquos flush on boththe left and right hand edges

bull Certain words that fall at the end of lines havebeen hyphenated even if they werenrsquot originallysplit by hyphens in the source text

These last two points about justification and hyphen-ation might seem utterly trivial but getting these fac-tors right turns out to be an important part of mak-ing readable documents readability is not just aboutwhich font you choose but about how the charactersand spaces are distributed on each line Itrsquos something

3Though apparently there is some evidence in M A Tinker 1963 that in-dented paragraphs increase readability

17

COMP10120 Report writing and Digital Typography

that you will have seen happen so often in profession-ally typeset materials that yoursquoll have taken it for grantedand you may not have spotted that it doesnrsquot happenin quite the same way when you use a wordproces-sor The principle behind justifying text seems easyenough at first glance you simply have to take any lsquoleftoverrsquo space that would be at the end of a line and re-distribute it between the words in some way to lsquospacethem outrsquo a bit more so that they take up all the avail-able horizontal room But it turns out to be much harderthan it seems and all the simple ways you might thinkof for doing this on a per-line basis give results thatare visually quite unsatisfactory with nasty patternsmade up of neighbouring whitespace appearing in thelayout and ruining everything The added complica-tion here is that to do the optimum job of shuffling thewords round on their lines you really need the flex-ibility of being able to hyphenate words to give youextra space on lines that would otherwise be tightlypacked with characters But if you hyphenate wordsbadly by breaking them in inappropriate places or doit too often then that makes the text hard to read tooItrsquos all deeply inconvenient and inter-related The bestsolution to this aesthetic conundrum so far was devel-oped by Knuth and Plass 1981 and later improved byFrank Liang during his PhD research (F M Liang1983) and itrsquos a technique that tries to optimise the lay-

18

COMP10120 Report writing and Digital Typography

out of whole paragraphs rather than individual linesThe algorithm takes into account all manner of differ-ent things language-specific character patterns the num-ber of consecutive lines that end with hyphens the wordlsquotightnessrsquo on each line and many others The detailsdonrsquot really matter here but the really important in-sight is that you get better results by working on a big-ger chunk of the document (in this case a paragraph at atime) rather than trying to independently optimise lotsof small bits (say lines) and hoping that the result ofjoining them all together turns out nicely This idea ofoptimising things globally versus locally is somethingyoursquoll see many times throughout your Computer Sci-ence degree watch out for it in all the algorithms courses

This highlights a fundamental difference betweenthe WYSIWYG paradigm and the way that documentsare produced using LATEX As wersquove seen small changesdown at the level of individual characters can have fairlylarge knock-on consequences for the optimal layout ofa document changing one letter for another affects thelength of a line which in turn affects the hyphenationoptions which then affects the length of a paragraphwhich means that the best place for a figure that was onpage 99 might now be on page 100 but that means thatall references to lsquopage 99rsquo now need a bit more room toaccount for the extra digit which means that the someline lengths have changed which means well you get

19

COMP10120 Report writing and Digital Typography

the idea Itrsquos more complicated than it first seems LATEXgets to see the whole of your document at once and cantherefore make decisions about how best to hyphen-ate lines position figures or whatever else it likes beforeit shows you the results so it can make solutions thatare optimal for the whole document as well as lookingat details such as ligated characters Wordprocessorscanrsquot afford to do this since it would be deeply distract-ing if every time you typed a character the whole lay-out of the document flapped around in front of youreyes Wordprocessors can only sensibly make little op-timisations at a local (probably per-line level) Itrsquos notthat wordprocessors are rubbish or that the people thatprogrammed them were lazy itrsquos a fundamentally dif-ferent way of working and knowing the pros and consof the different approaches will help you pick the righttool for the job

You may have noticed that actual text in your doc-ument (and in fact this one) takes up a (perhaps) sur-prisingly narrow horizontal region of the page Thislast lsquofeaturersquo might seem odd at first but it illustratesanother important typographical point that you maynever have thought of before reading long lines of textis hard because your eyes find it hard to move in acompletely straight line as they scan from left to rightSo the longer the line of words the more you have towork to keep your eyes from accidentally drifting up or

20

COMP10120 Report writing and Digital Typography

down onto a neighbouring line (perhaps yoursquove expe-rienced the phenomenon of accidentally re-reading thesame line over and over as your eyes get tired) It maynever have occurred to you but most books have rela-tively short lines of text and those that use large pagesoften split text into several columns so that individuallines are kept relatively short The widely trusted booklsquoThe Elements of Typographic Stylersquo (R Bringhurst1992) makes the following assertion

lsquoAnything from 45 to 75 characters is widely-regarded as a satisfactory length of line for a single-column page set in a serifed text face in a text sizeThe 66-character line (counting both letters andspaces) is widely regarded as idealrsquo

LATEX knows about this issue so made a sensible de-fault decision for you You may have noticed that thereis a subtle difference in appearance of this chapter fromprevious ones the lines are shorter and paragraphs areindented We wanted to use the default LATEX layoutfor this chapter but changed it for earlier chapters inan effort to save paper

Therersquos one last unusual thing to note your para-graph of gibberish text in between the real words fromBleak House and the Lorem Ipsum almost certainly standsout and looks really quite odd (it might even have con-fused LATEXrsquos hyphenation rules enough to have ended

21

COMP10120 Report writing and Digital Typography

up with one or more lines sticking out proud of theright hand margin) Let your eyes relax so that yourvision blurs for a moment you can still probably spotthat the gibberish paragraph looks out of place Itrsquosquite likely that you even found creating the gibber-ish unexpectedly hard The interesting thing here isthat as humans we spend so much time reading andwriting lsquoproperrsquo natural language that we become at-tuned to the patterns of letters words and the underly-ing lsquorhythmrsquo of our written language that its very hardto artificially reproduce something that looks plausiblethe frequency of the letters you chose by randomly hit-ting keys and the length and patterns of the words youput in place most likely donrsquot match the natural pat-terns of real languages so they just look plain wrongCuriously the Lorem Ipsum text that you got from thewebsite probably doesnrsquot look so bad in spite of it notbeing made up of real words But thatrsquos not surprisingsince Lorem Ipsum is specifically created to be used asa placeholder for real text when typesetting While thewords are meaningless Latin-like things their lengthand the distribution of characters and word lengths arechosen to mimic patterns in real language

Next letrsquos give our document some structure by di-viding it up into sections On the line before BleakHouse starts add the command

22

COMP10120 Report writing and Digital Typography

sectionBleak House

making sure it appears on a line of its own Then justbefore your paragraph of gibberish put a similar in-struction (again on its own line) and then create a finalsection before the Lorem Ipsum Rerun pdflatex andlook at the results You should see the section headingsappear in the appropriate places in the PDF automati-cally having been given section numbers Experimentby adding in a couple of sub-sections towards the endof the document using the subsection commandwhich like the section command above takes as aparameter some text contained in curly brackets

Now at the top of your document after the begindocumentline and before the command defining the first sectionadd the following two commands each on their ownline

tableofcontentsnewpage

Re-run pdflatex twice and check that the effect is whatyoursquod expect You need to process the source twice be-cause on the first run LATEX gathers and stores informa-tion about what to put in the table of contents and onlycreates it on the second run

23

COMP10120 Report writing and Digital Typography

33 Common formatting features

Before we give you some more exercises to do here is abrief introduction to some commonly used features ofLATEX

331 Enumerated and bulleted lists

Creating bulleted or numbered lists in LATEX is straight-forward and is done like this

beginenumerateitem My first itemitem My second itemitem The last thing on my listendenumerate

You must make sure that you both begin and end yourlist and that each item is terminated by a newline Chang-ing enumerate to itemize gives you a bulleted ratherthan numbered list (note the American spelling of lsquoitem-izersquo)

332 Changing the appearance of text

Text can be typeset in bold font using the textbfin italics using textitand in a fixed-width fontusing texttt as in the example below

24

COMP10120 Report writing and Digital Typography

Some textttsay the textbfworld will end in textitfire

which is typeset as

Some say the world will end in fire

333 Cross referencing

LATEX allows you to cross-reference almost anything inthe document which includes sections sub-sections andfigures To use the cross-referencing feature you simplyinsert the command

labelmymarker

at the point in the document you want to refer to andthen use the command

refmymarker

when you want to use the reference Obviously youreplace the text mymarkerwith something more mean-ingful An important tip here is to call the marker some-thing that refers to the content of that part of the doc-ument and to avoid the temptation to use numbers(so donrsquot call your marker section1 instead call itintroduction if you reorder your document itrsquos stilllikely to be the introduction but it may no longer beSection 1) For example

25

COMP10120 Report writing and Digital Typography

sectionReflection on Welcome WeeklabelwelcomeweekI spent most of welcome week getting to know my wayaround campus I should have made more effort to joinsocieties I think I must remember to get to theStudentsrsquo Union and take a look around there

subsectionThings I enjoyedEverything so far has been wonderful with the caveat Imentioned in Section refwelcomeweek

subsectionThings I didnrsquot enjoyIrsquove discovered that I donrsquot like soggy chips

The really useful thing about cross-referencing in LATEXis that yoursquoll get warnings when you compile your doc-ument if cross-references are undefined or used incor-rectly This means you donrsquot have to manually checkevery reference in your document to make sure itrsquos stillright You do however have to run LATEX twice forsimilar reasons to those given above

334 Figures and pictures

Including figures and pictures in your document is easyYou do it like this

beginfigure

26

COMP10120 Report writing and Digital Typography

Figure 33Some men possibly Dutch looking at cheeses

centerlineincludegraphics[width=10cm]imagesmen-and-cheesejpgcaptionSome men possibly Dutch looking at cheeseslabelfiguremenandcheesesendfigure

which is the code we used to create Figure 38 You canprobably see whatrsquos happening The command includegraphicsgets your image which can be PDF PNG JPG GIF orPostScript The beginfigureendfigurecode lsquowrapsrsquo up whatever picture yoursquore including andallows LATEX to treat it as an unbreakable floating thingthat it will position for you as best it can in the docu-ment while maintaining an overall nice typographicallayout This floating of figures can sometimes result inthe figure ending up in a place you didnrsquot expect but inmost cases LATEX will make the most sensible choice Itrsquos

27

COMP10120 Report writing and Digital Typography

possible to employ finer control over figure placementbut thatrsquos beyond the scope of this introduction

The includegraphics command is not built into core LATEX but is in an additional package whichneeds to be explicitly loaded We load this package byusing the command usepackagegraphicx in thedocument preamble ie after the documentclasscommand but before begindocument There arehundreds of such packages that extend LATEXrsquos func-tionality the lab scripts you are reading now use over30 of them

Exercise 3 Including images

Create a document imagetex that contains some text(maybe from rsquoLorem Ipsumrsquo) together with a figurecontaining an image of your choice perhaps the oneyou made in Intro Lab 2 like Steversquos Mr Noodle Thereshould also be a reference to the figure in the text Youshould first use the program convert

convert

(check its manpage) to create a PDF version of the image

Exercise 4 A reflection on your studies

Your first proper LATEX document will be a very briefreflection on your studies so far

Write a hand-crafted LATEX document called courses-reflectiontex

28

COMP10120 Report writing and Digital Typography

(exact name as usual please otherwise submitwill notwork) It will have the following structure

1 A table of contents

2 A brief paragraph saying what the document isabout

3 A section appropriately titled for one of your courseunits containing

bull a brief paragraph saying what the unit is about

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the most about the unit

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the least about the unit

A repeat of item 3 for each other unit you are study-ing These sections should appear in alphabeticalorder by course code (eg COMP10120)

After completing and successfully compiling and view-ing your document you should spell-check it as fol-lows

ispell courses-reflectiontex

29

COMP10120 Report writing and Digital Typography

Once you are completely satisfied with it produce ahard copy ready for marking

34 Typesetting Mathematics

Earlier we saw this formula

x =minusbplusmn

radicb2 minus 4ac

2aIt looks nice doesnrsquot it To tell LATEX to display thisyou have to type a bit of magic but itrsquos easily-learnedmagic To create such a formula in a WYSIWYG edi-tor there is also magic involved but it usually involvesa lot of mouse-clicking and remembering special keycombinations like rsquocontrol-thisrsquo and rsquoalt-thatrsquo In LATEXit doesnrsquot You simply type this

[ x = frac-b pm sqrtb^2-4ac2a ]

You can probably work out how most of this createsthe formula but it wonrsquot be obvious that the [ and ]symbols that enclose the formula mean lsquotypeset this asa displayed formula giving it some vertical space fromthe surrounding textrsquo If wersquod used ( and ) insteadto enclose the formula it would appear in-line like thisx = minusbplusmn

radicb2minus4ac2a It still looks very nice and observe

how itrsquos automatically been resized to fit and that the

30

COMP10120 Report writing and Digital Typography

lines of text have had their spacing changed a bit Thisall looks simple but the implementation inside LATEXand TEX is complex It involves parsing the descrip-tion of the formula to create a corresponding tree datastructure which is then recursively walked to workout the horizontal and vertical typographical spacingsneeded Yoursquoll meet these ideas in COMP11120 andCOMP26120 Algorithms and Imperative Programming

Herersquos another example taken from COMP27112Computer Graphics (itrsquos a lsquosimplersquo local illuminationmodel incorporating ambient diffuse and specular re-flection by multiple lights)

I = kaIa +

Msumi=1

Ipidprimei[kd(N middot Li) + ks(Ri middot V )n]

We write this in LATEX as follows

[ I = k_a I_a + sum_i=1^M fracI_p_idrsquo_i [ k_d(hatN cdot hatL_i)+ k_s(hatR_i cdot hatV)^n] ]

Try to match the LATEX commands with the formula dis-played above Yoursquoll see lots of curly brackets and thisexample illustrates their two uses in LATEX The firstis to provide an argument to a command for exam-ple hatN means lsquoapply the hat command to N rsquowhich creates N the vector N with a little hat on

31

COMP10120 Report writing and Digital Typography

The second use of curly brackets is to group thingstogether to avoid ambiguities In the example you cansee sum_i=1^M which creates a summation signand its lower and upper limits

sumMi=1 We wrap the

lower bound i=1 in curly brackets to group it into anindivisible unit If we were to omit the brackets writ-ing sum_i=1^M LATEX would then produce

sumi = 1M

which is not at all what we want (even LATEX canrsquot al-ways know what we really want)

One final example If we tell LATEX

[ T_1 = left[beginarraycccccos theta amp -sin theta amp 0 amp delta sin theta amp cos theta amp 0 amp epsilon 0 amp 0 amp 1 amp eta alpha amp beta amp gamma amp 1endarrayright] ]

wersquoll get a splendid matrix which expresses a particu-lar 3D geometrical transformation (Donrsquot worry if youdonrsquot recognise this yoursquoll be introduced to matrix no-tation in the latter part of COMP11120 MathematicalTechniques for Computer Science For now you can justtreat it as some mysterious maths)

32

COMP10120 Report writing and Digital Typography

T1 =

cos θ minus sin θ 0 δ

sin θ cos θ 0 ε

0 0 1 η

α β γ 1

In the LATEX code left[means lsquobig opening square

bracket pleasersquo ccccmeans lsquoan array with 4 columnsplease with the items in each column centredrsquo ampmeanslsquostart a new columnrsquo and means lsquostart a new rowrsquoYoursquoll notice that LATEX knows about greek letters itknows about most standard maths symbols too andalso the ways theyrsquore usually used

There are some symbols that you might need (forexample therefore which produces the usual threedots symbol there4) that are not part of standard LATEX Manysuch symbols are provided by the amssymb package ofsymbols compiled by the American Mathematical Soci-ety Details of the many symbols provided by this pack-age can be found online at

mirrormathkuedutex-archivefontsamsfontsdocamssymbpdf

To use these extra symbols you need to have usepackageamssymbin the document preamble

33

COMP10120 Report writing and Digital Typography

341 A longer piece of mathematics

We conclude this section with an example of a longerpiece of mathematics that shows how you might type-set a complete mathematical argument rather than asingle formula The example is Euclidrsquos proof of thefact that

radic2 is irrational Itrsquos an argument that has been

covered in COMP11120 and is an example of proof bycontradiction It starts by making the assumption thatit is not the case that

radic2 is irrational in other words that

we can find integers p and q withradic2 = pq

We can assume without losing anything that p andq have no common factors (Why)

radic2 = pq

qradic2 = p

2q2 = p2

This means that p2 is even from which we can also de-duce that p is even (Why)

This means that p = 2k for some k so

2q2 = (2k)2

there4 2q2 = 4k2

so q2 = 2k2

But this means that q2 and hence q is even Since p andq are both even we have a contradiction to our initialassumption so no such p and q exist

The way this is formatted is shown here

34

COMP10120 Report writing and Digital Typography

It starts by making the assumption that it is emphnot the casethat $sqrt2$ is irrational in other words that we can findintegers $p$ and $q$ with $sqrt2 = pq$

We can assume without losing anything that $p$ and $q$ haveemphno common factors (Why)

[beginarraylcl

sqrt2 amp = amp pq qsqrt2 amp = amp p 2q^2 amp = amp p^2

endarray]

This means that $p^2$ is even from which we can also deduce that $p$is even (Why)

This means that $p = 2k$ for some $k$ so ldots[beginarrayllcl

amp 2q^2 amp = amp (2k)^2 therefore amp 2q^2 amp = amp 4k^2 textso amp q^2 amp = amp 2k^2

endarray]

But this means that $q^2$ and hence $q$ is even Since $p$ and $q$are both even we have a contradiction to our initial assumptionso no such $p$ and $q$ exist

Notice the use of the array environment for gettingthings lined up You can find much more informationabout this on the web

LATEX really shines at typesetting mathematics and

35

COMP10120 Report writing and Digital Typography

it would take pages and pages to describe all the fea-tures Have a look at

enwikibooksorgwikiLaTeXMathematics

for a flavour

Exercise 5 Formatting mathematics

Now for an exercise that involves some mathematicsPlease create a file f-wtex which typesets the follow-ing piece of text and mathematics

There are many positive integer solutions tothe equation

x2 + y2 = z2

which can be rewritten as

z =radicx2 + y2

For example (3 4 5) or (5 12 13) Such solu-tions are called Pythagorean triples

However for higher powers the situation isvery different and we have-

Theorem Fermat-WilesFor all natural numbers n ge 3 there are no

36

COMP10120 Report writing and Digital Typography

integers x y z satisfying the equation

xn + yn = zn

35 Curriculum vitaie

There are several scenarios where using LATEX ratherthan other word processing software can be useful

bull typesetting mathematics yoursquove just read about

bull writing a technical document

bull your final year project peport

bull writing an article you want to get published

bull writing a Curriculum vitae CV

Wersquoll now look at CVrsquos briefly

Exercise 6 Curriculum vitae

Creating a professional document is especially impor-tant when you write your CV because how your CVlooks (not just the content) will determine if you are in-vited to interview for job you are applying for Thatcould be a summer internship next year a year long

37

COMP10120 Report writing and Digital Typography

placement after your second year or graduate positionafter you leave University

As well using a text-editor and compiling files fromthe command line other tools are available for editingLATEXWe will look at one of these overleafcom

Create a basic CV which describes you your edu-cation (including University) and any experience youhave or interesting projects that you may have doneYou can do this using httpsoverleafcom andchoosing the ready-made templates at httpswwwoverleafcomgallerytaggedcv

As you progress through University it is a good ideato keep your CV up to date and get feedback from asmany people as you can There will be opportunities todebug your CV later (See httpgitiomycv if youare interested) but yoursquoll need a ldquobeta releaserdquo (version10) of your CV to get started The best time to start thisprocess is now

36 Some optional extras

Exercise 7 Exploring more LATEX features (op-tional but easy)

This exercise reinforces some of the things yoursquove donealready but also introduces some features of LATEX that

38

COMP10120 Report writing and Digital Typography

will be new to you It is labelled as optional because itisnrsquot marked but we would recommend that you all tryit

Take a copy of the file optinfocoursesCOMP10120ex3latex-introtexand follow the instructions it contains You should readit before you process it with LATEX

Exercise 8 A neat directory listing (optionalmore challenging)

The fact that LATEX source files are just text makes it easyto have them generated by a program You are going toexploit this and use LATEX to produce a neat documentcontaining a listing of the files in any directory

Find how to create tables in LATEX tables using thetabular environment Make a LATEX document by handthat uses a table to neatly show the information aboutthe files in some (small) directory (as produced by ls

-l) Write a shell script called neat-ls that takes anargument which is the path name of a directory andproduces a LATEX document containing the above tablefor the given directory The script could also process theLATEX and display the resulting pdf file Finally find outabout the longtable package and change your script touse that instead

39

COMP10120 Report writing and Digital Typography

Exercise 9 A cleaning rota (optional evenmore challenging)

Now you will write a shell script called make-rota thatgenerates a house cleaning rota (Very handy for nextyear ) This is a table with columns such as KitchenBathroom and Lounge The rows will be weeks in theyear labelled with a date (eg always a Sunday) Theidea is that house mates can write their initials in theboxes promising to clean the corresponding room inthat particular week Start by making a sample tableby hand

Your script should take a single argument which isthe date of the first day of the first row eg102013(the US format for 20 Oct 13) The result will be a docu-ment that contains as many rows as fit on a single page(find out by experimenting)

The dates of each row should be generated from thefirst See the manual page for date to figure out howyou can generate a date that is a number of weeks anddays later than an existing one

361 Marking Scheme

You can view a copy of the marking scheme used bysubmit and labprint at

40

COMP10120 Report writing and Digital Typography

studentnetcsmanchesteracukugtlpmsphpunit=COMP10120ampex=ex3xml

37 Next steps

LATEX is a very powerful tool and it does take a littlegetting used to But itrsquos not as scary as it might initiallyseem and you should find that it doesnrsquot take long tolearn the common commands and techniques to makeyour documents well-structured and readable As youbecome more comfortable with the basics and under-stand the principles of typesetting finding out how todo more complex and sophisticated things is easymdashthere are hundreds of tutorials on the web

Donrsquot get carried away though and use the featuresjudiciously just because yoursquove found a cool new com-mand doesnrsquot mean that you should use it just to showoff your LATEX skills content and structure always trumpstypographic twiddlings4

4For example footnotes like this are for some reason a really tempting fea-ture to use in LATEX and in this document we have abused them mercilessly toillustrate a point Footnotes were originally a means for mechanical typeset-ters to insert comments corrections or additions to existing documents withouthaving to adjust the layout of a whole page and of course in digital typographythis is no longer necessary They can justifiably be used for citations (though itrsquosnot common to do so these days) and URLs if you donrsquot want these intrudinginto the body of your text And in some very very rare cases they can be usedas an aside to the main flow of the text (which is what has been done in this doc-ument) But this should be used sparingly If something is important to sayput it in the main body of your text If itrsquos not then perhaps you should thinkabout leaving it out completely or find some other way of including it Asking

41

COMP10120 Report writing and Digital Typography

371 Acknowledgements

Figure 38 is from the Wikipedia article on cheese

372 License

The text of this exercise is licensed under the terms ofthe Creative Commons Attribution 20 Generic (CC BY30) License

38 Background

What follows is additional contextual information aroundLATEX

LATEX was originally written by Leslie LamportW anAmerican computer scientist now working at MicrosoftResearch although its development has long been takenover by a world-wide LATEX community Itrsquos actuallybuilt on top of another system called TEX a computertypesetting system designed by one of the worldrsquos mostinfluential Computer Scientists Donald KnuthW of Stan-ford University Knuth has said that he designed TEX

the reader to look down at the bottom of a page to find out whether somethingis important or not is irritating and as yoursquove probably found out already oftenmeans you lose track of your reading position They also give the impressionthat the author isnrsquot clear about whether something is important or not whichis never good And long footnotes like this onemdashwhile LATEX will typeset themperfectly wellmdashare just plain silly Best avoid

42

COMP10120 Report writing and Digital Typography

for lsquothe creation of beautiful booksmdashand especially forbooks that contain a lot of mathematicsrsquo(D Knuth1984) Figure 34 shows what these eminent men looklike

So whatrsquos the purpose of LATEX Itrsquos purely a layerof software to make TEX easier to use in everyday sit-uations This is a good idea because although TEX isamazingly powerful it operates at a very low-level whichmakes it hard for non-expert users

Figure 34Don Knuth and Leslie Lamport

381 Pronunciation

The name TEX is intended by its creator to be pronouncedwith the final consonant as in the word loch or the nameBach but English speakers often pronounce it like thefirst syllable of technical The first syllable of LATEX is

43

COMP10120 Report writing and Digital Typography

pronounced as in rsquolayrsquo5

382 Why LATEX

Before we go any further why do we think LATEX is im-portant for youmdasha Computer Science studentmdashto knowabout Here are some reasons in no particular order

bull LATEX and TEX are superb examples of ComputerScience in action TEX was designed by Knuth fromfirst principlesmdashin other words from scratch TEXis actually a programming language and LATEX isa set of functions defined in the TEX language TheTEX lsquocompilerrsquo is written in WEBW a mixture ofdocumentation written in TeX and a PascalW sub-set in order to ensure portability it reads a TEXprogram and outputs documents TEX is completelyself-contained and designed to be portable to anycomputer architecture For example it implementsits own stackW and heapW (with garbage collectionW)and it does fixed-precision arithmeticW donrsquot worryif these terms donrsquot make much sense to you at themoment they soon will

5The Greek prefix lsquotexrsquo means lsquoartrsquo as well as lsquotechnologyrsquo so itrsquos a very nicelychosen name for a piece of software that produces such beautiful output Knuthexplained (D Knuth 1984) that one should lsquopronounce the X of TeX as a Greekchi not as an lsquoxrsquo so that TeX rhymes with the word blecchhhrsquo Wersquore not toosure that helps much unless you are confident in your pronunciation of theword lsquoblecchhrsquo Maybe itrsquos an American thing

44

COMP10120 Report writing and Digital Typography

bull LATEX is a new interesting way for you to thinkabout preparing documents

bull LATEX has a practical advantage for the writer inthat it helps you think more about what you wantto write rather than worrying about how it looks

bull LATEX is a powerful tool for professional scientificdocumentation and as a Computer Scientist youshould know about it

bull LATEX files are just plain text so can easily be cre-ated programatically For example the slides usedfor COMP16120 are generated automatically fromthe source of Johnrsquos book both are typeset usingLATEX The program labprint also produces itsoutput using LATEX using information drawn fromXMLW configuration files and ARCADE

bull Using LATEX is actually quite satisfying and thequality of its output may surprise you

In this lab session you are going to write severalshort documents using LATEX You could also write briefnotes in your logbook about how LATEX works and whatcommands you used inside the source of your docu-ments

45

COMP10120 Report writing and Digital Typography

383 Some history printing mathematics

Mathematics is hard to print on paper and on the Web(many websites resort to GIF or JPG images of mathsformulae which usually look horrible MathMLW pro-vides another approach but it is not yet widely used)

In the days before computers books and newspa-pers were printed with movable typeW made from lotsof little blocks of metal each with letters numbers andsymbols standing in relief which when inked left animpression on the paper (see Figure 35) The job ofthe printer (the printer here of course being a personnot a bit of electronics) was to gather together all theblocks in the right order between two horizontal stripsof wood to create a line of the document and then toassemble all those lines from top to bottom of a pageThus the term type settingW an incredible task whenyou think about it In the printerrsquos workshop by theway the blocks of metal were stored between jobs inwooden boxes called cases Letters like a b and c werestored in one case letters like A B and C were storedin a case sitting on top of that So a lower case and anupper case These terms may ring a bell

As technology progressed machines controlled bytypewriters would mechanically juggle the blocks intothe right order This conceptual model is the basis onwhich TEX operates Only now the metal blocks are

46

COMP10120 Report writing and Digital Typography

Figure 35On the left a piece of cast movable type in the Garamondfont On the right a case of cast metal type pieces andtypeset matter in a composing stick The text reads lsquoThequick brown fox jumps over the lazy dog and feels as if hewere in the seventh heaven of typography together with Her-mann Zapf the most famous artist of thersquo This document istypeset in a font called Palatino created by Hermann ZapfYou may have also seen rsquoZapf Dingbatsrsquo in the font lists ofvarious desktop applications Now you know why

little pieces of data arranged into data structuresThe one thing that traditional printers hated was

dealing with the typesetting of mathematics and theywould charge extra to do it It was incredibly fiddly toget the equations looking right they had to squeeze inextra bits of metal horizontally and vertically

When computers entered the printing world attemptsto print mathematics were limited by the printing tech-nology available It took a long time to reach the pointwhere computers could typeset mathematics beautifullyand that was the outstanding achievement of Knuthrsquos

47

COMP10120 Report writing and Digital Typography

TEXLetrsquos look at a quick example of the quality you get

from LATEX with a very simple formula that yoursquoll recog-nise

x =minusbplusmn

radicb2 minus 4ac

2aWersquoll revisit how LATEX typesets mathematics in Section 34

384 To WYSIWYG or not to WYSIWYG

Up until now you have probably used wordprocessingapplications such as Microsoft Word to create essaysletters and other (probably fairly short) documents Youmost likely know that the majority of modern wordprocessors use a paradigm called WYSIWYG or WhatYou See Is What You Get which means that you canmodify the visual style of the document yoursquore work-ing on by selecting the relevant bits and then choos-ing different attributes such as font size or colour usinga GUI In many ways this seems like such a sensibleand obvious way of doing things that you might bewondering why it even has a special name The rea-son is a historical one in the early days of comput-ing long before graphical window managers becamethe norm and when all you could display on screenwas fixed-width ASCII text in whatever the systemrsquos

48

COMP10120 Report writing and Digital Typography

default font was wordprocessors (eg Figure 36) onlyallowed you to format documents by using special se-quences of characters to cause particular effects Butthese effects were only visible when the document wasprinted So if you wanted a word to appear in boldtext in the wordprocessor you might write somethinglike [bold]hello world[bold] what you saw onscreen was not a direct reflection of what appeared onthe printed page If yoursquove written any HTML how-ever this process of marking up text may be familiarsee for example Figure 37 As computers moved todisplays able to draw things other than raw charac-ters on screen wordprocessors became capable of us-ing multiple fonts and styles as well as graphics anda new generation of applications appeared where whatyou saw on screen was an accurate reflection of how itwould appear when printed what you see (on screen)is what you get (on paper)

The huge advantage of WYSIWYG is that itrsquos reallyeasy to understand whatrsquos going on and most peoplecan create reasonably nicely formatted documents withrelatively little effort For short informal documentsone-off letters memos and such WYSIWYG works quitenicely But if yoursquove ever tried writing anything muchlonger or that includes images and tables you mayhave already started to see where the paradigm breaksdown For example if you write lsquoFigure 38 on page

49

COMP10120 Report writing and Digital Typography

Figure 36A screenshot of Wordperfect 51 running in Microsoft DOScirca 1989

51 shows a picture of some men looking at cheesersquo butthen later on edit your document to include some moretext at the start and a new picture of a some broccoli(as in Figure 39) yoursquod have to search through yourreport to find all mentions of lsquoFigure 38rsquo and lsquopage 51rsquoand manually update them to reflect the new number-ing This might be fine if you have two figures and fivepages but for a hundred-page report containing lots ofpictures you can see how this becomes tedious and er-ror prone very quickly

50

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 7: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

Figure 31The word lsquofirersquo typeset by (a) Microsoft Word 2011 withoutligated characters and (b) by LATEX showing the ligation ofthe characters lsquofrsquo and lsquoirsquo

Exercise 2 A larger example

Create yourself a new file called sectionstex by copy-ing fire-and-icetex In sectionstex replace the lineof poetry by copying and pasting the text from Figure32 (which contains the first three paragraphs of Dick-ensrsquo novel lsquoBleak Housersquo (C Dickens 1852))

Edit the text to make sure that there is a blank linebetween each of the three paragraphs (itrsquos not enoughthat each paragraph starts on a new line of its ownthere has to be an empty line in between them) Thatrsquoshow paragraphs are distinguished in LATEX (in fact itdoesnrsquot matter how many blank lines you put as longas there is at least one for the most part LATEX ignoresspare whitespace) After the lsquoBleak Housersquo text typea paragraph of gibberish by randomly hitting keys onthe keyboard and putting spaces in to make lsquowordsrsquo inthe text file You should end up with something like thefollowing but about three times as long (donrsquot cut andpaste this from here itrsquos important that you actually

14

COMP10120 Report writing and Digital Typography

London Michaelmas term lately over and theLord Chancellor sitting in Lincolnrsquos Inn HallImplacable November weather As much mud inthe streets as if the waters had but newly retiredfrom the face of the earth and it would not bewonderful to meet a Megalosaurus forty feetlong or so waddling like an elephantine lizardup Holborn Hill Smoke lowering down fromchimney-pots making a soft black drizzle withflakes of soot in it as big as full-grownsnowflakesndashgone into mourning one mightimagine for the death of the sun Dogsundistinguishable in mire Horses scarcelybetter splashed to their very blinkers Footpassengers jostling one anotherrsquos umbrellas in ageneral infection of ill temper and losing theirfoot-hold at street-corners where tens ofthousands of other foot passengers have beenslipping and sliding since the day broke (if thisday ever broke) adding new deposits to the crustupon crust of mud sticking at those pointstenaciously to the pavement and accumulatingat compound interest

Fog everywhere Fog up the river where it flowsamong green aits and meadows fog down theriver where it rolls defiled among the tiers ofshipping and the waterside pollutions of a great(and dirty) city Fog on the Essex marshes fogon the Kentish heights Fog creeping into thecabooses of collier-brigs fog lying out on theyards and hovering in the rigging of great shipsfog drooping on the gunwales of barges andsmall boats Fog in the eyes and throats ofancient Greenwich pensioners wheezing by thefiresides of their wards fog in the stem and bowlof the afternoon pipe of the wrathful skipperdown in his close cabin fog cruelly pinching thetoes and fingers of his shivering little rsquoprenticeboy on deck Chance people on the bridgespeeping over the parapets into a nether sky offog with fog all round them as if they were upin a balloon and hanging in the misty clouds

Gas looming through the fog in divers places inthe streets much as the sun may from thespongey fields be seen to loom by husbandmanand ploughboy Most of the shops lighted twohours before their timemdashas the gas seems toknow for it has a haggard and unwilling look

Figure 32Some sample text from the opening of the Dickensrsquo novellsquoBleak Housersquo (C Dickens 1852)

15

COMP10120 Report writing and Digital Typography

create some unique gibberish yourself)

Oisjdf oqweqwe oi soijs hbweo kbsd oijsdfoijqwknpiouh iusbdfspb sifuhygwqeb usgweijfblimqwoq oieuerwefwiu aokqjw uioshiufdsqiqks odfubfi psdiweneq

Be careful at this stage to only include letters (upper-case and lowercase) commas full-stops and perhapsnumbers in your gibberish text if you use any othersymbols you may upset LATEX

Next go to the website wwwlipsumcom and fol-low the instructions to generate yourself three para-graphs of whatrsquos called Lorem Ipsum text Copy andpaste that text into your LATEX document too (donrsquot worryabout what it means at this stage) again making surethat you have a blank line between the paragraphs

Run pdflatex and look at the resulting sectionspdfAgain at first glance therersquos nothing hugely excitinggoing on here the text from your tex file has beenassembled into a (probably) two page PDF documentBut in fact quite a few things have happened

bull The blank lines that separate the paragraphs inyour source file are gone and instead LATEX hasindented the first line of each paragraph Therersquosnothing profound here about the decision to in-dent paragraphs rather than (say) to leave a gap

16

COMP10120 Report writing and Digital Typography

between them (so called block paragraphs) itrsquosjust LATEXrsquos default paragraph style and can bechanged easily enough3

bull There are page numbers at the bottom of each page(except page 1) This is a very sensible default al-lowing you in meetings to ask people to lsquoturn topage 4rsquo and so on (itrsquos a bit odd and a source ofsome annoyance that most wordprocessors donrsquotdo this by default too) But you can easily switchpage numbers off change their style or move themelsewhere if you need to

bull The text is fully justified so that itrsquos flush on boththe left and right hand edges

bull Certain words that fall at the end of lines havebeen hyphenated even if they werenrsquot originallysplit by hyphens in the source text

These last two points about justification and hyphen-ation might seem utterly trivial but getting these fac-tors right turns out to be an important part of mak-ing readable documents readability is not just aboutwhich font you choose but about how the charactersand spaces are distributed on each line Itrsquos something

3Though apparently there is some evidence in M A Tinker 1963 that in-dented paragraphs increase readability

17

COMP10120 Report writing and Digital Typography

that you will have seen happen so often in profession-ally typeset materials that yoursquoll have taken it for grantedand you may not have spotted that it doesnrsquot happenin quite the same way when you use a wordproces-sor The principle behind justifying text seems easyenough at first glance you simply have to take any lsquoleftoverrsquo space that would be at the end of a line and re-distribute it between the words in some way to lsquospacethem outrsquo a bit more so that they take up all the avail-able horizontal room But it turns out to be much harderthan it seems and all the simple ways you might thinkof for doing this on a per-line basis give results thatare visually quite unsatisfactory with nasty patternsmade up of neighbouring whitespace appearing in thelayout and ruining everything The added complica-tion here is that to do the optimum job of shuffling thewords round on their lines you really need the flex-ibility of being able to hyphenate words to give youextra space on lines that would otherwise be tightlypacked with characters But if you hyphenate wordsbadly by breaking them in inappropriate places or doit too often then that makes the text hard to read tooItrsquos all deeply inconvenient and inter-related The bestsolution to this aesthetic conundrum so far was devel-oped by Knuth and Plass 1981 and later improved byFrank Liang during his PhD research (F M Liang1983) and itrsquos a technique that tries to optimise the lay-

18

COMP10120 Report writing and Digital Typography

out of whole paragraphs rather than individual linesThe algorithm takes into account all manner of differ-ent things language-specific character patterns the num-ber of consecutive lines that end with hyphens the wordlsquotightnessrsquo on each line and many others The detailsdonrsquot really matter here but the really important in-sight is that you get better results by working on a big-ger chunk of the document (in this case a paragraph at atime) rather than trying to independently optimise lotsof small bits (say lines) and hoping that the result ofjoining them all together turns out nicely This idea ofoptimising things globally versus locally is somethingyoursquoll see many times throughout your Computer Sci-ence degree watch out for it in all the algorithms courses

This highlights a fundamental difference betweenthe WYSIWYG paradigm and the way that documentsare produced using LATEX As wersquove seen small changesdown at the level of individual characters can have fairlylarge knock-on consequences for the optimal layout ofa document changing one letter for another affects thelength of a line which in turn affects the hyphenationoptions which then affects the length of a paragraphwhich means that the best place for a figure that was onpage 99 might now be on page 100 but that means thatall references to lsquopage 99rsquo now need a bit more room toaccount for the extra digit which means that the someline lengths have changed which means well you get

19

COMP10120 Report writing and Digital Typography

the idea Itrsquos more complicated than it first seems LATEXgets to see the whole of your document at once and cantherefore make decisions about how best to hyphen-ate lines position figures or whatever else it likes beforeit shows you the results so it can make solutions thatare optimal for the whole document as well as lookingat details such as ligated characters Wordprocessorscanrsquot afford to do this since it would be deeply distract-ing if every time you typed a character the whole lay-out of the document flapped around in front of youreyes Wordprocessors can only sensibly make little op-timisations at a local (probably per-line level) Itrsquos notthat wordprocessors are rubbish or that the people thatprogrammed them were lazy itrsquos a fundamentally dif-ferent way of working and knowing the pros and consof the different approaches will help you pick the righttool for the job

You may have noticed that actual text in your doc-ument (and in fact this one) takes up a (perhaps) sur-prisingly narrow horizontal region of the page Thislast lsquofeaturersquo might seem odd at first but it illustratesanother important typographical point that you maynever have thought of before reading long lines of textis hard because your eyes find it hard to move in acompletely straight line as they scan from left to rightSo the longer the line of words the more you have towork to keep your eyes from accidentally drifting up or

20

COMP10120 Report writing and Digital Typography

down onto a neighbouring line (perhaps yoursquove expe-rienced the phenomenon of accidentally re-reading thesame line over and over as your eyes get tired) It maynever have occurred to you but most books have rela-tively short lines of text and those that use large pagesoften split text into several columns so that individuallines are kept relatively short The widely trusted booklsquoThe Elements of Typographic Stylersquo (R Bringhurst1992) makes the following assertion

lsquoAnything from 45 to 75 characters is widely-regarded as a satisfactory length of line for a single-column page set in a serifed text face in a text sizeThe 66-character line (counting both letters andspaces) is widely regarded as idealrsquo

LATEX knows about this issue so made a sensible de-fault decision for you You may have noticed that thereis a subtle difference in appearance of this chapter fromprevious ones the lines are shorter and paragraphs areindented We wanted to use the default LATEX layoutfor this chapter but changed it for earlier chapters inan effort to save paper

Therersquos one last unusual thing to note your para-graph of gibberish text in between the real words fromBleak House and the Lorem Ipsum almost certainly standsout and looks really quite odd (it might even have con-fused LATEXrsquos hyphenation rules enough to have ended

21

COMP10120 Report writing and Digital Typography

up with one or more lines sticking out proud of theright hand margin) Let your eyes relax so that yourvision blurs for a moment you can still probably spotthat the gibberish paragraph looks out of place Itrsquosquite likely that you even found creating the gibber-ish unexpectedly hard The interesting thing here isthat as humans we spend so much time reading andwriting lsquoproperrsquo natural language that we become at-tuned to the patterns of letters words and the underly-ing lsquorhythmrsquo of our written language that its very hardto artificially reproduce something that looks plausiblethe frequency of the letters you chose by randomly hit-ting keys and the length and patterns of the words youput in place most likely donrsquot match the natural pat-terns of real languages so they just look plain wrongCuriously the Lorem Ipsum text that you got from thewebsite probably doesnrsquot look so bad in spite of it notbeing made up of real words But thatrsquos not surprisingsince Lorem Ipsum is specifically created to be used asa placeholder for real text when typesetting While thewords are meaningless Latin-like things their lengthand the distribution of characters and word lengths arechosen to mimic patterns in real language

Next letrsquos give our document some structure by di-viding it up into sections On the line before BleakHouse starts add the command

22

COMP10120 Report writing and Digital Typography

sectionBleak House

making sure it appears on a line of its own Then justbefore your paragraph of gibberish put a similar in-struction (again on its own line) and then create a finalsection before the Lorem Ipsum Rerun pdflatex andlook at the results You should see the section headingsappear in the appropriate places in the PDF automati-cally having been given section numbers Experimentby adding in a couple of sub-sections towards the endof the document using the subsection commandwhich like the section command above takes as aparameter some text contained in curly brackets

Now at the top of your document after the begindocumentline and before the command defining the first sectionadd the following two commands each on their ownline

tableofcontentsnewpage

Re-run pdflatex twice and check that the effect is whatyoursquod expect You need to process the source twice be-cause on the first run LATEX gathers and stores informa-tion about what to put in the table of contents and onlycreates it on the second run

23

COMP10120 Report writing and Digital Typography

33 Common formatting features

Before we give you some more exercises to do here is abrief introduction to some commonly used features ofLATEX

331 Enumerated and bulleted lists

Creating bulleted or numbered lists in LATEX is straight-forward and is done like this

beginenumerateitem My first itemitem My second itemitem The last thing on my listendenumerate

You must make sure that you both begin and end yourlist and that each item is terminated by a newline Chang-ing enumerate to itemize gives you a bulleted ratherthan numbered list (note the American spelling of lsquoitem-izersquo)

332 Changing the appearance of text

Text can be typeset in bold font using the textbfin italics using textitand in a fixed-width fontusing texttt as in the example below

24

COMP10120 Report writing and Digital Typography

Some textttsay the textbfworld will end in textitfire

which is typeset as

Some say the world will end in fire

333 Cross referencing

LATEX allows you to cross-reference almost anything inthe document which includes sections sub-sections andfigures To use the cross-referencing feature you simplyinsert the command

labelmymarker

at the point in the document you want to refer to andthen use the command

refmymarker

when you want to use the reference Obviously youreplace the text mymarkerwith something more mean-ingful An important tip here is to call the marker some-thing that refers to the content of that part of the doc-ument and to avoid the temptation to use numbers(so donrsquot call your marker section1 instead call itintroduction if you reorder your document itrsquos stilllikely to be the introduction but it may no longer beSection 1) For example

25

COMP10120 Report writing and Digital Typography

sectionReflection on Welcome WeeklabelwelcomeweekI spent most of welcome week getting to know my wayaround campus I should have made more effort to joinsocieties I think I must remember to get to theStudentsrsquo Union and take a look around there

subsectionThings I enjoyedEverything so far has been wonderful with the caveat Imentioned in Section refwelcomeweek

subsectionThings I didnrsquot enjoyIrsquove discovered that I donrsquot like soggy chips

The really useful thing about cross-referencing in LATEXis that yoursquoll get warnings when you compile your doc-ument if cross-references are undefined or used incor-rectly This means you donrsquot have to manually checkevery reference in your document to make sure itrsquos stillright You do however have to run LATEX twice forsimilar reasons to those given above

334 Figures and pictures

Including figures and pictures in your document is easyYou do it like this

beginfigure

26

COMP10120 Report writing and Digital Typography

Figure 33Some men possibly Dutch looking at cheeses

centerlineincludegraphics[width=10cm]imagesmen-and-cheesejpgcaptionSome men possibly Dutch looking at cheeseslabelfiguremenandcheesesendfigure

which is the code we used to create Figure 38 You canprobably see whatrsquos happening The command includegraphicsgets your image which can be PDF PNG JPG GIF orPostScript The beginfigureendfigurecode lsquowrapsrsquo up whatever picture yoursquore including andallows LATEX to treat it as an unbreakable floating thingthat it will position for you as best it can in the docu-ment while maintaining an overall nice typographicallayout This floating of figures can sometimes result inthe figure ending up in a place you didnrsquot expect but inmost cases LATEX will make the most sensible choice Itrsquos

27

COMP10120 Report writing and Digital Typography

possible to employ finer control over figure placementbut thatrsquos beyond the scope of this introduction

The includegraphics command is not built into core LATEX but is in an additional package whichneeds to be explicitly loaded We load this package byusing the command usepackagegraphicx in thedocument preamble ie after the documentclasscommand but before begindocument There arehundreds of such packages that extend LATEXrsquos func-tionality the lab scripts you are reading now use over30 of them

Exercise 3 Including images

Create a document imagetex that contains some text(maybe from rsquoLorem Ipsumrsquo) together with a figurecontaining an image of your choice perhaps the oneyou made in Intro Lab 2 like Steversquos Mr Noodle Thereshould also be a reference to the figure in the text Youshould first use the program convert

convert

(check its manpage) to create a PDF version of the image

Exercise 4 A reflection on your studies

Your first proper LATEX document will be a very briefreflection on your studies so far

Write a hand-crafted LATEX document called courses-reflectiontex

28

COMP10120 Report writing and Digital Typography

(exact name as usual please otherwise submitwill notwork) It will have the following structure

1 A table of contents

2 A brief paragraph saying what the document isabout

3 A section appropriately titled for one of your courseunits containing

bull a brief paragraph saying what the unit is about

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the most about the unit

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the least about the unit

A repeat of item 3 for each other unit you are study-ing These sections should appear in alphabeticalorder by course code (eg COMP10120)

After completing and successfully compiling and view-ing your document you should spell-check it as fol-lows

ispell courses-reflectiontex

29

COMP10120 Report writing and Digital Typography

Once you are completely satisfied with it produce ahard copy ready for marking

34 Typesetting Mathematics

Earlier we saw this formula

x =minusbplusmn

radicb2 minus 4ac

2aIt looks nice doesnrsquot it To tell LATEX to display thisyou have to type a bit of magic but itrsquos easily-learnedmagic To create such a formula in a WYSIWYG edi-tor there is also magic involved but it usually involvesa lot of mouse-clicking and remembering special keycombinations like rsquocontrol-thisrsquo and rsquoalt-thatrsquo In LATEXit doesnrsquot You simply type this

[ x = frac-b pm sqrtb^2-4ac2a ]

You can probably work out how most of this createsthe formula but it wonrsquot be obvious that the [ and ]symbols that enclose the formula mean lsquotypeset this asa displayed formula giving it some vertical space fromthe surrounding textrsquo If wersquod used ( and ) insteadto enclose the formula it would appear in-line like thisx = minusbplusmn

radicb2minus4ac2a It still looks very nice and observe

how itrsquos automatically been resized to fit and that the

30

COMP10120 Report writing and Digital Typography

lines of text have had their spacing changed a bit Thisall looks simple but the implementation inside LATEXand TEX is complex It involves parsing the descrip-tion of the formula to create a corresponding tree datastructure which is then recursively walked to workout the horizontal and vertical typographical spacingsneeded Yoursquoll meet these ideas in COMP11120 andCOMP26120 Algorithms and Imperative Programming

Herersquos another example taken from COMP27112Computer Graphics (itrsquos a lsquosimplersquo local illuminationmodel incorporating ambient diffuse and specular re-flection by multiple lights)

I = kaIa +

Msumi=1

Ipidprimei[kd(N middot Li) + ks(Ri middot V )n]

We write this in LATEX as follows

[ I = k_a I_a + sum_i=1^M fracI_p_idrsquo_i [ k_d(hatN cdot hatL_i)+ k_s(hatR_i cdot hatV)^n] ]

Try to match the LATEX commands with the formula dis-played above Yoursquoll see lots of curly brackets and thisexample illustrates their two uses in LATEX The firstis to provide an argument to a command for exam-ple hatN means lsquoapply the hat command to N rsquowhich creates N the vector N with a little hat on

31

COMP10120 Report writing and Digital Typography

The second use of curly brackets is to group thingstogether to avoid ambiguities In the example you cansee sum_i=1^M which creates a summation signand its lower and upper limits

sumMi=1 We wrap the

lower bound i=1 in curly brackets to group it into anindivisible unit If we were to omit the brackets writ-ing sum_i=1^M LATEX would then produce

sumi = 1M

which is not at all what we want (even LATEX canrsquot al-ways know what we really want)

One final example If we tell LATEX

[ T_1 = left[beginarraycccccos theta amp -sin theta amp 0 amp delta sin theta amp cos theta amp 0 amp epsilon 0 amp 0 amp 1 amp eta alpha amp beta amp gamma amp 1endarrayright] ]

wersquoll get a splendid matrix which expresses a particu-lar 3D geometrical transformation (Donrsquot worry if youdonrsquot recognise this yoursquoll be introduced to matrix no-tation in the latter part of COMP11120 MathematicalTechniques for Computer Science For now you can justtreat it as some mysterious maths)

32

COMP10120 Report writing and Digital Typography

T1 =

cos θ minus sin θ 0 δ

sin θ cos θ 0 ε

0 0 1 η

α β γ 1

In the LATEX code left[means lsquobig opening square

bracket pleasersquo ccccmeans lsquoan array with 4 columnsplease with the items in each column centredrsquo ampmeanslsquostart a new columnrsquo and means lsquostart a new rowrsquoYoursquoll notice that LATEX knows about greek letters itknows about most standard maths symbols too andalso the ways theyrsquore usually used

There are some symbols that you might need (forexample therefore which produces the usual threedots symbol there4) that are not part of standard LATEX Manysuch symbols are provided by the amssymb package ofsymbols compiled by the American Mathematical Soci-ety Details of the many symbols provided by this pack-age can be found online at

mirrormathkuedutex-archivefontsamsfontsdocamssymbpdf

To use these extra symbols you need to have usepackageamssymbin the document preamble

33

COMP10120 Report writing and Digital Typography

341 A longer piece of mathematics

We conclude this section with an example of a longerpiece of mathematics that shows how you might type-set a complete mathematical argument rather than asingle formula The example is Euclidrsquos proof of thefact that

radic2 is irrational Itrsquos an argument that has been

covered in COMP11120 and is an example of proof bycontradiction It starts by making the assumption thatit is not the case that

radic2 is irrational in other words that

we can find integers p and q withradic2 = pq

We can assume without losing anything that p andq have no common factors (Why)

radic2 = pq

qradic2 = p

2q2 = p2

This means that p2 is even from which we can also de-duce that p is even (Why)

This means that p = 2k for some k so

2q2 = (2k)2

there4 2q2 = 4k2

so q2 = 2k2

But this means that q2 and hence q is even Since p andq are both even we have a contradiction to our initialassumption so no such p and q exist

The way this is formatted is shown here

34

COMP10120 Report writing and Digital Typography

It starts by making the assumption that it is emphnot the casethat $sqrt2$ is irrational in other words that we can findintegers $p$ and $q$ with $sqrt2 = pq$

We can assume without losing anything that $p$ and $q$ haveemphno common factors (Why)

[beginarraylcl

sqrt2 amp = amp pq qsqrt2 amp = amp p 2q^2 amp = amp p^2

endarray]

This means that $p^2$ is even from which we can also deduce that $p$is even (Why)

This means that $p = 2k$ for some $k$ so ldots[beginarrayllcl

amp 2q^2 amp = amp (2k)^2 therefore amp 2q^2 amp = amp 4k^2 textso amp q^2 amp = amp 2k^2

endarray]

But this means that $q^2$ and hence $q$ is even Since $p$ and $q$are both even we have a contradiction to our initial assumptionso no such $p$ and $q$ exist

Notice the use of the array environment for gettingthings lined up You can find much more informationabout this on the web

LATEX really shines at typesetting mathematics and

35

COMP10120 Report writing and Digital Typography

it would take pages and pages to describe all the fea-tures Have a look at

enwikibooksorgwikiLaTeXMathematics

for a flavour

Exercise 5 Formatting mathematics

Now for an exercise that involves some mathematicsPlease create a file f-wtex which typesets the follow-ing piece of text and mathematics

There are many positive integer solutions tothe equation

x2 + y2 = z2

which can be rewritten as

z =radicx2 + y2

For example (3 4 5) or (5 12 13) Such solu-tions are called Pythagorean triples

However for higher powers the situation isvery different and we have-

Theorem Fermat-WilesFor all natural numbers n ge 3 there are no

36

COMP10120 Report writing and Digital Typography

integers x y z satisfying the equation

xn + yn = zn

35 Curriculum vitaie

There are several scenarios where using LATEX ratherthan other word processing software can be useful

bull typesetting mathematics yoursquove just read about

bull writing a technical document

bull your final year project peport

bull writing an article you want to get published

bull writing a Curriculum vitae CV

Wersquoll now look at CVrsquos briefly

Exercise 6 Curriculum vitae

Creating a professional document is especially impor-tant when you write your CV because how your CVlooks (not just the content) will determine if you are in-vited to interview for job you are applying for Thatcould be a summer internship next year a year long

37

COMP10120 Report writing and Digital Typography

placement after your second year or graduate positionafter you leave University

As well using a text-editor and compiling files fromthe command line other tools are available for editingLATEXWe will look at one of these overleafcom

Create a basic CV which describes you your edu-cation (including University) and any experience youhave or interesting projects that you may have doneYou can do this using httpsoverleafcom andchoosing the ready-made templates at httpswwwoverleafcomgallerytaggedcv

As you progress through University it is a good ideato keep your CV up to date and get feedback from asmany people as you can There will be opportunities todebug your CV later (See httpgitiomycv if youare interested) but yoursquoll need a ldquobeta releaserdquo (version10) of your CV to get started The best time to start thisprocess is now

36 Some optional extras

Exercise 7 Exploring more LATEX features (op-tional but easy)

This exercise reinforces some of the things yoursquove donealready but also introduces some features of LATEX that

38

COMP10120 Report writing and Digital Typography

will be new to you It is labelled as optional because itisnrsquot marked but we would recommend that you all tryit

Take a copy of the file optinfocoursesCOMP10120ex3latex-introtexand follow the instructions it contains You should readit before you process it with LATEX

Exercise 8 A neat directory listing (optionalmore challenging)

The fact that LATEX source files are just text makes it easyto have them generated by a program You are going toexploit this and use LATEX to produce a neat documentcontaining a listing of the files in any directory

Find how to create tables in LATEX tables using thetabular environment Make a LATEX document by handthat uses a table to neatly show the information aboutthe files in some (small) directory (as produced by ls

-l) Write a shell script called neat-ls that takes anargument which is the path name of a directory andproduces a LATEX document containing the above tablefor the given directory The script could also process theLATEX and display the resulting pdf file Finally find outabout the longtable package and change your script touse that instead

39

COMP10120 Report writing and Digital Typography

Exercise 9 A cleaning rota (optional evenmore challenging)

Now you will write a shell script called make-rota thatgenerates a house cleaning rota (Very handy for nextyear ) This is a table with columns such as KitchenBathroom and Lounge The rows will be weeks in theyear labelled with a date (eg always a Sunday) Theidea is that house mates can write their initials in theboxes promising to clean the corresponding room inthat particular week Start by making a sample tableby hand

Your script should take a single argument which isthe date of the first day of the first row eg102013(the US format for 20 Oct 13) The result will be a docu-ment that contains as many rows as fit on a single page(find out by experimenting)

The dates of each row should be generated from thefirst See the manual page for date to figure out howyou can generate a date that is a number of weeks anddays later than an existing one

361 Marking Scheme

You can view a copy of the marking scheme used bysubmit and labprint at

40

COMP10120 Report writing and Digital Typography

studentnetcsmanchesteracukugtlpmsphpunit=COMP10120ampex=ex3xml

37 Next steps

LATEX is a very powerful tool and it does take a littlegetting used to But itrsquos not as scary as it might initiallyseem and you should find that it doesnrsquot take long tolearn the common commands and techniques to makeyour documents well-structured and readable As youbecome more comfortable with the basics and under-stand the principles of typesetting finding out how todo more complex and sophisticated things is easymdashthere are hundreds of tutorials on the web

Donrsquot get carried away though and use the featuresjudiciously just because yoursquove found a cool new com-mand doesnrsquot mean that you should use it just to showoff your LATEX skills content and structure always trumpstypographic twiddlings4

4For example footnotes like this are for some reason a really tempting fea-ture to use in LATEX and in this document we have abused them mercilessly toillustrate a point Footnotes were originally a means for mechanical typeset-ters to insert comments corrections or additions to existing documents withouthaving to adjust the layout of a whole page and of course in digital typographythis is no longer necessary They can justifiably be used for citations (though itrsquosnot common to do so these days) and URLs if you donrsquot want these intrudinginto the body of your text And in some very very rare cases they can be usedas an aside to the main flow of the text (which is what has been done in this doc-ument) But this should be used sparingly If something is important to sayput it in the main body of your text If itrsquos not then perhaps you should thinkabout leaving it out completely or find some other way of including it Asking

41

COMP10120 Report writing and Digital Typography

371 Acknowledgements

Figure 38 is from the Wikipedia article on cheese

372 License

The text of this exercise is licensed under the terms ofthe Creative Commons Attribution 20 Generic (CC BY30) License

38 Background

What follows is additional contextual information aroundLATEX

LATEX was originally written by Leslie LamportW anAmerican computer scientist now working at MicrosoftResearch although its development has long been takenover by a world-wide LATEX community Itrsquos actuallybuilt on top of another system called TEX a computertypesetting system designed by one of the worldrsquos mostinfluential Computer Scientists Donald KnuthW of Stan-ford University Knuth has said that he designed TEX

the reader to look down at the bottom of a page to find out whether somethingis important or not is irritating and as yoursquove probably found out already oftenmeans you lose track of your reading position They also give the impressionthat the author isnrsquot clear about whether something is important or not whichis never good And long footnotes like this onemdashwhile LATEX will typeset themperfectly wellmdashare just plain silly Best avoid

42

COMP10120 Report writing and Digital Typography

for lsquothe creation of beautiful booksmdashand especially forbooks that contain a lot of mathematicsrsquo(D Knuth1984) Figure 34 shows what these eminent men looklike

So whatrsquos the purpose of LATEX Itrsquos purely a layerof software to make TEX easier to use in everyday sit-uations This is a good idea because although TEX isamazingly powerful it operates at a very low-level whichmakes it hard for non-expert users

Figure 34Don Knuth and Leslie Lamport

381 Pronunciation

The name TEX is intended by its creator to be pronouncedwith the final consonant as in the word loch or the nameBach but English speakers often pronounce it like thefirst syllable of technical The first syllable of LATEX is

43

COMP10120 Report writing and Digital Typography

pronounced as in rsquolayrsquo5

382 Why LATEX

Before we go any further why do we think LATEX is im-portant for youmdasha Computer Science studentmdashto knowabout Here are some reasons in no particular order

bull LATEX and TEX are superb examples of ComputerScience in action TEX was designed by Knuth fromfirst principlesmdashin other words from scratch TEXis actually a programming language and LATEX isa set of functions defined in the TEX language TheTEX lsquocompilerrsquo is written in WEBW a mixture ofdocumentation written in TeX and a PascalW sub-set in order to ensure portability it reads a TEXprogram and outputs documents TEX is completelyself-contained and designed to be portable to anycomputer architecture For example it implementsits own stackW and heapW (with garbage collectionW)and it does fixed-precision arithmeticW donrsquot worryif these terms donrsquot make much sense to you at themoment they soon will

5The Greek prefix lsquotexrsquo means lsquoartrsquo as well as lsquotechnologyrsquo so itrsquos a very nicelychosen name for a piece of software that produces such beautiful output Knuthexplained (D Knuth 1984) that one should lsquopronounce the X of TeX as a Greekchi not as an lsquoxrsquo so that TeX rhymes with the word blecchhhrsquo Wersquore not toosure that helps much unless you are confident in your pronunciation of theword lsquoblecchhrsquo Maybe itrsquos an American thing

44

COMP10120 Report writing and Digital Typography

bull LATEX is a new interesting way for you to thinkabout preparing documents

bull LATEX has a practical advantage for the writer inthat it helps you think more about what you wantto write rather than worrying about how it looks

bull LATEX is a powerful tool for professional scientificdocumentation and as a Computer Scientist youshould know about it

bull LATEX files are just plain text so can easily be cre-ated programatically For example the slides usedfor COMP16120 are generated automatically fromthe source of Johnrsquos book both are typeset usingLATEX The program labprint also produces itsoutput using LATEX using information drawn fromXMLW configuration files and ARCADE

bull Using LATEX is actually quite satisfying and thequality of its output may surprise you

In this lab session you are going to write severalshort documents using LATEX You could also write briefnotes in your logbook about how LATEX works and whatcommands you used inside the source of your docu-ments

45

COMP10120 Report writing and Digital Typography

383 Some history printing mathematics

Mathematics is hard to print on paper and on the Web(many websites resort to GIF or JPG images of mathsformulae which usually look horrible MathMLW pro-vides another approach but it is not yet widely used)

In the days before computers books and newspa-pers were printed with movable typeW made from lotsof little blocks of metal each with letters numbers andsymbols standing in relief which when inked left animpression on the paper (see Figure 35) The job ofthe printer (the printer here of course being a personnot a bit of electronics) was to gather together all theblocks in the right order between two horizontal stripsof wood to create a line of the document and then toassemble all those lines from top to bottom of a pageThus the term type settingW an incredible task whenyou think about it In the printerrsquos workshop by theway the blocks of metal were stored between jobs inwooden boxes called cases Letters like a b and c werestored in one case letters like A B and C were storedin a case sitting on top of that So a lower case and anupper case These terms may ring a bell

As technology progressed machines controlled bytypewriters would mechanically juggle the blocks intothe right order This conceptual model is the basis onwhich TEX operates Only now the metal blocks are

46

COMP10120 Report writing and Digital Typography

Figure 35On the left a piece of cast movable type in the Garamondfont On the right a case of cast metal type pieces andtypeset matter in a composing stick The text reads lsquoThequick brown fox jumps over the lazy dog and feels as if hewere in the seventh heaven of typography together with Her-mann Zapf the most famous artist of thersquo This document istypeset in a font called Palatino created by Hermann ZapfYou may have also seen rsquoZapf Dingbatsrsquo in the font lists ofvarious desktop applications Now you know why

little pieces of data arranged into data structuresThe one thing that traditional printers hated was

dealing with the typesetting of mathematics and theywould charge extra to do it It was incredibly fiddly toget the equations looking right they had to squeeze inextra bits of metal horizontally and vertically

When computers entered the printing world attemptsto print mathematics were limited by the printing tech-nology available It took a long time to reach the pointwhere computers could typeset mathematics beautifullyand that was the outstanding achievement of Knuthrsquos

47

COMP10120 Report writing and Digital Typography

TEXLetrsquos look at a quick example of the quality you get

from LATEX with a very simple formula that yoursquoll recog-nise

x =minusbplusmn

radicb2 minus 4ac

2aWersquoll revisit how LATEX typesets mathematics in Section 34

384 To WYSIWYG or not to WYSIWYG

Up until now you have probably used wordprocessingapplications such as Microsoft Word to create essaysletters and other (probably fairly short) documents Youmost likely know that the majority of modern wordprocessors use a paradigm called WYSIWYG or WhatYou See Is What You Get which means that you canmodify the visual style of the document yoursquore work-ing on by selecting the relevant bits and then choos-ing different attributes such as font size or colour usinga GUI In many ways this seems like such a sensibleand obvious way of doing things that you might bewondering why it even has a special name The rea-son is a historical one in the early days of comput-ing long before graphical window managers becamethe norm and when all you could display on screenwas fixed-width ASCII text in whatever the systemrsquos

48

COMP10120 Report writing and Digital Typography

default font was wordprocessors (eg Figure 36) onlyallowed you to format documents by using special se-quences of characters to cause particular effects Butthese effects were only visible when the document wasprinted So if you wanted a word to appear in boldtext in the wordprocessor you might write somethinglike [bold]hello world[bold] what you saw onscreen was not a direct reflection of what appeared onthe printed page If yoursquove written any HTML how-ever this process of marking up text may be familiarsee for example Figure 37 As computers moved todisplays able to draw things other than raw charac-ters on screen wordprocessors became capable of us-ing multiple fonts and styles as well as graphics anda new generation of applications appeared where whatyou saw on screen was an accurate reflection of how itwould appear when printed what you see (on screen)is what you get (on paper)

The huge advantage of WYSIWYG is that itrsquos reallyeasy to understand whatrsquos going on and most peoplecan create reasonably nicely formatted documents withrelatively little effort For short informal documentsone-off letters memos and such WYSIWYG works quitenicely But if yoursquove ever tried writing anything muchlonger or that includes images and tables you mayhave already started to see where the paradigm breaksdown For example if you write lsquoFigure 38 on page

49

COMP10120 Report writing and Digital Typography

Figure 36A screenshot of Wordperfect 51 running in Microsoft DOScirca 1989

51 shows a picture of some men looking at cheesersquo butthen later on edit your document to include some moretext at the start and a new picture of a some broccoli(as in Figure 39) yoursquod have to search through yourreport to find all mentions of lsquoFigure 38rsquo and lsquopage 51rsquoand manually update them to reflect the new number-ing This might be fine if you have two figures and fivepages but for a hundred-page report containing lots ofpictures you can see how this becomes tedious and er-ror prone very quickly

50

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 8: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

London Michaelmas term lately over and theLord Chancellor sitting in Lincolnrsquos Inn HallImplacable November weather As much mud inthe streets as if the waters had but newly retiredfrom the face of the earth and it would not bewonderful to meet a Megalosaurus forty feetlong or so waddling like an elephantine lizardup Holborn Hill Smoke lowering down fromchimney-pots making a soft black drizzle withflakes of soot in it as big as full-grownsnowflakesndashgone into mourning one mightimagine for the death of the sun Dogsundistinguishable in mire Horses scarcelybetter splashed to their very blinkers Footpassengers jostling one anotherrsquos umbrellas in ageneral infection of ill temper and losing theirfoot-hold at street-corners where tens ofthousands of other foot passengers have beenslipping and sliding since the day broke (if thisday ever broke) adding new deposits to the crustupon crust of mud sticking at those pointstenaciously to the pavement and accumulatingat compound interest

Fog everywhere Fog up the river where it flowsamong green aits and meadows fog down theriver where it rolls defiled among the tiers ofshipping and the waterside pollutions of a great(and dirty) city Fog on the Essex marshes fogon the Kentish heights Fog creeping into thecabooses of collier-brigs fog lying out on theyards and hovering in the rigging of great shipsfog drooping on the gunwales of barges andsmall boats Fog in the eyes and throats ofancient Greenwich pensioners wheezing by thefiresides of their wards fog in the stem and bowlof the afternoon pipe of the wrathful skipperdown in his close cabin fog cruelly pinching thetoes and fingers of his shivering little rsquoprenticeboy on deck Chance people on the bridgespeeping over the parapets into a nether sky offog with fog all round them as if they were upin a balloon and hanging in the misty clouds

Gas looming through the fog in divers places inthe streets much as the sun may from thespongey fields be seen to loom by husbandmanand ploughboy Most of the shops lighted twohours before their timemdashas the gas seems toknow for it has a haggard and unwilling look

Figure 32Some sample text from the opening of the Dickensrsquo novellsquoBleak Housersquo (C Dickens 1852)

15

COMP10120 Report writing and Digital Typography

create some unique gibberish yourself)

Oisjdf oqweqwe oi soijs hbweo kbsd oijsdfoijqwknpiouh iusbdfspb sifuhygwqeb usgweijfblimqwoq oieuerwefwiu aokqjw uioshiufdsqiqks odfubfi psdiweneq

Be careful at this stage to only include letters (upper-case and lowercase) commas full-stops and perhapsnumbers in your gibberish text if you use any othersymbols you may upset LATEX

Next go to the website wwwlipsumcom and fol-low the instructions to generate yourself three para-graphs of whatrsquos called Lorem Ipsum text Copy andpaste that text into your LATEX document too (donrsquot worryabout what it means at this stage) again making surethat you have a blank line between the paragraphs

Run pdflatex and look at the resulting sectionspdfAgain at first glance therersquos nothing hugely excitinggoing on here the text from your tex file has beenassembled into a (probably) two page PDF documentBut in fact quite a few things have happened

bull The blank lines that separate the paragraphs inyour source file are gone and instead LATEX hasindented the first line of each paragraph Therersquosnothing profound here about the decision to in-dent paragraphs rather than (say) to leave a gap

16

COMP10120 Report writing and Digital Typography

between them (so called block paragraphs) itrsquosjust LATEXrsquos default paragraph style and can bechanged easily enough3

bull There are page numbers at the bottom of each page(except page 1) This is a very sensible default al-lowing you in meetings to ask people to lsquoturn topage 4rsquo and so on (itrsquos a bit odd and a source ofsome annoyance that most wordprocessors donrsquotdo this by default too) But you can easily switchpage numbers off change their style or move themelsewhere if you need to

bull The text is fully justified so that itrsquos flush on boththe left and right hand edges

bull Certain words that fall at the end of lines havebeen hyphenated even if they werenrsquot originallysplit by hyphens in the source text

These last two points about justification and hyphen-ation might seem utterly trivial but getting these fac-tors right turns out to be an important part of mak-ing readable documents readability is not just aboutwhich font you choose but about how the charactersand spaces are distributed on each line Itrsquos something

3Though apparently there is some evidence in M A Tinker 1963 that in-dented paragraphs increase readability

17

COMP10120 Report writing and Digital Typography

that you will have seen happen so often in profession-ally typeset materials that yoursquoll have taken it for grantedand you may not have spotted that it doesnrsquot happenin quite the same way when you use a wordproces-sor The principle behind justifying text seems easyenough at first glance you simply have to take any lsquoleftoverrsquo space that would be at the end of a line and re-distribute it between the words in some way to lsquospacethem outrsquo a bit more so that they take up all the avail-able horizontal room But it turns out to be much harderthan it seems and all the simple ways you might thinkof for doing this on a per-line basis give results thatare visually quite unsatisfactory with nasty patternsmade up of neighbouring whitespace appearing in thelayout and ruining everything The added complica-tion here is that to do the optimum job of shuffling thewords round on their lines you really need the flex-ibility of being able to hyphenate words to give youextra space on lines that would otherwise be tightlypacked with characters But if you hyphenate wordsbadly by breaking them in inappropriate places or doit too often then that makes the text hard to read tooItrsquos all deeply inconvenient and inter-related The bestsolution to this aesthetic conundrum so far was devel-oped by Knuth and Plass 1981 and later improved byFrank Liang during his PhD research (F M Liang1983) and itrsquos a technique that tries to optimise the lay-

18

COMP10120 Report writing and Digital Typography

out of whole paragraphs rather than individual linesThe algorithm takes into account all manner of differ-ent things language-specific character patterns the num-ber of consecutive lines that end with hyphens the wordlsquotightnessrsquo on each line and many others The detailsdonrsquot really matter here but the really important in-sight is that you get better results by working on a big-ger chunk of the document (in this case a paragraph at atime) rather than trying to independently optimise lotsof small bits (say lines) and hoping that the result ofjoining them all together turns out nicely This idea ofoptimising things globally versus locally is somethingyoursquoll see many times throughout your Computer Sci-ence degree watch out for it in all the algorithms courses

This highlights a fundamental difference betweenthe WYSIWYG paradigm and the way that documentsare produced using LATEX As wersquove seen small changesdown at the level of individual characters can have fairlylarge knock-on consequences for the optimal layout ofa document changing one letter for another affects thelength of a line which in turn affects the hyphenationoptions which then affects the length of a paragraphwhich means that the best place for a figure that was onpage 99 might now be on page 100 but that means thatall references to lsquopage 99rsquo now need a bit more room toaccount for the extra digit which means that the someline lengths have changed which means well you get

19

COMP10120 Report writing and Digital Typography

the idea Itrsquos more complicated than it first seems LATEXgets to see the whole of your document at once and cantherefore make decisions about how best to hyphen-ate lines position figures or whatever else it likes beforeit shows you the results so it can make solutions thatare optimal for the whole document as well as lookingat details such as ligated characters Wordprocessorscanrsquot afford to do this since it would be deeply distract-ing if every time you typed a character the whole lay-out of the document flapped around in front of youreyes Wordprocessors can only sensibly make little op-timisations at a local (probably per-line level) Itrsquos notthat wordprocessors are rubbish or that the people thatprogrammed them were lazy itrsquos a fundamentally dif-ferent way of working and knowing the pros and consof the different approaches will help you pick the righttool for the job

You may have noticed that actual text in your doc-ument (and in fact this one) takes up a (perhaps) sur-prisingly narrow horizontal region of the page Thislast lsquofeaturersquo might seem odd at first but it illustratesanother important typographical point that you maynever have thought of before reading long lines of textis hard because your eyes find it hard to move in acompletely straight line as they scan from left to rightSo the longer the line of words the more you have towork to keep your eyes from accidentally drifting up or

20

COMP10120 Report writing and Digital Typography

down onto a neighbouring line (perhaps yoursquove expe-rienced the phenomenon of accidentally re-reading thesame line over and over as your eyes get tired) It maynever have occurred to you but most books have rela-tively short lines of text and those that use large pagesoften split text into several columns so that individuallines are kept relatively short The widely trusted booklsquoThe Elements of Typographic Stylersquo (R Bringhurst1992) makes the following assertion

lsquoAnything from 45 to 75 characters is widely-regarded as a satisfactory length of line for a single-column page set in a serifed text face in a text sizeThe 66-character line (counting both letters andspaces) is widely regarded as idealrsquo

LATEX knows about this issue so made a sensible de-fault decision for you You may have noticed that thereis a subtle difference in appearance of this chapter fromprevious ones the lines are shorter and paragraphs areindented We wanted to use the default LATEX layoutfor this chapter but changed it for earlier chapters inan effort to save paper

Therersquos one last unusual thing to note your para-graph of gibberish text in between the real words fromBleak House and the Lorem Ipsum almost certainly standsout and looks really quite odd (it might even have con-fused LATEXrsquos hyphenation rules enough to have ended

21

COMP10120 Report writing and Digital Typography

up with one or more lines sticking out proud of theright hand margin) Let your eyes relax so that yourvision blurs for a moment you can still probably spotthat the gibberish paragraph looks out of place Itrsquosquite likely that you even found creating the gibber-ish unexpectedly hard The interesting thing here isthat as humans we spend so much time reading andwriting lsquoproperrsquo natural language that we become at-tuned to the patterns of letters words and the underly-ing lsquorhythmrsquo of our written language that its very hardto artificially reproduce something that looks plausiblethe frequency of the letters you chose by randomly hit-ting keys and the length and patterns of the words youput in place most likely donrsquot match the natural pat-terns of real languages so they just look plain wrongCuriously the Lorem Ipsum text that you got from thewebsite probably doesnrsquot look so bad in spite of it notbeing made up of real words But thatrsquos not surprisingsince Lorem Ipsum is specifically created to be used asa placeholder for real text when typesetting While thewords are meaningless Latin-like things their lengthand the distribution of characters and word lengths arechosen to mimic patterns in real language

Next letrsquos give our document some structure by di-viding it up into sections On the line before BleakHouse starts add the command

22

COMP10120 Report writing and Digital Typography

sectionBleak House

making sure it appears on a line of its own Then justbefore your paragraph of gibberish put a similar in-struction (again on its own line) and then create a finalsection before the Lorem Ipsum Rerun pdflatex andlook at the results You should see the section headingsappear in the appropriate places in the PDF automati-cally having been given section numbers Experimentby adding in a couple of sub-sections towards the endof the document using the subsection commandwhich like the section command above takes as aparameter some text contained in curly brackets

Now at the top of your document after the begindocumentline and before the command defining the first sectionadd the following two commands each on their ownline

tableofcontentsnewpage

Re-run pdflatex twice and check that the effect is whatyoursquod expect You need to process the source twice be-cause on the first run LATEX gathers and stores informa-tion about what to put in the table of contents and onlycreates it on the second run

23

COMP10120 Report writing and Digital Typography

33 Common formatting features

Before we give you some more exercises to do here is abrief introduction to some commonly used features ofLATEX

331 Enumerated and bulleted lists

Creating bulleted or numbered lists in LATEX is straight-forward and is done like this

beginenumerateitem My first itemitem My second itemitem The last thing on my listendenumerate

You must make sure that you both begin and end yourlist and that each item is terminated by a newline Chang-ing enumerate to itemize gives you a bulleted ratherthan numbered list (note the American spelling of lsquoitem-izersquo)

332 Changing the appearance of text

Text can be typeset in bold font using the textbfin italics using textitand in a fixed-width fontusing texttt as in the example below

24

COMP10120 Report writing and Digital Typography

Some textttsay the textbfworld will end in textitfire

which is typeset as

Some say the world will end in fire

333 Cross referencing

LATEX allows you to cross-reference almost anything inthe document which includes sections sub-sections andfigures To use the cross-referencing feature you simplyinsert the command

labelmymarker

at the point in the document you want to refer to andthen use the command

refmymarker

when you want to use the reference Obviously youreplace the text mymarkerwith something more mean-ingful An important tip here is to call the marker some-thing that refers to the content of that part of the doc-ument and to avoid the temptation to use numbers(so donrsquot call your marker section1 instead call itintroduction if you reorder your document itrsquos stilllikely to be the introduction but it may no longer beSection 1) For example

25

COMP10120 Report writing and Digital Typography

sectionReflection on Welcome WeeklabelwelcomeweekI spent most of welcome week getting to know my wayaround campus I should have made more effort to joinsocieties I think I must remember to get to theStudentsrsquo Union and take a look around there

subsectionThings I enjoyedEverything so far has been wonderful with the caveat Imentioned in Section refwelcomeweek

subsectionThings I didnrsquot enjoyIrsquove discovered that I donrsquot like soggy chips

The really useful thing about cross-referencing in LATEXis that yoursquoll get warnings when you compile your doc-ument if cross-references are undefined or used incor-rectly This means you donrsquot have to manually checkevery reference in your document to make sure itrsquos stillright You do however have to run LATEX twice forsimilar reasons to those given above

334 Figures and pictures

Including figures and pictures in your document is easyYou do it like this

beginfigure

26

COMP10120 Report writing and Digital Typography

Figure 33Some men possibly Dutch looking at cheeses

centerlineincludegraphics[width=10cm]imagesmen-and-cheesejpgcaptionSome men possibly Dutch looking at cheeseslabelfiguremenandcheesesendfigure

which is the code we used to create Figure 38 You canprobably see whatrsquos happening The command includegraphicsgets your image which can be PDF PNG JPG GIF orPostScript The beginfigureendfigurecode lsquowrapsrsquo up whatever picture yoursquore including andallows LATEX to treat it as an unbreakable floating thingthat it will position for you as best it can in the docu-ment while maintaining an overall nice typographicallayout This floating of figures can sometimes result inthe figure ending up in a place you didnrsquot expect but inmost cases LATEX will make the most sensible choice Itrsquos

27

COMP10120 Report writing and Digital Typography

possible to employ finer control over figure placementbut thatrsquos beyond the scope of this introduction

The includegraphics command is not built into core LATEX but is in an additional package whichneeds to be explicitly loaded We load this package byusing the command usepackagegraphicx in thedocument preamble ie after the documentclasscommand but before begindocument There arehundreds of such packages that extend LATEXrsquos func-tionality the lab scripts you are reading now use over30 of them

Exercise 3 Including images

Create a document imagetex that contains some text(maybe from rsquoLorem Ipsumrsquo) together with a figurecontaining an image of your choice perhaps the oneyou made in Intro Lab 2 like Steversquos Mr Noodle Thereshould also be a reference to the figure in the text Youshould first use the program convert

convert

(check its manpage) to create a PDF version of the image

Exercise 4 A reflection on your studies

Your first proper LATEX document will be a very briefreflection on your studies so far

Write a hand-crafted LATEX document called courses-reflectiontex

28

COMP10120 Report writing and Digital Typography

(exact name as usual please otherwise submitwill notwork) It will have the following structure

1 A table of contents

2 A brief paragraph saying what the document isabout

3 A section appropriately titled for one of your courseunits containing

bull a brief paragraph saying what the unit is about

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the most about the unit

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the least about the unit

A repeat of item 3 for each other unit you are study-ing These sections should appear in alphabeticalorder by course code (eg COMP10120)

After completing and successfully compiling and view-ing your document you should spell-check it as fol-lows

ispell courses-reflectiontex

29

COMP10120 Report writing and Digital Typography

Once you are completely satisfied with it produce ahard copy ready for marking

34 Typesetting Mathematics

Earlier we saw this formula

x =minusbplusmn

radicb2 minus 4ac

2aIt looks nice doesnrsquot it To tell LATEX to display thisyou have to type a bit of magic but itrsquos easily-learnedmagic To create such a formula in a WYSIWYG edi-tor there is also magic involved but it usually involvesa lot of mouse-clicking and remembering special keycombinations like rsquocontrol-thisrsquo and rsquoalt-thatrsquo In LATEXit doesnrsquot You simply type this

[ x = frac-b pm sqrtb^2-4ac2a ]

You can probably work out how most of this createsthe formula but it wonrsquot be obvious that the [ and ]symbols that enclose the formula mean lsquotypeset this asa displayed formula giving it some vertical space fromthe surrounding textrsquo If wersquod used ( and ) insteadto enclose the formula it would appear in-line like thisx = minusbplusmn

radicb2minus4ac2a It still looks very nice and observe

how itrsquos automatically been resized to fit and that the

30

COMP10120 Report writing and Digital Typography

lines of text have had their spacing changed a bit Thisall looks simple but the implementation inside LATEXand TEX is complex It involves parsing the descrip-tion of the formula to create a corresponding tree datastructure which is then recursively walked to workout the horizontal and vertical typographical spacingsneeded Yoursquoll meet these ideas in COMP11120 andCOMP26120 Algorithms and Imperative Programming

Herersquos another example taken from COMP27112Computer Graphics (itrsquos a lsquosimplersquo local illuminationmodel incorporating ambient diffuse and specular re-flection by multiple lights)

I = kaIa +

Msumi=1

Ipidprimei[kd(N middot Li) + ks(Ri middot V )n]

We write this in LATEX as follows

[ I = k_a I_a + sum_i=1^M fracI_p_idrsquo_i [ k_d(hatN cdot hatL_i)+ k_s(hatR_i cdot hatV)^n] ]

Try to match the LATEX commands with the formula dis-played above Yoursquoll see lots of curly brackets and thisexample illustrates their two uses in LATEX The firstis to provide an argument to a command for exam-ple hatN means lsquoapply the hat command to N rsquowhich creates N the vector N with a little hat on

31

COMP10120 Report writing and Digital Typography

The second use of curly brackets is to group thingstogether to avoid ambiguities In the example you cansee sum_i=1^M which creates a summation signand its lower and upper limits

sumMi=1 We wrap the

lower bound i=1 in curly brackets to group it into anindivisible unit If we were to omit the brackets writ-ing sum_i=1^M LATEX would then produce

sumi = 1M

which is not at all what we want (even LATEX canrsquot al-ways know what we really want)

One final example If we tell LATEX

[ T_1 = left[beginarraycccccos theta amp -sin theta amp 0 amp delta sin theta amp cos theta amp 0 amp epsilon 0 amp 0 amp 1 amp eta alpha amp beta amp gamma amp 1endarrayright] ]

wersquoll get a splendid matrix which expresses a particu-lar 3D geometrical transformation (Donrsquot worry if youdonrsquot recognise this yoursquoll be introduced to matrix no-tation in the latter part of COMP11120 MathematicalTechniques for Computer Science For now you can justtreat it as some mysterious maths)

32

COMP10120 Report writing and Digital Typography

T1 =

cos θ minus sin θ 0 δ

sin θ cos θ 0 ε

0 0 1 η

α β γ 1

In the LATEX code left[means lsquobig opening square

bracket pleasersquo ccccmeans lsquoan array with 4 columnsplease with the items in each column centredrsquo ampmeanslsquostart a new columnrsquo and means lsquostart a new rowrsquoYoursquoll notice that LATEX knows about greek letters itknows about most standard maths symbols too andalso the ways theyrsquore usually used

There are some symbols that you might need (forexample therefore which produces the usual threedots symbol there4) that are not part of standard LATEX Manysuch symbols are provided by the amssymb package ofsymbols compiled by the American Mathematical Soci-ety Details of the many symbols provided by this pack-age can be found online at

mirrormathkuedutex-archivefontsamsfontsdocamssymbpdf

To use these extra symbols you need to have usepackageamssymbin the document preamble

33

COMP10120 Report writing and Digital Typography

341 A longer piece of mathematics

We conclude this section with an example of a longerpiece of mathematics that shows how you might type-set a complete mathematical argument rather than asingle formula The example is Euclidrsquos proof of thefact that

radic2 is irrational Itrsquos an argument that has been

covered in COMP11120 and is an example of proof bycontradiction It starts by making the assumption thatit is not the case that

radic2 is irrational in other words that

we can find integers p and q withradic2 = pq

We can assume without losing anything that p andq have no common factors (Why)

radic2 = pq

qradic2 = p

2q2 = p2

This means that p2 is even from which we can also de-duce that p is even (Why)

This means that p = 2k for some k so

2q2 = (2k)2

there4 2q2 = 4k2

so q2 = 2k2

But this means that q2 and hence q is even Since p andq are both even we have a contradiction to our initialassumption so no such p and q exist

The way this is formatted is shown here

34

COMP10120 Report writing and Digital Typography

It starts by making the assumption that it is emphnot the casethat $sqrt2$ is irrational in other words that we can findintegers $p$ and $q$ with $sqrt2 = pq$

We can assume without losing anything that $p$ and $q$ haveemphno common factors (Why)

[beginarraylcl

sqrt2 amp = amp pq qsqrt2 amp = amp p 2q^2 amp = amp p^2

endarray]

This means that $p^2$ is even from which we can also deduce that $p$is even (Why)

This means that $p = 2k$ for some $k$ so ldots[beginarrayllcl

amp 2q^2 amp = amp (2k)^2 therefore amp 2q^2 amp = amp 4k^2 textso amp q^2 amp = amp 2k^2

endarray]

But this means that $q^2$ and hence $q$ is even Since $p$ and $q$are both even we have a contradiction to our initial assumptionso no such $p$ and $q$ exist

Notice the use of the array environment for gettingthings lined up You can find much more informationabout this on the web

LATEX really shines at typesetting mathematics and

35

COMP10120 Report writing and Digital Typography

it would take pages and pages to describe all the fea-tures Have a look at

enwikibooksorgwikiLaTeXMathematics

for a flavour

Exercise 5 Formatting mathematics

Now for an exercise that involves some mathematicsPlease create a file f-wtex which typesets the follow-ing piece of text and mathematics

There are many positive integer solutions tothe equation

x2 + y2 = z2

which can be rewritten as

z =radicx2 + y2

For example (3 4 5) or (5 12 13) Such solu-tions are called Pythagorean triples

However for higher powers the situation isvery different and we have-

Theorem Fermat-WilesFor all natural numbers n ge 3 there are no

36

COMP10120 Report writing and Digital Typography

integers x y z satisfying the equation

xn + yn = zn

35 Curriculum vitaie

There are several scenarios where using LATEX ratherthan other word processing software can be useful

bull typesetting mathematics yoursquove just read about

bull writing a technical document

bull your final year project peport

bull writing an article you want to get published

bull writing a Curriculum vitae CV

Wersquoll now look at CVrsquos briefly

Exercise 6 Curriculum vitae

Creating a professional document is especially impor-tant when you write your CV because how your CVlooks (not just the content) will determine if you are in-vited to interview for job you are applying for Thatcould be a summer internship next year a year long

37

COMP10120 Report writing and Digital Typography

placement after your second year or graduate positionafter you leave University

As well using a text-editor and compiling files fromthe command line other tools are available for editingLATEXWe will look at one of these overleafcom

Create a basic CV which describes you your edu-cation (including University) and any experience youhave or interesting projects that you may have doneYou can do this using httpsoverleafcom andchoosing the ready-made templates at httpswwwoverleafcomgallerytaggedcv

As you progress through University it is a good ideato keep your CV up to date and get feedback from asmany people as you can There will be opportunities todebug your CV later (See httpgitiomycv if youare interested) but yoursquoll need a ldquobeta releaserdquo (version10) of your CV to get started The best time to start thisprocess is now

36 Some optional extras

Exercise 7 Exploring more LATEX features (op-tional but easy)

This exercise reinforces some of the things yoursquove donealready but also introduces some features of LATEX that

38

COMP10120 Report writing and Digital Typography

will be new to you It is labelled as optional because itisnrsquot marked but we would recommend that you all tryit

Take a copy of the file optinfocoursesCOMP10120ex3latex-introtexand follow the instructions it contains You should readit before you process it with LATEX

Exercise 8 A neat directory listing (optionalmore challenging)

The fact that LATEX source files are just text makes it easyto have them generated by a program You are going toexploit this and use LATEX to produce a neat documentcontaining a listing of the files in any directory

Find how to create tables in LATEX tables using thetabular environment Make a LATEX document by handthat uses a table to neatly show the information aboutthe files in some (small) directory (as produced by ls

-l) Write a shell script called neat-ls that takes anargument which is the path name of a directory andproduces a LATEX document containing the above tablefor the given directory The script could also process theLATEX and display the resulting pdf file Finally find outabout the longtable package and change your script touse that instead

39

COMP10120 Report writing and Digital Typography

Exercise 9 A cleaning rota (optional evenmore challenging)

Now you will write a shell script called make-rota thatgenerates a house cleaning rota (Very handy for nextyear ) This is a table with columns such as KitchenBathroom and Lounge The rows will be weeks in theyear labelled with a date (eg always a Sunday) Theidea is that house mates can write their initials in theboxes promising to clean the corresponding room inthat particular week Start by making a sample tableby hand

Your script should take a single argument which isthe date of the first day of the first row eg102013(the US format for 20 Oct 13) The result will be a docu-ment that contains as many rows as fit on a single page(find out by experimenting)

The dates of each row should be generated from thefirst See the manual page for date to figure out howyou can generate a date that is a number of weeks anddays later than an existing one

361 Marking Scheme

You can view a copy of the marking scheme used bysubmit and labprint at

40

COMP10120 Report writing and Digital Typography

studentnetcsmanchesteracukugtlpmsphpunit=COMP10120ampex=ex3xml

37 Next steps

LATEX is a very powerful tool and it does take a littlegetting used to But itrsquos not as scary as it might initiallyseem and you should find that it doesnrsquot take long tolearn the common commands and techniques to makeyour documents well-structured and readable As youbecome more comfortable with the basics and under-stand the principles of typesetting finding out how todo more complex and sophisticated things is easymdashthere are hundreds of tutorials on the web

Donrsquot get carried away though and use the featuresjudiciously just because yoursquove found a cool new com-mand doesnrsquot mean that you should use it just to showoff your LATEX skills content and structure always trumpstypographic twiddlings4

4For example footnotes like this are for some reason a really tempting fea-ture to use in LATEX and in this document we have abused them mercilessly toillustrate a point Footnotes were originally a means for mechanical typeset-ters to insert comments corrections or additions to existing documents withouthaving to adjust the layout of a whole page and of course in digital typographythis is no longer necessary They can justifiably be used for citations (though itrsquosnot common to do so these days) and URLs if you donrsquot want these intrudinginto the body of your text And in some very very rare cases they can be usedas an aside to the main flow of the text (which is what has been done in this doc-ument) But this should be used sparingly If something is important to sayput it in the main body of your text If itrsquos not then perhaps you should thinkabout leaving it out completely or find some other way of including it Asking

41

COMP10120 Report writing and Digital Typography

371 Acknowledgements

Figure 38 is from the Wikipedia article on cheese

372 License

The text of this exercise is licensed under the terms ofthe Creative Commons Attribution 20 Generic (CC BY30) License

38 Background

What follows is additional contextual information aroundLATEX

LATEX was originally written by Leslie LamportW anAmerican computer scientist now working at MicrosoftResearch although its development has long been takenover by a world-wide LATEX community Itrsquos actuallybuilt on top of another system called TEX a computertypesetting system designed by one of the worldrsquos mostinfluential Computer Scientists Donald KnuthW of Stan-ford University Knuth has said that he designed TEX

the reader to look down at the bottom of a page to find out whether somethingis important or not is irritating and as yoursquove probably found out already oftenmeans you lose track of your reading position They also give the impressionthat the author isnrsquot clear about whether something is important or not whichis never good And long footnotes like this onemdashwhile LATEX will typeset themperfectly wellmdashare just plain silly Best avoid

42

COMP10120 Report writing and Digital Typography

for lsquothe creation of beautiful booksmdashand especially forbooks that contain a lot of mathematicsrsquo(D Knuth1984) Figure 34 shows what these eminent men looklike

So whatrsquos the purpose of LATEX Itrsquos purely a layerof software to make TEX easier to use in everyday sit-uations This is a good idea because although TEX isamazingly powerful it operates at a very low-level whichmakes it hard for non-expert users

Figure 34Don Knuth and Leslie Lamport

381 Pronunciation

The name TEX is intended by its creator to be pronouncedwith the final consonant as in the word loch or the nameBach but English speakers often pronounce it like thefirst syllable of technical The first syllable of LATEX is

43

COMP10120 Report writing and Digital Typography

pronounced as in rsquolayrsquo5

382 Why LATEX

Before we go any further why do we think LATEX is im-portant for youmdasha Computer Science studentmdashto knowabout Here are some reasons in no particular order

bull LATEX and TEX are superb examples of ComputerScience in action TEX was designed by Knuth fromfirst principlesmdashin other words from scratch TEXis actually a programming language and LATEX isa set of functions defined in the TEX language TheTEX lsquocompilerrsquo is written in WEBW a mixture ofdocumentation written in TeX and a PascalW sub-set in order to ensure portability it reads a TEXprogram and outputs documents TEX is completelyself-contained and designed to be portable to anycomputer architecture For example it implementsits own stackW and heapW (with garbage collectionW)and it does fixed-precision arithmeticW donrsquot worryif these terms donrsquot make much sense to you at themoment they soon will

5The Greek prefix lsquotexrsquo means lsquoartrsquo as well as lsquotechnologyrsquo so itrsquos a very nicelychosen name for a piece of software that produces such beautiful output Knuthexplained (D Knuth 1984) that one should lsquopronounce the X of TeX as a Greekchi not as an lsquoxrsquo so that TeX rhymes with the word blecchhhrsquo Wersquore not toosure that helps much unless you are confident in your pronunciation of theword lsquoblecchhrsquo Maybe itrsquos an American thing

44

COMP10120 Report writing and Digital Typography

bull LATEX is a new interesting way for you to thinkabout preparing documents

bull LATEX has a practical advantage for the writer inthat it helps you think more about what you wantto write rather than worrying about how it looks

bull LATEX is a powerful tool for professional scientificdocumentation and as a Computer Scientist youshould know about it

bull LATEX files are just plain text so can easily be cre-ated programatically For example the slides usedfor COMP16120 are generated automatically fromthe source of Johnrsquos book both are typeset usingLATEX The program labprint also produces itsoutput using LATEX using information drawn fromXMLW configuration files and ARCADE

bull Using LATEX is actually quite satisfying and thequality of its output may surprise you

In this lab session you are going to write severalshort documents using LATEX You could also write briefnotes in your logbook about how LATEX works and whatcommands you used inside the source of your docu-ments

45

COMP10120 Report writing and Digital Typography

383 Some history printing mathematics

Mathematics is hard to print on paper and on the Web(many websites resort to GIF or JPG images of mathsformulae which usually look horrible MathMLW pro-vides another approach but it is not yet widely used)

In the days before computers books and newspa-pers were printed with movable typeW made from lotsof little blocks of metal each with letters numbers andsymbols standing in relief which when inked left animpression on the paper (see Figure 35) The job ofthe printer (the printer here of course being a personnot a bit of electronics) was to gather together all theblocks in the right order between two horizontal stripsof wood to create a line of the document and then toassemble all those lines from top to bottom of a pageThus the term type settingW an incredible task whenyou think about it In the printerrsquos workshop by theway the blocks of metal were stored between jobs inwooden boxes called cases Letters like a b and c werestored in one case letters like A B and C were storedin a case sitting on top of that So a lower case and anupper case These terms may ring a bell

As technology progressed machines controlled bytypewriters would mechanically juggle the blocks intothe right order This conceptual model is the basis onwhich TEX operates Only now the metal blocks are

46

COMP10120 Report writing and Digital Typography

Figure 35On the left a piece of cast movable type in the Garamondfont On the right a case of cast metal type pieces andtypeset matter in a composing stick The text reads lsquoThequick brown fox jumps over the lazy dog and feels as if hewere in the seventh heaven of typography together with Her-mann Zapf the most famous artist of thersquo This document istypeset in a font called Palatino created by Hermann ZapfYou may have also seen rsquoZapf Dingbatsrsquo in the font lists ofvarious desktop applications Now you know why

little pieces of data arranged into data structuresThe one thing that traditional printers hated was

dealing with the typesetting of mathematics and theywould charge extra to do it It was incredibly fiddly toget the equations looking right they had to squeeze inextra bits of metal horizontally and vertically

When computers entered the printing world attemptsto print mathematics were limited by the printing tech-nology available It took a long time to reach the pointwhere computers could typeset mathematics beautifullyand that was the outstanding achievement of Knuthrsquos

47

COMP10120 Report writing and Digital Typography

TEXLetrsquos look at a quick example of the quality you get

from LATEX with a very simple formula that yoursquoll recog-nise

x =minusbplusmn

radicb2 minus 4ac

2aWersquoll revisit how LATEX typesets mathematics in Section 34

384 To WYSIWYG or not to WYSIWYG

Up until now you have probably used wordprocessingapplications such as Microsoft Word to create essaysletters and other (probably fairly short) documents Youmost likely know that the majority of modern wordprocessors use a paradigm called WYSIWYG or WhatYou See Is What You Get which means that you canmodify the visual style of the document yoursquore work-ing on by selecting the relevant bits and then choos-ing different attributes such as font size or colour usinga GUI In many ways this seems like such a sensibleand obvious way of doing things that you might bewondering why it even has a special name The rea-son is a historical one in the early days of comput-ing long before graphical window managers becamethe norm and when all you could display on screenwas fixed-width ASCII text in whatever the systemrsquos

48

COMP10120 Report writing and Digital Typography

default font was wordprocessors (eg Figure 36) onlyallowed you to format documents by using special se-quences of characters to cause particular effects Butthese effects were only visible when the document wasprinted So if you wanted a word to appear in boldtext in the wordprocessor you might write somethinglike [bold]hello world[bold] what you saw onscreen was not a direct reflection of what appeared onthe printed page If yoursquove written any HTML how-ever this process of marking up text may be familiarsee for example Figure 37 As computers moved todisplays able to draw things other than raw charac-ters on screen wordprocessors became capable of us-ing multiple fonts and styles as well as graphics anda new generation of applications appeared where whatyou saw on screen was an accurate reflection of how itwould appear when printed what you see (on screen)is what you get (on paper)

The huge advantage of WYSIWYG is that itrsquos reallyeasy to understand whatrsquos going on and most peoplecan create reasonably nicely formatted documents withrelatively little effort For short informal documentsone-off letters memos and such WYSIWYG works quitenicely But if yoursquove ever tried writing anything muchlonger or that includes images and tables you mayhave already started to see where the paradigm breaksdown For example if you write lsquoFigure 38 on page

49

COMP10120 Report writing and Digital Typography

Figure 36A screenshot of Wordperfect 51 running in Microsoft DOScirca 1989

51 shows a picture of some men looking at cheesersquo butthen later on edit your document to include some moretext at the start and a new picture of a some broccoli(as in Figure 39) yoursquod have to search through yourreport to find all mentions of lsquoFigure 38rsquo and lsquopage 51rsquoand manually update them to reflect the new number-ing This might be fine if you have two figures and fivepages but for a hundred-page report containing lots ofpictures you can see how this becomes tedious and er-ror prone very quickly

50

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 9: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

create some unique gibberish yourself)

Oisjdf oqweqwe oi soijs hbweo kbsd oijsdfoijqwknpiouh iusbdfspb sifuhygwqeb usgweijfblimqwoq oieuerwefwiu aokqjw uioshiufdsqiqks odfubfi psdiweneq

Be careful at this stage to only include letters (upper-case and lowercase) commas full-stops and perhapsnumbers in your gibberish text if you use any othersymbols you may upset LATEX

Next go to the website wwwlipsumcom and fol-low the instructions to generate yourself three para-graphs of whatrsquos called Lorem Ipsum text Copy andpaste that text into your LATEX document too (donrsquot worryabout what it means at this stage) again making surethat you have a blank line between the paragraphs

Run pdflatex and look at the resulting sectionspdfAgain at first glance therersquos nothing hugely excitinggoing on here the text from your tex file has beenassembled into a (probably) two page PDF documentBut in fact quite a few things have happened

bull The blank lines that separate the paragraphs inyour source file are gone and instead LATEX hasindented the first line of each paragraph Therersquosnothing profound here about the decision to in-dent paragraphs rather than (say) to leave a gap

16

COMP10120 Report writing and Digital Typography

between them (so called block paragraphs) itrsquosjust LATEXrsquos default paragraph style and can bechanged easily enough3

bull There are page numbers at the bottom of each page(except page 1) This is a very sensible default al-lowing you in meetings to ask people to lsquoturn topage 4rsquo and so on (itrsquos a bit odd and a source ofsome annoyance that most wordprocessors donrsquotdo this by default too) But you can easily switchpage numbers off change their style or move themelsewhere if you need to

bull The text is fully justified so that itrsquos flush on boththe left and right hand edges

bull Certain words that fall at the end of lines havebeen hyphenated even if they werenrsquot originallysplit by hyphens in the source text

These last two points about justification and hyphen-ation might seem utterly trivial but getting these fac-tors right turns out to be an important part of mak-ing readable documents readability is not just aboutwhich font you choose but about how the charactersand spaces are distributed on each line Itrsquos something

3Though apparently there is some evidence in M A Tinker 1963 that in-dented paragraphs increase readability

17

COMP10120 Report writing and Digital Typography

that you will have seen happen so often in profession-ally typeset materials that yoursquoll have taken it for grantedand you may not have spotted that it doesnrsquot happenin quite the same way when you use a wordproces-sor The principle behind justifying text seems easyenough at first glance you simply have to take any lsquoleftoverrsquo space that would be at the end of a line and re-distribute it between the words in some way to lsquospacethem outrsquo a bit more so that they take up all the avail-able horizontal room But it turns out to be much harderthan it seems and all the simple ways you might thinkof for doing this on a per-line basis give results thatare visually quite unsatisfactory with nasty patternsmade up of neighbouring whitespace appearing in thelayout and ruining everything The added complica-tion here is that to do the optimum job of shuffling thewords round on their lines you really need the flex-ibility of being able to hyphenate words to give youextra space on lines that would otherwise be tightlypacked with characters But if you hyphenate wordsbadly by breaking them in inappropriate places or doit too often then that makes the text hard to read tooItrsquos all deeply inconvenient and inter-related The bestsolution to this aesthetic conundrum so far was devel-oped by Knuth and Plass 1981 and later improved byFrank Liang during his PhD research (F M Liang1983) and itrsquos a technique that tries to optimise the lay-

18

COMP10120 Report writing and Digital Typography

out of whole paragraphs rather than individual linesThe algorithm takes into account all manner of differ-ent things language-specific character patterns the num-ber of consecutive lines that end with hyphens the wordlsquotightnessrsquo on each line and many others The detailsdonrsquot really matter here but the really important in-sight is that you get better results by working on a big-ger chunk of the document (in this case a paragraph at atime) rather than trying to independently optimise lotsof small bits (say lines) and hoping that the result ofjoining them all together turns out nicely This idea ofoptimising things globally versus locally is somethingyoursquoll see many times throughout your Computer Sci-ence degree watch out for it in all the algorithms courses

This highlights a fundamental difference betweenthe WYSIWYG paradigm and the way that documentsare produced using LATEX As wersquove seen small changesdown at the level of individual characters can have fairlylarge knock-on consequences for the optimal layout ofa document changing one letter for another affects thelength of a line which in turn affects the hyphenationoptions which then affects the length of a paragraphwhich means that the best place for a figure that was onpage 99 might now be on page 100 but that means thatall references to lsquopage 99rsquo now need a bit more room toaccount for the extra digit which means that the someline lengths have changed which means well you get

19

COMP10120 Report writing and Digital Typography

the idea Itrsquos more complicated than it first seems LATEXgets to see the whole of your document at once and cantherefore make decisions about how best to hyphen-ate lines position figures or whatever else it likes beforeit shows you the results so it can make solutions thatare optimal for the whole document as well as lookingat details such as ligated characters Wordprocessorscanrsquot afford to do this since it would be deeply distract-ing if every time you typed a character the whole lay-out of the document flapped around in front of youreyes Wordprocessors can only sensibly make little op-timisations at a local (probably per-line level) Itrsquos notthat wordprocessors are rubbish or that the people thatprogrammed them were lazy itrsquos a fundamentally dif-ferent way of working and knowing the pros and consof the different approaches will help you pick the righttool for the job

You may have noticed that actual text in your doc-ument (and in fact this one) takes up a (perhaps) sur-prisingly narrow horizontal region of the page Thislast lsquofeaturersquo might seem odd at first but it illustratesanother important typographical point that you maynever have thought of before reading long lines of textis hard because your eyes find it hard to move in acompletely straight line as they scan from left to rightSo the longer the line of words the more you have towork to keep your eyes from accidentally drifting up or

20

COMP10120 Report writing and Digital Typography

down onto a neighbouring line (perhaps yoursquove expe-rienced the phenomenon of accidentally re-reading thesame line over and over as your eyes get tired) It maynever have occurred to you but most books have rela-tively short lines of text and those that use large pagesoften split text into several columns so that individuallines are kept relatively short The widely trusted booklsquoThe Elements of Typographic Stylersquo (R Bringhurst1992) makes the following assertion

lsquoAnything from 45 to 75 characters is widely-regarded as a satisfactory length of line for a single-column page set in a serifed text face in a text sizeThe 66-character line (counting both letters andspaces) is widely regarded as idealrsquo

LATEX knows about this issue so made a sensible de-fault decision for you You may have noticed that thereis a subtle difference in appearance of this chapter fromprevious ones the lines are shorter and paragraphs areindented We wanted to use the default LATEX layoutfor this chapter but changed it for earlier chapters inan effort to save paper

Therersquos one last unusual thing to note your para-graph of gibberish text in between the real words fromBleak House and the Lorem Ipsum almost certainly standsout and looks really quite odd (it might even have con-fused LATEXrsquos hyphenation rules enough to have ended

21

COMP10120 Report writing and Digital Typography

up with one or more lines sticking out proud of theright hand margin) Let your eyes relax so that yourvision blurs for a moment you can still probably spotthat the gibberish paragraph looks out of place Itrsquosquite likely that you even found creating the gibber-ish unexpectedly hard The interesting thing here isthat as humans we spend so much time reading andwriting lsquoproperrsquo natural language that we become at-tuned to the patterns of letters words and the underly-ing lsquorhythmrsquo of our written language that its very hardto artificially reproduce something that looks plausiblethe frequency of the letters you chose by randomly hit-ting keys and the length and patterns of the words youput in place most likely donrsquot match the natural pat-terns of real languages so they just look plain wrongCuriously the Lorem Ipsum text that you got from thewebsite probably doesnrsquot look so bad in spite of it notbeing made up of real words But thatrsquos not surprisingsince Lorem Ipsum is specifically created to be used asa placeholder for real text when typesetting While thewords are meaningless Latin-like things their lengthand the distribution of characters and word lengths arechosen to mimic patterns in real language

Next letrsquos give our document some structure by di-viding it up into sections On the line before BleakHouse starts add the command

22

COMP10120 Report writing and Digital Typography

sectionBleak House

making sure it appears on a line of its own Then justbefore your paragraph of gibberish put a similar in-struction (again on its own line) and then create a finalsection before the Lorem Ipsum Rerun pdflatex andlook at the results You should see the section headingsappear in the appropriate places in the PDF automati-cally having been given section numbers Experimentby adding in a couple of sub-sections towards the endof the document using the subsection commandwhich like the section command above takes as aparameter some text contained in curly brackets

Now at the top of your document after the begindocumentline and before the command defining the first sectionadd the following two commands each on their ownline

tableofcontentsnewpage

Re-run pdflatex twice and check that the effect is whatyoursquod expect You need to process the source twice be-cause on the first run LATEX gathers and stores informa-tion about what to put in the table of contents and onlycreates it on the second run

23

COMP10120 Report writing and Digital Typography

33 Common formatting features

Before we give you some more exercises to do here is abrief introduction to some commonly used features ofLATEX

331 Enumerated and bulleted lists

Creating bulleted or numbered lists in LATEX is straight-forward and is done like this

beginenumerateitem My first itemitem My second itemitem The last thing on my listendenumerate

You must make sure that you both begin and end yourlist and that each item is terminated by a newline Chang-ing enumerate to itemize gives you a bulleted ratherthan numbered list (note the American spelling of lsquoitem-izersquo)

332 Changing the appearance of text

Text can be typeset in bold font using the textbfin italics using textitand in a fixed-width fontusing texttt as in the example below

24

COMP10120 Report writing and Digital Typography

Some textttsay the textbfworld will end in textitfire

which is typeset as

Some say the world will end in fire

333 Cross referencing

LATEX allows you to cross-reference almost anything inthe document which includes sections sub-sections andfigures To use the cross-referencing feature you simplyinsert the command

labelmymarker

at the point in the document you want to refer to andthen use the command

refmymarker

when you want to use the reference Obviously youreplace the text mymarkerwith something more mean-ingful An important tip here is to call the marker some-thing that refers to the content of that part of the doc-ument and to avoid the temptation to use numbers(so donrsquot call your marker section1 instead call itintroduction if you reorder your document itrsquos stilllikely to be the introduction but it may no longer beSection 1) For example

25

COMP10120 Report writing and Digital Typography

sectionReflection on Welcome WeeklabelwelcomeweekI spent most of welcome week getting to know my wayaround campus I should have made more effort to joinsocieties I think I must remember to get to theStudentsrsquo Union and take a look around there

subsectionThings I enjoyedEverything so far has been wonderful with the caveat Imentioned in Section refwelcomeweek

subsectionThings I didnrsquot enjoyIrsquove discovered that I donrsquot like soggy chips

The really useful thing about cross-referencing in LATEXis that yoursquoll get warnings when you compile your doc-ument if cross-references are undefined or used incor-rectly This means you donrsquot have to manually checkevery reference in your document to make sure itrsquos stillright You do however have to run LATEX twice forsimilar reasons to those given above

334 Figures and pictures

Including figures and pictures in your document is easyYou do it like this

beginfigure

26

COMP10120 Report writing and Digital Typography

Figure 33Some men possibly Dutch looking at cheeses

centerlineincludegraphics[width=10cm]imagesmen-and-cheesejpgcaptionSome men possibly Dutch looking at cheeseslabelfiguremenandcheesesendfigure

which is the code we used to create Figure 38 You canprobably see whatrsquos happening The command includegraphicsgets your image which can be PDF PNG JPG GIF orPostScript The beginfigureendfigurecode lsquowrapsrsquo up whatever picture yoursquore including andallows LATEX to treat it as an unbreakable floating thingthat it will position for you as best it can in the docu-ment while maintaining an overall nice typographicallayout This floating of figures can sometimes result inthe figure ending up in a place you didnrsquot expect but inmost cases LATEX will make the most sensible choice Itrsquos

27

COMP10120 Report writing and Digital Typography

possible to employ finer control over figure placementbut thatrsquos beyond the scope of this introduction

The includegraphics command is not built into core LATEX but is in an additional package whichneeds to be explicitly loaded We load this package byusing the command usepackagegraphicx in thedocument preamble ie after the documentclasscommand but before begindocument There arehundreds of such packages that extend LATEXrsquos func-tionality the lab scripts you are reading now use over30 of them

Exercise 3 Including images

Create a document imagetex that contains some text(maybe from rsquoLorem Ipsumrsquo) together with a figurecontaining an image of your choice perhaps the oneyou made in Intro Lab 2 like Steversquos Mr Noodle Thereshould also be a reference to the figure in the text Youshould first use the program convert

convert

(check its manpage) to create a PDF version of the image

Exercise 4 A reflection on your studies

Your first proper LATEX document will be a very briefreflection on your studies so far

Write a hand-crafted LATEX document called courses-reflectiontex

28

COMP10120 Report writing and Digital Typography

(exact name as usual please otherwise submitwill notwork) It will have the following structure

1 A table of contents

2 A brief paragraph saying what the document isabout

3 A section appropriately titled for one of your courseunits containing

bull a brief paragraph saying what the unit is about

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the most about the unit

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the least about the unit

A repeat of item 3 for each other unit you are study-ing These sections should appear in alphabeticalorder by course code (eg COMP10120)

After completing and successfully compiling and view-ing your document you should spell-check it as fol-lows

ispell courses-reflectiontex

29

COMP10120 Report writing and Digital Typography

Once you are completely satisfied with it produce ahard copy ready for marking

34 Typesetting Mathematics

Earlier we saw this formula

x =minusbplusmn

radicb2 minus 4ac

2aIt looks nice doesnrsquot it To tell LATEX to display thisyou have to type a bit of magic but itrsquos easily-learnedmagic To create such a formula in a WYSIWYG edi-tor there is also magic involved but it usually involvesa lot of mouse-clicking and remembering special keycombinations like rsquocontrol-thisrsquo and rsquoalt-thatrsquo In LATEXit doesnrsquot You simply type this

[ x = frac-b pm sqrtb^2-4ac2a ]

You can probably work out how most of this createsthe formula but it wonrsquot be obvious that the [ and ]symbols that enclose the formula mean lsquotypeset this asa displayed formula giving it some vertical space fromthe surrounding textrsquo If wersquod used ( and ) insteadto enclose the formula it would appear in-line like thisx = minusbplusmn

radicb2minus4ac2a It still looks very nice and observe

how itrsquos automatically been resized to fit and that the

30

COMP10120 Report writing and Digital Typography

lines of text have had their spacing changed a bit Thisall looks simple but the implementation inside LATEXand TEX is complex It involves parsing the descrip-tion of the formula to create a corresponding tree datastructure which is then recursively walked to workout the horizontal and vertical typographical spacingsneeded Yoursquoll meet these ideas in COMP11120 andCOMP26120 Algorithms and Imperative Programming

Herersquos another example taken from COMP27112Computer Graphics (itrsquos a lsquosimplersquo local illuminationmodel incorporating ambient diffuse and specular re-flection by multiple lights)

I = kaIa +

Msumi=1

Ipidprimei[kd(N middot Li) + ks(Ri middot V )n]

We write this in LATEX as follows

[ I = k_a I_a + sum_i=1^M fracI_p_idrsquo_i [ k_d(hatN cdot hatL_i)+ k_s(hatR_i cdot hatV)^n] ]

Try to match the LATEX commands with the formula dis-played above Yoursquoll see lots of curly brackets and thisexample illustrates their two uses in LATEX The firstis to provide an argument to a command for exam-ple hatN means lsquoapply the hat command to N rsquowhich creates N the vector N with a little hat on

31

COMP10120 Report writing and Digital Typography

The second use of curly brackets is to group thingstogether to avoid ambiguities In the example you cansee sum_i=1^M which creates a summation signand its lower and upper limits

sumMi=1 We wrap the

lower bound i=1 in curly brackets to group it into anindivisible unit If we were to omit the brackets writ-ing sum_i=1^M LATEX would then produce

sumi = 1M

which is not at all what we want (even LATEX canrsquot al-ways know what we really want)

One final example If we tell LATEX

[ T_1 = left[beginarraycccccos theta amp -sin theta amp 0 amp delta sin theta amp cos theta amp 0 amp epsilon 0 amp 0 amp 1 amp eta alpha amp beta amp gamma amp 1endarrayright] ]

wersquoll get a splendid matrix which expresses a particu-lar 3D geometrical transformation (Donrsquot worry if youdonrsquot recognise this yoursquoll be introduced to matrix no-tation in the latter part of COMP11120 MathematicalTechniques for Computer Science For now you can justtreat it as some mysterious maths)

32

COMP10120 Report writing and Digital Typography

T1 =

cos θ minus sin θ 0 δ

sin θ cos θ 0 ε

0 0 1 η

α β γ 1

In the LATEX code left[means lsquobig opening square

bracket pleasersquo ccccmeans lsquoan array with 4 columnsplease with the items in each column centredrsquo ampmeanslsquostart a new columnrsquo and means lsquostart a new rowrsquoYoursquoll notice that LATEX knows about greek letters itknows about most standard maths symbols too andalso the ways theyrsquore usually used

There are some symbols that you might need (forexample therefore which produces the usual threedots symbol there4) that are not part of standard LATEX Manysuch symbols are provided by the amssymb package ofsymbols compiled by the American Mathematical Soci-ety Details of the many symbols provided by this pack-age can be found online at

mirrormathkuedutex-archivefontsamsfontsdocamssymbpdf

To use these extra symbols you need to have usepackageamssymbin the document preamble

33

COMP10120 Report writing and Digital Typography

341 A longer piece of mathematics

We conclude this section with an example of a longerpiece of mathematics that shows how you might type-set a complete mathematical argument rather than asingle formula The example is Euclidrsquos proof of thefact that

radic2 is irrational Itrsquos an argument that has been

covered in COMP11120 and is an example of proof bycontradiction It starts by making the assumption thatit is not the case that

radic2 is irrational in other words that

we can find integers p and q withradic2 = pq

We can assume without losing anything that p andq have no common factors (Why)

radic2 = pq

qradic2 = p

2q2 = p2

This means that p2 is even from which we can also de-duce that p is even (Why)

This means that p = 2k for some k so

2q2 = (2k)2

there4 2q2 = 4k2

so q2 = 2k2

But this means that q2 and hence q is even Since p andq are both even we have a contradiction to our initialassumption so no such p and q exist

The way this is formatted is shown here

34

COMP10120 Report writing and Digital Typography

It starts by making the assumption that it is emphnot the casethat $sqrt2$ is irrational in other words that we can findintegers $p$ and $q$ with $sqrt2 = pq$

We can assume without losing anything that $p$ and $q$ haveemphno common factors (Why)

[beginarraylcl

sqrt2 amp = amp pq qsqrt2 amp = amp p 2q^2 amp = amp p^2

endarray]

This means that $p^2$ is even from which we can also deduce that $p$is even (Why)

This means that $p = 2k$ for some $k$ so ldots[beginarrayllcl

amp 2q^2 amp = amp (2k)^2 therefore amp 2q^2 amp = amp 4k^2 textso amp q^2 amp = amp 2k^2

endarray]

But this means that $q^2$ and hence $q$ is even Since $p$ and $q$are both even we have a contradiction to our initial assumptionso no such $p$ and $q$ exist

Notice the use of the array environment for gettingthings lined up You can find much more informationabout this on the web

LATEX really shines at typesetting mathematics and

35

COMP10120 Report writing and Digital Typography

it would take pages and pages to describe all the fea-tures Have a look at

enwikibooksorgwikiLaTeXMathematics

for a flavour

Exercise 5 Formatting mathematics

Now for an exercise that involves some mathematicsPlease create a file f-wtex which typesets the follow-ing piece of text and mathematics

There are many positive integer solutions tothe equation

x2 + y2 = z2

which can be rewritten as

z =radicx2 + y2

For example (3 4 5) or (5 12 13) Such solu-tions are called Pythagorean triples

However for higher powers the situation isvery different and we have-

Theorem Fermat-WilesFor all natural numbers n ge 3 there are no

36

COMP10120 Report writing and Digital Typography

integers x y z satisfying the equation

xn + yn = zn

35 Curriculum vitaie

There are several scenarios where using LATEX ratherthan other word processing software can be useful

bull typesetting mathematics yoursquove just read about

bull writing a technical document

bull your final year project peport

bull writing an article you want to get published

bull writing a Curriculum vitae CV

Wersquoll now look at CVrsquos briefly

Exercise 6 Curriculum vitae

Creating a professional document is especially impor-tant when you write your CV because how your CVlooks (not just the content) will determine if you are in-vited to interview for job you are applying for Thatcould be a summer internship next year a year long

37

COMP10120 Report writing and Digital Typography

placement after your second year or graduate positionafter you leave University

As well using a text-editor and compiling files fromthe command line other tools are available for editingLATEXWe will look at one of these overleafcom

Create a basic CV which describes you your edu-cation (including University) and any experience youhave or interesting projects that you may have doneYou can do this using httpsoverleafcom andchoosing the ready-made templates at httpswwwoverleafcomgallerytaggedcv

As you progress through University it is a good ideato keep your CV up to date and get feedback from asmany people as you can There will be opportunities todebug your CV later (See httpgitiomycv if youare interested) but yoursquoll need a ldquobeta releaserdquo (version10) of your CV to get started The best time to start thisprocess is now

36 Some optional extras

Exercise 7 Exploring more LATEX features (op-tional but easy)

This exercise reinforces some of the things yoursquove donealready but also introduces some features of LATEX that

38

COMP10120 Report writing and Digital Typography

will be new to you It is labelled as optional because itisnrsquot marked but we would recommend that you all tryit

Take a copy of the file optinfocoursesCOMP10120ex3latex-introtexand follow the instructions it contains You should readit before you process it with LATEX

Exercise 8 A neat directory listing (optionalmore challenging)

The fact that LATEX source files are just text makes it easyto have them generated by a program You are going toexploit this and use LATEX to produce a neat documentcontaining a listing of the files in any directory

Find how to create tables in LATEX tables using thetabular environment Make a LATEX document by handthat uses a table to neatly show the information aboutthe files in some (small) directory (as produced by ls

-l) Write a shell script called neat-ls that takes anargument which is the path name of a directory andproduces a LATEX document containing the above tablefor the given directory The script could also process theLATEX and display the resulting pdf file Finally find outabout the longtable package and change your script touse that instead

39

COMP10120 Report writing and Digital Typography

Exercise 9 A cleaning rota (optional evenmore challenging)

Now you will write a shell script called make-rota thatgenerates a house cleaning rota (Very handy for nextyear ) This is a table with columns such as KitchenBathroom and Lounge The rows will be weeks in theyear labelled with a date (eg always a Sunday) Theidea is that house mates can write their initials in theboxes promising to clean the corresponding room inthat particular week Start by making a sample tableby hand

Your script should take a single argument which isthe date of the first day of the first row eg102013(the US format for 20 Oct 13) The result will be a docu-ment that contains as many rows as fit on a single page(find out by experimenting)

The dates of each row should be generated from thefirst See the manual page for date to figure out howyou can generate a date that is a number of weeks anddays later than an existing one

361 Marking Scheme

You can view a copy of the marking scheme used bysubmit and labprint at

40

COMP10120 Report writing and Digital Typography

studentnetcsmanchesteracukugtlpmsphpunit=COMP10120ampex=ex3xml

37 Next steps

LATEX is a very powerful tool and it does take a littlegetting used to But itrsquos not as scary as it might initiallyseem and you should find that it doesnrsquot take long tolearn the common commands and techniques to makeyour documents well-structured and readable As youbecome more comfortable with the basics and under-stand the principles of typesetting finding out how todo more complex and sophisticated things is easymdashthere are hundreds of tutorials on the web

Donrsquot get carried away though and use the featuresjudiciously just because yoursquove found a cool new com-mand doesnrsquot mean that you should use it just to showoff your LATEX skills content and structure always trumpstypographic twiddlings4

4For example footnotes like this are for some reason a really tempting fea-ture to use in LATEX and in this document we have abused them mercilessly toillustrate a point Footnotes were originally a means for mechanical typeset-ters to insert comments corrections or additions to existing documents withouthaving to adjust the layout of a whole page and of course in digital typographythis is no longer necessary They can justifiably be used for citations (though itrsquosnot common to do so these days) and URLs if you donrsquot want these intrudinginto the body of your text And in some very very rare cases they can be usedas an aside to the main flow of the text (which is what has been done in this doc-ument) But this should be used sparingly If something is important to sayput it in the main body of your text If itrsquos not then perhaps you should thinkabout leaving it out completely or find some other way of including it Asking

41

COMP10120 Report writing and Digital Typography

371 Acknowledgements

Figure 38 is from the Wikipedia article on cheese

372 License

The text of this exercise is licensed under the terms ofthe Creative Commons Attribution 20 Generic (CC BY30) License

38 Background

What follows is additional contextual information aroundLATEX

LATEX was originally written by Leslie LamportW anAmerican computer scientist now working at MicrosoftResearch although its development has long been takenover by a world-wide LATEX community Itrsquos actuallybuilt on top of another system called TEX a computertypesetting system designed by one of the worldrsquos mostinfluential Computer Scientists Donald KnuthW of Stan-ford University Knuth has said that he designed TEX

the reader to look down at the bottom of a page to find out whether somethingis important or not is irritating and as yoursquove probably found out already oftenmeans you lose track of your reading position They also give the impressionthat the author isnrsquot clear about whether something is important or not whichis never good And long footnotes like this onemdashwhile LATEX will typeset themperfectly wellmdashare just plain silly Best avoid

42

COMP10120 Report writing and Digital Typography

for lsquothe creation of beautiful booksmdashand especially forbooks that contain a lot of mathematicsrsquo(D Knuth1984) Figure 34 shows what these eminent men looklike

So whatrsquos the purpose of LATEX Itrsquos purely a layerof software to make TEX easier to use in everyday sit-uations This is a good idea because although TEX isamazingly powerful it operates at a very low-level whichmakes it hard for non-expert users

Figure 34Don Knuth and Leslie Lamport

381 Pronunciation

The name TEX is intended by its creator to be pronouncedwith the final consonant as in the word loch or the nameBach but English speakers often pronounce it like thefirst syllable of technical The first syllable of LATEX is

43

COMP10120 Report writing and Digital Typography

pronounced as in rsquolayrsquo5

382 Why LATEX

Before we go any further why do we think LATEX is im-portant for youmdasha Computer Science studentmdashto knowabout Here are some reasons in no particular order

bull LATEX and TEX are superb examples of ComputerScience in action TEX was designed by Knuth fromfirst principlesmdashin other words from scratch TEXis actually a programming language and LATEX isa set of functions defined in the TEX language TheTEX lsquocompilerrsquo is written in WEBW a mixture ofdocumentation written in TeX and a PascalW sub-set in order to ensure portability it reads a TEXprogram and outputs documents TEX is completelyself-contained and designed to be portable to anycomputer architecture For example it implementsits own stackW and heapW (with garbage collectionW)and it does fixed-precision arithmeticW donrsquot worryif these terms donrsquot make much sense to you at themoment they soon will

5The Greek prefix lsquotexrsquo means lsquoartrsquo as well as lsquotechnologyrsquo so itrsquos a very nicelychosen name for a piece of software that produces such beautiful output Knuthexplained (D Knuth 1984) that one should lsquopronounce the X of TeX as a Greekchi not as an lsquoxrsquo so that TeX rhymes with the word blecchhhrsquo Wersquore not toosure that helps much unless you are confident in your pronunciation of theword lsquoblecchhrsquo Maybe itrsquos an American thing

44

COMP10120 Report writing and Digital Typography

bull LATEX is a new interesting way for you to thinkabout preparing documents

bull LATEX has a practical advantage for the writer inthat it helps you think more about what you wantto write rather than worrying about how it looks

bull LATEX is a powerful tool for professional scientificdocumentation and as a Computer Scientist youshould know about it

bull LATEX files are just plain text so can easily be cre-ated programatically For example the slides usedfor COMP16120 are generated automatically fromthe source of Johnrsquos book both are typeset usingLATEX The program labprint also produces itsoutput using LATEX using information drawn fromXMLW configuration files and ARCADE

bull Using LATEX is actually quite satisfying and thequality of its output may surprise you

In this lab session you are going to write severalshort documents using LATEX You could also write briefnotes in your logbook about how LATEX works and whatcommands you used inside the source of your docu-ments

45

COMP10120 Report writing and Digital Typography

383 Some history printing mathematics

Mathematics is hard to print on paper and on the Web(many websites resort to GIF or JPG images of mathsformulae which usually look horrible MathMLW pro-vides another approach but it is not yet widely used)

In the days before computers books and newspa-pers were printed with movable typeW made from lotsof little blocks of metal each with letters numbers andsymbols standing in relief which when inked left animpression on the paper (see Figure 35) The job ofthe printer (the printer here of course being a personnot a bit of electronics) was to gather together all theblocks in the right order between two horizontal stripsof wood to create a line of the document and then toassemble all those lines from top to bottom of a pageThus the term type settingW an incredible task whenyou think about it In the printerrsquos workshop by theway the blocks of metal were stored between jobs inwooden boxes called cases Letters like a b and c werestored in one case letters like A B and C were storedin a case sitting on top of that So a lower case and anupper case These terms may ring a bell

As technology progressed machines controlled bytypewriters would mechanically juggle the blocks intothe right order This conceptual model is the basis onwhich TEX operates Only now the metal blocks are

46

COMP10120 Report writing and Digital Typography

Figure 35On the left a piece of cast movable type in the Garamondfont On the right a case of cast metal type pieces andtypeset matter in a composing stick The text reads lsquoThequick brown fox jumps over the lazy dog and feels as if hewere in the seventh heaven of typography together with Her-mann Zapf the most famous artist of thersquo This document istypeset in a font called Palatino created by Hermann ZapfYou may have also seen rsquoZapf Dingbatsrsquo in the font lists ofvarious desktop applications Now you know why

little pieces of data arranged into data structuresThe one thing that traditional printers hated was

dealing with the typesetting of mathematics and theywould charge extra to do it It was incredibly fiddly toget the equations looking right they had to squeeze inextra bits of metal horizontally and vertically

When computers entered the printing world attemptsto print mathematics were limited by the printing tech-nology available It took a long time to reach the pointwhere computers could typeset mathematics beautifullyand that was the outstanding achievement of Knuthrsquos

47

COMP10120 Report writing and Digital Typography

TEXLetrsquos look at a quick example of the quality you get

from LATEX with a very simple formula that yoursquoll recog-nise

x =minusbplusmn

radicb2 minus 4ac

2aWersquoll revisit how LATEX typesets mathematics in Section 34

384 To WYSIWYG or not to WYSIWYG

Up until now you have probably used wordprocessingapplications such as Microsoft Word to create essaysletters and other (probably fairly short) documents Youmost likely know that the majority of modern wordprocessors use a paradigm called WYSIWYG or WhatYou See Is What You Get which means that you canmodify the visual style of the document yoursquore work-ing on by selecting the relevant bits and then choos-ing different attributes such as font size or colour usinga GUI In many ways this seems like such a sensibleand obvious way of doing things that you might bewondering why it even has a special name The rea-son is a historical one in the early days of comput-ing long before graphical window managers becamethe norm and when all you could display on screenwas fixed-width ASCII text in whatever the systemrsquos

48

COMP10120 Report writing and Digital Typography

default font was wordprocessors (eg Figure 36) onlyallowed you to format documents by using special se-quences of characters to cause particular effects Butthese effects were only visible when the document wasprinted So if you wanted a word to appear in boldtext in the wordprocessor you might write somethinglike [bold]hello world[bold] what you saw onscreen was not a direct reflection of what appeared onthe printed page If yoursquove written any HTML how-ever this process of marking up text may be familiarsee for example Figure 37 As computers moved todisplays able to draw things other than raw charac-ters on screen wordprocessors became capable of us-ing multiple fonts and styles as well as graphics anda new generation of applications appeared where whatyou saw on screen was an accurate reflection of how itwould appear when printed what you see (on screen)is what you get (on paper)

The huge advantage of WYSIWYG is that itrsquos reallyeasy to understand whatrsquos going on and most peoplecan create reasonably nicely formatted documents withrelatively little effort For short informal documentsone-off letters memos and such WYSIWYG works quitenicely But if yoursquove ever tried writing anything muchlonger or that includes images and tables you mayhave already started to see where the paradigm breaksdown For example if you write lsquoFigure 38 on page

49

COMP10120 Report writing and Digital Typography

Figure 36A screenshot of Wordperfect 51 running in Microsoft DOScirca 1989

51 shows a picture of some men looking at cheesersquo butthen later on edit your document to include some moretext at the start and a new picture of a some broccoli(as in Figure 39) yoursquod have to search through yourreport to find all mentions of lsquoFigure 38rsquo and lsquopage 51rsquoand manually update them to reflect the new number-ing This might be fine if you have two figures and fivepages but for a hundred-page report containing lots ofpictures you can see how this becomes tedious and er-ror prone very quickly

50

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 10: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

between them (so called block paragraphs) itrsquosjust LATEXrsquos default paragraph style and can bechanged easily enough3

bull There are page numbers at the bottom of each page(except page 1) This is a very sensible default al-lowing you in meetings to ask people to lsquoturn topage 4rsquo and so on (itrsquos a bit odd and a source ofsome annoyance that most wordprocessors donrsquotdo this by default too) But you can easily switchpage numbers off change their style or move themelsewhere if you need to

bull The text is fully justified so that itrsquos flush on boththe left and right hand edges

bull Certain words that fall at the end of lines havebeen hyphenated even if they werenrsquot originallysplit by hyphens in the source text

These last two points about justification and hyphen-ation might seem utterly trivial but getting these fac-tors right turns out to be an important part of mak-ing readable documents readability is not just aboutwhich font you choose but about how the charactersand spaces are distributed on each line Itrsquos something

3Though apparently there is some evidence in M A Tinker 1963 that in-dented paragraphs increase readability

17

COMP10120 Report writing and Digital Typography

that you will have seen happen so often in profession-ally typeset materials that yoursquoll have taken it for grantedand you may not have spotted that it doesnrsquot happenin quite the same way when you use a wordproces-sor The principle behind justifying text seems easyenough at first glance you simply have to take any lsquoleftoverrsquo space that would be at the end of a line and re-distribute it between the words in some way to lsquospacethem outrsquo a bit more so that they take up all the avail-able horizontal room But it turns out to be much harderthan it seems and all the simple ways you might thinkof for doing this on a per-line basis give results thatare visually quite unsatisfactory with nasty patternsmade up of neighbouring whitespace appearing in thelayout and ruining everything The added complica-tion here is that to do the optimum job of shuffling thewords round on their lines you really need the flex-ibility of being able to hyphenate words to give youextra space on lines that would otherwise be tightlypacked with characters But if you hyphenate wordsbadly by breaking them in inappropriate places or doit too often then that makes the text hard to read tooItrsquos all deeply inconvenient and inter-related The bestsolution to this aesthetic conundrum so far was devel-oped by Knuth and Plass 1981 and later improved byFrank Liang during his PhD research (F M Liang1983) and itrsquos a technique that tries to optimise the lay-

18

COMP10120 Report writing and Digital Typography

out of whole paragraphs rather than individual linesThe algorithm takes into account all manner of differ-ent things language-specific character patterns the num-ber of consecutive lines that end with hyphens the wordlsquotightnessrsquo on each line and many others The detailsdonrsquot really matter here but the really important in-sight is that you get better results by working on a big-ger chunk of the document (in this case a paragraph at atime) rather than trying to independently optimise lotsof small bits (say lines) and hoping that the result ofjoining them all together turns out nicely This idea ofoptimising things globally versus locally is somethingyoursquoll see many times throughout your Computer Sci-ence degree watch out for it in all the algorithms courses

This highlights a fundamental difference betweenthe WYSIWYG paradigm and the way that documentsare produced using LATEX As wersquove seen small changesdown at the level of individual characters can have fairlylarge knock-on consequences for the optimal layout ofa document changing one letter for another affects thelength of a line which in turn affects the hyphenationoptions which then affects the length of a paragraphwhich means that the best place for a figure that was onpage 99 might now be on page 100 but that means thatall references to lsquopage 99rsquo now need a bit more room toaccount for the extra digit which means that the someline lengths have changed which means well you get

19

COMP10120 Report writing and Digital Typography

the idea Itrsquos more complicated than it first seems LATEXgets to see the whole of your document at once and cantherefore make decisions about how best to hyphen-ate lines position figures or whatever else it likes beforeit shows you the results so it can make solutions thatare optimal for the whole document as well as lookingat details such as ligated characters Wordprocessorscanrsquot afford to do this since it would be deeply distract-ing if every time you typed a character the whole lay-out of the document flapped around in front of youreyes Wordprocessors can only sensibly make little op-timisations at a local (probably per-line level) Itrsquos notthat wordprocessors are rubbish or that the people thatprogrammed them were lazy itrsquos a fundamentally dif-ferent way of working and knowing the pros and consof the different approaches will help you pick the righttool for the job

You may have noticed that actual text in your doc-ument (and in fact this one) takes up a (perhaps) sur-prisingly narrow horizontal region of the page Thislast lsquofeaturersquo might seem odd at first but it illustratesanother important typographical point that you maynever have thought of before reading long lines of textis hard because your eyes find it hard to move in acompletely straight line as they scan from left to rightSo the longer the line of words the more you have towork to keep your eyes from accidentally drifting up or

20

COMP10120 Report writing and Digital Typography

down onto a neighbouring line (perhaps yoursquove expe-rienced the phenomenon of accidentally re-reading thesame line over and over as your eyes get tired) It maynever have occurred to you but most books have rela-tively short lines of text and those that use large pagesoften split text into several columns so that individuallines are kept relatively short The widely trusted booklsquoThe Elements of Typographic Stylersquo (R Bringhurst1992) makes the following assertion

lsquoAnything from 45 to 75 characters is widely-regarded as a satisfactory length of line for a single-column page set in a serifed text face in a text sizeThe 66-character line (counting both letters andspaces) is widely regarded as idealrsquo

LATEX knows about this issue so made a sensible de-fault decision for you You may have noticed that thereis a subtle difference in appearance of this chapter fromprevious ones the lines are shorter and paragraphs areindented We wanted to use the default LATEX layoutfor this chapter but changed it for earlier chapters inan effort to save paper

Therersquos one last unusual thing to note your para-graph of gibberish text in between the real words fromBleak House and the Lorem Ipsum almost certainly standsout and looks really quite odd (it might even have con-fused LATEXrsquos hyphenation rules enough to have ended

21

COMP10120 Report writing and Digital Typography

up with one or more lines sticking out proud of theright hand margin) Let your eyes relax so that yourvision blurs for a moment you can still probably spotthat the gibberish paragraph looks out of place Itrsquosquite likely that you even found creating the gibber-ish unexpectedly hard The interesting thing here isthat as humans we spend so much time reading andwriting lsquoproperrsquo natural language that we become at-tuned to the patterns of letters words and the underly-ing lsquorhythmrsquo of our written language that its very hardto artificially reproduce something that looks plausiblethe frequency of the letters you chose by randomly hit-ting keys and the length and patterns of the words youput in place most likely donrsquot match the natural pat-terns of real languages so they just look plain wrongCuriously the Lorem Ipsum text that you got from thewebsite probably doesnrsquot look so bad in spite of it notbeing made up of real words But thatrsquos not surprisingsince Lorem Ipsum is specifically created to be used asa placeholder for real text when typesetting While thewords are meaningless Latin-like things their lengthand the distribution of characters and word lengths arechosen to mimic patterns in real language

Next letrsquos give our document some structure by di-viding it up into sections On the line before BleakHouse starts add the command

22

COMP10120 Report writing and Digital Typography

sectionBleak House

making sure it appears on a line of its own Then justbefore your paragraph of gibberish put a similar in-struction (again on its own line) and then create a finalsection before the Lorem Ipsum Rerun pdflatex andlook at the results You should see the section headingsappear in the appropriate places in the PDF automati-cally having been given section numbers Experimentby adding in a couple of sub-sections towards the endof the document using the subsection commandwhich like the section command above takes as aparameter some text contained in curly brackets

Now at the top of your document after the begindocumentline and before the command defining the first sectionadd the following two commands each on their ownline

tableofcontentsnewpage

Re-run pdflatex twice and check that the effect is whatyoursquod expect You need to process the source twice be-cause on the first run LATEX gathers and stores informa-tion about what to put in the table of contents and onlycreates it on the second run

23

COMP10120 Report writing and Digital Typography

33 Common formatting features

Before we give you some more exercises to do here is abrief introduction to some commonly used features ofLATEX

331 Enumerated and bulleted lists

Creating bulleted or numbered lists in LATEX is straight-forward and is done like this

beginenumerateitem My first itemitem My second itemitem The last thing on my listendenumerate

You must make sure that you both begin and end yourlist and that each item is terminated by a newline Chang-ing enumerate to itemize gives you a bulleted ratherthan numbered list (note the American spelling of lsquoitem-izersquo)

332 Changing the appearance of text

Text can be typeset in bold font using the textbfin italics using textitand in a fixed-width fontusing texttt as in the example below

24

COMP10120 Report writing and Digital Typography

Some textttsay the textbfworld will end in textitfire

which is typeset as

Some say the world will end in fire

333 Cross referencing

LATEX allows you to cross-reference almost anything inthe document which includes sections sub-sections andfigures To use the cross-referencing feature you simplyinsert the command

labelmymarker

at the point in the document you want to refer to andthen use the command

refmymarker

when you want to use the reference Obviously youreplace the text mymarkerwith something more mean-ingful An important tip here is to call the marker some-thing that refers to the content of that part of the doc-ument and to avoid the temptation to use numbers(so donrsquot call your marker section1 instead call itintroduction if you reorder your document itrsquos stilllikely to be the introduction but it may no longer beSection 1) For example

25

COMP10120 Report writing and Digital Typography

sectionReflection on Welcome WeeklabelwelcomeweekI spent most of welcome week getting to know my wayaround campus I should have made more effort to joinsocieties I think I must remember to get to theStudentsrsquo Union and take a look around there

subsectionThings I enjoyedEverything so far has been wonderful with the caveat Imentioned in Section refwelcomeweek

subsectionThings I didnrsquot enjoyIrsquove discovered that I donrsquot like soggy chips

The really useful thing about cross-referencing in LATEXis that yoursquoll get warnings when you compile your doc-ument if cross-references are undefined or used incor-rectly This means you donrsquot have to manually checkevery reference in your document to make sure itrsquos stillright You do however have to run LATEX twice forsimilar reasons to those given above

334 Figures and pictures

Including figures and pictures in your document is easyYou do it like this

beginfigure

26

COMP10120 Report writing and Digital Typography

Figure 33Some men possibly Dutch looking at cheeses

centerlineincludegraphics[width=10cm]imagesmen-and-cheesejpgcaptionSome men possibly Dutch looking at cheeseslabelfiguremenandcheesesendfigure

which is the code we used to create Figure 38 You canprobably see whatrsquos happening The command includegraphicsgets your image which can be PDF PNG JPG GIF orPostScript The beginfigureendfigurecode lsquowrapsrsquo up whatever picture yoursquore including andallows LATEX to treat it as an unbreakable floating thingthat it will position for you as best it can in the docu-ment while maintaining an overall nice typographicallayout This floating of figures can sometimes result inthe figure ending up in a place you didnrsquot expect but inmost cases LATEX will make the most sensible choice Itrsquos

27

COMP10120 Report writing and Digital Typography

possible to employ finer control over figure placementbut thatrsquos beyond the scope of this introduction

The includegraphics command is not built into core LATEX but is in an additional package whichneeds to be explicitly loaded We load this package byusing the command usepackagegraphicx in thedocument preamble ie after the documentclasscommand but before begindocument There arehundreds of such packages that extend LATEXrsquos func-tionality the lab scripts you are reading now use over30 of them

Exercise 3 Including images

Create a document imagetex that contains some text(maybe from rsquoLorem Ipsumrsquo) together with a figurecontaining an image of your choice perhaps the oneyou made in Intro Lab 2 like Steversquos Mr Noodle Thereshould also be a reference to the figure in the text Youshould first use the program convert

convert

(check its manpage) to create a PDF version of the image

Exercise 4 A reflection on your studies

Your first proper LATEX document will be a very briefreflection on your studies so far

Write a hand-crafted LATEX document called courses-reflectiontex

28

COMP10120 Report writing and Digital Typography

(exact name as usual please otherwise submitwill notwork) It will have the following structure

1 A table of contents

2 A brief paragraph saying what the document isabout

3 A section appropriately titled for one of your courseunits containing

bull a brief paragraph saying what the unit is about

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the most about the unit

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the least about the unit

A repeat of item 3 for each other unit you are study-ing These sections should appear in alphabeticalorder by course code (eg COMP10120)

After completing and successfully compiling and view-ing your document you should spell-check it as fol-lows

ispell courses-reflectiontex

29

COMP10120 Report writing and Digital Typography

Once you are completely satisfied with it produce ahard copy ready for marking

34 Typesetting Mathematics

Earlier we saw this formula

x =minusbplusmn

radicb2 minus 4ac

2aIt looks nice doesnrsquot it To tell LATEX to display thisyou have to type a bit of magic but itrsquos easily-learnedmagic To create such a formula in a WYSIWYG edi-tor there is also magic involved but it usually involvesa lot of mouse-clicking and remembering special keycombinations like rsquocontrol-thisrsquo and rsquoalt-thatrsquo In LATEXit doesnrsquot You simply type this

[ x = frac-b pm sqrtb^2-4ac2a ]

You can probably work out how most of this createsthe formula but it wonrsquot be obvious that the [ and ]symbols that enclose the formula mean lsquotypeset this asa displayed formula giving it some vertical space fromthe surrounding textrsquo If wersquod used ( and ) insteadto enclose the formula it would appear in-line like thisx = minusbplusmn

radicb2minus4ac2a It still looks very nice and observe

how itrsquos automatically been resized to fit and that the

30

COMP10120 Report writing and Digital Typography

lines of text have had their spacing changed a bit Thisall looks simple but the implementation inside LATEXand TEX is complex It involves parsing the descrip-tion of the formula to create a corresponding tree datastructure which is then recursively walked to workout the horizontal and vertical typographical spacingsneeded Yoursquoll meet these ideas in COMP11120 andCOMP26120 Algorithms and Imperative Programming

Herersquos another example taken from COMP27112Computer Graphics (itrsquos a lsquosimplersquo local illuminationmodel incorporating ambient diffuse and specular re-flection by multiple lights)

I = kaIa +

Msumi=1

Ipidprimei[kd(N middot Li) + ks(Ri middot V )n]

We write this in LATEX as follows

[ I = k_a I_a + sum_i=1^M fracI_p_idrsquo_i [ k_d(hatN cdot hatL_i)+ k_s(hatR_i cdot hatV)^n] ]

Try to match the LATEX commands with the formula dis-played above Yoursquoll see lots of curly brackets and thisexample illustrates their two uses in LATEX The firstis to provide an argument to a command for exam-ple hatN means lsquoapply the hat command to N rsquowhich creates N the vector N with a little hat on

31

COMP10120 Report writing and Digital Typography

The second use of curly brackets is to group thingstogether to avoid ambiguities In the example you cansee sum_i=1^M which creates a summation signand its lower and upper limits

sumMi=1 We wrap the

lower bound i=1 in curly brackets to group it into anindivisible unit If we were to omit the brackets writ-ing sum_i=1^M LATEX would then produce

sumi = 1M

which is not at all what we want (even LATEX canrsquot al-ways know what we really want)

One final example If we tell LATEX

[ T_1 = left[beginarraycccccos theta amp -sin theta amp 0 amp delta sin theta amp cos theta amp 0 amp epsilon 0 amp 0 amp 1 amp eta alpha amp beta amp gamma amp 1endarrayright] ]

wersquoll get a splendid matrix which expresses a particu-lar 3D geometrical transformation (Donrsquot worry if youdonrsquot recognise this yoursquoll be introduced to matrix no-tation in the latter part of COMP11120 MathematicalTechniques for Computer Science For now you can justtreat it as some mysterious maths)

32

COMP10120 Report writing and Digital Typography

T1 =

cos θ minus sin θ 0 δ

sin θ cos θ 0 ε

0 0 1 η

α β γ 1

In the LATEX code left[means lsquobig opening square

bracket pleasersquo ccccmeans lsquoan array with 4 columnsplease with the items in each column centredrsquo ampmeanslsquostart a new columnrsquo and means lsquostart a new rowrsquoYoursquoll notice that LATEX knows about greek letters itknows about most standard maths symbols too andalso the ways theyrsquore usually used

There are some symbols that you might need (forexample therefore which produces the usual threedots symbol there4) that are not part of standard LATEX Manysuch symbols are provided by the amssymb package ofsymbols compiled by the American Mathematical Soci-ety Details of the many symbols provided by this pack-age can be found online at

mirrormathkuedutex-archivefontsamsfontsdocamssymbpdf

To use these extra symbols you need to have usepackageamssymbin the document preamble

33

COMP10120 Report writing and Digital Typography

341 A longer piece of mathematics

We conclude this section with an example of a longerpiece of mathematics that shows how you might type-set a complete mathematical argument rather than asingle formula The example is Euclidrsquos proof of thefact that

radic2 is irrational Itrsquos an argument that has been

covered in COMP11120 and is an example of proof bycontradiction It starts by making the assumption thatit is not the case that

radic2 is irrational in other words that

we can find integers p and q withradic2 = pq

We can assume without losing anything that p andq have no common factors (Why)

radic2 = pq

qradic2 = p

2q2 = p2

This means that p2 is even from which we can also de-duce that p is even (Why)

This means that p = 2k for some k so

2q2 = (2k)2

there4 2q2 = 4k2

so q2 = 2k2

But this means that q2 and hence q is even Since p andq are both even we have a contradiction to our initialassumption so no such p and q exist

The way this is formatted is shown here

34

COMP10120 Report writing and Digital Typography

It starts by making the assumption that it is emphnot the casethat $sqrt2$ is irrational in other words that we can findintegers $p$ and $q$ with $sqrt2 = pq$

We can assume without losing anything that $p$ and $q$ haveemphno common factors (Why)

[beginarraylcl

sqrt2 amp = amp pq qsqrt2 amp = amp p 2q^2 amp = amp p^2

endarray]

This means that $p^2$ is even from which we can also deduce that $p$is even (Why)

This means that $p = 2k$ for some $k$ so ldots[beginarrayllcl

amp 2q^2 amp = amp (2k)^2 therefore amp 2q^2 amp = amp 4k^2 textso amp q^2 amp = amp 2k^2

endarray]

But this means that $q^2$ and hence $q$ is even Since $p$ and $q$are both even we have a contradiction to our initial assumptionso no such $p$ and $q$ exist

Notice the use of the array environment for gettingthings lined up You can find much more informationabout this on the web

LATEX really shines at typesetting mathematics and

35

COMP10120 Report writing and Digital Typography

it would take pages and pages to describe all the fea-tures Have a look at

enwikibooksorgwikiLaTeXMathematics

for a flavour

Exercise 5 Formatting mathematics

Now for an exercise that involves some mathematicsPlease create a file f-wtex which typesets the follow-ing piece of text and mathematics

There are many positive integer solutions tothe equation

x2 + y2 = z2

which can be rewritten as

z =radicx2 + y2

For example (3 4 5) or (5 12 13) Such solu-tions are called Pythagorean triples

However for higher powers the situation isvery different and we have-

Theorem Fermat-WilesFor all natural numbers n ge 3 there are no

36

COMP10120 Report writing and Digital Typography

integers x y z satisfying the equation

xn + yn = zn

35 Curriculum vitaie

There are several scenarios where using LATEX ratherthan other word processing software can be useful

bull typesetting mathematics yoursquove just read about

bull writing a technical document

bull your final year project peport

bull writing an article you want to get published

bull writing a Curriculum vitae CV

Wersquoll now look at CVrsquos briefly

Exercise 6 Curriculum vitae

Creating a professional document is especially impor-tant when you write your CV because how your CVlooks (not just the content) will determine if you are in-vited to interview for job you are applying for Thatcould be a summer internship next year a year long

37

COMP10120 Report writing and Digital Typography

placement after your second year or graduate positionafter you leave University

As well using a text-editor and compiling files fromthe command line other tools are available for editingLATEXWe will look at one of these overleafcom

Create a basic CV which describes you your edu-cation (including University) and any experience youhave or interesting projects that you may have doneYou can do this using httpsoverleafcom andchoosing the ready-made templates at httpswwwoverleafcomgallerytaggedcv

As you progress through University it is a good ideato keep your CV up to date and get feedback from asmany people as you can There will be opportunities todebug your CV later (See httpgitiomycv if youare interested) but yoursquoll need a ldquobeta releaserdquo (version10) of your CV to get started The best time to start thisprocess is now

36 Some optional extras

Exercise 7 Exploring more LATEX features (op-tional but easy)

This exercise reinforces some of the things yoursquove donealready but also introduces some features of LATEX that

38

COMP10120 Report writing and Digital Typography

will be new to you It is labelled as optional because itisnrsquot marked but we would recommend that you all tryit

Take a copy of the file optinfocoursesCOMP10120ex3latex-introtexand follow the instructions it contains You should readit before you process it with LATEX

Exercise 8 A neat directory listing (optionalmore challenging)

The fact that LATEX source files are just text makes it easyto have them generated by a program You are going toexploit this and use LATEX to produce a neat documentcontaining a listing of the files in any directory

Find how to create tables in LATEX tables using thetabular environment Make a LATEX document by handthat uses a table to neatly show the information aboutthe files in some (small) directory (as produced by ls

-l) Write a shell script called neat-ls that takes anargument which is the path name of a directory andproduces a LATEX document containing the above tablefor the given directory The script could also process theLATEX and display the resulting pdf file Finally find outabout the longtable package and change your script touse that instead

39

COMP10120 Report writing and Digital Typography

Exercise 9 A cleaning rota (optional evenmore challenging)

Now you will write a shell script called make-rota thatgenerates a house cleaning rota (Very handy for nextyear ) This is a table with columns such as KitchenBathroom and Lounge The rows will be weeks in theyear labelled with a date (eg always a Sunday) Theidea is that house mates can write their initials in theboxes promising to clean the corresponding room inthat particular week Start by making a sample tableby hand

Your script should take a single argument which isthe date of the first day of the first row eg102013(the US format for 20 Oct 13) The result will be a docu-ment that contains as many rows as fit on a single page(find out by experimenting)

The dates of each row should be generated from thefirst See the manual page for date to figure out howyou can generate a date that is a number of weeks anddays later than an existing one

361 Marking Scheme

You can view a copy of the marking scheme used bysubmit and labprint at

40

COMP10120 Report writing and Digital Typography

studentnetcsmanchesteracukugtlpmsphpunit=COMP10120ampex=ex3xml

37 Next steps

LATEX is a very powerful tool and it does take a littlegetting used to But itrsquos not as scary as it might initiallyseem and you should find that it doesnrsquot take long tolearn the common commands and techniques to makeyour documents well-structured and readable As youbecome more comfortable with the basics and under-stand the principles of typesetting finding out how todo more complex and sophisticated things is easymdashthere are hundreds of tutorials on the web

Donrsquot get carried away though and use the featuresjudiciously just because yoursquove found a cool new com-mand doesnrsquot mean that you should use it just to showoff your LATEX skills content and structure always trumpstypographic twiddlings4

4For example footnotes like this are for some reason a really tempting fea-ture to use in LATEX and in this document we have abused them mercilessly toillustrate a point Footnotes were originally a means for mechanical typeset-ters to insert comments corrections or additions to existing documents withouthaving to adjust the layout of a whole page and of course in digital typographythis is no longer necessary They can justifiably be used for citations (though itrsquosnot common to do so these days) and URLs if you donrsquot want these intrudinginto the body of your text And in some very very rare cases they can be usedas an aside to the main flow of the text (which is what has been done in this doc-ument) But this should be used sparingly If something is important to sayput it in the main body of your text If itrsquos not then perhaps you should thinkabout leaving it out completely or find some other way of including it Asking

41

COMP10120 Report writing and Digital Typography

371 Acknowledgements

Figure 38 is from the Wikipedia article on cheese

372 License

The text of this exercise is licensed under the terms ofthe Creative Commons Attribution 20 Generic (CC BY30) License

38 Background

What follows is additional contextual information aroundLATEX

LATEX was originally written by Leslie LamportW anAmerican computer scientist now working at MicrosoftResearch although its development has long been takenover by a world-wide LATEX community Itrsquos actuallybuilt on top of another system called TEX a computertypesetting system designed by one of the worldrsquos mostinfluential Computer Scientists Donald KnuthW of Stan-ford University Knuth has said that he designed TEX

the reader to look down at the bottom of a page to find out whether somethingis important or not is irritating and as yoursquove probably found out already oftenmeans you lose track of your reading position They also give the impressionthat the author isnrsquot clear about whether something is important or not whichis never good And long footnotes like this onemdashwhile LATEX will typeset themperfectly wellmdashare just plain silly Best avoid

42

COMP10120 Report writing and Digital Typography

for lsquothe creation of beautiful booksmdashand especially forbooks that contain a lot of mathematicsrsquo(D Knuth1984) Figure 34 shows what these eminent men looklike

So whatrsquos the purpose of LATEX Itrsquos purely a layerof software to make TEX easier to use in everyday sit-uations This is a good idea because although TEX isamazingly powerful it operates at a very low-level whichmakes it hard for non-expert users

Figure 34Don Knuth and Leslie Lamport

381 Pronunciation

The name TEX is intended by its creator to be pronouncedwith the final consonant as in the word loch or the nameBach but English speakers often pronounce it like thefirst syllable of technical The first syllable of LATEX is

43

COMP10120 Report writing and Digital Typography

pronounced as in rsquolayrsquo5

382 Why LATEX

Before we go any further why do we think LATEX is im-portant for youmdasha Computer Science studentmdashto knowabout Here are some reasons in no particular order

bull LATEX and TEX are superb examples of ComputerScience in action TEX was designed by Knuth fromfirst principlesmdashin other words from scratch TEXis actually a programming language and LATEX isa set of functions defined in the TEX language TheTEX lsquocompilerrsquo is written in WEBW a mixture ofdocumentation written in TeX and a PascalW sub-set in order to ensure portability it reads a TEXprogram and outputs documents TEX is completelyself-contained and designed to be portable to anycomputer architecture For example it implementsits own stackW and heapW (with garbage collectionW)and it does fixed-precision arithmeticW donrsquot worryif these terms donrsquot make much sense to you at themoment they soon will

5The Greek prefix lsquotexrsquo means lsquoartrsquo as well as lsquotechnologyrsquo so itrsquos a very nicelychosen name for a piece of software that produces such beautiful output Knuthexplained (D Knuth 1984) that one should lsquopronounce the X of TeX as a Greekchi not as an lsquoxrsquo so that TeX rhymes with the word blecchhhrsquo Wersquore not toosure that helps much unless you are confident in your pronunciation of theword lsquoblecchhrsquo Maybe itrsquos an American thing

44

COMP10120 Report writing and Digital Typography

bull LATEX is a new interesting way for you to thinkabout preparing documents

bull LATEX has a practical advantage for the writer inthat it helps you think more about what you wantto write rather than worrying about how it looks

bull LATEX is a powerful tool for professional scientificdocumentation and as a Computer Scientist youshould know about it

bull LATEX files are just plain text so can easily be cre-ated programatically For example the slides usedfor COMP16120 are generated automatically fromthe source of Johnrsquos book both are typeset usingLATEX The program labprint also produces itsoutput using LATEX using information drawn fromXMLW configuration files and ARCADE

bull Using LATEX is actually quite satisfying and thequality of its output may surprise you

In this lab session you are going to write severalshort documents using LATEX You could also write briefnotes in your logbook about how LATEX works and whatcommands you used inside the source of your docu-ments

45

COMP10120 Report writing and Digital Typography

383 Some history printing mathematics

Mathematics is hard to print on paper and on the Web(many websites resort to GIF or JPG images of mathsformulae which usually look horrible MathMLW pro-vides another approach but it is not yet widely used)

In the days before computers books and newspa-pers were printed with movable typeW made from lotsof little blocks of metal each with letters numbers andsymbols standing in relief which when inked left animpression on the paper (see Figure 35) The job ofthe printer (the printer here of course being a personnot a bit of electronics) was to gather together all theblocks in the right order between two horizontal stripsof wood to create a line of the document and then toassemble all those lines from top to bottom of a pageThus the term type settingW an incredible task whenyou think about it In the printerrsquos workshop by theway the blocks of metal were stored between jobs inwooden boxes called cases Letters like a b and c werestored in one case letters like A B and C were storedin a case sitting on top of that So a lower case and anupper case These terms may ring a bell

As technology progressed machines controlled bytypewriters would mechanically juggle the blocks intothe right order This conceptual model is the basis onwhich TEX operates Only now the metal blocks are

46

COMP10120 Report writing and Digital Typography

Figure 35On the left a piece of cast movable type in the Garamondfont On the right a case of cast metal type pieces andtypeset matter in a composing stick The text reads lsquoThequick brown fox jumps over the lazy dog and feels as if hewere in the seventh heaven of typography together with Her-mann Zapf the most famous artist of thersquo This document istypeset in a font called Palatino created by Hermann ZapfYou may have also seen rsquoZapf Dingbatsrsquo in the font lists ofvarious desktop applications Now you know why

little pieces of data arranged into data structuresThe one thing that traditional printers hated was

dealing with the typesetting of mathematics and theywould charge extra to do it It was incredibly fiddly toget the equations looking right they had to squeeze inextra bits of metal horizontally and vertically

When computers entered the printing world attemptsto print mathematics were limited by the printing tech-nology available It took a long time to reach the pointwhere computers could typeset mathematics beautifullyand that was the outstanding achievement of Knuthrsquos

47

COMP10120 Report writing and Digital Typography

TEXLetrsquos look at a quick example of the quality you get

from LATEX with a very simple formula that yoursquoll recog-nise

x =minusbplusmn

radicb2 minus 4ac

2aWersquoll revisit how LATEX typesets mathematics in Section 34

384 To WYSIWYG or not to WYSIWYG

Up until now you have probably used wordprocessingapplications such as Microsoft Word to create essaysletters and other (probably fairly short) documents Youmost likely know that the majority of modern wordprocessors use a paradigm called WYSIWYG or WhatYou See Is What You Get which means that you canmodify the visual style of the document yoursquore work-ing on by selecting the relevant bits and then choos-ing different attributes such as font size or colour usinga GUI In many ways this seems like such a sensibleand obvious way of doing things that you might bewondering why it even has a special name The rea-son is a historical one in the early days of comput-ing long before graphical window managers becamethe norm and when all you could display on screenwas fixed-width ASCII text in whatever the systemrsquos

48

COMP10120 Report writing and Digital Typography

default font was wordprocessors (eg Figure 36) onlyallowed you to format documents by using special se-quences of characters to cause particular effects Butthese effects were only visible when the document wasprinted So if you wanted a word to appear in boldtext in the wordprocessor you might write somethinglike [bold]hello world[bold] what you saw onscreen was not a direct reflection of what appeared onthe printed page If yoursquove written any HTML how-ever this process of marking up text may be familiarsee for example Figure 37 As computers moved todisplays able to draw things other than raw charac-ters on screen wordprocessors became capable of us-ing multiple fonts and styles as well as graphics anda new generation of applications appeared where whatyou saw on screen was an accurate reflection of how itwould appear when printed what you see (on screen)is what you get (on paper)

The huge advantage of WYSIWYG is that itrsquos reallyeasy to understand whatrsquos going on and most peoplecan create reasonably nicely formatted documents withrelatively little effort For short informal documentsone-off letters memos and such WYSIWYG works quitenicely But if yoursquove ever tried writing anything muchlonger or that includes images and tables you mayhave already started to see where the paradigm breaksdown For example if you write lsquoFigure 38 on page

49

COMP10120 Report writing and Digital Typography

Figure 36A screenshot of Wordperfect 51 running in Microsoft DOScirca 1989

51 shows a picture of some men looking at cheesersquo butthen later on edit your document to include some moretext at the start and a new picture of a some broccoli(as in Figure 39) yoursquod have to search through yourreport to find all mentions of lsquoFigure 38rsquo and lsquopage 51rsquoand manually update them to reflect the new number-ing This might be fine if you have two figures and fivepages but for a hundred-page report containing lots ofpictures you can see how this becomes tedious and er-ror prone very quickly

50

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 11: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

that you will have seen happen so often in profession-ally typeset materials that yoursquoll have taken it for grantedand you may not have spotted that it doesnrsquot happenin quite the same way when you use a wordproces-sor The principle behind justifying text seems easyenough at first glance you simply have to take any lsquoleftoverrsquo space that would be at the end of a line and re-distribute it between the words in some way to lsquospacethem outrsquo a bit more so that they take up all the avail-able horizontal room But it turns out to be much harderthan it seems and all the simple ways you might thinkof for doing this on a per-line basis give results thatare visually quite unsatisfactory with nasty patternsmade up of neighbouring whitespace appearing in thelayout and ruining everything The added complica-tion here is that to do the optimum job of shuffling thewords round on their lines you really need the flex-ibility of being able to hyphenate words to give youextra space on lines that would otherwise be tightlypacked with characters But if you hyphenate wordsbadly by breaking them in inappropriate places or doit too often then that makes the text hard to read tooItrsquos all deeply inconvenient and inter-related The bestsolution to this aesthetic conundrum so far was devel-oped by Knuth and Plass 1981 and later improved byFrank Liang during his PhD research (F M Liang1983) and itrsquos a technique that tries to optimise the lay-

18

COMP10120 Report writing and Digital Typography

out of whole paragraphs rather than individual linesThe algorithm takes into account all manner of differ-ent things language-specific character patterns the num-ber of consecutive lines that end with hyphens the wordlsquotightnessrsquo on each line and many others The detailsdonrsquot really matter here but the really important in-sight is that you get better results by working on a big-ger chunk of the document (in this case a paragraph at atime) rather than trying to independently optimise lotsof small bits (say lines) and hoping that the result ofjoining them all together turns out nicely This idea ofoptimising things globally versus locally is somethingyoursquoll see many times throughout your Computer Sci-ence degree watch out for it in all the algorithms courses

This highlights a fundamental difference betweenthe WYSIWYG paradigm and the way that documentsare produced using LATEX As wersquove seen small changesdown at the level of individual characters can have fairlylarge knock-on consequences for the optimal layout ofa document changing one letter for another affects thelength of a line which in turn affects the hyphenationoptions which then affects the length of a paragraphwhich means that the best place for a figure that was onpage 99 might now be on page 100 but that means thatall references to lsquopage 99rsquo now need a bit more room toaccount for the extra digit which means that the someline lengths have changed which means well you get

19

COMP10120 Report writing and Digital Typography

the idea Itrsquos more complicated than it first seems LATEXgets to see the whole of your document at once and cantherefore make decisions about how best to hyphen-ate lines position figures or whatever else it likes beforeit shows you the results so it can make solutions thatare optimal for the whole document as well as lookingat details such as ligated characters Wordprocessorscanrsquot afford to do this since it would be deeply distract-ing if every time you typed a character the whole lay-out of the document flapped around in front of youreyes Wordprocessors can only sensibly make little op-timisations at a local (probably per-line level) Itrsquos notthat wordprocessors are rubbish or that the people thatprogrammed them were lazy itrsquos a fundamentally dif-ferent way of working and knowing the pros and consof the different approaches will help you pick the righttool for the job

You may have noticed that actual text in your doc-ument (and in fact this one) takes up a (perhaps) sur-prisingly narrow horizontal region of the page Thislast lsquofeaturersquo might seem odd at first but it illustratesanother important typographical point that you maynever have thought of before reading long lines of textis hard because your eyes find it hard to move in acompletely straight line as they scan from left to rightSo the longer the line of words the more you have towork to keep your eyes from accidentally drifting up or

20

COMP10120 Report writing and Digital Typography

down onto a neighbouring line (perhaps yoursquove expe-rienced the phenomenon of accidentally re-reading thesame line over and over as your eyes get tired) It maynever have occurred to you but most books have rela-tively short lines of text and those that use large pagesoften split text into several columns so that individuallines are kept relatively short The widely trusted booklsquoThe Elements of Typographic Stylersquo (R Bringhurst1992) makes the following assertion

lsquoAnything from 45 to 75 characters is widely-regarded as a satisfactory length of line for a single-column page set in a serifed text face in a text sizeThe 66-character line (counting both letters andspaces) is widely regarded as idealrsquo

LATEX knows about this issue so made a sensible de-fault decision for you You may have noticed that thereis a subtle difference in appearance of this chapter fromprevious ones the lines are shorter and paragraphs areindented We wanted to use the default LATEX layoutfor this chapter but changed it for earlier chapters inan effort to save paper

Therersquos one last unusual thing to note your para-graph of gibberish text in between the real words fromBleak House and the Lorem Ipsum almost certainly standsout and looks really quite odd (it might even have con-fused LATEXrsquos hyphenation rules enough to have ended

21

COMP10120 Report writing and Digital Typography

up with one or more lines sticking out proud of theright hand margin) Let your eyes relax so that yourvision blurs for a moment you can still probably spotthat the gibberish paragraph looks out of place Itrsquosquite likely that you even found creating the gibber-ish unexpectedly hard The interesting thing here isthat as humans we spend so much time reading andwriting lsquoproperrsquo natural language that we become at-tuned to the patterns of letters words and the underly-ing lsquorhythmrsquo of our written language that its very hardto artificially reproduce something that looks plausiblethe frequency of the letters you chose by randomly hit-ting keys and the length and patterns of the words youput in place most likely donrsquot match the natural pat-terns of real languages so they just look plain wrongCuriously the Lorem Ipsum text that you got from thewebsite probably doesnrsquot look so bad in spite of it notbeing made up of real words But thatrsquos not surprisingsince Lorem Ipsum is specifically created to be used asa placeholder for real text when typesetting While thewords are meaningless Latin-like things their lengthand the distribution of characters and word lengths arechosen to mimic patterns in real language

Next letrsquos give our document some structure by di-viding it up into sections On the line before BleakHouse starts add the command

22

COMP10120 Report writing and Digital Typography

sectionBleak House

making sure it appears on a line of its own Then justbefore your paragraph of gibberish put a similar in-struction (again on its own line) and then create a finalsection before the Lorem Ipsum Rerun pdflatex andlook at the results You should see the section headingsappear in the appropriate places in the PDF automati-cally having been given section numbers Experimentby adding in a couple of sub-sections towards the endof the document using the subsection commandwhich like the section command above takes as aparameter some text contained in curly brackets

Now at the top of your document after the begindocumentline and before the command defining the first sectionadd the following two commands each on their ownline

tableofcontentsnewpage

Re-run pdflatex twice and check that the effect is whatyoursquod expect You need to process the source twice be-cause on the first run LATEX gathers and stores informa-tion about what to put in the table of contents and onlycreates it on the second run

23

COMP10120 Report writing and Digital Typography

33 Common formatting features

Before we give you some more exercises to do here is abrief introduction to some commonly used features ofLATEX

331 Enumerated and bulleted lists

Creating bulleted or numbered lists in LATEX is straight-forward and is done like this

beginenumerateitem My first itemitem My second itemitem The last thing on my listendenumerate

You must make sure that you both begin and end yourlist and that each item is terminated by a newline Chang-ing enumerate to itemize gives you a bulleted ratherthan numbered list (note the American spelling of lsquoitem-izersquo)

332 Changing the appearance of text

Text can be typeset in bold font using the textbfin italics using textitand in a fixed-width fontusing texttt as in the example below

24

COMP10120 Report writing and Digital Typography

Some textttsay the textbfworld will end in textitfire

which is typeset as

Some say the world will end in fire

333 Cross referencing

LATEX allows you to cross-reference almost anything inthe document which includes sections sub-sections andfigures To use the cross-referencing feature you simplyinsert the command

labelmymarker

at the point in the document you want to refer to andthen use the command

refmymarker

when you want to use the reference Obviously youreplace the text mymarkerwith something more mean-ingful An important tip here is to call the marker some-thing that refers to the content of that part of the doc-ument and to avoid the temptation to use numbers(so donrsquot call your marker section1 instead call itintroduction if you reorder your document itrsquos stilllikely to be the introduction but it may no longer beSection 1) For example

25

COMP10120 Report writing and Digital Typography

sectionReflection on Welcome WeeklabelwelcomeweekI spent most of welcome week getting to know my wayaround campus I should have made more effort to joinsocieties I think I must remember to get to theStudentsrsquo Union and take a look around there

subsectionThings I enjoyedEverything so far has been wonderful with the caveat Imentioned in Section refwelcomeweek

subsectionThings I didnrsquot enjoyIrsquove discovered that I donrsquot like soggy chips

The really useful thing about cross-referencing in LATEXis that yoursquoll get warnings when you compile your doc-ument if cross-references are undefined or used incor-rectly This means you donrsquot have to manually checkevery reference in your document to make sure itrsquos stillright You do however have to run LATEX twice forsimilar reasons to those given above

334 Figures and pictures

Including figures and pictures in your document is easyYou do it like this

beginfigure

26

COMP10120 Report writing and Digital Typography

Figure 33Some men possibly Dutch looking at cheeses

centerlineincludegraphics[width=10cm]imagesmen-and-cheesejpgcaptionSome men possibly Dutch looking at cheeseslabelfiguremenandcheesesendfigure

which is the code we used to create Figure 38 You canprobably see whatrsquos happening The command includegraphicsgets your image which can be PDF PNG JPG GIF orPostScript The beginfigureendfigurecode lsquowrapsrsquo up whatever picture yoursquore including andallows LATEX to treat it as an unbreakable floating thingthat it will position for you as best it can in the docu-ment while maintaining an overall nice typographicallayout This floating of figures can sometimes result inthe figure ending up in a place you didnrsquot expect but inmost cases LATEX will make the most sensible choice Itrsquos

27

COMP10120 Report writing and Digital Typography

possible to employ finer control over figure placementbut thatrsquos beyond the scope of this introduction

The includegraphics command is not built into core LATEX but is in an additional package whichneeds to be explicitly loaded We load this package byusing the command usepackagegraphicx in thedocument preamble ie after the documentclasscommand but before begindocument There arehundreds of such packages that extend LATEXrsquos func-tionality the lab scripts you are reading now use over30 of them

Exercise 3 Including images

Create a document imagetex that contains some text(maybe from rsquoLorem Ipsumrsquo) together with a figurecontaining an image of your choice perhaps the oneyou made in Intro Lab 2 like Steversquos Mr Noodle Thereshould also be a reference to the figure in the text Youshould first use the program convert

convert

(check its manpage) to create a PDF version of the image

Exercise 4 A reflection on your studies

Your first proper LATEX document will be a very briefreflection on your studies so far

Write a hand-crafted LATEX document called courses-reflectiontex

28

COMP10120 Report writing and Digital Typography

(exact name as usual please otherwise submitwill notwork) It will have the following structure

1 A table of contents

2 A brief paragraph saying what the document isabout

3 A section appropriately titled for one of your courseunits containing

bull a brief paragraph saying what the unit is about

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the most about the unit

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the least about the unit

A repeat of item 3 for each other unit you are study-ing These sections should appear in alphabeticalorder by course code (eg COMP10120)

After completing and successfully compiling and view-ing your document you should spell-check it as fol-lows

ispell courses-reflectiontex

29

COMP10120 Report writing and Digital Typography

Once you are completely satisfied with it produce ahard copy ready for marking

34 Typesetting Mathematics

Earlier we saw this formula

x =minusbplusmn

radicb2 minus 4ac

2aIt looks nice doesnrsquot it To tell LATEX to display thisyou have to type a bit of magic but itrsquos easily-learnedmagic To create such a formula in a WYSIWYG edi-tor there is also magic involved but it usually involvesa lot of mouse-clicking and remembering special keycombinations like rsquocontrol-thisrsquo and rsquoalt-thatrsquo In LATEXit doesnrsquot You simply type this

[ x = frac-b pm sqrtb^2-4ac2a ]

You can probably work out how most of this createsthe formula but it wonrsquot be obvious that the [ and ]symbols that enclose the formula mean lsquotypeset this asa displayed formula giving it some vertical space fromthe surrounding textrsquo If wersquod used ( and ) insteadto enclose the formula it would appear in-line like thisx = minusbplusmn

radicb2minus4ac2a It still looks very nice and observe

how itrsquos automatically been resized to fit and that the

30

COMP10120 Report writing and Digital Typography

lines of text have had their spacing changed a bit Thisall looks simple but the implementation inside LATEXand TEX is complex It involves parsing the descrip-tion of the formula to create a corresponding tree datastructure which is then recursively walked to workout the horizontal and vertical typographical spacingsneeded Yoursquoll meet these ideas in COMP11120 andCOMP26120 Algorithms and Imperative Programming

Herersquos another example taken from COMP27112Computer Graphics (itrsquos a lsquosimplersquo local illuminationmodel incorporating ambient diffuse and specular re-flection by multiple lights)

I = kaIa +

Msumi=1

Ipidprimei[kd(N middot Li) + ks(Ri middot V )n]

We write this in LATEX as follows

[ I = k_a I_a + sum_i=1^M fracI_p_idrsquo_i [ k_d(hatN cdot hatL_i)+ k_s(hatR_i cdot hatV)^n] ]

Try to match the LATEX commands with the formula dis-played above Yoursquoll see lots of curly brackets and thisexample illustrates their two uses in LATEX The firstis to provide an argument to a command for exam-ple hatN means lsquoapply the hat command to N rsquowhich creates N the vector N with a little hat on

31

COMP10120 Report writing and Digital Typography

The second use of curly brackets is to group thingstogether to avoid ambiguities In the example you cansee sum_i=1^M which creates a summation signand its lower and upper limits

sumMi=1 We wrap the

lower bound i=1 in curly brackets to group it into anindivisible unit If we were to omit the brackets writ-ing sum_i=1^M LATEX would then produce

sumi = 1M

which is not at all what we want (even LATEX canrsquot al-ways know what we really want)

One final example If we tell LATEX

[ T_1 = left[beginarraycccccos theta amp -sin theta amp 0 amp delta sin theta amp cos theta amp 0 amp epsilon 0 amp 0 amp 1 amp eta alpha amp beta amp gamma amp 1endarrayright] ]

wersquoll get a splendid matrix which expresses a particu-lar 3D geometrical transformation (Donrsquot worry if youdonrsquot recognise this yoursquoll be introduced to matrix no-tation in the latter part of COMP11120 MathematicalTechniques for Computer Science For now you can justtreat it as some mysterious maths)

32

COMP10120 Report writing and Digital Typography

T1 =

cos θ minus sin θ 0 δ

sin θ cos θ 0 ε

0 0 1 η

α β γ 1

In the LATEX code left[means lsquobig opening square

bracket pleasersquo ccccmeans lsquoan array with 4 columnsplease with the items in each column centredrsquo ampmeanslsquostart a new columnrsquo and means lsquostart a new rowrsquoYoursquoll notice that LATEX knows about greek letters itknows about most standard maths symbols too andalso the ways theyrsquore usually used

There are some symbols that you might need (forexample therefore which produces the usual threedots symbol there4) that are not part of standard LATEX Manysuch symbols are provided by the amssymb package ofsymbols compiled by the American Mathematical Soci-ety Details of the many symbols provided by this pack-age can be found online at

mirrormathkuedutex-archivefontsamsfontsdocamssymbpdf

To use these extra symbols you need to have usepackageamssymbin the document preamble

33

COMP10120 Report writing and Digital Typography

341 A longer piece of mathematics

We conclude this section with an example of a longerpiece of mathematics that shows how you might type-set a complete mathematical argument rather than asingle formula The example is Euclidrsquos proof of thefact that

radic2 is irrational Itrsquos an argument that has been

covered in COMP11120 and is an example of proof bycontradiction It starts by making the assumption thatit is not the case that

radic2 is irrational in other words that

we can find integers p and q withradic2 = pq

We can assume without losing anything that p andq have no common factors (Why)

radic2 = pq

qradic2 = p

2q2 = p2

This means that p2 is even from which we can also de-duce that p is even (Why)

This means that p = 2k for some k so

2q2 = (2k)2

there4 2q2 = 4k2

so q2 = 2k2

But this means that q2 and hence q is even Since p andq are both even we have a contradiction to our initialassumption so no such p and q exist

The way this is formatted is shown here

34

COMP10120 Report writing and Digital Typography

It starts by making the assumption that it is emphnot the casethat $sqrt2$ is irrational in other words that we can findintegers $p$ and $q$ with $sqrt2 = pq$

We can assume without losing anything that $p$ and $q$ haveemphno common factors (Why)

[beginarraylcl

sqrt2 amp = amp pq qsqrt2 amp = amp p 2q^2 amp = amp p^2

endarray]

This means that $p^2$ is even from which we can also deduce that $p$is even (Why)

This means that $p = 2k$ for some $k$ so ldots[beginarrayllcl

amp 2q^2 amp = amp (2k)^2 therefore amp 2q^2 amp = amp 4k^2 textso amp q^2 amp = amp 2k^2

endarray]

But this means that $q^2$ and hence $q$ is even Since $p$ and $q$are both even we have a contradiction to our initial assumptionso no such $p$ and $q$ exist

Notice the use of the array environment for gettingthings lined up You can find much more informationabout this on the web

LATEX really shines at typesetting mathematics and

35

COMP10120 Report writing and Digital Typography

it would take pages and pages to describe all the fea-tures Have a look at

enwikibooksorgwikiLaTeXMathematics

for a flavour

Exercise 5 Formatting mathematics

Now for an exercise that involves some mathematicsPlease create a file f-wtex which typesets the follow-ing piece of text and mathematics

There are many positive integer solutions tothe equation

x2 + y2 = z2

which can be rewritten as

z =radicx2 + y2

For example (3 4 5) or (5 12 13) Such solu-tions are called Pythagorean triples

However for higher powers the situation isvery different and we have-

Theorem Fermat-WilesFor all natural numbers n ge 3 there are no

36

COMP10120 Report writing and Digital Typography

integers x y z satisfying the equation

xn + yn = zn

35 Curriculum vitaie

There are several scenarios where using LATEX ratherthan other word processing software can be useful

bull typesetting mathematics yoursquove just read about

bull writing a technical document

bull your final year project peport

bull writing an article you want to get published

bull writing a Curriculum vitae CV

Wersquoll now look at CVrsquos briefly

Exercise 6 Curriculum vitae

Creating a professional document is especially impor-tant when you write your CV because how your CVlooks (not just the content) will determine if you are in-vited to interview for job you are applying for Thatcould be a summer internship next year a year long

37

COMP10120 Report writing and Digital Typography

placement after your second year or graduate positionafter you leave University

As well using a text-editor and compiling files fromthe command line other tools are available for editingLATEXWe will look at one of these overleafcom

Create a basic CV which describes you your edu-cation (including University) and any experience youhave or interesting projects that you may have doneYou can do this using httpsoverleafcom andchoosing the ready-made templates at httpswwwoverleafcomgallerytaggedcv

As you progress through University it is a good ideato keep your CV up to date and get feedback from asmany people as you can There will be opportunities todebug your CV later (See httpgitiomycv if youare interested) but yoursquoll need a ldquobeta releaserdquo (version10) of your CV to get started The best time to start thisprocess is now

36 Some optional extras

Exercise 7 Exploring more LATEX features (op-tional but easy)

This exercise reinforces some of the things yoursquove donealready but also introduces some features of LATEX that

38

COMP10120 Report writing and Digital Typography

will be new to you It is labelled as optional because itisnrsquot marked but we would recommend that you all tryit

Take a copy of the file optinfocoursesCOMP10120ex3latex-introtexand follow the instructions it contains You should readit before you process it with LATEX

Exercise 8 A neat directory listing (optionalmore challenging)

The fact that LATEX source files are just text makes it easyto have them generated by a program You are going toexploit this and use LATEX to produce a neat documentcontaining a listing of the files in any directory

Find how to create tables in LATEX tables using thetabular environment Make a LATEX document by handthat uses a table to neatly show the information aboutthe files in some (small) directory (as produced by ls

-l) Write a shell script called neat-ls that takes anargument which is the path name of a directory andproduces a LATEX document containing the above tablefor the given directory The script could also process theLATEX and display the resulting pdf file Finally find outabout the longtable package and change your script touse that instead

39

COMP10120 Report writing and Digital Typography

Exercise 9 A cleaning rota (optional evenmore challenging)

Now you will write a shell script called make-rota thatgenerates a house cleaning rota (Very handy for nextyear ) This is a table with columns such as KitchenBathroom and Lounge The rows will be weeks in theyear labelled with a date (eg always a Sunday) Theidea is that house mates can write their initials in theboxes promising to clean the corresponding room inthat particular week Start by making a sample tableby hand

Your script should take a single argument which isthe date of the first day of the first row eg102013(the US format for 20 Oct 13) The result will be a docu-ment that contains as many rows as fit on a single page(find out by experimenting)

The dates of each row should be generated from thefirst See the manual page for date to figure out howyou can generate a date that is a number of weeks anddays later than an existing one

361 Marking Scheme

You can view a copy of the marking scheme used bysubmit and labprint at

40

COMP10120 Report writing and Digital Typography

studentnetcsmanchesteracukugtlpmsphpunit=COMP10120ampex=ex3xml

37 Next steps

LATEX is a very powerful tool and it does take a littlegetting used to But itrsquos not as scary as it might initiallyseem and you should find that it doesnrsquot take long tolearn the common commands and techniques to makeyour documents well-structured and readable As youbecome more comfortable with the basics and under-stand the principles of typesetting finding out how todo more complex and sophisticated things is easymdashthere are hundreds of tutorials on the web

Donrsquot get carried away though and use the featuresjudiciously just because yoursquove found a cool new com-mand doesnrsquot mean that you should use it just to showoff your LATEX skills content and structure always trumpstypographic twiddlings4

4For example footnotes like this are for some reason a really tempting fea-ture to use in LATEX and in this document we have abused them mercilessly toillustrate a point Footnotes were originally a means for mechanical typeset-ters to insert comments corrections or additions to existing documents withouthaving to adjust the layout of a whole page and of course in digital typographythis is no longer necessary They can justifiably be used for citations (though itrsquosnot common to do so these days) and URLs if you donrsquot want these intrudinginto the body of your text And in some very very rare cases they can be usedas an aside to the main flow of the text (which is what has been done in this doc-ument) But this should be used sparingly If something is important to sayput it in the main body of your text If itrsquos not then perhaps you should thinkabout leaving it out completely or find some other way of including it Asking

41

COMP10120 Report writing and Digital Typography

371 Acknowledgements

Figure 38 is from the Wikipedia article on cheese

372 License

The text of this exercise is licensed under the terms ofthe Creative Commons Attribution 20 Generic (CC BY30) License

38 Background

What follows is additional contextual information aroundLATEX

LATEX was originally written by Leslie LamportW anAmerican computer scientist now working at MicrosoftResearch although its development has long been takenover by a world-wide LATEX community Itrsquos actuallybuilt on top of another system called TEX a computertypesetting system designed by one of the worldrsquos mostinfluential Computer Scientists Donald KnuthW of Stan-ford University Knuth has said that he designed TEX

the reader to look down at the bottom of a page to find out whether somethingis important or not is irritating and as yoursquove probably found out already oftenmeans you lose track of your reading position They also give the impressionthat the author isnrsquot clear about whether something is important or not whichis never good And long footnotes like this onemdashwhile LATEX will typeset themperfectly wellmdashare just plain silly Best avoid

42

COMP10120 Report writing and Digital Typography

for lsquothe creation of beautiful booksmdashand especially forbooks that contain a lot of mathematicsrsquo(D Knuth1984) Figure 34 shows what these eminent men looklike

So whatrsquos the purpose of LATEX Itrsquos purely a layerof software to make TEX easier to use in everyday sit-uations This is a good idea because although TEX isamazingly powerful it operates at a very low-level whichmakes it hard for non-expert users

Figure 34Don Knuth and Leslie Lamport

381 Pronunciation

The name TEX is intended by its creator to be pronouncedwith the final consonant as in the word loch or the nameBach but English speakers often pronounce it like thefirst syllable of technical The first syllable of LATEX is

43

COMP10120 Report writing and Digital Typography

pronounced as in rsquolayrsquo5

382 Why LATEX

Before we go any further why do we think LATEX is im-portant for youmdasha Computer Science studentmdashto knowabout Here are some reasons in no particular order

bull LATEX and TEX are superb examples of ComputerScience in action TEX was designed by Knuth fromfirst principlesmdashin other words from scratch TEXis actually a programming language and LATEX isa set of functions defined in the TEX language TheTEX lsquocompilerrsquo is written in WEBW a mixture ofdocumentation written in TeX and a PascalW sub-set in order to ensure portability it reads a TEXprogram and outputs documents TEX is completelyself-contained and designed to be portable to anycomputer architecture For example it implementsits own stackW and heapW (with garbage collectionW)and it does fixed-precision arithmeticW donrsquot worryif these terms donrsquot make much sense to you at themoment they soon will

5The Greek prefix lsquotexrsquo means lsquoartrsquo as well as lsquotechnologyrsquo so itrsquos a very nicelychosen name for a piece of software that produces such beautiful output Knuthexplained (D Knuth 1984) that one should lsquopronounce the X of TeX as a Greekchi not as an lsquoxrsquo so that TeX rhymes with the word blecchhhrsquo Wersquore not toosure that helps much unless you are confident in your pronunciation of theword lsquoblecchhrsquo Maybe itrsquos an American thing

44

COMP10120 Report writing and Digital Typography

bull LATEX is a new interesting way for you to thinkabout preparing documents

bull LATEX has a practical advantage for the writer inthat it helps you think more about what you wantto write rather than worrying about how it looks

bull LATEX is a powerful tool for professional scientificdocumentation and as a Computer Scientist youshould know about it

bull LATEX files are just plain text so can easily be cre-ated programatically For example the slides usedfor COMP16120 are generated automatically fromthe source of Johnrsquos book both are typeset usingLATEX The program labprint also produces itsoutput using LATEX using information drawn fromXMLW configuration files and ARCADE

bull Using LATEX is actually quite satisfying and thequality of its output may surprise you

In this lab session you are going to write severalshort documents using LATEX You could also write briefnotes in your logbook about how LATEX works and whatcommands you used inside the source of your docu-ments

45

COMP10120 Report writing and Digital Typography

383 Some history printing mathematics

Mathematics is hard to print on paper and on the Web(many websites resort to GIF or JPG images of mathsformulae which usually look horrible MathMLW pro-vides another approach but it is not yet widely used)

In the days before computers books and newspa-pers were printed with movable typeW made from lotsof little blocks of metal each with letters numbers andsymbols standing in relief which when inked left animpression on the paper (see Figure 35) The job ofthe printer (the printer here of course being a personnot a bit of electronics) was to gather together all theblocks in the right order between two horizontal stripsof wood to create a line of the document and then toassemble all those lines from top to bottom of a pageThus the term type settingW an incredible task whenyou think about it In the printerrsquos workshop by theway the blocks of metal were stored between jobs inwooden boxes called cases Letters like a b and c werestored in one case letters like A B and C were storedin a case sitting on top of that So a lower case and anupper case These terms may ring a bell

As technology progressed machines controlled bytypewriters would mechanically juggle the blocks intothe right order This conceptual model is the basis onwhich TEX operates Only now the metal blocks are

46

COMP10120 Report writing and Digital Typography

Figure 35On the left a piece of cast movable type in the Garamondfont On the right a case of cast metal type pieces andtypeset matter in a composing stick The text reads lsquoThequick brown fox jumps over the lazy dog and feels as if hewere in the seventh heaven of typography together with Her-mann Zapf the most famous artist of thersquo This document istypeset in a font called Palatino created by Hermann ZapfYou may have also seen rsquoZapf Dingbatsrsquo in the font lists ofvarious desktop applications Now you know why

little pieces of data arranged into data structuresThe one thing that traditional printers hated was

dealing with the typesetting of mathematics and theywould charge extra to do it It was incredibly fiddly toget the equations looking right they had to squeeze inextra bits of metal horizontally and vertically

When computers entered the printing world attemptsto print mathematics were limited by the printing tech-nology available It took a long time to reach the pointwhere computers could typeset mathematics beautifullyand that was the outstanding achievement of Knuthrsquos

47

COMP10120 Report writing and Digital Typography

TEXLetrsquos look at a quick example of the quality you get

from LATEX with a very simple formula that yoursquoll recog-nise

x =minusbplusmn

radicb2 minus 4ac

2aWersquoll revisit how LATEX typesets mathematics in Section 34

384 To WYSIWYG or not to WYSIWYG

Up until now you have probably used wordprocessingapplications such as Microsoft Word to create essaysletters and other (probably fairly short) documents Youmost likely know that the majority of modern wordprocessors use a paradigm called WYSIWYG or WhatYou See Is What You Get which means that you canmodify the visual style of the document yoursquore work-ing on by selecting the relevant bits and then choos-ing different attributes such as font size or colour usinga GUI In many ways this seems like such a sensibleand obvious way of doing things that you might bewondering why it even has a special name The rea-son is a historical one in the early days of comput-ing long before graphical window managers becamethe norm and when all you could display on screenwas fixed-width ASCII text in whatever the systemrsquos

48

COMP10120 Report writing and Digital Typography

default font was wordprocessors (eg Figure 36) onlyallowed you to format documents by using special se-quences of characters to cause particular effects Butthese effects were only visible when the document wasprinted So if you wanted a word to appear in boldtext in the wordprocessor you might write somethinglike [bold]hello world[bold] what you saw onscreen was not a direct reflection of what appeared onthe printed page If yoursquove written any HTML how-ever this process of marking up text may be familiarsee for example Figure 37 As computers moved todisplays able to draw things other than raw charac-ters on screen wordprocessors became capable of us-ing multiple fonts and styles as well as graphics anda new generation of applications appeared where whatyou saw on screen was an accurate reflection of how itwould appear when printed what you see (on screen)is what you get (on paper)

The huge advantage of WYSIWYG is that itrsquos reallyeasy to understand whatrsquos going on and most peoplecan create reasonably nicely formatted documents withrelatively little effort For short informal documentsone-off letters memos and such WYSIWYG works quitenicely But if yoursquove ever tried writing anything muchlonger or that includes images and tables you mayhave already started to see where the paradigm breaksdown For example if you write lsquoFigure 38 on page

49

COMP10120 Report writing and Digital Typography

Figure 36A screenshot of Wordperfect 51 running in Microsoft DOScirca 1989

51 shows a picture of some men looking at cheesersquo butthen later on edit your document to include some moretext at the start and a new picture of a some broccoli(as in Figure 39) yoursquod have to search through yourreport to find all mentions of lsquoFigure 38rsquo and lsquopage 51rsquoand manually update them to reflect the new number-ing This might be fine if you have two figures and fivepages but for a hundred-page report containing lots ofpictures you can see how this becomes tedious and er-ror prone very quickly

50

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 12: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

out of whole paragraphs rather than individual linesThe algorithm takes into account all manner of differ-ent things language-specific character patterns the num-ber of consecutive lines that end with hyphens the wordlsquotightnessrsquo on each line and many others The detailsdonrsquot really matter here but the really important in-sight is that you get better results by working on a big-ger chunk of the document (in this case a paragraph at atime) rather than trying to independently optimise lotsof small bits (say lines) and hoping that the result ofjoining them all together turns out nicely This idea ofoptimising things globally versus locally is somethingyoursquoll see many times throughout your Computer Sci-ence degree watch out for it in all the algorithms courses

This highlights a fundamental difference betweenthe WYSIWYG paradigm and the way that documentsare produced using LATEX As wersquove seen small changesdown at the level of individual characters can have fairlylarge knock-on consequences for the optimal layout ofa document changing one letter for another affects thelength of a line which in turn affects the hyphenationoptions which then affects the length of a paragraphwhich means that the best place for a figure that was onpage 99 might now be on page 100 but that means thatall references to lsquopage 99rsquo now need a bit more room toaccount for the extra digit which means that the someline lengths have changed which means well you get

19

COMP10120 Report writing and Digital Typography

the idea Itrsquos more complicated than it first seems LATEXgets to see the whole of your document at once and cantherefore make decisions about how best to hyphen-ate lines position figures or whatever else it likes beforeit shows you the results so it can make solutions thatare optimal for the whole document as well as lookingat details such as ligated characters Wordprocessorscanrsquot afford to do this since it would be deeply distract-ing if every time you typed a character the whole lay-out of the document flapped around in front of youreyes Wordprocessors can only sensibly make little op-timisations at a local (probably per-line level) Itrsquos notthat wordprocessors are rubbish or that the people thatprogrammed them were lazy itrsquos a fundamentally dif-ferent way of working and knowing the pros and consof the different approaches will help you pick the righttool for the job

You may have noticed that actual text in your doc-ument (and in fact this one) takes up a (perhaps) sur-prisingly narrow horizontal region of the page Thislast lsquofeaturersquo might seem odd at first but it illustratesanother important typographical point that you maynever have thought of before reading long lines of textis hard because your eyes find it hard to move in acompletely straight line as they scan from left to rightSo the longer the line of words the more you have towork to keep your eyes from accidentally drifting up or

20

COMP10120 Report writing and Digital Typography

down onto a neighbouring line (perhaps yoursquove expe-rienced the phenomenon of accidentally re-reading thesame line over and over as your eyes get tired) It maynever have occurred to you but most books have rela-tively short lines of text and those that use large pagesoften split text into several columns so that individuallines are kept relatively short The widely trusted booklsquoThe Elements of Typographic Stylersquo (R Bringhurst1992) makes the following assertion

lsquoAnything from 45 to 75 characters is widely-regarded as a satisfactory length of line for a single-column page set in a serifed text face in a text sizeThe 66-character line (counting both letters andspaces) is widely regarded as idealrsquo

LATEX knows about this issue so made a sensible de-fault decision for you You may have noticed that thereis a subtle difference in appearance of this chapter fromprevious ones the lines are shorter and paragraphs areindented We wanted to use the default LATEX layoutfor this chapter but changed it for earlier chapters inan effort to save paper

Therersquos one last unusual thing to note your para-graph of gibberish text in between the real words fromBleak House and the Lorem Ipsum almost certainly standsout and looks really quite odd (it might even have con-fused LATEXrsquos hyphenation rules enough to have ended

21

COMP10120 Report writing and Digital Typography

up with one or more lines sticking out proud of theright hand margin) Let your eyes relax so that yourvision blurs for a moment you can still probably spotthat the gibberish paragraph looks out of place Itrsquosquite likely that you even found creating the gibber-ish unexpectedly hard The interesting thing here isthat as humans we spend so much time reading andwriting lsquoproperrsquo natural language that we become at-tuned to the patterns of letters words and the underly-ing lsquorhythmrsquo of our written language that its very hardto artificially reproduce something that looks plausiblethe frequency of the letters you chose by randomly hit-ting keys and the length and patterns of the words youput in place most likely donrsquot match the natural pat-terns of real languages so they just look plain wrongCuriously the Lorem Ipsum text that you got from thewebsite probably doesnrsquot look so bad in spite of it notbeing made up of real words But thatrsquos not surprisingsince Lorem Ipsum is specifically created to be used asa placeholder for real text when typesetting While thewords are meaningless Latin-like things their lengthand the distribution of characters and word lengths arechosen to mimic patterns in real language

Next letrsquos give our document some structure by di-viding it up into sections On the line before BleakHouse starts add the command

22

COMP10120 Report writing and Digital Typography

sectionBleak House

making sure it appears on a line of its own Then justbefore your paragraph of gibberish put a similar in-struction (again on its own line) and then create a finalsection before the Lorem Ipsum Rerun pdflatex andlook at the results You should see the section headingsappear in the appropriate places in the PDF automati-cally having been given section numbers Experimentby adding in a couple of sub-sections towards the endof the document using the subsection commandwhich like the section command above takes as aparameter some text contained in curly brackets

Now at the top of your document after the begindocumentline and before the command defining the first sectionadd the following two commands each on their ownline

tableofcontentsnewpage

Re-run pdflatex twice and check that the effect is whatyoursquod expect You need to process the source twice be-cause on the first run LATEX gathers and stores informa-tion about what to put in the table of contents and onlycreates it on the second run

23

COMP10120 Report writing and Digital Typography

33 Common formatting features

Before we give you some more exercises to do here is abrief introduction to some commonly used features ofLATEX

331 Enumerated and bulleted lists

Creating bulleted or numbered lists in LATEX is straight-forward and is done like this

beginenumerateitem My first itemitem My second itemitem The last thing on my listendenumerate

You must make sure that you both begin and end yourlist and that each item is terminated by a newline Chang-ing enumerate to itemize gives you a bulleted ratherthan numbered list (note the American spelling of lsquoitem-izersquo)

332 Changing the appearance of text

Text can be typeset in bold font using the textbfin italics using textitand in a fixed-width fontusing texttt as in the example below

24

COMP10120 Report writing and Digital Typography

Some textttsay the textbfworld will end in textitfire

which is typeset as

Some say the world will end in fire

333 Cross referencing

LATEX allows you to cross-reference almost anything inthe document which includes sections sub-sections andfigures To use the cross-referencing feature you simplyinsert the command

labelmymarker

at the point in the document you want to refer to andthen use the command

refmymarker

when you want to use the reference Obviously youreplace the text mymarkerwith something more mean-ingful An important tip here is to call the marker some-thing that refers to the content of that part of the doc-ument and to avoid the temptation to use numbers(so donrsquot call your marker section1 instead call itintroduction if you reorder your document itrsquos stilllikely to be the introduction but it may no longer beSection 1) For example

25

COMP10120 Report writing and Digital Typography

sectionReflection on Welcome WeeklabelwelcomeweekI spent most of welcome week getting to know my wayaround campus I should have made more effort to joinsocieties I think I must remember to get to theStudentsrsquo Union and take a look around there

subsectionThings I enjoyedEverything so far has been wonderful with the caveat Imentioned in Section refwelcomeweek

subsectionThings I didnrsquot enjoyIrsquove discovered that I donrsquot like soggy chips

The really useful thing about cross-referencing in LATEXis that yoursquoll get warnings when you compile your doc-ument if cross-references are undefined or used incor-rectly This means you donrsquot have to manually checkevery reference in your document to make sure itrsquos stillright You do however have to run LATEX twice forsimilar reasons to those given above

334 Figures and pictures

Including figures and pictures in your document is easyYou do it like this

beginfigure

26

COMP10120 Report writing and Digital Typography

Figure 33Some men possibly Dutch looking at cheeses

centerlineincludegraphics[width=10cm]imagesmen-and-cheesejpgcaptionSome men possibly Dutch looking at cheeseslabelfiguremenandcheesesendfigure

which is the code we used to create Figure 38 You canprobably see whatrsquos happening The command includegraphicsgets your image which can be PDF PNG JPG GIF orPostScript The beginfigureendfigurecode lsquowrapsrsquo up whatever picture yoursquore including andallows LATEX to treat it as an unbreakable floating thingthat it will position for you as best it can in the docu-ment while maintaining an overall nice typographicallayout This floating of figures can sometimes result inthe figure ending up in a place you didnrsquot expect but inmost cases LATEX will make the most sensible choice Itrsquos

27

COMP10120 Report writing and Digital Typography

possible to employ finer control over figure placementbut thatrsquos beyond the scope of this introduction

The includegraphics command is not built into core LATEX but is in an additional package whichneeds to be explicitly loaded We load this package byusing the command usepackagegraphicx in thedocument preamble ie after the documentclasscommand but before begindocument There arehundreds of such packages that extend LATEXrsquos func-tionality the lab scripts you are reading now use over30 of them

Exercise 3 Including images

Create a document imagetex that contains some text(maybe from rsquoLorem Ipsumrsquo) together with a figurecontaining an image of your choice perhaps the oneyou made in Intro Lab 2 like Steversquos Mr Noodle Thereshould also be a reference to the figure in the text Youshould first use the program convert

convert

(check its manpage) to create a PDF version of the image

Exercise 4 A reflection on your studies

Your first proper LATEX document will be a very briefreflection on your studies so far

Write a hand-crafted LATEX document called courses-reflectiontex

28

COMP10120 Report writing and Digital Typography

(exact name as usual please otherwise submitwill notwork) It will have the following structure

1 A table of contents

2 A brief paragraph saying what the document isabout

3 A section appropriately titled for one of your courseunits containing

bull a brief paragraph saying what the unit is about

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the most about the unit

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the least about the unit

A repeat of item 3 for each other unit you are study-ing These sections should appear in alphabeticalorder by course code (eg COMP10120)

After completing and successfully compiling and view-ing your document you should spell-check it as fol-lows

ispell courses-reflectiontex

29

COMP10120 Report writing and Digital Typography

Once you are completely satisfied with it produce ahard copy ready for marking

34 Typesetting Mathematics

Earlier we saw this formula

x =minusbplusmn

radicb2 minus 4ac

2aIt looks nice doesnrsquot it To tell LATEX to display thisyou have to type a bit of magic but itrsquos easily-learnedmagic To create such a formula in a WYSIWYG edi-tor there is also magic involved but it usually involvesa lot of mouse-clicking and remembering special keycombinations like rsquocontrol-thisrsquo and rsquoalt-thatrsquo In LATEXit doesnrsquot You simply type this

[ x = frac-b pm sqrtb^2-4ac2a ]

You can probably work out how most of this createsthe formula but it wonrsquot be obvious that the [ and ]symbols that enclose the formula mean lsquotypeset this asa displayed formula giving it some vertical space fromthe surrounding textrsquo If wersquod used ( and ) insteadto enclose the formula it would appear in-line like thisx = minusbplusmn

radicb2minus4ac2a It still looks very nice and observe

how itrsquos automatically been resized to fit and that the

30

COMP10120 Report writing and Digital Typography

lines of text have had their spacing changed a bit Thisall looks simple but the implementation inside LATEXand TEX is complex It involves parsing the descrip-tion of the formula to create a corresponding tree datastructure which is then recursively walked to workout the horizontal and vertical typographical spacingsneeded Yoursquoll meet these ideas in COMP11120 andCOMP26120 Algorithms and Imperative Programming

Herersquos another example taken from COMP27112Computer Graphics (itrsquos a lsquosimplersquo local illuminationmodel incorporating ambient diffuse and specular re-flection by multiple lights)

I = kaIa +

Msumi=1

Ipidprimei[kd(N middot Li) + ks(Ri middot V )n]

We write this in LATEX as follows

[ I = k_a I_a + sum_i=1^M fracI_p_idrsquo_i [ k_d(hatN cdot hatL_i)+ k_s(hatR_i cdot hatV)^n] ]

Try to match the LATEX commands with the formula dis-played above Yoursquoll see lots of curly brackets and thisexample illustrates their two uses in LATEX The firstis to provide an argument to a command for exam-ple hatN means lsquoapply the hat command to N rsquowhich creates N the vector N with a little hat on

31

COMP10120 Report writing and Digital Typography

The second use of curly brackets is to group thingstogether to avoid ambiguities In the example you cansee sum_i=1^M which creates a summation signand its lower and upper limits

sumMi=1 We wrap the

lower bound i=1 in curly brackets to group it into anindivisible unit If we were to omit the brackets writ-ing sum_i=1^M LATEX would then produce

sumi = 1M

which is not at all what we want (even LATEX canrsquot al-ways know what we really want)

One final example If we tell LATEX

[ T_1 = left[beginarraycccccos theta amp -sin theta amp 0 amp delta sin theta amp cos theta amp 0 amp epsilon 0 amp 0 amp 1 amp eta alpha amp beta amp gamma amp 1endarrayright] ]

wersquoll get a splendid matrix which expresses a particu-lar 3D geometrical transformation (Donrsquot worry if youdonrsquot recognise this yoursquoll be introduced to matrix no-tation in the latter part of COMP11120 MathematicalTechniques for Computer Science For now you can justtreat it as some mysterious maths)

32

COMP10120 Report writing and Digital Typography

T1 =

cos θ minus sin θ 0 δ

sin θ cos θ 0 ε

0 0 1 η

α β γ 1

In the LATEX code left[means lsquobig opening square

bracket pleasersquo ccccmeans lsquoan array with 4 columnsplease with the items in each column centredrsquo ampmeanslsquostart a new columnrsquo and means lsquostart a new rowrsquoYoursquoll notice that LATEX knows about greek letters itknows about most standard maths symbols too andalso the ways theyrsquore usually used

There are some symbols that you might need (forexample therefore which produces the usual threedots symbol there4) that are not part of standard LATEX Manysuch symbols are provided by the amssymb package ofsymbols compiled by the American Mathematical Soci-ety Details of the many symbols provided by this pack-age can be found online at

mirrormathkuedutex-archivefontsamsfontsdocamssymbpdf

To use these extra symbols you need to have usepackageamssymbin the document preamble

33

COMP10120 Report writing and Digital Typography

341 A longer piece of mathematics

We conclude this section with an example of a longerpiece of mathematics that shows how you might type-set a complete mathematical argument rather than asingle formula The example is Euclidrsquos proof of thefact that

radic2 is irrational Itrsquos an argument that has been

covered in COMP11120 and is an example of proof bycontradiction It starts by making the assumption thatit is not the case that

radic2 is irrational in other words that

we can find integers p and q withradic2 = pq

We can assume without losing anything that p andq have no common factors (Why)

radic2 = pq

qradic2 = p

2q2 = p2

This means that p2 is even from which we can also de-duce that p is even (Why)

This means that p = 2k for some k so

2q2 = (2k)2

there4 2q2 = 4k2

so q2 = 2k2

But this means that q2 and hence q is even Since p andq are both even we have a contradiction to our initialassumption so no such p and q exist

The way this is formatted is shown here

34

COMP10120 Report writing and Digital Typography

It starts by making the assumption that it is emphnot the casethat $sqrt2$ is irrational in other words that we can findintegers $p$ and $q$ with $sqrt2 = pq$

We can assume without losing anything that $p$ and $q$ haveemphno common factors (Why)

[beginarraylcl

sqrt2 amp = amp pq qsqrt2 amp = amp p 2q^2 amp = amp p^2

endarray]

This means that $p^2$ is even from which we can also deduce that $p$is even (Why)

This means that $p = 2k$ for some $k$ so ldots[beginarrayllcl

amp 2q^2 amp = amp (2k)^2 therefore amp 2q^2 amp = amp 4k^2 textso amp q^2 amp = amp 2k^2

endarray]

But this means that $q^2$ and hence $q$ is even Since $p$ and $q$are both even we have a contradiction to our initial assumptionso no such $p$ and $q$ exist

Notice the use of the array environment for gettingthings lined up You can find much more informationabout this on the web

LATEX really shines at typesetting mathematics and

35

COMP10120 Report writing and Digital Typography

it would take pages and pages to describe all the fea-tures Have a look at

enwikibooksorgwikiLaTeXMathematics

for a flavour

Exercise 5 Formatting mathematics

Now for an exercise that involves some mathematicsPlease create a file f-wtex which typesets the follow-ing piece of text and mathematics

There are many positive integer solutions tothe equation

x2 + y2 = z2

which can be rewritten as

z =radicx2 + y2

For example (3 4 5) or (5 12 13) Such solu-tions are called Pythagorean triples

However for higher powers the situation isvery different and we have-

Theorem Fermat-WilesFor all natural numbers n ge 3 there are no

36

COMP10120 Report writing and Digital Typography

integers x y z satisfying the equation

xn + yn = zn

35 Curriculum vitaie

There are several scenarios where using LATEX ratherthan other word processing software can be useful

bull typesetting mathematics yoursquove just read about

bull writing a technical document

bull your final year project peport

bull writing an article you want to get published

bull writing a Curriculum vitae CV

Wersquoll now look at CVrsquos briefly

Exercise 6 Curriculum vitae

Creating a professional document is especially impor-tant when you write your CV because how your CVlooks (not just the content) will determine if you are in-vited to interview for job you are applying for Thatcould be a summer internship next year a year long

37

COMP10120 Report writing and Digital Typography

placement after your second year or graduate positionafter you leave University

As well using a text-editor and compiling files fromthe command line other tools are available for editingLATEXWe will look at one of these overleafcom

Create a basic CV which describes you your edu-cation (including University) and any experience youhave or interesting projects that you may have doneYou can do this using httpsoverleafcom andchoosing the ready-made templates at httpswwwoverleafcomgallerytaggedcv

As you progress through University it is a good ideato keep your CV up to date and get feedback from asmany people as you can There will be opportunities todebug your CV later (See httpgitiomycv if youare interested) but yoursquoll need a ldquobeta releaserdquo (version10) of your CV to get started The best time to start thisprocess is now

36 Some optional extras

Exercise 7 Exploring more LATEX features (op-tional but easy)

This exercise reinforces some of the things yoursquove donealready but also introduces some features of LATEX that

38

COMP10120 Report writing and Digital Typography

will be new to you It is labelled as optional because itisnrsquot marked but we would recommend that you all tryit

Take a copy of the file optinfocoursesCOMP10120ex3latex-introtexand follow the instructions it contains You should readit before you process it with LATEX

Exercise 8 A neat directory listing (optionalmore challenging)

The fact that LATEX source files are just text makes it easyto have them generated by a program You are going toexploit this and use LATEX to produce a neat documentcontaining a listing of the files in any directory

Find how to create tables in LATEX tables using thetabular environment Make a LATEX document by handthat uses a table to neatly show the information aboutthe files in some (small) directory (as produced by ls

-l) Write a shell script called neat-ls that takes anargument which is the path name of a directory andproduces a LATEX document containing the above tablefor the given directory The script could also process theLATEX and display the resulting pdf file Finally find outabout the longtable package and change your script touse that instead

39

COMP10120 Report writing and Digital Typography

Exercise 9 A cleaning rota (optional evenmore challenging)

Now you will write a shell script called make-rota thatgenerates a house cleaning rota (Very handy for nextyear ) This is a table with columns such as KitchenBathroom and Lounge The rows will be weeks in theyear labelled with a date (eg always a Sunday) Theidea is that house mates can write their initials in theboxes promising to clean the corresponding room inthat particular week Start by making a sample tableby hand

Your script should take a single argument which isthe date of the first day of the first row eg102013(the US format for 20 Oct 13) The result will be a docu-ment that contains as many rows as fit on a single page(find out by experimenting)

The dates of each row should be generated from thefirst See the manual page for date to figure out howyou can generate a date that is a number of weeks anddays later than an existing one

361 Marking Scheme

You can view a copy of the marking scheme used bysubmit and labprint at

40

COMP10120 Report writing and Digital Typography

studentnetcsmanchesteracukugtlpmsphpunit=COMP10120ampex=ex3xml

37 Next steps

LATEX is a very powerful tool and it does take a littlegetting used to But itrsquos not as scary as it might initiallyseem and you should find that it doesnrsquot take long tolearn the common commands and techniques to makeyour documents well-structured and readable As youbecome more comfortable with the basics and under-stand the principles of typesetting finding out how todo more complex and sophisticated things is easymdashthere are hundreds of tutorials on the web

Donrsquot get carried away though and use the featuresjudiciously just because yoursquove found a cool new com-mand doesnrsquot mean that you should use it just to showoff your LATEX skills content and structure always trumpstypographic twiddlings4

4For example footnotes like this are for some reason a really tempting fea-ture to use in LATEX and in this document we have abused them mercilessly toillustrate a point Footnotes were originally a means for mechanical typeset-ters to insert comments corrections or additions to existing documents withouthaving to adjust the layout of a whole page and of course in digital typographythis is no longer necessary They can justifiably be used for citations (though itrsquosnot common to do so these days) and URLs if you donrsquot want these intrudinginto the body of your text And in some very very rare cases they can be usedas an aside to the main flow of the text (which is what has been done in this doc-ument) But this should be used sparingly If something is important to sayput it in the main body of your text If itrsquos not then perhaps you should thinkabout leaving it out completely or find some other way of including it Asking

41

COMP10120 Report writing and Digital Typography

371 Acknowledgements

Figure 38 is from the Wikipedia article on cheese

372 License

The text of this exercise is licensed under the terms ofthe Creative Commons Attribution 20 Generic (CC BY30) License

38 Background

What follows is additional contextual information aroundLATEX

LATEX was originally written by Leslie LamportW anAmerican computer scientist now working at MicrosoftResearch although its development has long been takenover by a world-wide LATEX community Itrsquos actuallybuilt on top of another system called TEX a computertypesetting system designed by one of the worldrsquos mostinfluential Computer Scientists Donald KnuthW of Stan-ford University Knuth has said that he designed TEX

the reader to look down at the bottom of a page to find out whether somethingis important or not is irritating and as yoursquove probably found out already oftenmeans you lose track of your reading position They also give the impressionthat the author isnrsquot clear about whether something is important or not whichis never good And long footnotes like this onemdashwhile LATEX will typeset themperfectly wellmdashare just plain silly Best avoid

42

COMP10120 Report writing and Digital Typography

for lsquothe creation of beautiful booksmdashand especially forbooks that contain a lot of mathematicsrsquo(D Knuth1984) Figure 34 shows what these eminent men looklike

So whatrsquos the purpose of LATEX Itrsquos purely a layerof software to make TEX easier to use in everyday sit-uations This is a good idea because although TEX isamazingly powerful it operates at a very low-level whichmakes it hard for non-expert users

Figure 34Don Knuth and Leslie Lamport

381 Pronunciation

The name TEX is intended by its creator to be pronouncedwith the final consonant as in the word loch or the nameBach but English speakers often pronounce it like thefirst syllable of technical The first syllable of LATEX is

43

COMP10120 Report writing and Digital Typography

pronounced as in rsquolayrsquo5

382 Why LATEX

Before we go any further why do we think LATEX is im-portant for youmdasha Computer Science studentmdashto knowabout Here are some reasons in no particular order

bull LATEX and TEX are superb examples of ComputerScience in action TEX was designed by Knuth fromfirst principlesmdashin other words from scratch TEXis actually a programming language and LATEX isa set of functions defined in the TEX language TheTEX lsquocompilerrsquo is written in WEBW a mixture ofdocumentation written in TeX and a PascalW sub-set in order to ensure portability it reads a TEXprogram and outputs documents TEX is completelyself-contained and designed to be portable to anycomputer architecture For example it implementsits own stackW and heapW (with garbage collectionW)and it does fixed-precision arithmeticW donrsquot worryif these terms donrsquot make much sense to you at themoment they soon will

5The Greek prefix lsquotexrsquo means lsquoartrsquo as well as lsquotechnologyrsquo so itrsquos a very nicelychosen name for a piece of software that produces such beautiful output Knuthexplained (D Knuth 1984) that one should lsquopronounce the X of TeX as a Greekchi not as an lsquoxrsquo so that TeX rhymes with the word blecchhhrsquo Wersquore not toosure that helps much unless you are confident in your pronunciation of theword lsquoblecchhrsquo Maybe itrsquos an American thing

44

COMP10120 Report writing and Digital Typography

bull LATEX is a new interesting way for you to thinkabout preparing documents

bull LATEX has a practical advantage for the writer inthat it helps you think more about what you wantto write rather than worrying about how it looks

bull LATEX is a powerful tool for professional scientificdocumentation and as a Computer Scientist youshould know about it

bull LATEX files are just plain text so can easily be cre-ated programatically For example the slides usedfor COMP16120 are generated automatically fromthe source of Johnrsquos book both are typeset usingLATEX The program labprint also produces itsoutput using LATEX using information drawn fromXMLW configuration files and ARCADE

bull Using LATEX is actually quite satisfying and thequality of its output may surprise you

In this lab session you are going to write severalshort documents using LATEX You could also write briefnotes in your logbook about how LATEX works and whatcommands you used inside the source of your docu-ments

45

COMP10120 Report writing and Digital Typography

383 Some history printing mathematics

Mathematics is hard to print on paper and on the Web(many websites resort to GIF or JPG images of mathsformulae which usually look horrible MathMLW pro-vides another approach but it is not yet widely used)

In the days before computers books and newspa-pers were printed with movable typeW made from lotsof little blocks of metal each with letters numbers andsymbols standing in relief which when inked left animpression on the paper (see Figure 35) The job ofthe printer (the printer here of course being a personnot a bit of electronics) was to gather together all theblocks in the right order between two horizontal stripsof wood to create a line of the document and then toassemble all those lines from top to bottom of a pageThus the term type settingW an incredible task whenyou think about it In the printerrsquos workshop by theway the blocks of metal were stored between jobs inwooden boxes called cases Letters like a b and c werestored in one case letters like A B and C were storedin a case sitting on top of that So a lower case and anupper case These terms may ring a bell

As technology progressed machines controlled bytypewriters would mechanically juggle the blocks intothe right order This conceptual model is the basis onwhich TEX operates Only now the metal blocks are

46

COMP10120 Report writing and Digital Typography

Figure 35On the left a piece of cast movable type in the Garamondfont On the right a case of cast metal type pieces andtypeset matter in a composing stick The text reads lsquoThequick brown fox jumps over the lazy dog and feels as if hewere in the seventh heaven of typography together with Her-mann Zapf the most famous artist of thersquo This document istypeset in a font called Palatino created by Hermann ZapfYou may have also seen rsquoZapf Dingbatsrsquo in the font lists ofvarious desktop applications Now you know why

little pieces of data arranged into data structuresThe one thing that traditional printers hated was

dealing with the typesetting of mathematics and theywould charge extra to do it It was incredibly fiddly toget the equations looking right they had to squeeze inextra bits of metal horizontally and vertically

When computers entered the printing world attemptsto print mathematics were limited by the printing tech-nology available It took a long time to reach the pointwhere computers could typeset mathematics beautifullyand that was the outstanding achievement of Knuthrsquos

47

COMP10120 Report writing and Digital Typography

TEXLetrsquos look at a quick example of the quality you get

from LATEX with a very simple formula that yoursquoll recog-nise

x =minusbplusmn

radicb2 minus 4ac

2aWersquoll revisit how LATEX typesets mathematics in Section 34

384 To WYSIWYG or not to WYSIWYG

Up until now you have probably used wordprocessingapplications such as Microsoft Word to create essaysletters and other (probably fairly short) documents Youmost likely know that the majority of modern wordprocessors use a paradigm called WYSIWYG or WhatYou See Is What You Get which means that you canmodify the visual style of the document yoursquore work-ing on by selecting the relevant bits and then choos-ing different attributes such as font size or colour usinga GUI In many ways this seems like such a sensibleand obvious way of doing things that you might bewondering why it even has a special name The rea-son is a historical one in the early days of comput-ing long before graphical window managers becamethe norm and when all you could display on screenwas fixed-width ASCII text in whatever the systemrsquos

48

COMP10120 Report writing and Digital Typography

default font was wordprocessors (eg Figure 36) onlyallowed you to format documents by using special se-quences of characters to cause particular effects Butthese effects were only visible when the document wasprinted So if you wanted a word to appear in boldtext in the wordprocessor you might write somethinglike [bold]hello world[bold] what you saw onscreen was not a direct reflection of what appeared onthe printed page If yoursquove written any HTML how-ever this process of marking up text may be familiarsee for example Figure 37 As computers moved todisplays able to draw things other than raw charac-ters on screen wordprocessors became capable of us-ing multiple fonts and styles as well as graphics anda new generation of applications appeared where whatyou saw on screen was an accurate reflection of how itwould appear when printed what you see (on screen)is what you get (on paper)

The huge advantage of WYSIWYG is that itrsquos reallyeasy to understand whatrsquos going on and most peoplecan create reasonably nicely formatted documents withrelatively little effort For short informal documentsone-off letters memos and such WYSIWYG works quitenicely But if yoursquove ever tried writing anything muchlonger or that includes images and tables you mayhave already started to see where the paradigm breaksdown For example if you write lsquoFigure 38 on page

49

COMP10120 Report writing and Digital Typography

Figure 36A screenshot of Wordperfect 51 running in Microsoft DOScirca 1989

51 shows a picture of some men looking at cheesersquo butthen later on edit your document to include some moretext at the start and a new picture of a some broccoli(as in Figure 39) yoursquod have to search through yourreport to find all mentions of lsquoFigure 38rsquo and lsquopage 51rsquoand manually update them to reflect the new number-ing This might be fine if you have two figures and fivepages but for a hundred-page report containing lots ofpictures you can see how this becomes tedious and er-ror prone very quickly

50

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 13: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

the idea Itrsquos more complicated than it first seems LATEXgets to see the whole of your document at once and cantherefore make decisions about how best to hyphen-ate lines position figures or whatever else it likes beforeit shows you the results so it can make solutions thatare optimal for the whole document as well as lookingat details such as ligated characters Wordprocessorscanrsquot afford to do this since it would be deeply distract-ing if every time you typed a character the whole lay-out of the document flapped around in front of youreyes Wordprocessors can only sensibly make little op-timisations at a local (probably per-line level) Itrsquos notthat wordprocessors are rubbish or that the people thatprogrammed them were lazy itrsquos a fundamentally dif-ferent way of working and knowing the pros and consof the different approaches will help you pick the righttool for the job

You may have noticed that actual text in your doc-ument (and in fact this one) takes up a (perhaps) sur-prisingly narrow horizontal region of the page Thislast lsquofeaturersquo might seem odd at first but it illustratesanother important typographical point that you maynever have thought of before reading long lines of textis hard because your eyes find it hard to move in acompletely straight line as they scan from left to rightSo the longer the line of words the more you have towork to keep your eyes from accidentally drifting up or

20

COMP10120 Report writing and Digital Typography

down onto a neighbouring line (perhaps yoursquove expe-rienced the phenomenon of accidentally re-reading thesame line over and over as your eyes get tired) It maynever have occurred to you but most books have rela-tively short lines of text and those that use large pagesoften split text into several columns so that individuallines are kept relatively short The widely trusted booklsquoThe Elements of Typographic Stylersquo (R Bringhurst1992) makes the following assertion

lsquoAnything from 45 to 75 characters is widely-regarded as a satisfactory length of line for a single-column page set in a serifed text face in a text sizeThe 66-character line (counting both letters andspaces) is widely regarded as idealrsquo

LATEX knows about this issue so made a sensible de-fault decision for you You may have noticed that thereis a subtle difference in appearance of this chapter fromprevious ones the lines are shorter and paragraphs areindented We wanted to use the default LATEX layoutfor this chapter but changed it for earlier chapters inan effort to save paper

Therersquos one last unusual thing to note your para-graph of gibberish text in between the real words fromBleak House and the Lorem Ipsum almost certainly standsout and looks really quite odd (it might even have con-fused LATEXrsquos hyphenation rules enough to have ended

21

COMP10120 Report writing and Digital Typography

up with one or more lines sticking out proud of theright hand margin) Let your eyes relax so that yourvision blurs for a moment you can still probably spotthat the gibberish paragraph looks out of place Itrsquosquite likely that you even found creating the gibber-ish unexpectedly hard The interesting thing here isthat as humans we spend so much time reading andwriting lsquoproperrsquo natural language that we become at-tuned to the patterns of letters words and the underly-ing lsquorhythmrsquo of our written language that its very hardto artificially reproduce something that looks plausiblethe frequency of the letters you chose by randomly hit-ting keys and the length and patterns of the words youput in place most likely donrsquot match the natural pat-terns of real languages so they just look plain wrongCuriously the Lorem Ipsum text that you got from thewebsite probably doesnrsquot look so bad in spite of it notbeing made up of real words But thatrsquos not surprisingsince Lorem Ipsum is specifically created to be used asa placeholder for real text when typesetting While thewords are meaningless Latin-like things their lengthand the distribution of characters and word lengths arechosen to mimic patterns in real language

Next letrsquos give our document some structure by di-viding it up into sections On the line before BleakHouse starts add the command

22

COMP10120 Report writing and Digital Typography

sectionBleak House

making sure it appears on a line of its own Then justbefore your paragraph of gibberish put a similar in-struction (again on its own line) and then create a finalsection before the Lorem Ipsum Rerun pdflatex andlook at the results You should see the section headingsappear in the appropriate places in the PDF automati-cally having been given section numbers Experimentby adding in a couple of sub-sections towards the endof the document using the subsection commandwhich like the section command above takes as aparameter some text contained in curly brackets

Now at the top of your document after the begindocumentline and before the command defining the first sectionadd the following two commands each on their ownline

tableofcontentsnewpage

Re-run pdflatex twice and check that the effect is whatyoursquod expect You need to process the source twice be-cause on the first run LATEX gathers and stores informa-tion about what to put in the table of contents and onlycreates it on the second run

23

COMP10120 Report writing and Digital Typography

33 Common formatting features

Before we give you some more exercises to do here is abrief introduction to some commonly used features ofLATEX

331 Enumerated and bulleted lists

Creating bulleted or numbered lists in LATEX is straight-forward and is done like this

beginenumerateitem My first itemitem My second itemitem The last thing on my listendenumerate

You must make sure that you both begin and end yourlist and that each item is terminated by a newline Chang-ing enumerate to itemize gives you a bulleted ratherthan numbered list (note the American spelling of lsquoitem-izersquo)

332 Changing the appearance of text

Text can be typeset in bold font using the textbfin italics using textitand in a fixed-width fontusing texttt as in the example below

24

COMP10120 Report writing and Digital Typography

Some textttsay the textbfworld will end in textitfire

which is typeset as

Some say the world will end in fire

333 Cross referencing

LATEX allows you to cross-reference almost anything inthe document which includes sections sub-sections andfigures To use the cross-referencing feature you simplyinsert the command

labelmymarker

at the point in the document you want to refer to andthen use the command

refmymarker

when you want to use the reference Obviously youreplace the text mymarkerwith something more mean-ingful An important tip here is to call the marker some-thing that refers to the content of that part of the doc-ument and to avoid the temptation to use numbers(so donrsquot call your marker section1 instead call itintroduction if you reorder your document itrsquos stilllikely to be the introduction but it may no longer beSection 1) For example

25

COMP10120 Report writing and Digital Typography

sectionReflection on Welcome WeeklabelwelcomeweekI spent most of welcome week getting to know my wayaround campus I should have made more effort to joinsocieties I think I must remember to get to theStudentsrsquo Union and take a look around there

subsectionThings I enjoyedEverything so far has been wonderful with the caveat Imentioned in Section refwelcomeweek

subsectionThings I didnrsquot enjoyIrsquove discovered that I donrsquot like soggy chips

The really useful thing about cross-referencing in LATEXis that yoursquoll get warnings when you compile your doc-ument if cross-references are undefined or used incor-rectly This means you donrsquot have to manually checkevery reference in your document to make sure itrsquos stillright You do however have to run LATEX twice forsimilar reasons to those given above

334 Figures and pictures

Including figures and pictures in your document is easyYou do it like this

beginfigure

26

COMP10120 Report writing and Digital Typography

Figure 33Some men possibly Dutch looking at cheeses

centerlineincludegraphics[width=10cm]imagesmen-and-cheesejpgcaptionSome men possibly Dutch looking at cheeseslabelfiguremenandcheesesendfigure

which is the code we used to create Figure 38 You canprobably see whatrsquos happening The command includegraphicsgets your image which can be PDF PNG JPG GIF orPostScript The beginfigureendfigurecode lsquowrapsrsquo up whatever picture yoursquore including andallows LATEX to treat it as an unbreakable floating thingthat it will position for you as best it can in the docu-ment while maintaining an overall nice typographicallayout This floating of figures can sometimes result inthe figure ending up in a place you didnrsquot expect but inmost cases LATEX will make the most sensible choice Itrsquos

27

COMP10120 Report writing and Digital Typography

possible to employ finer control over figure placementbut thatrsquos beyond the scope of this introduction

The includegraphics command is not built into core LATEX but is in an additional package whichneeds to be explicitly loaded We load this package byusing the command usepackagegraphicx in thedocument preamble ie after the documentclasscommand but before begindocument There arehundreds of such packages that extend LATEXrsquos func-tionality the lab scripts you are reading now use over30 of them

Exercise 3 Including images

Create a document imagetex that contains some text(maybe from rsquoLorem Ipsumrsquo) together with a figurecontaining an image of your choice perhaps the oneyou made in Intro Lab 2 like Steversquos Mr Noodle Thereshould also be a reference to the figure in the text Youshould first use the program convert

convert

(check its manpage) to create a PDF version of the image

Exercise 4 A reflection on your studies

Your first proper LATEX document will be a very briefreflection on your studies so far

Write a hand-crafted LATEX document called courses-reflectiontex

28

COMP10120 Report writing and Digital Typography

(exact name as usual please otherwise submitwill notwork) It will have the following structure

1 A table of contents

2 A brief paragraph saying what the document isabout

3 A section appropriately titled for one of your courseunits containing

bull a brief paragraph saying what the unit is about

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the most about the unit

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the least about the unit

A repeat of item 3 for each other unit you are study-ing These sections should appear in alphabeticalorder by course code (eg COMP10120)

After completing and successfully compiling and view-ing your document you should spell-check it as fol-lows

ispell courses-reflectiontex

29

COMP10120 Report writing and Digital Typography

Once you are completely satisfied with it produce ahard copy ready for marking

34 Typesetting Mathematics

Earlier we saw this formula

x =minusbplusmn

radicb2 minus 4ac

2aIt looks nice doesnrsquot it To tell LATEX to display thisyou have to type a bit of magic but itrsquos easily-learnedmagic To create such a formula in a WYSIWYG edi-tor there is also magic involved but it usually involvesa lot of mouse-clicking and remembering special keycombinations like rsquocontrol-thisrsquo and rsquoalt-thatrsquo In LATEXit doesnrsquot You simply type this

[ x = frac-b pm sqrtb^2-4ac2a ]

You can probably work out how most of this createsthe formula but it wonrsquot be obvious that the [ and ]symbols that enclose the formula mean lsquotypeset this asa displayed formula giving it some vertical space fromthe surrounding textrsquo If wersquod used ( and ) insteadto enclose the formula it would appear in-line like thisx = minusbplusmn

radicb2minus4ac2a It still looks very nice and observe

how itrsquos automatically been resized to fit and that the

30

COMP10120 Report writing and Digital Typography

lines of text have had their spacing changed a bit Thisall looks simple but the implementation inside LATEXand TEX is complex It involves parsing the descrip-tion of the formula to create a corresponding tree datastructure which is then recursively walked to workout the horizontal and vertical typographical spacingsneeded Yoursquoll meet these ideas in COMP11120 andCOMP26120 Algorithms and Imperative Programming

Herersquos another example taken from COMP27112Computer Graphics (itrsquos a lsquosimplersquo local illuminationmodel incorporating ambient diffuse and specular re-flection by multiple lights)

I = kaIa +

Msumi=1

Ipidprimei[kd(N middot Li) + ks(Ri middot V )n]

We write this in LATEX as follows

[ I = k_a I_a + sum_i=1^M fracI_p_idrsquo_i [ k_d(hatN cdot hatL_i)+ k_s(hatR_i cdot hatV)^n] ]

Try to match the LATEX commands with the formula dis-played above Yoursquoll see lots of curly brackets and thisexample illustrates their two uses in LATEX The firstis to provide an argument to a command for exam-ple hatN means lsquoapply the hat command to N rsquowhich creates N the vector N with a little hat on

31

COMP10120 Report writing and Digital Typography

The second use of curly brackets is to group thingstogether to avoid ambiguities In the example you cansee sum_i=1^M which creates a summation signand its lower and upper limits

sumMi=1 We wrap the

lower bound i=1 in curly brackets to group it into anindivisible unit If we were to omit the brackets writ-ing sum_i=1^M LATEX would then produce

sumi = 1M

which is not at all what we want (even LATEX canrsquot al-ways know what we really want)

One final example If we tell LATEX

[ T_1 = left[beginarraycccccos theta amp -sin theta amp 0 amp delta sin theta amp cos theta amp 0 amp epsilon 0 amp 0 amp 1 amp eta alpha amp beta amp gamma amp 1endarrayright] ]

wersquoll get a splendid matrix which expresses a particu-lar 3D geometrical transformation (Donrsquot worry if youdonrsquot recognise this yoursquoll be introduced to matrix no-tation in the latter part of COMP11120 MathematicalTechniques for Computer Science For now you can justtreat it as some mysterious maths)

32

COMP10120 Report writing and Digital Typography

T1 =

cos θ minus sin θ 0 δ

sin θ cos θ 0 ε

0 0 1 η

α β γ 1

In the LATEX code left[means lsquobig opening square

bracket pleasersquo ccccmeans lsquoan array with 4 columnsplease with the items in each column centredrsquo ampmeanslsquostart a new columnrsquo and means lsquostart a new rowrsquoYoursquoll notice that LATEX knows about greek letters itknows about most standard maths symbols too andalso the ways theyrsquore usually used

There are some symbols that you might need (forexample therefore which produces the usual threedots symbol there4) that are not part of standard LATEX Manysuch symbols are provided by the amssymb package ofsymbols compiled by the American Mathematical Soci-ety Details of the many symbols provided by this pack-age can be found online at

mirrormathkuedutex-archivefontsamsfontsdocamssymbpdf

To use these extra symbols you need to have usepackageamssymbin the document preamble

33

COMP10120 Report writing and Digital Typography

341 A longer piece of mathematics

We conclude this section with an example of a longerpiece of mathematics that shows how you might type-set a complete mathematical argument rather than asingle formula The example is Euclidrsquos proof of thefact that

radic2 is irrational Itrsquos an argument that has been

covered in COMP11120 and is an example of proof bycontradiction It starts by making the assumption thatit is not the case that

radic2 is irrational in other words that

we can find integers p and q withradic2 = pq

We can assume without losing anything that p andq have no common factors (Why)

radic2 = pq

qradic2 = p

2q2 = p2

This means that p2 is even from which we can also de-duce that p is even (Why)

This means that p = 2k for some k so

2q2 = (2k)2

there4 2q2 = 4k2

so q2 = 2k2

But this means that q2 and hence q is even Since p andq are both even we have a contradiction to our initialassumption so no such p and q exist

The way this is formatted is shown here

34

COMP10120 Report writing and Digital Typography

It starts by making the assumption that it is emphnot the casethat $sqrt2$ is irrational in other words that we can findintegers $p$ and $q$ with $sqrt2 = pq$

We can assume without losing anything that $p$ and $q$ haveemphno common factors (Why)

[beginarraylcl

sqrt2 amp = amp pq qsqrt2 amp = amp p 2q^2 amp = amp p^2

endarray]

This means that $p^2$ is even from which we can also deduce that $p$is even (Why)

This means that $p = 2k$ for some $k$ so ldots[beginarrayllcl

amp 2q^2 amp = amp (2k)^2 therefore amp 2q^2 amp = amp 4k^2 textso amp q^2 amp = amp 2k^2

endarray]

But this means that $q^2$ and hence $q$ is even Since $p$ and $q$are both even we have a contradiction to our initial assumptionso no such $p$ and $q$ exist

Notice the use of the array environment for gettingthings lined up You can find much more informationabout this on the web

LATEX really shines at typesetting mathematics and

35

COMP10120 Report writing and Digital Typography

it would take pages and pages to describe all the fea-tures Have a look at

enwikibooksorgwikiLaTeXMathematics

for a flavour

Exercise 5 Formatting mathematics

Now for an exercise that involves some mathematicsPlease create a file f-wtex which typesets the follow-ing piece of text and mathematics

There are many positive integer solutions tothe equation

x2 + y2 = z2

which can be rewritten as

z =radicx2 + y2

For example (3 4 5) or (5 12 13) Such solu-tions are called Pythagorean triples

However for higher powers the situation isvery different and we have-

Theorem Fermat-WilesFor all natural numbers n ge 3 there are no

36

COMP10120 Report writing and Digital Typography

integers x y z satisfying the equation

xn + yn = zn

35 Curriculum vitaie

There are several scenarios where using LATEX ratherthan other word processing software can be useful

bull typesetting mathematics yoursquove just read about

bull writing a technical document

bull your final year project peport

bull writing an article you want to get published

bull writing a Curriculum vitae CV

Wersquoll now look at CVrsquos briefly

Exercise 6 Curriculum vitae

Creating a professional document is especially impor-tant when you write your CV because how your CVlooks (not just the content) will determine if you are in-vited to interview for job you are applying for Thatcould be a summer internship next year a year long

37

COMP10120 Report writing and Digital Typography

placement after your second year or graduate positionafter you leave University

As well using a text-editor and compiling files fromthe command line other tools are available for editingLATEXWe will look at one of these overleafcom

Create a basic CV which describes you your edu-cation (including University) and any experience youhave or interesting projects that you may have doneYou can do this using httpsoverleafcom andchoosing the ready-made templates at httpswwwoverleafcomgallerytaggedcv

As you progress through University it is a good ideato keep your CV up to date and get feedback from asmany people as you can There will be opportunities todebug your CV later (See httpgitiomycv if youare interested) but yoursquoll need a ldquobeta releaserdquo (version10) of your CV to get started The best time to start thisprocess is now

36 Some optional extras

Exercise 7 Exploring more LATEX features (op-tional but easy)

This exercise reinforces some of the things yoursquove donealready but also introduces some features of LATEX that

38

COMP10120 Report writing and Digital Typography

will be new to you It is labelled as optional because itisnrsquot marked but we would recommend that you all tryit

Take a copy of the file optinfocoursesCOMP10120ex3latex-introtexand follow the instructions it contains You should readit before you process it with LATEX

Exercise 8 A neat directory listing (optionalmore challenging)

The fact that LATEX source files are just text makes it easyto have them generated by a program You are going toexploit this and use LATEX to produce a neat documentcontaining a listing of the files in any directory

Find how to create tables in LATEX tables using thetabular environment Make a LATEX document by handthat uses a table to neatly show the information aboutthe files in some (small) directory (as produced by ls

-l) Write a shell script called neat-ls that takes anargument which is the path name of a directory andproduces a LATEX document containing the above tablefor the given directory The script could also process theLATEX and display the resulting pdf file Finally find outabout the longtable package and change your script touse that instead

39

COMP10120 Report writing and Digital Typography

Exercise 9 A cleaning rota (optional evenmore challenging)

Now you will write a shell script called make-rota thatgenerates a house cleaning rota (Very handy for nextyear ) This is a table with columns such as KitchenBathroom and Lounge The rows will be weeks in theyear labelled with a date (eg always a Sunday) Theidea is that house mates can write their initials in theboxes promising to clean the corresponding room inthat particular week Start by making a sample tableby hand

Your script should take a single argument which isthe date of the first day of the first row eg102013(the US format for 20 Oct 13) The result will be a docu-ment that contains as many rows as fit on a single page(find out by experimenting)

The dates of each row should be generated from thefirst See the manual page for date to figure out howyou can generate a date that is a number of weeks anddays later than an existing one

361 Marking Scheme

You can view a copy of the marking scheme used bysubmit and labprint at

40

COMP10120 Report writing and Digital Typography

studentnetcsmanchesteracukugtlpmsphpunit=COMP10120ampex=ex3xml

37 Next steps

LATEX is a very powerful tool and it does take a littlegetting used to But itrsquos not as scary as it might initiallyseem and you should find that it doesnrsquot take long tolearn the common commands and techniques to makeyour documents well-structured and readable As youbecome more comfortable with the basics and under-stand the principles of typesetting finding out how todo more complex and sophisticated things is easymdashthere are hundreds of tutorials on the web

Donrsquot get carried away though and use the featuresjudiciously just because yoursquove found a cool new com-mand doesnrsquot mean that you should use it just to showoff your LATEX skills content and structure always trumpstypographic twiddlings4

4For example footnotes like this are for some reason a really tempting fea-ture to use in LATEX and in this document we have abused them mercilessly toillustrate a point Footnotes were originally a means for mechanical typeset-ters to insert comments corrections or additions to existing documents withouthaving to adjust the layout of a whole page and of course in digital typographythis is no longer necessary They can justifiably be used for citations (though itrsquosnot common to do so these days) and URLs if you donrsquot want these intrudinginto the body of your text And in some very very rare cases they can be usedas an aside to the main flow of the text (which is what has been done in this doc-ument) But this should be used sparingly If something is important to sayput it in the main body of your text If itrsquos not then perhaps you should thinkabout leaving it out completely or find some other way of including it Asking

41

COMP10120 Report writing and Digital Typography

371 Acknowledgements

Figure 38 is from the Wikipedia article on cheese

372 License

The text of this exercise is licensed under the terms ofthe Creative Commons Attribution 20 Generic (CC BY30) License

38 Background

What follows is additional contextual information aroundLATEX

LATEX was originally written by Leslie LamportW anAmerican computer scientist now working at MicrosoftResearch although its development has long been takenover by a world-wide LATEX community Itrsquos actuallybuilt on top of another system called TEX a computertypesetting system designed by one of the worldrsquos mostinfluential Computer Scientists Donald KnuthW of Stan-ford University Knuth has said that he designed TEX

the reader to look down at the bottom of a page to find out whether somethingis important or not is irritating and as yoursquove probably found out already oftenmeans you lose track of your reading position They also give the impressionthat the author isnrsquot clear about whether something is important or not whichis never good And long footnotes like this onemdashwhile LATEX will typeset themperfectly wellmdashare just plain silly Best avoid

42

COMP10120 Report writing and Digital Typography

for lsquothe creation of beautiful booksmdashand especially forbooks that contain a lot of mathematicsrsquo(D Knuth1984) Figure 34 shows what these eminent men looklike

So whatrsquos the purpose of LATEX Itrsquos purely a layerof software to make TEX easier to use in everyday sit-uations This is a good idea because although TEX isamazingly powerful it operates at a very low-level whichmakes it hard for non-expert users

Figure 34Don Knuth and Leslie Lamport

381 Pronunciation

The name TEX is intended by its creator to be pronouncedwith the final consonant as in the word loch or the nameBach but English speakers often pronounce it like thefirst syllable of technical The first syllable of LATEX is

43

COMP10120 Report writing and Digital Typography

pronounced as in rsquolayrsquo5

382 Why LATEX

Before we go any further why do we think LATEX is im-portant for youmdasha Computer Science studentmdashto knowabout Here are some reasons in no particular order

bull LATEX and TEX are superb examples of ComputerScience in action TEX was designed by Knuth fromfirst principlesmdashin other words from scratch TEXis actually a programming language and LATEX isa set of functions defined in the TEX language TheTEX lsquocompilerrsquo is written in WEBW a mixture ofdocumentation written in TeX and a PascalW sub-set in order to ensure portability it reads a TEXprogram and outputs documents TEX is completelyself-contained and designed to be portable to anycomputer architecture For example it implementsits own stackW and heapW (with garbage collectionW)and it does fixed-precision arithmeticW donrsquot worryif these terms donrsquot make much sense to you at themoment they soon will

5The Greek prefix lsquotexrsquo means lsquoartrsquo as well as lsquotechnologyrsquo so itrsquos a very nicelychosen name for a piece of software that produces such beautiful output Knuthexplained (D Knuth 1984) that one should lsquopronounce the X of TeX as a Greekchi not as an lsquoxrsquo so that TeX rhymes with the word blecchhhrsquo Wersquore not toosure that helps much unless you are confident in your pronunciation of theword lsquoblecchhrsquo Maybe itrsquos an American thing

44

COMP10120 Report writing and Digital Typography

bull LATEX is a new interesting way for you to thinkabout preparing documents

bull LATEX has a practical advantage for the writer inthat it helps you think more about what you wantto write rather than worrying about how it looks

bull LATEX is a powerful tool for professional scientificdocumentation and as a Computer Scientist youshould know about it

bull LATEX files are just plain text so can easily be cre-ated programatically For example the slides usedfor COMP16120 are generated automatically fromthe source of Johnrsquos book both are typeset usingLATEX The program labprint also produces itsoutput using LATEX using information drawn fromXMLW configuration files and ARCADE

bull Using LATEX is actually quite satisfying and thequality of its output may surprise you

In this lab session you are going to write severalshort documents using LATEX You could also write briefnotes in your logbook about how LATEX works and whatcommands you used inside the source of your docu-ments

45

COMP10120 Report writing and Digital Typography

383 Some history printing mathematics

Mathematics is hard to print on paper and on the Web(many websites resort to GIF or JPG images of mathsformulae which usually look horrible MathMLW pro-vides another approach but it is not yet widely used)

In the days before computers books and newspa-pers were printed with movable typeW made from lotsof little blocks of metal each with letters numbers andsymbols standing in relief which when inked left animpression on the paper (see Figure 35) The job ofthe printer (the printer here of course being a personnot a bit of electronics) was to gather together all theblocks in the right order between two horizontal stripsof wood to create a line of the document and then toassemble all those lines from top to bottom of a pageThus the term type settingW an incredible task whenyou think about it In the printerrsquos workshop by theway the blocks of metal were stored between jobs inwooden boxes called cases Letters like a b and c werestored in one case letters like A B and C were storedin a case sitting on top of that So a lower case and anupper case These terms may ring a bell

As technology progressed machines controlled bytypewriters would mechanically juggle the blocks intothe right order This conceptual model is the basis onwhich TEX operates Only now the metal blocks are

46

COMP10120 Report writing and Digital Typography

Figure 35On the left a piece of cast movable type in the Garamondfont On the right a case of cast metal type pieces andtypeset matter in a composing stick The text reads lsquoThequick brown fox jumps over the lazy dog and feels as if hewere in the seventh heaven of typography together with Her-mann Zapf the most famous artist of thersquo This document istypeset in a font called Palatino created by Hermann ZapfYou may have also seen rsquoZapf Dingbatsrsquo in the font lists ofvarious desktop applications Now you know why

little pieces of data arranged into data structuresThe one thing that traditional printers hated was

dealing with the typesetting of mathematics and theywould charge extra to do it It was incredibly fiddly toget the equations looking right they had to squeeze inextra bits of metal horizontally and vertically

When computers entered the printing world attemptsto print mathematics were limited by the printing tech-nology available It took a long time to reach the pointwhere computers could typeset mathematics beautifullyand that was the outstanding achievement of Knuthrsquos

47

COMP10120 Report writing and Digital Typography

TEXLetrsquos look at a quick example of the quality you get

from LATEX with a very simple formula that yoursquoll recog-nise

x =minusbplusmn

radicb2 minus 4ac

2aWersquoll revisit how LATEX typesets mathematics in Section 34

384 To WYSIWYG or not to WYSIWYG

Up until now you have probably used wordprocessingapplications such as Microsoft Word to create essaysletters and other (probably fairly short) documents Youmost likely know that the majority of modern wordprocessors use a paradigm called WYSIWYG or WhatYou See Is What You Get which means that you canmodify the visual style of the document yoursquore work-ing on by selecting the relevant bits and then choos-ing different attributes such as font size or colour usinga GUI In many ways this seems like such a sensibleand obvious way of doing things that you might bewondering why it even has a special name The rea-son is a historical one in the early days of comput-ing long before graphical window managers becamethe norm and when all you could display on screenwas fixed-width ASCII text in whatever the systemrsquos

48

COMP10120 Report writing and Digital Typography

default font was wordprocessors (eg Figure 36) onlyallowed you to format documents by using special se-quences of characters to cause particular effects Butthese effects were only visible when the document wasprinted So if you wanted a word to appear in boldtext in the wordprocessor you might write somethinglike [bold]hello world[bold] what you saw onscreen was not a direct reflection of what appeared onthe printed page If yoursquove written any HTML how-ever this process of marking up text may be familiarsee for example Figure 37 As computers moved todisplays able to draw things other than raw charac-ters on screen wordprocessors became capable of us-ing multiple fonts and styles as well as graphics anda new generation of applications appeared where whatyou saw on screen was an accurate reflection of how itwould appear when printed what you see (on screen)is what you get (on paper)

The huge advantage of WYSIWYG is that itrsquos reallyeasy to understand whatrsquos going on and most peoplecan create reasonably nicely formatted documents withrelatively little effort For short informal documentsone-off letters memos and such WYSIWYG works quitenicely But if yoursquove ever tried writing anything muchlonger or that includes images and tables you mayhave already started to see where the paradigm breaksdown For example if you write lsquoFigure 38 on page

49

COMP10120 Report writing and Digital Typography

Figure 36A screenshot of Wordperfect 51 running in Microsoft DOScirca 1989

51 shows a picture of some men looking at cheesersquo butthen later on edit your document to include some moretext at the start and a new picture of a some broccoli(as in Figure 39) yoursquod have to search through yourreport to find all mentions of lsquoFigure 38rsquo and lsquopage 51rsquoand manually update them to reflect the new number-ing This might be fine if you have two figures and fivepages but for a hundred-page report containing lots ofpictures you can see how this becomes tedious and er-ror prone very quickly

50

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 14: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

down onto a neighbouring line (perhaps yoursquove expe-rienced the phenomenon of accidentally re-reading thesame line over and over as your eyes get tired) It maynever have occurred to you but most books have rela-tively short lines of text and those that use large pagesoften split text into several columns so that individuallines are kept relatively short The widely trusted booklsquoThe Elements of Typographic Stylersquo (R Bringhurst1992) makes the following assertion

lsquoAnything from 45 to 75 characters is widely-regarded as a satisfactory length of line for a single-column page set in a serifed text face in a text sizeThe 66-character line (counting both letters andspaces) is widely regarded as idealrsquo

LATEX knows about this issue so made a sensible de-fault decision for you You may have noticed that thereis a subtle difference in appearance of this chapter fromprevious ones the lines are shorter and paragraphs areindented We wanted to use the default LATEX layoutfor this chapter but changed it for earlier chapters inan effort to save paper

Therersquos one last unusual thing to note your para-graph of gibberish text in between the real words fromBleak House and the Lorem Ipsum almost certainly standsout and looks really quite odd (it might even have con-fused LATEXrsquos hyphenation rules enough to have ended

21

COMP10120 Report writing and Digital Typography

up with one or more lines sticking out proud of theright hand margin) Let your eyes relax so that yourvision blurs for a moment you can still probably spotthat the gibberish paragraph looks out of place Itrsquosquite likely that you even found creating the gibber-ish unexpectedly hard The interesting thing here isthat as humans we spend so much time reading andwriting lsquoproperrsquo natural language that we become at-tuned to the patterns of letters words and the underly-ing lsquorhythmrsquo of our written language that its very hardto artificially reproduce something that looks plausiblethe frequency of the letters you chose by randomly hit-ting keys and the length and patterns of the words youput in place most likely donrsquot match the natural pat-terns of real languages so they just look plain wrongCuriously the Lorem Ipsum text that you got from thewebsite probably doesnrsquot look so bad in spite of it notbeing made up of real words But thatrsquos not surprisingsince Lorem Ipsum is specifically created to be used asa placeholder for real text when typesetting While thewords are meaningless Latin-like things their lengthand the distribution of characters and word lengths arechosen to mimic patterns in real language

Next letrsquos give our document some structure by di-viding it up into sections On the line before BleakHouse starts add the command

22

COMP10120 Report writing and Digital Typography

sectionBleak House

making sure it appears on a line of its own Then justbefore your paragraph of gibberish put a similar in-struction (again on its own line) and then create a finalsection before the Lorem Ipsum Rerun pdflatex andlook at the results You should see the section headingsappear in the appropriate places in the PDF automati-cally having been given section numbers Experimentby adding in a couple of sub-sections towards the endof the document using the subsection commandwhich like the section command above takes as aparameter some text contained in curly brackets

Now at the top of your document after the begindocumentline and before the command defining the first sectionadd the following two commands each on their ownline

tableofcontentsnewpage

Re-run pdflatex twice and check that the effect is whatyoursquod expect You need to process the source twice be-cause on the first run LATEX gathers and stores informa-tion about what to put in the table of contents and onlycreates it on the second run

23

COMP10120 Report writing and Digital Typography

33 Common formatting features

Before we give you some more exercises to do here is abrief introduction to some commonly used features ofLATEX

331 Enumerated and bulleted lists

Creating bulleted or numbered lists in LATEX is straight-forward and is done like this

beginenumerateitem My first itemitem My second itemitem The last thing on my listendenumerate

You must make sure that you both begin and end yourlist and that each item is terminated by a newline Chang-ing enumerate to itemize gives you a bulleted ratherthan numbered list (note the American spelling of lsquoitem-izersquo)

332 Changing the appearance of text

Text can be typeset in bold font using the textbfin italics using textitand in a fixed-width fontusing texttt as in the example below

24

COMP10120 Report writing and Digital Typography

Some textttsay the textbfworld will end in textitfire

which is typeset as

Some say the world will end in fire

333 Cross referencing

LATEX allows you to cross-reference almost anything inthe document which includes sections sub-sections andfigures To use the cross-referencing feature you simplyinsert the command

labelmymarker

at the point in the document you want to refer to andthen use the command

refmymarker

when you want to use the reference Obviously youreplace the text mymarkerwith something more mean-ingful An important tip here is to call the marker some-thing that refers to the content of that part of the doc-ument and to avoid the temptation to use numbers(so donrsquot call your marker section1 instead call itintroduction if you reorder your document itrsquos stilllikely to be the introduction but it may no longer beSection 1) For example

25

COMP10120 Report writing and Digital Typography

sectionReflection on Welcome WeeklabelwelcomeweekI spent most of welcome week getting to know my wayaround campus I should have made more effort to joinsocieties I think I must remember to get to theStudentsrsquo Union and take a look around there

subsectionThings I enjoyedEverything so far has been wonderful with the caveat Imentioned in Section refwelcomeweek

subsectionThings I didnrsquot enjoyIrsquove discovered that I donrsquot like soggy chips

The really useful thing about cross-referencing in LATEXis that yoursquoll get warnings when you compile your doc-ument if cross-references are undefined or used incor-rectly This means you donrsquot have to manually checkevery reference in your document to make sure itrsquos stillright You do however have to run LATEX twice forsimilar reasons to those given above

334 Figures and pictures

Including figures and pictures in your document is easyYou do it like this

beginfigure

26

COMP10120 Report writing and Digital Typography

Figure 33Some men possibly Dutch looking at cheeses

centerlineincludegraphics[width=10cm]imagesmen-and-cheesejpgcaptionSome men possibly Dutch looking at cheeseslabelfiguremenandcheesesendfigure

which is the code we used to create Figure 38 You canprobably see whatrsquos happening The command includegraphicsgets your image which can be PDF PNG JPG GIF orPostScript The beginfigureendfigurecode lsquowrapsrsquo up whatever picture yoursquore including andallows LATEX to treat it as an unbreakable floating thingthat it will position for you as best it can in the docu-ment while maintaining an overall nice typographicallayout This floating of figures can sometimes result inthe figure ending up in a place you didnrsquot expect but inmost cases LATEX will make the most sensible choice Itrsquos

27

COMP10120 Report writing and Digital Typography

possible to employ finer control over figure placementbut thatrsquos beyond the scope of this introduction

The includegraphics command is not built into core LATEX but is in an additional package whichneeds to be explicitly loaded We load this package byusing the command usepackagegraphicx in thedocument preamble ie after the documentclasscommand but before begindocument There arehundreds of such packages that extend LATEXrsquos func-tionality the lab scripts you are reading now use over30 of them

Exercise 3 Including images

Create a document imagetex that contains some text(maybe from rsquoLorem Ipsumrsquo) together with a figurecontaining an image of your choice perhaps the oneyou made in Intro Lab 2 like Steversquos Mr Noodle Thereshould also be a reference to the figure in the text Youshould first use the program convert

convert

(check its manpage) to create a PDF version of the image

Exercise 4 A reflection on your studies

Your first proper LATEX document will be a very briefreflection on your studies so far

Write a hand-crafted LATEX document called courses-reflectiontex

28

COMP10120 Report writing and Digital Typography

(exact name as usual please otherwise submitwill notwork) It will have the following structure

1 A table of contents

2 A brief paragraph saying what the document isabout

3 A section appropriately titled for one of your courseunits containing

bull a brief paragraph saying what the unit is about

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the most about the unit

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the least about the unit

A repeat of item 3 for each other unit you are study-ing These sections should appear in alphabeticalorder by course code (eg COMP10120)

After completing and successfully compiling and view-ing your document you should spell-check it as fol-lows

ispell courses-reflectiontex

29

COMP10120 Report writing and Digital Typography

Once you are completely satisfied with it produce ahard copy ready for marking

34 Typesetting Mathematics

Earlier we saw this formula

x =minusbplusmn

radicb2 minus 4ac

2aIt looks nice doesnrsquot it To tell LATEX to display thisyou have to type a bit of magic but itrsquos easily-learnedmagic To create such a formula in a WYSIWYG edi-tor there is also magic involved but it usually involvesa lot of mouse-clicking and remembering special keycombinations like rsquocontrol-thisrsquo and rsquoalt-thatrsquo In LATEXit doesnrsquot You simply type this

[ x = frac-b pm sqrtb^2-4ac2a ]

You can probably work out how most of this createsthe formula but it wonrsquot be obvious that the [ and ]symbols that enclose the formula mean lsquotypeset this asa displayed formula giving it some vertical space fromthe surrounding textrsquo If wersquod used ( and ) insteadto enclose the formula it would appear in-line like thisx = minusbplusmn

radicb2minus4ac2a It still looks very nice and observe

how itrsquos automatically been resized to fit and that the

30

COMP10120 Report writing and Digital Typography

lines of text have had their spacing changed a bit Thisall looks simple but the implementation inside LATEXand TEX is complex It involves parsing the descrip-tion of the formula to create a corresponding tree datastructure which is then recursively walked to workout the horizontal and vertical typographical spacingsneeded Yoursquoll meet these ideas in COMP11120 andCOMP26120 Algorithms and Imperative Programming

Herersquos another example taken from COMP27112Computer Graphics (itrsquos a lsquosimplersquo local illuminationmodel incorporating ambient diffuse and specular re-flection by multiple lights)

I = kaIa +

Msumi=1

Ipidprimei[kd(N middot Li) + ks(Ri middot V )n]

We write this in LATEX as follows

[ I = k_a I_a + sum_i=1^M fracI_p_idrsquo_i [ k_d(hatN cdot hatL_i)+ k_s(hatR_i cdot hatV)^n] ]

Try to match the LATEX commands with the formula dis-played above Yoursquoll see lots of curly brackets and thisexample illustrates their two uses in LATEX The firstis to provide an argument to a command for exam-ple hatN means lsquoapply the hat command to N rsquowhich creates N the vector N with a little hat on

31

COMP10120 Report writing and Digital Typography

The second use of curly brackets is to group thingstogether to avoid ambiguities In the example you cansee sum_i=1^M which creates a summation signand its lower and upper limits

sumMi=1 We wrap the

lower bound i=1 in curly brackets to group it into anindivisible unit If we were to omit the brackets writ-ing sum_i=1^M LATEX would then produce

sumi = 1M

which is not at all what we want (even LATEX canrsquot al-ways know what we really want)

One final example If we tell LATEX

[ T_1 = left[beginarraycccccos theta amp -sin theta amp 0 amp delta sin theta amp cos theta amp 0 amp epsilon 0 amp 0 amp 1 amp eta alpha amp beta amp gamma amp 1endarrayright] ]

wersquoll get a splendid matrix which expresses a particu-lar 3D geometrical transformation (Donrsquot worry if youdonrsquot recognise this yoursquoll be introduced to matrix no-tation in the latter part of COMP11120 MathematicalTechniques for Computer Science For now you can justtreat it as some mysterious maths)

32

COMP10120 Report writing and Digital Typography

T1 =

cos θ minus sin θ 0 δ

sin θ cos θ 0 ε

0 0 1 η

α β γ 1

In the LATEX code left[means lsquobig opening square

bracket pleasersquo ccccmeans lsquoan array with 4 columnsplease with the items in each column centredrsquo ampmeanslsquostart a new columnrsquo and means lsquostart a new rowrsquoYoursquoll notice that LATEX knows about greek letters itknows about most standard maths symbols too andalso the ways theyrsquore usually used

There are some symbols that you might need (forexample therefore which produces the usual threedots symbol there4) that are not part of standard LATEX Manysuch symbols are provided by the amssymb package ofsymbols compiled by the American Mathematical Soci-ety Details of the many symbols provided by this pack-age can be found online at

mirrormathkuedutex-archivefontsamsfontsdocamssymbpdf

To use these extra symbols you need to have usepackageamssymbin the document preamble

33

COMP10120 Report writing and Digital Typography

341 A longer piece of mathematics

We conclude this section with an example of a longerpiece of mathematics that shows how you might type-set a complete mathematical argument rather than asingle formula The example is Euclidrsquos proof of thefact that

radic2 is irrational Itrsquos an argument that has been

covered in COMP11120 and is an example of proof bycontradiction It starts by making the assumption thatit is not the case that

radic2 is irrational in other words that

we can find integers p and q withradic2 = pq

We can assume without losing anything that p andq have no common factors (Why)

radic2 = pq

qradic2 = p

2q2 = p2

This means that p2 is even from which we can also de-duce that p is even (Why)

This means that p = 2k for some k so

2q2 = (2k)2

there4 2q2 = 4k2

so q2 = 2k2

But this means that q2 and hence q is even Since p andq are both even we have a contradiction to our initialassumption so no such p and q exist

The way this is formatted is shown here

34

COMP10120 Report writing and Digital Typography

It starts by making the assumption that it is emphnot the casethat $sqrt2$ is irrational in other words that we can findintegers $p$ and $q$ with $sqrt2 = pq$

We can assume without losing anything that $p$ and $q$ haveemphno common factors (Why)

[beginarraylcl

sqrt2 amp = amp pq qsqrt2 amp = amp p 2q^2 amp = amp p^2

endarray]

This means that $p^2$ is even from which we can also deduce that $p$is even (Why)

This means that $p = 2k$ for some $k$ so ldots[beginarrayllcl

amp 2q^2 amp = amp (2k)^2 therefore amp 2q^2 amp = amp 4k^2 textso amp q^2 amp = amp 2k^2

endarray]

But this means that $q^2$ and hence $q$ is even Since $p$ and $q$are both even we have a contradiction to our initial assumptionso no such $p$ and $q$ exist

Notice the use of the array environment for gettingthings lined up You can find much more informationabout this on the web

LATEX really shines at typesetting mathematics and

35

COMP10120 Report writing and Digital Typography

it would take pages and pages to describe all the fea-tures Have a look at

enwikibooksorgwikiLaTeXMathematics

for a flavour

Exercise 5 Formatting mathematics

Now for an exercise that involves some mathematicsPlease create a file f-wtex which typesets the follow-ing piece of text and mathematics

There are many positive integer solutions tothe equation

x2 + y2 = z2

which can be rewritten as

z =radicx2 + y2

For example (3 4 5) or (5 12 13) Such solu-tions are called Pythagorean triples

However for higher powers the situation isvery different and we have-

Theorem Fermat-WilesFor all natural numbers n ge 3 there are no

36

COMP10120 Report writing and Digital Typography

integers x y z satisfying the equation

xn + yn = zn

35 Curriculum vitaie

There are several scenarios where using LATEX ratherthan other word processing software can be useful

bull typesetting mathematics yoursquove just read about

bull writing a technical document

bull your final year project peport

bull writing an article you want to get published

bull writing a Curriculum vitae CV

Wersquoll now look at CVrsquos briefly

Exercise 6 Curriculum vitae

Creating a professional document is especially impor-tant when you write your CV because how your CVlooks (not just the content) will determine if you are in-vited to interview for job you are applying for Thatcould be a summer internship next year a year long

37

COMP10120 Report writing and Digital Typography

placement after your second year or graduate positionafter you leave University

As well using a text-editor and compiling files fromthe command line other tools are available for editingLATEXWe will look at one of these overleafcom

Create a basic CV which describes you your edu-cation (including University) and any experience youhave or interesting projects that you may have doneYou can do this using httpsoverleafcom andchoosing the ready-made templates at httpswwwoverleafcomgallerytaggedcv

As you progress through University it is a good ideato keep your CV up to date and get feedback from asmany people as you can There will be opportunities todebug your CV later (See httpgitiomycv if youare interested) but yoursquoll need a ldquobeta releaserdquo (version10) of your CV to get started The best time to start thisprocess is now

36 Some optional extras

Exercise 7 Exploring more LATEX features (op-tional but easy)

This exercise reinforces some of the things yoursquove donealready but also introduces some features of LATEX that

38

COMP10120 Report writing and Digital Typography

will be new to you It is labelled as optional because itisnrsquot marked but we would recommend that you all tryit

Take a copy of the file optinfocoursesCOMP10120ex3latex-introtexand follow the instructions it contains You should readit before you process it with LATEX

Exercise 8 A neat directory listing (optionalmore challenging)

The fact that LATEX source files are just text makes it easyto have them generated by a program You are going toexploit this and use LATEX to produce a neat documentcontaining a listing of the files in any directory

Find how to create tables in LATEX tables using thetabular environment Make a LATEX document by handthat uses a table to neatly show the information aboutthe files in some (small) directory (as produced by ls

-l) Write a shell script called neat-ls that takes anargument which is the path name of a directory andproduces a LATEX document containing the above tablefor the given directory The script could also process theLATEX and display the resulting pdf file Finally find outabout the longtable package and change your script touse that instead

39

COMP10120 Report writing and Digital Typography

Exercise 9 A cleaning rota (optional evenmore challenging)

Now you will write a shell script called make-rota thatgenerates a house cleaning rota (Very handy for nextyear ) This is a table with columns such as KitchenBathroom and Lounge The rows will be weeks in theyear labelled with a date (eg always a Sunday) Theidea is that house mates can write their initials in theboxes promising to clean the corresponding room inthat particular week Start by making a sample tableby hand

Your script should take a single argument which isthe date of the first day of the first row eg102013(the US format for 20 Oct 13) The result will be a docu-ment that contains as many rows as fit on a single page(find out by experimenting)

The dates of each row should be generated from thefirst See the manual page for date to figure out howyou can generate a date that is a number of weeks anddays later than an existing one

361 Marking Scheme

You can view a copy of the marking scheme used bysubmit and labprint at

40

COMP10120 Report writing and Digital Typography

studentnetcsmanchesteracukugtlpmsphpunit=COMP10120ampex=ex3xml

37 Next steps

LATEX is a very powerful tool and it does take a littlegetting used to But itrsquos not as scary as it might initiallyseem and you should find that it doesnrsquot take long tolearn the common commands and techniques to makeyour documents well-structured and readable As youbecome more comfortable with the basics and under-stand the principles of typesetting finding out how todo more complex and sophisticated things is easymdashthere are hundreds of tutorials on the web

Donrsquot get carried away though and use the featuresjudiciously just because yoursquove found a cool new com-mand doesnrsquot mean that you should use it just to showoff your LATEX skills content and structure always trumpstypographic twiddlings4

4For example footnotes like this are for some reason a really tempting fea-ture to use in LATEX and in this document we have abused them mercilessly toillustrate a point Footnotes were originally a means for mechanical typeset-ters to insert comments corrections or additions to existing documents withouthaving to adjust the layout of a whole page and of course in digital typographythis is no longer necessary They can justifiably be used for citations (though itrsquosnot common to do so these days) and URLs if you donrsquot want these intrudinginto the body of your text And in some very very rare cases they can be usedas an aside to the main flow of the text (which is what has been done in this doc-ument) But this should be used sparingly If something is important to sayput it in the main body of your text If itrsquos not then perhaps you should thinkabout leaving it out completely or find some other way of including it Asking

41

COMP10120 Report writing and Digital Typography

371 Acknowledgements

Figure 38 is from the Wikipedia article on cheese

372 License

The text of this exercise is licensed under the terms ofthe Creative Commons Attribution 20 Generic (CC BY30) License

38 Background

What follows is additional contextual information aroundLATEX

LATEX was originally written by Leslie LamportW anAmerican computer scientist now working at MicrosoftResearch although its development has long been takenover by a world-wide LATEX community Itrsquos actuallybuilt on top of another system called TEX a computertypesetting system designed by one of the worldrsquos mostinfluential Computer Scientists Donald KnuthW of Stan-ford University Knuth has said that he designed TEX

the reader to look down at the bottom of a page to find out whether somethingis important or not is irritating and as yoursquove probably found out already oftenmeans you lose track of your reading position They also give the impressionthat the author isnrsquot clear about whether something is important or not whichis never good And long footnotes like this onemdashwhile LATEX will typeset themperfectly wellmdashare just plain silly Best avoid

42

COMP10120 Report writing and Digital Typography

for lsquothe creation of beautiful booksmdashand especially forbooks that contain a lot of mathematicsrsquo(D Knuth1984) Figure 34 shows what these eminent men looklike

So whatrsquos the purpose of LATEX Itrsquos purely a layerof software to make TEX easier to use in everyday sit-uations This is a good idea because although TEX isamazingly powerful it operates at a very low-level whichmakes it hard for non-expert users

Figure 34Don Knuth and Leslie Lamport

381 Pronunciation

The name TEX is intended by its creator to be pronouncedwith the final consonant as in the word loch or the nameBach but English speakers often pronounce it like thefirst syllable of technical The first syllable of LATEX is

43

COMP10120 Report writing and Digital Typography

pronounced as in rsquolayrsquo5

382 Why LATEX

Before we go any further why do we think LATEX is im-portant for youmdasha Computer Science studentmdashto knowabout Here are some reasons in no particular order

bull LATEX and TEX are superb examples of ComputerScience in action TEX was designed by Knuth fromfirst principlesmdashin other words from scratch TEXis actually a programming language and LATEX isa set of functions defined in the TEX language TheTEX lsquocompilerrsquo is written in WEBW a mixture ofdocumentation written in TeX and a PascalW sub-set in order to ensure portability it reads a TEXprogram and outputs documents TEX is completelyself-contained and designed to be portable to anycomputer architecture For example it implementsits own stackW and heapW (with garbage collectionW)and it does fixed-precision arithmeticW donrsquot worryif these terms donrsquot make much sense to you at themoment they soon will

5The Greek prefix lsquotexrsquo means lsquoartrsquo as well as lsquotechnologyrsquo so itrsquos a very nicelychosen name for a piece of software that produces such beautiful output Knuthexplained (D Knuth 1984) that one should lsquopronounce the X of TeX as a Greekchi not as an lsquoxrsquo so that TeX rhymes with the word blecchhhrsquo Wersquore not toosure that helps much unless you are confident in your pronunciation of theword lsquoblecchhrsquo Maybe itrsquos an American thing

44

COMP10120 Report writing and Digital Typography

bull LATEX is a new interesting way for you to thinkabout preparing documents

bull LATEX has a practical advantage for the writer inthat it helps you think more about what you wantto write rather than worrying about how it looks

bull LATEX is a powerful tool for professional scientificdocumentation and as a Computer Scientist youshould know about it

bull LATEX files are just plain text so can easily be cre-ated programatically For example the slides usedfor COMP16120 are generated automatically fromthe source of Johnrsquos book both are typeset usingLATEX The program labprint also produces itsoutput using LATEX using information drawn fromXMLW configuration files and ARCADE

bull Using LATEX is actually quite satisfying and thequality of its output may surprise you

In this lab session you are going to write severalshort documents using LATEX You could also write briefnotes in your logbook about how LATEX works and whatcommands you used inside the source of your docu-ments

45

COMP10120 Report writing and Digital Typography

383 Some history printing mathematics

Mathematics is hard to print on paper and on the Web(many websites resort to GIF or JPG images of mathsformulae which usually look horrible MathMLW pro-vides another approach but it is not yet widely used)

In the days before computers books and newspa-pers were printed with movable typeW made from lotsof little blocks of metal each with letters numbers andsymbols standing in relief which when inked left animpression on the paper (see Figure 35) The job ofthe printer (the printer here of course being a personnot a bit of electronics) was to gather together all theblocks in the right order between two horizontal stripsof wood to create a line of the document and then toassemble all those lines from top to bottom of a pageThus the term type settingW an incredible task whenyou think about it In the printerrsquos workshop by theway the blocks of metal were stored between jobs inwooden boxes called cases Letters like a b and c werestored in one case letters like A B and C were storedin a case sitting on top of that So a lower case and anupper case These terms may ring a bell

As technology progressed machines controlled bytypewriters would mechanically juggle the blocks intothe right order This conceptual model is the basis onwhich TEX operates Only now the metal blocks are

46

COMP10120 Report writing and Digital Typography

Figure 35On the left a piece of cast movable type in the Garamondfont On the right a case of cast metal type pieces andtypeset matter in a composing stick The text reads lsquoThequick brown fox jumps over the lazy dog and feels as if hewere in the seventh heaven of typography together with Her-mann Zapf the most famous artist of thersquo This document istypeset in a font called Palatino created by Hermann ZapfYou may have also seen rsquoZapf Dingbatsrsquo in the font lists ofvarious desktop applications Now you know why

little pieces of data arranged into data structuresThe one thing that traditional printers hated was

dealing with the typesetting of mathematics and theywould charge extra to do it It was incredibly fiddly toget the equations looking right they had to squeeze inextra bits of metal horizontally and vertically

When computers entered the printing world attemptsto print mathematics were limited by the printing tech-nology available It took a long time to reach the pointwhere computers could typeset mathematics beautifullyand that was the outstanding achievement of Knuthrsquos

47

COMP10120 Report writing and Digital Typography

TEXLetrsquos look at a quick example of the quality you get

from LATEX with a very simple formula that yoursquoll recog-nise

x =minusbplusmn

radicb2 minus 4ac

2aWersquoll revisit how LATEX typesets mathematics in Section 34

384 To WYSIWYG or not to WYSIWYG

Up until now you have probably used wordprocessingapplications such as Microsoft Word to create essaysletters and other (probably fairly short) documents Youmost likely know that the majority of modern wordprocessors use a paradigm called WYSIWYG or WhatYou See Is What You Get which means that you canmodify the visual style of the document yoursquore work-ing on by selecting the relevant bits and then choos-ing different attributes such as font size or colour usinga GUI In many ways this seems like such a sensibleand obvious way of doing things that you might bewondering why it even has a special name The rea-son is a historical one in the early days of comput-ing long before graphical window managers becamethe norm and when all you could display on screenwas fixed-width ASCII text in whatever the systemrsquos

48

COMP10120 Report writing and Digital Typography

default font was wordprocessors (eg Figure 36) onlyallowed you to format documents by using special se-quences of characters to cause particular effects Butthese effects were only visible when the document wasprinted So if you wanted a word to appear in boldtext in the wordprocessor you might write somethinglike [bold]hello world[bold] what you saw onscreen was not a direct reflection of what appeared onthe printed page If yoursquove written any HTML how-ever this process of marking up text may be familiarsee for example Figure 37 As computers moved todisplays able to draw things other than raw charac-ters on screen wordprocessors became capable of us-ing multiple fonts and styles as well as graphics anda new generation of applications appeared where whatyou saw on screen was an accurate reflection of how itwould appear when printed what you see (on screen)is what you get (on paper)

The huge advantage of WYSIWYG is that itrsquos reallyeasy to understand whatrsquos going on and most peoplecan create reasonably nicely formatted documents withrelatively little effort For short informal documentsone-off letters memos and such WYSIWYG works quitenicely But if yoursquove ever tried writing anything muchlonger or that includes images and tables you mayhave already started to see where the paradigm breaksdown For example if you write lsquoFigure 38 on page

49

COMP10120 Report writing and Digital Typography

Figure 36A screenshot of Wordperfect 51 running in Microsoft DOScirca 1989

51 shows a picture of some men looking at cheesersquo butthen later on edit your document to include some moretext at the start and a new picture of a some broccoli(as in Figure 39) yoursquod have to search through yourreport to find all mentions of lsquoFigure 38rsquo and lsquopage 51rsquoand manually update them to reflect the new number-ing This might be fine if you have two figures and fivepages but for a hundred-page report containing lots ofpictures you can see how this becomes tedious and er-ror prone very quickly

50

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 15: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

up with one or more lines sticking out proud of theright hand margin) Let your eyes relax so that yourvision blurs for a moment you can still probably spotthat the gibberish paragraph looks out of place Itrsquosquite likely that you even found creating the gibber-ish unexpectedly hard The interesting thing here isthat as humans we spend so much time reading andwriting lsquoproperrsquo natural language that we become at-tuned to the patterns of letters words and the underly-ing lsquorhythmrsquo of our written language that its very hardto artificially reproduce something that looks plausiblethe frequency of the letters you chose by randomly hit-ting keys and the length and patterns of the words youput in place most likely donrsquot match the natural pat-terns of real languages so they just look plain wrongCuriously the Lorem Ipsum text that you got from thewebsite probably doesnrsquot look so bad in spite of it notbeing made up of real words But thatrsquos not surprisingsince Lorem Ipsum is specifically created to be used asa placeholder for real text when typesetting While thewords are meaningless Latin-like things their lengthand the distribution of characters and word lengths arechosen to mimic patterns in real language

Next letrsquos give our document some structure by di-viding it up into sections On the line before BleakHouse starts add the command

22

COMP10120 Report writing and Digital Typography

sectionBleak House

making sure it appears on a line of its own Then justbefore your paragraph of gibberish put a similar in-struction (again on its own line) and then create a finalsection before the Lorem Ipsum Rerun pdflatex andlook at the results You should see the section headingsappear in the appropriate places in the PDF automati-cally having been given section numbers Experimentby adding in a couple of sub-sections towards the endof the document using the subsection commandwhich like the section command above takes as aparameter some text contained in curly brackets

Now at the top of your document after the begindocumentline and before the command defining the first sectionadd the following two commands each on their ownline

tableofcontentsnewpage

Re-run pdflatex twice and check that the effect is whatyoursquod expect You need to process the source twice be-cause on the first run LATEX gathers and stores informa-tion about what to put in the table of contents and onlycreates it on the second run

23

COMP10120 Report writing and Digital Typography

33 Common formatting features

Before we give you some more exercises to do here is abrief introduction to some commonly used features ofLATEX

331 Enumerated and bulleted lists

Creating bulleted or numbered lists in LATEX is straight-forward and is done like this

beginenumerateitem My first itemitem My second itemitem The last thing on my listendenumerate

You must make sure that you both begin and end yourlist and that each item is terminated by a newline Chang-ing enumerate to itemize gives you a bulleted ratherthan numbered list (note the American spelling of lsquoitem-izersquo)

332 Changing the appearance of text

Text can be typeset in bold font using the textbfin italics using textitand in a fixed-width fontusing texttt as in the example below

24

COMP10120 Report writing and Digital Typography

Some textttsay the textbfworld will end in textitfire

which is typeset as

Some say the world will end in fire

333 Cross referencing

LATEX allows you to cross-reference almost anything inthe document which includes sections sub-sections andfigures To use the cross-referencing feature you simplyinsert the command

labelmymarker

at the point in the document you want to refer to andthen use the command

refmymarker

when you want to use the reference Obviously youreplace the text mymarkerwith something more mean-ingful An important tip here is to call the marker some-thing that refers to the content of that part of the doc-ument and to avoid the temptation to use numbers(so donrsquot call your marker section1 instead call itintroduction if you reorder your document itrsquos stilllikely to be the introduction but it may no longer beSection 1) For example

25

COMP10120 Report writing and Digital Typography

sectionReflection on Welcome WeeklabelwelcomeweekI spent most of welcome week getting to know my wayaround campus I should have made more effort to joinsocieties I think I must remember to get to theStudentsrsquo Union and take a look around there

subsectionThings I enjoyedEverything so far has been wonderful with the caveat Imentioned in Section refwelcomeweek

subsectionThings I didnrsquot enjoyIrsquove discovered that I donrsquot like soggy chips

The really useful thing about cross-referencing in LATEXis that yoursquoll get warnings when you compile your doc-ument if cross-references are undefined or used incor-rectly This means you donrsquot have to manually checkevery reference in your document to make sure itrsquos stillright You do however have to run LATEX twice forsimilar reasons to those given above

334 Figures and pictures

Including figures and pictures in your document is easyYou do it like this

beginfigure

26

COMP10120 Report writing and Digital Typography

Figure 33Some men possibly Dutch looking at cheeses

centerlineincludegraphics[width=10cm]imagesmen-and-cheesejpgcaptionSome men possibly Dutch looking at cheeseslabelfiguremenandcheesesendfigure

which is the code we used to create Figure 38 You canprobably see whatrsquos happening The command includegraphicsgets your image which can be PDF PNG JPG GIF orPostScript The beginfigureendfigurecode lsquowrapsrsquo up whatever picture yoursquore including andallows LATEX to treat it as an unbreakable floating thingthat it will position for you as best it can in the docu-ment while maintaining an overall nice typographicallayout This floating of figures can sometimes result inthe figure ending up in a place you didnrsquot expect but inmost cases LATEX will make the most sensible choice Itrsquos

27

COMP10120 Report writing and Digital Typography

possible to employ finer control over figure placementbut thatrsquos beyond the scope of this introduction

The includegraphics command is not built into core LATEX but is in an additional package whichneeds to be explicitly loaded We load this package byusing the command usepackagegraphicx in thedocument preamble ie after the documentclasscommand but before begindocument There arehundreds of such packages that extend LATEXrsquos func-tionality the lab scripts you are reading now use over30 of them

Exercise 3 Including images

Create a document imagetex that contains some text(maybe from rsquoLorem Ipsumrsquo) together with a figurecontaining an image of your choice perhaps the oneyou made in Intro Lab 2 like Steversquos Mr Noodle Thereshould also be a reference to the figure in the text Youshould first use the program convert

convert

(check its manpage) to create a PDF version of the image

Exercise 4 A reflection on your studies

Your first proper LATEX document will be a very briefreflection on your studies so far

Write a hand-crafted LATEX document called courses-reflectiontex

28

COMP10120 Report writing and Digital Typography

(exact name as usual please otherwise submitwill notwork) It will have the following structure

1 A table of contents

2 A brief paragraph saying what the document isabout

3 A section appropriately titled for one of your courseunits containing

bull a brief paragraph saying what the unit is about

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the most about the unit

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the least about the unit

A repeat of item 3 for each other unit you are study-ing These sections should appear in alphabeticalorder by course code (eg COMP10120)

After completing and successfully compiling and view-ing your document you should spell-check it as fol-lows

ispell courses-reflectiontex

29

COMP10120 Report writing and Digital Typography

Once you are completely satisfied with it produce ahard copy ready for marking

34 Typesetting Mathematics

Earlier we saw this formula

x =minusbplusmn

radicb2 minus 4ac

2aIt looks nice doesnrsquot it To tell LATEX to display thisyou have to type a bit of magic but itrsquos easily-learnedmagic To create such a formula in a WYSIWYG edi-tor there is also magic involved but it usually involvesa lot of mouse-clicking and remembering special keycombinations like rsquocontrol-thisrsquo and rsquoalt-thatrsquo In LATEXit doesnrsquot You simply type this

[ x = frac-b pm sqrtb^2-4ac2a ]

You can probably work out how most of this createsthe formula but it wonrsquot be obvious that the [ and ]symbols that enclose the formula mean lsquotypeset this asa displayed formula giving it some vertical space fromthe surrounding textrsquo If wersquod used ( and ) insteadto enclose the formula it would appear in-line like thisx = minusbplusmn

radicb2minus4ac2a It still looks very nice and observe

how itrsquos automatically been resized to fit and that the

30

COMP10120 Report writing and Digital Typography

lines of text have had their spacing changed a bit Thisall looks simple but the implementation inside LATEXand TEX is complex It involves parsing the descrip-tion of the formula to create a corresponding tree datastructure which is then recursively walked to workout the horizontal and vertical typographical spacingsneeded Yoursquoll meet these ideas in COMP11120 andCOMP26120 Algorithms and Imperative Programming

Herersquos another example taken from COMP27112Computer Graphics (itrsquos a lsquosimplersquo local illuminationmodel incorporating ambient diffuse and specular re-flection by multiple lights)

I = kaIa +

Msumi=1

Ipidprimei[kd(N middot Li) + ks(Ri middot V )n]

We write this in LATEX as follows

[ I = k_a I_a + sum_i=1^M fracI_p_idrsquo_i [ k_d(hatN cdot hatL_i)+ k_s(hatR_i cdot hatV)^n] ]

Try to match the LATEX commands with the formula dis-played above Yoursquoll see lots of curly brackets and thisexample illustrates their two uses in LATEX The firstis to provide an argument to a command for exam-ple hatN means lsquoapply the hat command to N rsquowhich creates N the vector N with a little hat on

31

COMP10120 Report writing and Digital Typography

The second use of curly brackets is to group thingstogether to avoid ambiguities In the example you cansee sum_i=1^M which creates a summation signand its lower and upper limits

sumMi=1 We wrap the

lower bound i=1 in curly brackets to group it into anindivisible unit If we were to omit the brackets writ-ing sum_i=1^M LATEX would then produce

sumi = 1M

which is not at all what we want (even LATEX canrsquot al-ways know what we really want)

One final example If we tell LATEX

[ T_1 = left[beginarraycccccos theta amp -sin theta amp 0 amp delta sin theta amp cos theta amp 0 amp epsilon 0 amp 0 amp 1 amp eta alpha amp beta amp gamma amp 1endarrayright] ]

wersquoll get a splendid matrix which expresses a particu-lar 3D geometrical transformation (Donrsquot worry if youdonrsquot recognise this yoursquoll be introduced to matrix no-tation in the latter part of COMP11120 MathematicalTechniques for Computer Science For now you can justtreat it as some mysterious maths)

32

COMP10120 Report writing and Digital Typography

T1 =

cos θ minus sin θ 0 δ

sin θ cos θ 0 ε

0 0 1 η

α β γ 1

In the LATEX code left[means lsquobig opening square

bracket pleasersquo ccccmeans lsquoan array with 4 columnsplease with the items in each column centredrsquo ampmeanslsquostart a new columnrsquo and means lsquostart a new rowrsquoYoursquoll notice that LATEX knows about greek letters itknows about most standard maths symbols too andalso the ways theyrsquore usually used

There are some symbols that you might need (forexample therefore which produces the usual threedots symbol there4) that are not part of standard LATEX Manysuch symbols are provided by the amssymb package ofsymbols compiled by the American Mathematical Soci-ety Details of the many symbols provided by this pack-age can be found online at

mirrormathkuedutex-archivefontsamsfontsdocamssymbpdf

To use these extra symbols you need to have usepackageamssymbin the document preamble

33

COMP10120 Report writing and Digital Typography

341 A longer piece of mathematics

We conclude this section with an example of a longerpiece of mathematics that shows how you might type-set a complete mathematical argument rather than asingle formula The example is Euclidrsquos proof of thefact that

radic2 is irrational Itrsquos an argument that has been

covered in COMP11120 and is an example of proof bycontradiction It starts by making the assumption thatit is not the case that

radic2 is irrational in other words that

we can find integers p and q withradic2 = pq

We can assume without losing anything that p andq have no common factors (Why)

radic2 = pq

qradic2 = p

2q2 = p2

This means that p2 is even from which we can also de-duce that p is even (Why)

This means that p = 2k for some k so

2q2 = (2k)2

there4 2q2 = 4k2

so q2 = 2k2

But this means that q2 and hence q is even Since p andq are both even we have a contradiction to our initialassumption so no such p and q exist

The way this is formatted is shown here

34

COMP10120 Report writing and Digital Typography

It starts by making the assumption that it is emphnot the casethat $sqrt2$ is irrational in other words that we can findintegers $p$ and $q$ with $sqrt2 = pq$

We can assume without losing anything that $p$ and $q$ haveemphno common factors (Why)

[beginarraylcl

sqrt2 amp = amp pq qsqrt2 amp = amp p 2q^2 amp = amp p^2

endarray]

This means that $p^2$ is even from which we can also deduce that $p$is even (Why)

This means that $p = 2k$ for some $k$ so ldots[beginarrayllcl

amp 2q^2 amp = amp (2k)^2 therefore amp 2q^2 amp = amp 4k^2 textso amp q^2 amp = amp 2k^2

endarray]

But this means that $q^2$ and hence $q$ is even Since $p$ and $q$are both even we have a contradiction to our initial assumptionso no such $p$ and $q$ exist

Notice the use of the array environment for gettingthings lined up You can find much more informationabout this on the web

LATEX really shines at typesetting mathematics and

35

COMP10120 Report writing and Digital Typography

it would take pages and pages to describe all the fea-tures Have a look at

enwikibooksorgwikiLaTeXMathematics

for a flavour

Exercise 5 Formatting mathematics

Now for an exercise that involves some mathematicsPlease create a file f-wtex which typesets the follow-ing piece of text and mathematics

There are many positive integer solutions tothe equation

x2 + y2 = z2

which can be rewritten as

z =radicx2 + y2

For example (3 4 5) or (5 12 13) Such solu-tions are called Pythagorean triples

However for higher powers the situation isvery different and we have-

Theorem Fermat-WilesFor all natural numbers n ge 3 there are no

36

COMP10120 Report writing and Digital Typography

integers x y z satisfying the equation

xn + yn = zn

35 Curriculum vitaie

There are several scenarios where using LATEX ratherthan other word processing software can be useful

bull typesetting mathematics yoursquove just read about

bull writing a technical document

bull your final year project peport

bull writing an article you want to get published

bull writing a Curriculum vitae CV

Wersquoll now look at CVrsquos briefly

Exercise 6 Curriculum vitae

Creating a professional document is especially impor-tant when you write your CV because how your CVlooks (not just the content) will determine if you are in-vited to interview for job you are applying for Thatcould be a summer internship next year a year long

37

COMP10120 Report writing and Digital Typography

placement after your second year or graduate positionafter you leave University

As well using a text-editor and compiling files fromthe command line other tools are available for editingLATEXWe will look at one of these overleafcom

Create a basic CV which describes you your edu-cation (including University) and any experience youhave or interesting projects that you may have doneYou can do this using httpsoverleafcom andchoosing the ready-made templates at httpswwwoverleafcomgallerytaggedcv

As you progress through University it is a good ideato keep your CV up to date and get feedback from asmany people as you can There will be opportunities todebug your CV later (See httpgitiomycv if youare interested) but yoursquoll need a ldquobeta releaserdquo (version10) of your CV to get started The best time to start thisprocess is now

36 Some optional extras

Exercise 7 Exploring more LATEX features (op-tional but easy)

This exercise reinforces some of the things yoursquove donealready but also introduces some features of LATEX that

38

COMP10120 Report writing and Digital Typography

will be new to you It is labelled as optional because itisnrsquot marked but we would recommend that you all tryit

Take a copy of the file optinfocoursesCOMP10120ex3latex-introtexand follow the instructions it contains You should readit before you process it with LATEX

Exercise 8 A neat directory listing (optionalmore challenging)

The fact that LATEX source files are just text makes it easyto have them generated by a program You are going toexploit this and use LATEX to produce a neat documentcontaining a listing of the files in any directory

Find how to create tables in LATEX tables using thetabular environment Make a LATEX document by handthat uses a table to neatly show the information aboutthe files in some (small) directory (as produced by ls

-l) Write a shell script called neat-ls that takes anargument which is the path name of a directory andproduces a LATEX document containing the above tablefor the given directory The script could also process theLATEX and display the resulting pdf file Finally find outabout the longtable package and change your script touse that instead

39

COMP10120 Report writing and Digital Typography

Exercise 9 A cleaning rota (optional evenmore challenging)

Now you will write a shell script called make-rota thatgenerates a house cleaning rota (Very handy for nextyear ) This is a table with columns such as KitchenBathroom and Lounge The rows will be weeks in theyear labelled with a date (eg always a Sunday) Theidea is that house mates can write their initials in theboxes promising to clean the corresponding room inthat particular week Start by making a sample tableby hand

Your script should take a single argument which isthe date of the first day of the first row eg102013(the US format for 20 Oct 13) The result will be a docu-ment that contains as many rows as fit on a single page(find out by experimenting)

The dates of each row should be generated from thefirst See the manual page for date to figure out howyou can generate a date that is a number of weeks anddays later than an existing one

361 Marking Scheme

You can view a copy of the marking scheme used bysubmit and labprint at

40

COMP10120 Report writing and Digital Typography

studentnetcsmanchesteracukugtlpmsphpunit=COMP10120ampex=ex3xml

37 Next steps

LATEX is a very powerful tool and it does take a littlegetting used to But itrsquos not as scary as it might initiallyseem and you should find that it doesnrsquot take long tolearn the common commands and techniques to makeyour documents well-structured and readable As youbecome more comfortable with the basics and under-stand the principles of typesetting finding out how todo more complex and sophisticated things is easymdashthere are hundreds of tutorials on the web

Donrsquot get carried away though and use the featuresjudiciously just because yoursquove found a cool new com-mand doesnrsquot mean that you should use it just to showoff your LATEX skills content and structure always trumpstypographic twiddlings4

4For example footnotes like this are for some reason a really tempting fea-ture to use in LATEX and in this document we have abused them mercilessly toillustrate a point Footnotes were originally a means for mechanical typeset-ters to insert comments corrections or additions to existing documents withouthaving to adjust the layout of a whole page and of course in digital typographythis is no longer necessary They can justifiably be used for citations (though itrsquosnot common to do so these days) and URLs if you donrsquot want these intrudinginto the body of your text And in some very very rare cases they can be usedas an aside to the main flow of the text (which is what has been done in this doc-ument) But this should be used sparingly If something is important to sayput it in the main body of your text If itrsquos not then perhaps you should thinkabout leaving it out completely or find some other way of including it Asking

41

COMP10120 Report writing and Digital Typography

371 Acknowledgements

Figure 38 is from the Wikipedia article on cheese

372 License

The text of this exercise is licensed under the terms ofthe Creative Commons Attribution 20 Generic (CC BY30) License

38 Background

What follows is additional contextual information aroundLATEX

LATEX was originally written by Leslie LamportW anAmerican computer scientist now working at MicrosoftResearch although its development has long been takenover by a world-wide LATEX community Itrsquos actuallybuilt on top of another system called TEX a computertypesetting system designed by one of the worldrsquos mostinfluential Computer Scientists Donald KnuthW of Stan-ford University Knuth has said that he designed TEX

the reader to look down at the bottom of a page to find out whether somethingis important or not is irritating and as yoursquove probably found out already oftenmeans you lose track of your reading position They also give the impressionthat the author isnrsquot clear about whether something is important or not whichis never good And long footnotes like this onemdashwhile LATEX will typeset themperfectly wellmdashare just plain silly Best avoid

42

COMP10120 Report writing and Digital Typography

for lsquothe creation of beautiful booksmdashand especially forbooks that contain a lot of mathematicsrsquo(D Knuth1984) Figure 34 shows what these eminent men looklike

So whatrsquos the purpose of LATEX Itrsquos purely a layerof software to make TEX easier to use in everyday sit-uations This is a good idea because although TEX isamazingly powerful it operates at a very low-level whichmakes it hard for non-expert users

Figure 34Don Knuth and Leslie Lamport

381 Pronunciation

The name TEX is intended by its creator to be pronouncedwith the final consonant as in the word loch or the nameBach but English speakers often pronounce it like thefirst syllable of technical The first syllable of LATEX is

43

COMP10120 Report writing and Digital Typography

pronounced as in rsquolayrsquo5

382 Why LATEX

Before we go any further why do we think LATEX is im-portant for youmdasha Computer Science studentmdashto knowabout Here are some reasons in no particular order

bull LATEX and TEX are superb examples of ComputerScience in action TEX was designed by Knuth fromfirst principlesmdashin other words from scratch TEXis actually a programming language and LATEX isa set of functions defined in the TEX language TheTEX lsquocompilerrsquo is written in WEBW a mixture ofdocumentation written in TeX and a PascalW sub-set in order to ensure portability it reads a TEXprogram and outputs documents TEX is completelyself-contained and designed to be portable to anycomputer architecture For example it implementsits own stackW and heapW (with garbage collectionW)and it does fixed-precision arithmeticW donrsquot worryif these terms donrsquot make much sense to you at themoment they soon will

5The Greek prefix lsquotexrsquo means lsquoartrsquo as well as lsquotechnologyrsquo so itrsquos a very nicelychosen name for a piece of software that produces such beautiful output Knuthexplained (D Knuth 1984) that one should lsquopronounce the X of TeX as a Greekchi not as an lsquoxrsquo so that TeX rhymes with the word blecchhhrsquo Wersquore not toosure that helps much unless you are confident in your pronunciation of theword lsquoblecchhrsquo Maybe itrsquos an American thing

44

COMP10120 Report writing and Digital Typography

bull LATEX is a new interesting way for you to thinkabout preparing documents

bull LATEX has a practical advantage for the writer inthat it helps you think more about what you wantto write rather than worrying about how it looks

bull LATEX is a powerful tool for professional scientificdocumentation and as a Computer Scientist youshould know about it

bull LATEX files are just plain text so can easily be cre-ated programatically For example the slides usedfor COMP16120 are generated automatically fromthe source of Johnrsquos book both are typeset usingLATEX The program labprint also produces itsoutput using LATEX using information drawn fromXMLW configuration files and ARCADE

bull Using LATEX is actually quite satisfying and thequality of its output may surprise you

In this lab session you are going to write severalshort documents using LATEX You could also write briefnotes in your logbook about how LATEX works and whatcommands you used inside the source of your docu-ments

45

COMP10120 Report writing and Digital Typography

383 Some history printing mathematics

Mathematics is hard to print on paper and on the Web(many websites resort to GIF or JPG images of mathsformulae which usually look horrible MathMLW pro-vides another approach but it is not yet widely used)

In the days before computers books and newspa-pers were printed with movable typeW made from lotsof little blocks of metal each with letters numbers andsymbols standing in relief which when inked left animpression on the paper (see Figure 35) The job ofthe printer (the printer here of course being a personnot a bit of electronics) was to gather together all theblocks in the right order between two horizontal stripsof wood to create a line of the document and then toassemble all those lines from top to bottom of a pageThus the term type settingW an incredible task whenyou think about it In the printerrsquos workshop by theway the blocks of metal were stored between jobs inwooden boxes called cases Letters like a b and c werestored in one case letters like A B and C were storedin a case sitting on top of that So a lower case and anupper case These terms may ring a bell

As technology progressed machines controlled bytypewriters would mechanically juggle the blocks intothe right order This conceptual model is the basis onwhich TEX operates Only now the metal blocks are

46

COMP10120 Report writing and Digital Typography

Figure 35On the left a piece of cast movable type in the Garamondfont On the right a case of cast metal type pieces andtypeset matter in a composing stick The text reads lsquoThequick brown fox jumps over the lazy dog and feels as if hewere in the seventh heaven of typography together with Her-mann Zapf the most famous artist of thersquo This document istypeset in a font called Palatino created by Hermann ZapfYou may have also seen rsquoZapf Dingbatsrsquo in the font lists ofvarious desktop applications Now you know why

little pieces of data arranged into data structuresThe one thing that traditional printers hated was

dealing with the typesetting of mathematics and theywould charge extra to do it It was incredibly fiddly toget the equations looking right they had to squeeze inextra bits of metal horizontally and vertically

When computers entered the printing world attemptsto print mathematics were limited by the printing tech-nology available It took a long time to reach the pointwhere computers could typeset mathematics beautifullyand that was the outstanding achievement of Knuthrsquos

47

COMP10120 Report writing and Digital Typography

TEXLetrsquos look at a quick example of the quality you get

from LATEX with a very simple formula that yoursquoll recog-nise

x =minusbplusmn

radicb2 minus 4ac

2aWersquoll revisit how LATEX typesets mathematics in Section 34

384 To WYSIWYG or not to WYSIWYG

Up until now you have probably used wordprocessingapplications such as Microsoft Word to create essaysletters and other (probably fairly short) documents Youmost likely know that the majority of modern wordprocessors use a paradigm called WYSIWYG or WhatYou See Is What You Get which means that you canmodify the visual style of the document yoursquore work-ing on by selecting the relevant bits and then choos-ing different attributes such as font size or colour usinga GUI In many ways this seems like such a sensibleand obvious way of doing things that you might bewondering why it even has a special name The rea-son is a historical one in the early days of comput-ing long before graphical window managers becamethe norm and when all you could display on screenwas fixed-width ASCII text in whatever the systemrsquos

48

COMP10120 Report writing and Digital Typography

default font was wordprocessors (eg Figure 36) onlyallowed you to format documents by using special se-quences of characters to cause particular effects Butthese effects were only visible when the document wasprinted So if you wanted a word to appear in boldtext in the wordprocessor you might write somethinglike [bold]hello world[bold] what you saw onscreen was not a direct reflection of what appeared onthe printed page If yoursquove written any HTML how-ever this process of marking up text may be familiarsee for example Figure 37 As computers moved todisplays able to draw things other than raw charac-ters on screen wordprocessors became capable of us-ing multiple fonts and styles as well as graphics anda new generation of applications appeared where whatyou saw on screen was an accurate reflection of how itwould appear when printed what you see (on screen)is what you get (on paper)

The huge advantage of WYSIWYG is that itrsquos reallyeasy to understand whatrsquos going on and most peoplecan create reasonably nicely formatted documents withrelatively little effort For short informal documentsone-off letters memos and such WYSIWYG works quitenicely But if yoursquove ever tried writing anything muchlonger or that includes images and tables you mayhave already started to see where the paradigm breaksdown For example if you write lsquoFigure 38 on page

49

COMP10120 Report writing and Digital Typography

Figure 36A screenshot of Wordperfect 51 running in Microsoft DOScirca 1989

51 shows a picture of some men looking at cheesersquo butthen later on edit your document to include some moretext at the start and a new picture of a some broccoli(as in Figure 39) yoursquod have to search through yourreport to find all mentions of lsquoFigure 38rsquo and lsquopage 51rsquoand manually update them to reflect the new number-ing This might be fine if you have two figures and fivepages but for a hundred-page report containing lots ofpictures you can see how this becomes tedious and er-ror prone very quickly

50

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 16: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

sectionBleak House

making sure it appears on a line of its own Then justbefore your paragraph of gibberish put a similar in-struction (again on its own line) and then create a finalsection before the Lorem Ipsum Rerun pdflatex andlook at the results You should see the section headingsappear in the appropriate places in the PDF automati-cally having been given section numbers Experimentby adding in a couple of sub-sections towards the endof the document using the subsection commandwhich like the section command above takes as aparameter some text contained in curly brackets

Now at the top of your document after the begindocumentline and before the command defining the first sectionadd the following two commands each on their ownline

tableofcontentsnewpage

Re-run pdflatex twice and check that the effect is whatyoursquod expect You need to process the source twice be-cause on the first run LATEX gathers and stores informa-tion about what to put in the table of contents and onlycreates it on the second run

23

COMP10120 Report writing and Digital Typography

33 Common formatting features

Before we give you some more exercises to do here is abrief introduction to some commonly used features ofLATEX

331 Enumerated and bulleted lists

Creating bulleted or numbered lists in LATEX is straight-forward and is done like this

beginenumerateitem My first itemitem My second itemitem The last thing on my listendenumerate

You must make sure that you both begin and end yourlist and that each item is terminated by a newline Chang-ing enumerate to itemize gives you a bulleted ratherthan numbered list (note the American spelling of lsquoitem-izersquo)

332 Changing the appearance of text

Text can be typeset in bold font using the textbfin italics using textitand in a fixed-width fontusing texttt as in the example below

24

COMP10120 Report writing and Digital Typography

Some textttsay the textbfworld will end in textitfire

which is typeset as

Some say the world will end in fire

333 Cross referencing

LATEX allows you to cross-reference almost anything inthe document which includes sections sub-sections andfigures To use the cross-referencing feature you simplyinsert the command

labelmymarker

at the point in the document you want to refer to andthen use the command

refmymarker

when you want to use the reference Obviously youreplace the text mymarkerwith something more mean-ingful An important tip here is to call the marker some-thing that refers to the content of that part of the doc-ument and to avoid the temptation to use numbers(so donrsquot call your marker section1 instead call itintroduction if you reorder your document itrsquos stilllikely to be the introduction but it may no longer beSection 1) For example

25

COMP10120 Report writing and Digital Typography

sectionReflection on Welcome WeeklabelwelcomeweekI spent most of welcome week getting to know my wayaround campus I should have made more effort to joinsocieties I think I must remember to get to theStudentsrsquo Union and take a look around there

subsectionThings I enjoyedEverything so far has been wonderful with the caveat Imentioned in Section refwelcomeweek

subsectionThings I didnrsquot enjoyIrsquove discovered that I donrsquot like soggy chips

The really useful thing about cross-referencing in LATEXis that yoursquoll get warnings when you compile your doc-ument if cross-references are undefined or used incor-rectly This means you donrsquot have to manually checkevery reference in your document to make sure itrsquos stillright You do however have to run LATEX twice forsimilar reasons to those given above

334 Figures and pictures

Including figures and pictures in your document is easyYou do it like this

beginfigure

26

COMP10120 Report writing and Digital Typography

Figure 33Some men possibly Dutch looking at cheeses

centerlineincludegraphics[width=10cm]imagesmen-and-cheesejpgcaptionSome men possibly Dutch looking at cheeseslabelfiguremenandcheesesendfigure

which is the code we used to create Figure 38 You canprobably see whatrsquos happening The command includegraphicsgets your image which can be PDF PNG JPG GIF orPostScript The beginfigureendfigurecode lsquowrapsrsquo up whatever picture yoursquore including andallows LATEX to treat it as an unbreakable floating thingthat it will position for you as best it can in the docu-ment while maintaining an overall nice typographicallayout This floating of figures can sometimes result inthe figure ending up in a place you didnrsquot expect but inmost cases LATEX will make the most sensible choice Itrsquos

27

COMP10120 Report writing and Digital Typography

possible to employ finer control over figure placementbut thatrsquos beyond the scope of this introduction

The includegraphics command is not built into core LATEX but is in an additional package whichneeds to be explicitly loaded We load this package byusing the command usepackagegraphicx in thedocument preamble ie after the documentclasscommand but before begindocument There arehundreds of such packages that extend LATEXrsquos func-tionality the lab scripts you are reading now use over30 of them

Exercise 3 Including images

Create a document imagetex that contains some text(maybe from rsquoLorem Ipsumrsquo) together with a figurecontaining an image of your choice perhaps the oneyou made in Intro Lab 2 like Steversquos Mr Noodle Thereshould also be a reference to the figure in the text Youshould first use the program convert

convert

(check its manpage) to create a PDF version of the image

Exercise 4 A reflection on your studies

Your first proper LATEX document will be a very briefreflection on your studies so far

Write a hand-crafted LATEX document called courses-reflectiontex

28

COMP10120 Report writing and Digital Typography

(exact name as usual please otherwise submitwill notwork) It will have the following structure

1 A table of contents

2 A brief paragraph saying what the document isabout

3 A section appropriately titled for one of your courseunits containing

bull a brief paragraph saying what the unit is about

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the most about the unit

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the least about the unit

A repeat of item 3 for each other unit you are study-ing These sections should appear in alphabeticalorder by course code (eg COMP10120)

After completing and successfully compiling and view-ing your document you should spell-check it as fol-lows

ispell courses-reflectiontex

29

COMP10120 Report writing and Digital Typography

Once you are completely satisfied with it produce ahard copy ready for marking

34 Typesetting Mathematics

Earlier we saw this formula

x =minusbplusmn

radicb2 minus 4ac

2aIt looks nice doesnrsquot it To tell LATEX to display thisyou have to type a bit of magic but itrsquos easily-learnedmagic To create such a formula in a WYSIWYG edi-tor there is also magic involved but it usually involvesa lot of mouse-clicking and remembering special keycombinations like rsquocontrol-thisrsquo and rsquoalt-thatrsquo In LATEXit doesnrsquot You simply type this

[ x = frac-b pm sqrtb^2-4ac2a ]

You can probably work out how most of this createsthe formula but it wonrsquot be obvious that the [ and ]symbols that enclose the formula mean lsquotypeset this asa displayed formula giving it some vertical space fromthe surrounding textrsquo If wersquod used ( and ) insteadto enclose the formula it would appear in-line like thisx = minusbplusmn

radicb2minus4ac2a It still looks very nice and observe

how itrsquos automatically been resized to fit and that the

30

COMP10120 Report writing and Digital Typography

lines of text have had their spacing changed a bit Thisall looks simple but the implementation inside LATEXand TEX is complex It involves parsing the descrip-tion of the formula to create a corresponding tree datastructure which is then recursively walked to workout the horizontal and vertical typographical spacingsneeded Yoursquoll meet these ideas in COMP11120 andCOMP26120 Algorithms and Imperative Programming

Herersquos another example taken from COMP27112Computer Graphics (itrsquos a lsquosimplersquo local illuminationmodel incorporating ambient diffuse and specular re-flection by multiple lights)

I = kaIa +

Msumi=1

Ipidprimei[kd(N middot Li) + ks(Ri middot V )n]

We write this in LATEX as follows

[ I = k_a I_a + sum_i=1^M fracI_p_idrsquo_i [ k_d(hatN cdot hatL_i)+ k_s(hatR_i cdot hatV)^n] ]

Try to match the LATEX commands with the formula dis-played above Yoursquoll see lots of curly brackets and thisexample illustrates their two uses in LATEX The firstis to provide an argument to a command for exam-ple hatN means lsquoapply the hat command to N rsquowhich creates N the vector N with a little hat on

31

COMP10120 Report writing and Digital Typography

The second use of curly brackets is to group thingstogether to avoid ambiguities In the example you cansee sum_i=1^M which creates a summation signand its lower and upper limits

sumMi=1 We wrap the

lower bound i=1 in curly brackets to group it into anindivisible unit If we were to omit the brackets writ-ing sum_i=1^M LATEX would then produce

sumi = 1M

which is not at all what we want (even LATEX canrsquot al-ways know what we really want)

One final example If we tell LATEX

[ T_1 = left[beginarraycccccos theta amp -sin theta amp 0 amp delta sin theta amp cos theta amp 0 amp epsilon 0 amp 0 amp 1 amp eta alpha amp beta amp gamma amp 1endarrayright] ]

wersquoll get a splendid matrix which expresses a particu-lar 3D geometrical transformation (Donrsquot worry if youdonrsquot recognise this yoursquoll be introduced to matrix no-tation in the latter part of COMP11120 MathematicalTechniques for Computer Science For now you can justtreat it as some mysterious maths)

32

COMP10120 Report writing and Digital Typography

T1 =

cos θ minus sin θ 0 δ

sin θ cos θ 0 ε

0 0 1 η

α β γ 1

In the LATEX code left[means lsquobig opening square

bracket pleasersquo ccccmeans lsquoan array with 4 columnsplease with the items in each column centredrsquo ampmeanslsquostart a new columnrsquo and means lsquostart a new rowrsquoYoursquoll notice that LATEX knows about greek letters itknows about most standard maths symbols too andalso the ways theyrsquore usually used

There are some symbols that you might need (forexample therefore which produces the usual threedots symbol there4) that are not part of standard LATEX Manysuch symbols are provided by the amssymb package ofsymbols compiled by the American Mathematical Soci-ety Details of the many symbols provided by this pack-age can be found online at

mirrormathkuedutex-archivefontsamsfontsdocamssymbpdf

To use these extra symbols you need to have usepackageamssymbin the document preamble

33

COMP10120 Report writing and Digital Typography

341 A longer piece of mathematics

We conclude this section with an example of a longerpiece of mathematics that shows how you might type-set a complete mathematical argument rather than asingle formula The example is Euclidrsquos proof of thefact that

radic2 is irrational Itrsquos an argument that has been

covered in COMP11120 and is an example of proof bycontradiction It starts by making the assumption thatit is not the case that

radic2 is irrational in other words that

we can find integers p and q withradic2 = pq

We can assume without losing anything that p andq have no common factors (Why)

radic2 = pq

qradic2 = p

2q2 = p2

This means that p2 is even from which we can also de-duce that p is even (Why)

This means that p = 2k for some k so

2q2 = (2k)2

there4 2q2 = 4k2

so q2 = 2k2

But this means that q2 and hence q is even Since p andq are both even we have a contradiction to our initialassumption so no such p and q exist

The way this is formatted is shown here

34

COMP10120 Report writing and Digital Typography

It starts by making the assumption that it is emphnot the casethat $sqrt2$ is irrational in other words that we can findintegers $p$ and $q$ with $sqrt2 = pq$

We can assume without losing anything that $p$ and $q$ haveemphno common factors (Why)

[beginarraylcl

sqrt2 amp = amp pq qsqrt2 amp = amp p 2q^2 amp = amp p^2

endarray]

This means that $p^2$ is even from which we can also deduce that $p$is even (Why)

This means that $p = 2k$ for some $k$ so ldots[beginarrayllcl

amp 2q^2 amp = amp (2k)^2 therefore amp 2q^2 amp = amp 4k^2 textso amp q^2 amp = amp 2k^2

endarray]

But this means that $q^2$ and hence $q$ is even Since $p$ and $q$are both even we have a contradiction to our initial assumptionso no such $p$ and $q$ exist

Notice the use of the array environment for gettingthings lined up You can find much more informationabout this on the web

LATEX really shines at typesetting mathematics and

35

COMP10120 Report writing and Digital Typography

it would take pages and pages to describe all the fea-tures Have a look at

enwikibooksorgwikiLaTeXMathematics

for a flavour

Exercise 5 Formatting mathematics

Now for an exercise that involves some mathematicsPlease create a file f-wtex which typesets the follow-ing piece of text and mathematics

There are many positive integer solutions tothe equation

x2 + y2 = z2

which can be rewritten as

z =radicx2 + y2

For example (3 4 5) or (5 12 13) Such solu-tions are called Pythagorean triples

However for higher powers the situation isvery different and we have-

Theorem Fermat-WilesFor all natural numbers n ge 3 there are no

36

COMP10120 Report writing and Digital Typography

integers x y z satisfying the equation

xn + yn = zn

35 Curriculum vitaie

There are several scenarios where using LATEX ratherthan other word processing software can be useful

bull typesetting mathematics yoursquove just read about

bull writing a technical document

bull your final year project peport

bull writing an article you want to get published

bull writing a Curriculum vitae CV

Wersquoll now look at CVrsquos briefly

Exercise 6 Curriculum vitae

Creating a professional document is especially impor-tant when you write your CV because how your CVlooks (not just the content) will determine if you are in-vited to interview for job you are applying for Thatcould be a summer internship next year a year long

37

COMP10120 Report writing and Digital Typography

placement after your second year or graduate positionafter you leave University

As well using a text-editor and compiling files fromthe command line other tools are available for editingLATEXWe will look at one of these overleafcom

Create a basic CV which describes you your edu-cation (including University) and any experience youhave or interesting projects that you may have doneYou can do this using httpsoverleafcom andchoosing the ready-made templates at httpswwwoverleafcomgallerytaggedcv

As you progress through University it is a good ideato keep your CV up to date and get feedback from asmany people as you can There will be opportunities todebug your CV later (See httpgitiomycv if youare interested) but yoursquoll need a ldquobeta releaserdquo (version10) of your CV to get started The best time to start thisprocess is now

36 Some optional extras

Exercise 7 Exploring more LATEX features (op-tional but easy)

This exercise reinforces some of the things yoursquove donealready but also introduces some features of LATEX that

38

COMP10120 Report writing and Digital Typography

will be new to you It is labelled as optional because itisnrsquot marked but we would recommend that you all tryit

Take a copy of the file optinfocoursesCOMP10120ex3latex-introtexand follow the instructions it contains You should readit before you process it with LATEX

Exercise 8 A neat directory listing (optionalmore challenging)

The fact that LATEX source files are just text makes it easyto have them generated by a program You are going toexploit this and use LATEX to produce a neat documentcontaining a listing of the files in any directory

Find how to create tables in LATEX tables using thetabular environment Make a LATEX document by handthat uses a table to neatly show the information aboutthe files in some (small) directory (as produced by ls

-l) Write a shell script called neat-ls that takes anargument which is the path name of a directory andproduces a LATEX document containing the above tablefor the given directory The script could also process theLATEX and display the resulting pdf file Finally find outabout the longtable package and change your script touse that instead

39

COMP10120 Report writing and Digital Typography

Exercise 9 A cleaning rota (optional evenmore challenging)

Now you will write a shell script called make-rota thatgenerates a house cleaning rota (Very handy for nextyear ) This is a table with columns such as KitchenBathroom and Lounge The rows will be weeks in theyear labelled with a date (eg always a Sunday) Theidea is that house mates can write their initials in theboxes promising to clean the corresponding room inthat particular week Start by making a sample tableby hand

Your script should take a single argument which isthe date of the first day of the first row eg102013(the US format for 20 Oct 13) The result will be a docu-ment that contains as many rows as fit on a single page(find out by experimenting)

The dates of each row should be generated from thefirst See the manual page for date to figure out howyou can generate a date that is a number of weeks anddays later than an existing one

361 Marking Scheme

You can view a copy of the marking scheme used bysubmit and labprint at

40

COMP10120 Report writing and Digital Typography

studentnetcsmanchesteracukugtlpmsphpunit=COMP10120ampex=ex3xml

37 Next steps

LATEX is a very powerful tool and it does take a littlegetting used to But itrsquos not as scary as it might initiallyseem and you should find that it doesnrsquot take long tolearn the common commands and techniques to makeyour documents well-structured and readable As youbecome more comfortable with the basics and under-stand the principles of typesetting finding out how todo more complex and sophisticated things is easymdashthere are hundreds of tutorials on the web

Donrsquot get carried away though and use the featuresjudiciously just because yoursquove found a cool new com-mand doesnrsquot mean that you should use it just to showoff your LATEX skills content and structure always trumpstypographic twiddlings4

4For example footnotes like this are for some reason a really tempting fea-ture to use in LATEX and in this document we have abused them mercilessly toillustrate a point Footnotes were originally a means for mechanical typeset-ters to insert comments corrections or additions to existing documents withouthaving to adjust the layout of a whole page and of course in digital typographythis is no longer necessary They can justifiably be used for citations (though itrsquosnot common to do so these days) and URLs if you donrsquot want these intrudinginto the body of your text And in some very very rare cases they can be usedas an aside to the main flow of the text (which is what has been done in this doc-ument) But this should be used sparingly If something is important to sayput it in the main body of your text If itrsquos not then perhaps you should thinkabout leaving it out completely or find some other way of including it Asking

41

COMP10120 Report writing and Digital Typography

371 Acknowledgements

Figure 38 is from the Wikipedia article on cheese

372 License

The text of this exercise is licensed under the terms ofthe Creative Commons Attribution 20 Generic (CC BY30) License

38 Background

What follows is additional contextual information aroundLATEX

LATEX was originally written by Leslie LamportW anAmerican computer scientist now working at MicrosoftResearch although its development has long been takenover by a world-wide LATEX community Itrsquos actuallybuilt on top of another system called TEX a computertypesetting system designed by one of the worldrsquos mostinfluential Computer Scientists Donald KnuthW of Stan-ford University Knuth has said that he designed TEX

the reader to look down at the bottom of a page to find out whether somethingis important or not is irritating and as yoursquove probably found out already oftenmeans you lose track of your reading position They also give the impressionthat the author isnrsquot clear about whether something is important or not whichis never good And long footnotes like this onemdashwhile LATEX will typeset themperfectly wellmdashare just plain silly Best avoid

42

COMP10120 Report writing and Digital Typography

for lsquothe creation of beautiful booksmdashand especially forbooks that contain a lot of mathematicsrsquo(D Knuth1984) Figure 34 shows what these eminent men looklike

So whatrsquos the purpose of LATEX Itrsquos purely a layerof software to make TEX easier to use in everyday sit-uations This is a good idea because although TEX isamazingly powerful it operates at a very low-level whichmakes it hard for non-expert users

Figure 34Don Knuth and Leslie Lamport

381 Pronunciation

The name TEX is intended by its creator to be pronouncedwith the final consonant as in the word loch or the nameBach but English speakers often pronounce it like thefirst syllable of technical The first syllable of LATEX is

43

COMP10120 Report writing and Digital Typography

pronounced as in rsquolayrsquo5

382 Why LATEX

Before we go any further why do we think LATEX is im-portant for youmdasha Computer Science studentmdashto knowabout Here are some reasons in no particular order

bull LATEX and TEX are superb examples of ComputerScience in action TEX was designed by Knuth fromfirst principlesmdashin other words from scratch TEXis actually a programming language and LATEX isa set of functions defined in the TEX language TheTEX lsquocompilerrsquo is written in WEBW a mixture ofdocumentation written in TeX and a PascalW sub-set in order to ensure portability it reads a TEXprogram and outputs documents TEX is completelyself-contained and designed to be portable to anycomputer architecture For example it implementsits own stackW and heapW (with garbage collectionW)and it does fixed-precision arithmeticW donrsquot worryif these terms donrsquot make much sense to you at themoment they soon will

5The Greek prefix lsquotexrsquo means lsquoartrsquo as well as lsquotechnologyrsquo so itrsquos a very nicelychosen name for a piece of software that produces such beautiful output Knuthexplained (D Knuth 1984) that one should lsquopronounce the X of TeX as a Greekchi not as an lsquoxrsquo so that TeX rhymes with the word blecchhhrsquo Wersquore not toosure that helps much unless you are confident in your pronunciation of theword lsquoblecchhrsquo Maybe itrsquos an American thing

44

COMP10120 Report writing and Digital Typography

bull LATEX is a new interesting way for you to thinkabout preparing documents

bull LATEX has a practical advantage for the writer inthat it helps you think more about what you wantto write rather than worrying about how it looks

bull LATEX is a powerful tool for professional scientificdocumentation and as a Computer Scientist youshould know about it

bull LATEX files are just plain text so can easily be cre-ated programatically For example the slides usedfor COMP16120 are generated automatically fromthe source of Johnrsquos book both are typeset usingLATEX The program labprint also produces itsoutput using LATEX using information drawn fromXMLW configuration files and ARCADE

bull Using LATEX is actually quite satisfying and thequality of its output may surprise you

In this lab session you are going to write severalshort documents using LATEX You could also write briefnotes in your logbook about how LATEX works and whatcommands you used inside the source of your docu-ments

45

COMP10120 Report writing and Digital Typography

383 Some history printing mathematics

Mathematics is hard to print on paper and on the Web(many websites resort to GIF or JPG images of mathsformulae which usually look horrible MathMLW pro-vides another approach but it is not yet widely used)

In the days before computers books and newspa-pers were printed with movable typeW made from lotsof little blocks of metal each with letters numbers andsymbols standing in relief which when inked left animpression on the paper (see Figure 35) The job ofthe printer (the printer here of course being a personnot a bit of electronics) was to gather together all theblocks in the right order between two horizontal stripsof wood to create a line of the document and then toassemble all those lines from top to bottom of a pageThus the term type settingW an incredible task whenyou think about it In the printerrsquos workshop by theway the blocks of metal were stored between jobs inwooden boxes called cases Letters like a b and c werestored in one case letters like A B and C were storedin a case sitting on top of that So a lower case and anupper case These terms may ring a bell

As technology progressed machines controlled bytypewriters would mechanically juggle the blocks intothe right order This conceptual model is the basis onwhich TEX operates Only now the metal blocks are

46

COMP10120 Report writing and Digital Typography

Figure 35On the left a piece of cast movable type in the Garamondfont On the right a case of cast metal type pieces andtypeset matter in a composing stick The text reads lsquoThequick brown fox jumps over the lazy dog and feels as if hewere in the seventh heaven of typography together with Her-mann Zapf the most famous artist of thersquo This document istypeset in a font called Palatino created by Hermann ZapfYou may have also seen rsquoZapf Dingbatsrsquo in the font lists ofvarious desktop applications Now you know why

little pieces of data arranged into data structuresThe one thing that traditional printers hated was

dealing with the typesetting of mathematics and theywould charge extra to do it It was incredibly fiddly toget the equations looking right they had to squeeze inextra bits of metal horizontally and vertically

When computers entered the printing world attemptsto print mathematics were limited by the printing tech-nology available It took a long time to reach the pointwhere computers could typeset mathematics beautifullyand that was the outstanding achievement of Knuthrsquos

47

COMP10120 Report writing and Digital Typography

TEXLetrsquos look at a quick example of the quality you get

from LATEX with a very simple formula that yoursquoll recog-nise

x =minusbplusmn

radicb2 minus 4ac

2aWersquoll revisit how LATEX typesets mathematics in Section 34

384 To WYSIWYG or not to WYSIWYG

Up until now you have probably used wordprocessingapplications such as Microsoft Word to create essaysletters and other (probably fairly short) documents Youmost likely know that the majority of modern wordprocessors use a paradigm called WYSIWYG or WhatYou See Is What You Get which means that you canmodify the visual style of the document yoursquore work-ing on by selecting the relevant bits and then choos-ing different attributes such as font size or colour usinga GUI In many ways this seems like such a sensibleand obvious way of doing things that you might bewondering why it even has a special name The rea-son is a historical one in the early days of comput-ing long before graphical window managers becamethe norm and when all you could display on screenwas fixed-width ASCII text in whatever the systemrsquos

48

COMP10120 Report writing and Digital Typography

default font was wordprocessors (eg Figure 36) onlyallowed you to format documents by using special se-quences of characters to cause particular effects Butthese effects were only visible when the document wasprinted So if you wanted a word to appear in boldtext in the wordprocessor you might write somethinglike [bold]hello world[bold] what you saw onscreen was not a direct reflection of what appeared onthe printed page If yoursquove written any HTML how-ever this process of marking up text may be familiarsee for example Figure 37 As computers moved todisplays able to draw things other than raw charac-ters on screen wordprocessors became capable of us-ing multiple fonts and styles as well as graphics anda new generation of applications appeared where whatyou saw on screen was an accurate reflection of how itwould appear when printed what you see (on screen)is what you get (on paper)

The huge advantage of WYSIWYG is that itrsquos reallyeasy to understand whatrsquos going on and most peoplecan create reasonably nicely formatted documents withrelatively little effort For short informal documentsone-off letters memos and such WYSIWYG works quitenicely But if yoursquove ever tried writing anything muchlonger or that includes images and tables you mayhave already started to see where the paradigm breaksdown For example if you write lsquoFigure 38 on page

49

COMP10120 Report writing and Digital Typography

Figure 36A screenshot of Wordperfect 51 running in Microsoft DOScirca 1989

51 shows a picture of some men looking at cheesersquo butthen later on edit your document to include some moretext at the start and a new picture of a some broccoli(as in Figure 39) yoursquod have to search through yourreport to find all mentions of lsquoFigure 38rsquo and lsquopage 51rsquoand manually update them to reflect the new number-ing This might be fine if you have two figures and fivepages but for a hundred-page report containing lots ofpictures you can see how this becomes tedious and er-ror prone very quickly

50

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 17: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

33 Common formatting features

Before we give you some more exercises to do here is abrief introduction to some commonly used features ofLATEX

331 Enumerated and bulleted lists

Creating bulleted or numbered lists in LATEX is straight-forward and is done like this

beginenumerateitem My first itemitem My second itemitem The last thing on my listendenumerate

You must make sure that you both begin and end yourlist and that each item is terminated by a newline Chang-ing enumerate to itemize gives you a bulleted ratherthan numbered list (note the American spelling of lsquoitem-izersquo)

332 Changing the appearance of text

Text can be typeset in bold font using the textbfin italics using textitand in a fixed-width fontusing texttt as in the example below

24

COMP10120 Report writing and Digital Typography

Some textttsay the textbfworld will end in textitfire

which is typeset as

Some say the world will end in fire

333 Cross referencing

LATEX allows you to cross-reference almost anything inthe document which includes sections sub-sections andfigures To use the cross-referencing feature you simplyinsert the command

labelmymarker

at the point in the document you want to refer to andthen use the command

refmymarker

when you want to use the reference Obviously youreplace the text mymarkerwith something more mean-ingful An important tip here is to call the marker some-thing that refers to the content of that part of the doc-ument and to avoid the temptation to use numbers(so donrsquot call your marker section1 instead call itintroduction if you reorder your document itrsquos stilllikely to be the introduction but it may no longer beSection 1) For example

25

COMP10120 Report writing and Digital Typography

sectionReflection on Welcome WeeklabelwelcomeweekI spent most of welcome week getting to know my wayaround campus I should have made more effort to joinsocieties I think I must remember to get to theStudentsrsquo Union and take a look around there

subsectionThings I enjoyedEverything so far has been wonderful with the caveat Imentioned in Section refwelcomeweek

subsectionThings I didnrsquot enjoyIrsquove discovered that I donrsquot like soggy chips

The really useful thing about cross-referencing in LATEXis that yoursquoll get warnings when you compile your doc-ument if cross-references are undefined or used incor-rectly This means you donrsquot have to manually checkevery reference in your document to make sure itrsquos stillright You do however have to run LATEX twice forsimilar reasons to those given above

334 Figures and pictures

Including figures and pictures in your document is easyYou do it like this

beginfigure

26

COMP10120 Report writing and Digital Typography

Figure 33Some men possibly Dutch looking at cheeses

centerlineincludegraphics[width=10cm]imagesmen-and-cheesejpgcaptionSome men possibly Dutch looking at cheeseslabelfiguremenandcheesesendfigure

which is the code we used to create Figure 38 You canprobably see whatrsquos happening The command includegraphicsgets your image which can be PDF PNG JPG GIF orPostScript The beginfigureendfigurecode lsquowrapsrsquo up whatever picture yoursquore including andallows LATEX to treat it as an unbreakable floating thingthat it will position for you as best it can in the docu-ment while maintaining an overall nice typographicallayout This floating of figures can sometimes result inthe figure ending up in a place you didnrsquot expect but inmost cases LATEX will make the most sensible choice Itrsquos

27

COMP10120 Report writing and Digital Typography

possible to employ finer control over figure placementbut thatrsquos beyond the scope of this introduction

The includegraphics command is not built into core LATEX but is in an additional package whichneeds to be explicitly loaded We load this package byusing the command usepackagegraphicx in thedocument preamble ie after the documentclasscommand but before begindocument There arehundreds of such packages that extend LATEXrsquos func-tionality the lab scripts you are reading now use over30 of them

Exercise 3 Including images

Create a document imagetex that contains some text(maybe from rsquoLorem Ipsumrsquo) together with a figurecontaining an image of your choice perhaps the oneyou made in Intro Lab 2 like Steversquos Mr Noodle Thereshould also be a reference to the figure in the text Youshould first use the program convert

convert

(check its manpage) to create a PDF version of the image

Exercise 4 A reflection on your studies

Your first proper LATEX document will be a very briefreflection on your studies so far

Write a hand-crafted LATEX document called courses-reflectiontex

28

COMP10120 Report writing and Digital Typography

(exact name as usual please otherwise submitwill notwork) It will have the following structure

1 A table of contents

2 A brief paragraph saying what the document isabout

3 A section appropriately titled for one of your courseunits containing

bull a brief paragraph saying what the unit is about

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the most about the unit

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the least about the unit

A repeat of item 3 for each other unit you are study-ing These sections should appear in alphabeticalorder by course code (eg COMP10120)

After completing and successfully compiling and view-ing your document you should spell-check it as fol-lows

ispell courses-reflectiontex

29

COMP10120 Report writing and Digital Typography

Once you are completely satisfied with it produce ahard copy ready for marking

34 Typesetting Mathematics

Earlier we saw this formula

x =minusbplusmn

radicb2 minus 4ac

2aIt looks nice doesnrsquot it To tell LATEX to display thisyou have to type a bit of magic but itrsquos easily-learnedmagic To create such a formula in a WYSIWYG edi-tor there is also magic involved but it usually involvesa lot of mouse-clicking and remembering special keycombinations like rsquocontrol-thisrsquo and rsquoalt-thatrsquo In LATEXit doesnrsquot You simply type this

[ x = frac-b pm sqrtb^2-4ac2a ]

You can probably work out how most of this createsthe formula but it wonrsquot be obvious that the [ and ]symbols that enclose the formula mean lsquotypeset this asa displayed formula giving it some vertical space fromthe surrounding textrsquo If wersquod used ( and ) insteadto enclose the formula it would appear in-line like thisx = minusbplusmn

radicb2minus4ac2a It still looks very nice and observe

how itrsquos automatically been resized to fit and that the

30

COMP10120 Report writing and Digital Typography

lines of text have had their spacing changed a bit Thisall looks simple but the implementation inside LATEXand TEX is complex It involves parsing the descrip-tion of the formula to create a corresponding tree datastructure which is then recursively walked to workout the horizontal and vertical typographical spacingsneeded Yoursquoll meet these ideas in COMP11120 andCOMP26120 Algorithms and Imperative Programming

Herersquos another example taken from COMP27112Computer Graphics (itrsquos a lsquosimplersquo local illuminationmodel incorporating ambient diffuse and specular re-flection by multiple lights)

I = kaIa +

Msumi=1

Ipidprimei[kd(N middot Li) + ks(Ri middot V )n]

We write this in LATEX as follows

[ I = k_a I_a + sum_i=1^M fracI_p_idrsquo_i [ k_d(hatN cdot hatL_i)+ k_s(hatR_i cdot hatV)^n] ]

Try to match the LATEX commands with the formula dis-played above Yoursquoll see lots of curly brackets and thisexample illustrates their two uses in LATEX The firstis to provide an argument to a command for exam-ple hatN means lsquoapply the hat command to N rsquowhich creates N the vector N with a little hat on

31

COMP10120 Report writing and Digital Typography

The second use of curly brackets is to group thingstogether to avoid ambiguities In the example you cansee sum_i=1^M which creates a summation signand its lower and upper limits

sumMi=1 We wrap the

lower bound i=1 in curly brackets to group it into anindivisible unit If we were to omit the brackets writ-ing sum_i=1^M LATEX would then produce

sumi = 1M

which is not at all what we want (even LATEX canrsquot al-ways know what we really want)

One final example If we tell LATEX

[ T_1 = left[beginarraycccccos theta amp -sin theta amp 0 amp delta sin theta amp cos theta amp 0 amp epsilon 0 amp 0 amp 1 amp eta alpha amp beta amp gamma amp 1endarrayright] ]

wersquoll get a splendid matrix which expresses a particu-lar 3D geometrical transformation (Donrsquot worry if youdonrsquot recognise this yoursquoll be introduced to matrix no-tation in the latter part of COMP11120 MathematicalTechniques for Computer Science For now you can justtreat it as some mysterious maths)

32

COMP10120 Report writing and Digital Typography

T1 =

cos θ minus sin θ 0 δ

sin θ cos θ 0 ε

0 0 1 η

α β γ 1

In the LATEX code left[means lsquobig opening square

bracket pleasersquo ccccmeans lsquoan array with 4 columnsplease with the items in each column centredrsquo ampmeanslsquostart a new columnrsquo and means lsquostart a new rowrsquoYoursquoll notice that LATEX knows about greek letters itknows about most standard maths symbols too andalso the ways theyrsquore usually used

There are some symbols that you might need (forexample therefore which produces the usual threedots symbol there4) that are not part of standard LATEX Manysuch symbols are provided by the amssymb package ofsymbols compiled by the American Mathematical Soci-ety Details of the many symbols provided by this pack-age can be found online at

mirrormathkuedutex-archivefontsamsfontsdocamssymbpdf

To use these extra symbols you need to have usepackageamssymbin the document preamble

33

COMP10120 Report writing and Digital Typography

341 A longer piece of mathematics

We conclude this section with an example of a longerpiece of mathematics that shows how you might type-set a complete mathematical argument rather than asingle formula The example is Euclidrsquos proof of thefact that

radic2 is irrational Itrsquos an argument that has been

covered in COMP11120 and is an example of proof bycontradiction It starts by making the assumption thatit is not the case that

radic2 is irrational in other words that

we can find integers p and q withradic2 = pq

We can assume without losing anything that p andq have no common factors (Why)

radic2 = pq

qradic2 = p

2q2 = p2

This means that p2 is even from which we can also de-duce that p is even (Why)

This means that p = 2k for some k so

2q2 = (2k)2

there4 2q2 = 4k2

so q2 = 2k2

But this means that q2 and hence q is even Since p andq are both even we have a contradiction to our initialassumption so no such p and q exist

The way this is formatted is shown here

34

COMP10120 Report writing and Digital Typography

It starts by making the assumption that it is emphnot the casethat $sqrt2$ is irrational in other words that we can findintegers $p$ and $q$ with $sqrt2 = pq$

We can assume without losing anything that $p$ and $q$ haveemphno common factors (Why)

[beginarraylcl

sqrt2 amp = amp pq qsqrt2 amp = amp p 2q^2 amp = amp p^2

endarray]

This means that $p^2$ is even from which we can also deduce that $p$is even (Why)

This means that $p = 2k$ for some $k$ so ldots[beginarrayllcl

amp 2q^2 amp = amp (2k)^2 therefore amp 2q^2 amp = amp 4k^2 textso amp q^2 amp = amp 2k^2

endarray]

But this means that $q^2$ and hence $q$ is even Since $p$ and $q$are both even we have a contradiction to our initial assumptionso no such $p$ and $q$ exist

Notice the use of the array environment for gettingthings lined up You can find much more informationabout this on the web

LATEX really shines at typesetting mathematics and

35

COMP10120 Report writing and Digital Typography

it would take pages and pages to describe all the fea-tures Have a look at

enwikibooksorgwikiLaTeXMathematics

for a flavour

Exercise 5 Formatting mathematics

Now for an exercise that involves some mathematicsPlease create a file f-wtex which typesets the follow-ing piece of text and mathematics

There are many positive integer solutions tothe equation

x2 + y2 = z2

which can be rewritten as

z =radicx2 + y2

For example (3 4 5) or (5 12 13) Such solu-tions are called Pythagorean triples

However for higher powers the situation isvery different and we have-

Theorem Fermat-WilesFor all natural numbers n ge 3 there are no

36

COMP10120 Report writing and Digital Typography

integers x y z satisfying the equation

xn + yn = zn

35 Curriculum vitaie

There are several scenarios where using LATEX ratherthan other word processing software can be useful

bull typesetting mathematics yoursquove just read about

bull writing a technical document

bull your final year project peport

bull writing an article you want to get published

bull writing a Curriculum vitae CV

Wersquoll now look at CVrsquos briefly

Exercise 6 Curriculum vitae

Creating a professional document is especially impor-tant when you write your CV because how your CVlooks (not just the content) will determine if you are in-vited to interview for job you are applying for Thatcould be a summer internship next year a year long

37

COMP10120 Report writing and Digital Typography

placement after your second year or graduate positionafter you leave University

As well using a text-editor and compiling files fromthe command line other tools are available for editingLATEXWe will look at one of these overleafcom

Create a basic CV which describes you your edu-cation (including University) and any experience youhave or interesting projects that you may have doneYou can do this using httpsoverleafcom andchoosing the ready-made templates at httpswwwoverleafcomgallerytaggedcv

As you progress through University it is a good ideato keep your CV up to date and get feedback from asmany people as you can There will be opportunities todebug your CV later (See httpgitiomycv if youare interested) but yoursquoll need a ldquobeta releaserdquo (version10) of your CV to get started The best time to start thisprocess is now

36 Some optional extras

Exercise 7 Exploring more LATEX features (op-tional but easy)

This exercise reinforces some of the things yoursquove donealready but also introduces some features of LATEX that

38

COMP10120 Report writing and Digital Typography

will be new to you It is labelled as optional because itisnrsquot marked but we would recommend that you all tryit

Take a copy of the file optinfocoursesCOMP10120ex3latex-introtexand follow the instructions it contains You should readit before you process it with LATEX

Exercise 8 A neat directory listing (optionalmore challenging)

The fact that LATEX source files are just text makes it easyto have them generated by a program You are going toexploit this and use LATEX to produce a neat documentcontaining a listing of the files in any directory

Find how to create tables in LATEX tables using thetabular environment Make a LATEX document by handthat uses a table to neatly show the information aboutthe files in some (small) directory (as produced by ls

-l) Write a shell script called neat-ls that takes anargument which is the path name of a directory andproduces a LATEX document containing the above tablefor the given directory The script could also process theLATEX and display the resulting pdf file Finally find outabout the longtable package and change your script touse that instead

39

COMP10120 Report writing and Digital Typography

Exercise 9 A cleaning rota (optional evenmore challenging)

Now you will write a shell script called make-rota thatgenerates a house cleaning rota (Very handy for nextyear ) This is a table with columns such as KitchenBathroom and Lounge The rows will be weeks in theyear labelled with a date (eg always a Sunday) Theidea is that house mates can write their initials in theboxes promising to clean the corresponding room inthat particular week Start by making a sample tableby hand

Your script should take a single argument which isthe date of the first day of the first row eg102013(the US format for 20 Oct 13) The result will be a docu-ment that contains as many rows as fit on a single page(find out by experimenting)

The dates of each row should be generated from thefirst See the manual page for date to figure out howyou can generate a date that is a number of weeks anddays later than an existing one

361 Marking Scheme

You can view a copy of the marking scheme used bysubmit and labprint at

40

COMP10120 Report writing and Digital Typography

studentnetcsmanchesteracukugtlpmsphpunit=COMP10120ampex=ex3xml

37 Next steps

LATEX is a very powerful tool and it does take a littlegetting used to But itrsquos not as scary as it might initiallyseem and you should find that it doesnrsquot take long tolearn the common commands and techniques to makeyour documents well-structured and readable As youbecome more comfortable with the basics and under-stand the principles of typesetting finding out how todo more complex and sophisticated things is easymdashthere are hundreds of tutorials on the web

Donrsquot get carried away though and use the featuresjudiciously just because yoursquove found a cool new com-mand doesnrsquot mean that you should use it just to showoff your LATEX skills content and structure always trumpstypographic twiddlings4

4For example footnotes like this are for some reason a really tempting fea-ture to use in LATEX and in this document we have abused them mercilessly toillustrate a point Footnotes were originally a means for mechanical typeset-ters to insert comments corrections or additions to existing documents withouthaving to adjust the layout of a whole page and of course in digital typographythis is no longer necessary They can justifiably be used for citations (though itrsquosnot common to do so these days) and URLs if you donrsquot want these intrudinginto the body of your text And in some very very rare cases they can be usedas an aside to the main flow of the text (which is what has been done in this doc-ument) But this should be used sparingly If something is important to sayput it in the main body of your text If itrsquos not then perhaps you should thinkabout leaving it out completely or find some other way of including it Asking

41

COMP10120 Report writing and Digital Typography

371 Acknowledgements

Figure 38 is from the Wikipedia article on cheese

372 License

The text of this exercise is licensed under the terms ofthe Creative Commons Attribution 20 Generic (CC BY30) License

38 Background

What follows is additional contextual information aroundLATEX

LATEX was originally written by Leslie LamportW anAmerican computer scientist now working at MicrosoftResearch although its development has long been takenover by a world-wide LATEX community Itrsquos actuallybuilt on top of another system called TEX a computertypesetting system designed by one of the worldrsquos mostinfluential Computer Scientists Donald KnuthW of Stan-ford University Knuth has said that he designed TEX

the reader to look down at the bottom of a page to find out whether somethingis important or not is irritating and as yoursquove probably found out already oftenmeans you lose track of your reading position They also give the impressionthat the author isnrsquot clear about whether something is important or not whichis never good And long footnotes like this onemdashwhile LATEX will typeset themperfectly wellmdashare just plain silly Best avoid

42

COMP10120 Report writing and Digital Typography

for lsquothe creation of beautiful booksmdashand especially forbooks that contain a lot of mathematicsrsquo(D Knuth1984) Figure 34 shows what these eminent men looklike

So whatrsquos the purpose of LATEX Itrsquos purely a layerof software to make TEX easier to use in everyday sit-uations This is a good idea because although TEX isamazingly powerful it operates at a very low-level whichmakes it hard for non-expert users

Figure 34Don Knuth and Leslie Lamport

381 Pronunciation

The name TEX is intended by its creator to be pronouncedwith the final consonant as in the word loch or the nameBach but English speakers often pronounce it like thefirst syllable of technical The first syllable of LATEX is

43

COMP10120 Report writing and Digital Typography

pronounced as in rsquolayrsquo5

382 Why LATEX

Before we go any further why do we think LATEX is im-portant for youmdasha Computer Science studentmdashto knowabout Here are some reasons in no particular order

bull LATEX and TEX are superb examples of ComputerScience in action TEX was designed by Knuth fromfirst principlesmdashin other words from scratch TEXis actually a programming language and LATEX isa set of functions defined in the TEX language TheTEX lsquocompilerrsquo is written in WEBW a mixture ofdocumentation written in TeX and a PascalW sub-set in order to ensure portability it reads a TEXprogram and outputs documents TEX is completelyself-contained and designed to be portable to anycomputer architecture For example it implementsits own stackW and heapW (with garbage collectionW)and it does fixed-precision arithmeticW donrsquot worryif these terms donrsquot make much sense to you at themoment they soon will

5The Greek prefix lsquotexrsquo means lsquoartrsquo as well as lsquotechnologyrsquo so itrsquos a very nicelychosen name for a piece of software that produces such beautiful output Knuthexplained (D Knuth 1984) that one should lsquopronounce the X of TeX as a Greekchi not as an lsquoxrsquo so that TeX rhymes with the word blecchhhrsquo Wersquore not toosure that helps much unless you are confident in your pronunciation of theword lsquoblecchhrsquo Maybe itrsquos an American thing

44

COMP10120 Report writing and Digital Typography

bull LATEX is a new interesting way for you to thinkabout preparing documents

bull LATEX has a practical advantage for the writer inthat it helps you think more about what you wantto write rather than worrying about how it looks

bull LATEX is a powerful tool for professional scientificdocumentation and as a Computer Scientist youshould know about it

bull LATEX files are just plain text so can easily be cre-ated programatically For example the slides usedfor COMP16120 are generated automatically fromthe source of Johnrsquos book both are typeset usingLATEX The program labprint also produces itsoutput using LATEX using information drawn fromXMLW configuration files and ARCADE

bull Using LATEX is actually quite satisfying and thequality of its output may surprise you

In this lab session you are going to write severalshort documents using LATEX You could also write briefnotes in your logbook about how LATEX works and whatcommands you used inside the source of your docu-ments

45

COMP10120 Report writing and Digital Typography

383 Some history printing mathematics

Mathematics is hard to print on paper and on the Web(many websites resort to GIF or JPG images of mathsformulae which usually look horrible MathMLW pro-vides another approach but it is not yet widely used)

In the days before computers books and newspa-pers were printed with movable typeW made from lotsof little blocks of metal each with letters numbers andsymbols standing in relief which when inked left animpression on the paper (see Figure 35) The job ofthe printer (the printer here of course being a personnot a bit of electronics) was to gather together all theblocks in the right order between two horizontal stripsof wood to create a line of the document and then toassemble all those lines from top to bottom of a pageThus the term type settingW an incredible task whenyou think about it In the printerrsquos workshop by theway the blocks of metal were stored between jobs inwooden boxes called cases Letters like a b and c werestored in one case letters like A B and C were storedin a case sitting on top of that So a lower case and anupper case These terms may ring a bell

As technology progressed machines controlled bytypewriters would mechanically juggle the blocks intothe right order This conceptual model is the basis onwhich TEX operates Only now the metal blocks are

46

COMP10120 Report writing and Digital Typography

Figure 35On the left a piece of cast movable type in the Garamondfont On the right a case of cast metal type pieces andtypeset matter in a composing stick The text reads lsquoThequick brown fox jumps over the lazy dog and feels as if hewere in the seventh heaven of typography together with Her-mann Zapf the most famous artist of thersquo This document istypeset in a font called Palatino created by Hermann ZapfYou may have also seen rsquoZapf Dingbatsrsquo in the font lists ofvarious desktop applications Now you know why

little pieces of data arranged into data structuresThe one thing that traditional printers hated was

dealing with the typesetting of mathematics and theywould charge extra to do it It was incredibly fiddly toget the equations looking right they had to squeeze inextra bits of metal horizontally and vertically

When computers entered the printing world attemptsto print mathematics were limited by the printing tech-nology available It took a long time to reach the pointwhere computers could typeset mathematics beautifullyand that was the outstanding achievement of Knuthrsquos

47

COMP10120 Report writing and Digital Typography

TEXLetrsquos look at a quick example of the quality you get

from LATEX with a very simple formula that yoursquoll recog-nise

x =minusbplusmn

radicb2 minus 4ac

2aWersquoll revisit how LATEX typesets mathematics in Section 34

384 To WYSIWYG or not to WYSIWYG

Up until now you have probably used wordprocessingapplications such as Microsoft Word to create essaysletters and other (probably fairly short) documents Youmost likely know that the majority of modern wordprocessors use a paradigm called WYSIWYG or WhatYou See Is What You Get which means that you canmodify the visual style of the document yoursquore work-ing on by selecting the relevant bits and then choos-ing different attributes such as font size or colour usinga GUI In many ways this seems like such a sensibleand obvious way of doing things that you might bewondering why it even has a special name The rea-son is a historical one in the early days of comput-ing long before graphical window managers becamethe norm and when all you could display on screenwas fixed-width ASCII text in whatever the systemrsquos

48

COMP10120 Report writing and Digital Typography

default font was wordprocessors (eg Figure 36) onlyallowed you to format documents by using special se-quences of characters to cause particular effects Butthese effects were only visible when the document wasprinted So if you wanted a word to appear in boldtext in the wordprocessor you might write somethinglike [bold]hello world[bold] what you saw onscreen was not a direct reflection of what appeared onthe printed page If yoursquove written any HTML how-ever this process of marking up text may be familiarsee for example Figure 37 As computers moved todisplays able to draw things other than raw charac-ters on screen wordprocessors became capable of us-ing multiple fonts and styles as well as graphics anda new generation of applications appeared where whatyou saw on screen was an accurate reflection of how itwould appear when printed what you see (on screen)is what you get (on paper)

The huge advantage of WYSIWYG is that itrsquos reallyeasy to understand whatrsquos going on and most peoplecan create reasonably nicely formatted documents withrelatively little effort For short informal documentsone-off letters memos and such WYSIWYG works quitenicely But if yoursquove ever tried writing anything muchlonger or that includes images and tables you mayhave already started to see where the paradigm breaksdown For example if you write lsquoFigure 38 on page

49

COMP10120 Report writing and Digital Typography

Figure 36A screenshot of Wordperfect 51 running in Microsoft DOScirca 1989

51 shows a picture of some men looking at cheesersquo butthen later on edit your document to include some moretext at the start and a new picture of a some broccoli(as in Figure 39) yoursquod have to search through yourreport to find all mentions of lsquoFigure 38rsquo and lsquopage 51rsquoand manually update them to reflect the new number-ing This might be fine if you have two figures and fivepages but for a hundred-page report containing lots ofpictures you can see how this becomes tedious and er-ror prone very quickly

50

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 18: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

Some textttsay the textbfworld will end in textitfire

which is typeset as

Some say the world will end in fire

333 Cross referencing

LATEX allows you to cross-reference almost anything inthe document which includes sections sub-sections andfigures To use the cross-referencing feature you simplyinsert the command

labelmymarker

at the point in the document you want to refer to andthen use the command

refmymarker

when you want to use the reference Obviously youreplace the text mymarkerwith something more mean-ingful An important tip here is to call the marker some-thing that refers to the content of that part of the doc-ument and to avoid the temptation to use numbers(so donrsquot call your marker section1 instead call itintroduction if you reorder your document itrsquos stilllikely to be the introduction but it may no longer beSection 1) For example

25

COMP10120 Report writing and Digital Typography

sectionReflection on Welcome WeeklabelwelcomeweekI spent most of welcome week getting to know my wayaround campus I should have made more effort to joinsocieties I think I must remember to get to theStudentsrsquo Union and take a look around there

subsectionThings I enjoyedEverything so far has been wonderful with the caveat Imentioned in Section refwelcomeweek

subsectionThings I didnrsquot enjoyIrsquove discovered that I donrsquot like soggy chips

The really useful thing about cross-referencing in LATEXis that yoursquoll get warnings when you compile your doc-ument if cross-references are undefined or used incor-rectly This means you donrsquot have to manually checkevery reference in your document to make sure itrsquos stillright You do however have to run LATEX twice forsimilar reasons to those given above

334 Figures and pictures

Including figures and pictures in your document is easyYou do it like this

beginfigure

26

COMP10120 Report writing and Digital Typography

Figure 33Some men possibly Dutch looking at cheeses

centerlineincludegraphics[width=10cm]imagesmen-and-cheesejpgcaptionSome men possibly Dutch looking at cheeseslabelfiguremenandcheesesendfigure

which is the code we used to create Figure 38 You canprobably see whatrsquos happening The command includegraphicsgets your image which can be PDF PNG JPG GIF orPostScript The beginfigureendfigurecode lsquowrapsrsquo up whatever picture yoursquore including andallows LATEX to treat it as an unbreakable floating thingthat it will position for you as best it can in the docu-ment while maintaining an overall nice typographicallayout This floating of figures can sometimes result inthe figure ending up in a place you didnrsquot expect but inmost cases LATEX will make the most sensible choice Itrsquos

27

COMP10120 Report writing and Digital Typography

possible to employ finer control over figure placementbut thatrsquos beyond the scope of this introduction

The includegraphics command is not built into core LATEX but is in an additional package whichneeds to be explicitly loaded We load this package byusing the command usepackagegraphicx in thedocument preamble ie after the documentclasscommand but before begindocument There arehundreds of such packages that extend LATEXrsquos func-tionality the lab scripts you are reading now use over30 of them

Exercise 3 Including images

Create a document imagetex that contains some text(maybe from rsquoLorem Ipsumrsquo) together with a figurecontaining an image of your choice perhaps the oneyou made in Intro Lab 2 like Steversquos Mr Noodle Thereshould also be a reference to the figure in the text Youshould first use the program convert

convert

(check its manpage) to create a PDF version of the image

Exercise 4 A reflection on your studies

Your first proper LATEX document will be a very briefreflection on your studies so far

Write a hand-crafted LATEX document called courses-reflectiontex

28

COMP10120 Report writing and Digital Typography

(exact name as usual please otherwise submitwill notwork) It will have the following structure

1 A table of contents

2 A brief paragraph saying what the document isabout

3 A section appropriately titled for one of your courseunits containing

bull a brief paragraph saying what the unit is about

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the most about the unit

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the least about the unit

A repeat of item 3 for each other unit you are study-ing These sections should appear in alphabeticalorder by course code (eg COMP10120)

After completing and successfully compiling and view-ing your document you should spell-check it as fol-lows

ispell courses-reflectiontex

29

COMP10120 Report writing and Digital Typography

Once you are completely satisfied with it produce ahard copy ready for marking

34 Typesetting Mathematics

Earlier we saw this formula

x =minusbplusmn

radicb2 minus 4ac

2aIt looks nice doesnrsquot it To tell LATEX to display thisyou have to type a bit of magic but itrsquos easily-learnedmagic To create such a formula in a WYSIWYG edi-tor there is also magic involved but it usually involvesa lot of mouse-clicking and remembering special keycombinations like rsquocontrol-thisrsquo and rsquoalt-thatrsquo In LATEXit doesnrsquot You simply type this

[ x = frac-b pm sqrtb^2-4ac2a ]

You can probably work out how most of this createsthe formula but it wonrsquot be obvious that the [ and ]symbols that enclose the formula mean lsquotypeset this asa displayed formula giving it some vertical space fromthe surrounding textrsquo If wersquod used ( and ) insteadto enclose the formula it would appear in-line like thisx = minusbplusmn

radicb2minus4ac2a It still looks very nice and observe

how itrsquos automatically been resized to fit and that the

30

COMP10120 Report writing and Digital Typography

lines of text have had their spacing changed a bit Thisall looks simple but the implementation inside LATEXand TEX is complex It involves parsing the descrip-tion of the formula to create a corresponding tree datastructure which is then recursively walked to workout the horizontal and vertical typographical spacingsneeded Yoursquoll meet these ideas in COMP11120 andCOMP26120 Algorithms and Imperative Programming

Herersquos another example taken from COMP27112Computer Graphics (itrsquos a lsquosimplersquo local illuminationmodel incorporating ambient diffuse and specular re-flection by multiple lights)

I = kaIa +

Msumi=1

Ipidprimei[kd(N middot Li) + ks(Ri middot V )n]

We write this in LATEX as follows

[ I = k_a I_a + sum_i=1^M fracI_p_idrsquo_i [ k_d(hatN cdot hatL_i)+ k_s(hatR_i cdot hatV)^n] ]

Try to match the LATEX commands with the formula dis-played above Yoursquoll see lots of curly brackets and thisexample illustrates their two uses in LATEX The firstis to provide an argument to a command for exam-ple hatN means lsquoapply the hat command to N rsquowhich creates N the vector N with a little hat on

31

COMP10120 Report writing and Digital Typography

The second use of curly brackets is to group thingstogether to avoid ambiguities In the example you cansee sum_i=1^M which creates a summation signand its lower and upper limits

sumMi=1 We wrap the

lower bound i=1 in curly brackets to group it into anindivisible unit If we were to omit the brackets writ-ing sum_i=1^M LATEX would then produce

sumi = 1M

which is not at all what we want (even LATEX canrsquot al-ways know what we really want)

One final example If we tell LATEX

[ T_1 = left[beginarraycccccos theta amp -sin theta amp 0 amp delta sin theta amp cos theta amp 0 amp epsilon 0 amp 0 amp 1 amp eta alpha amp beta amp gamma amp 1endarrayright] ]

wersquoll get a splendid matrix which expresses a particu-lar 3D geometrical transformation (Donrsquot worry if youdonrsquot recognise this yoursquoll be introduced to matrix no-tation in the latter part of COMP11120 MathematicalTechniques for Computer Science For now you can justtreat it as some mysterious maths)

32

COMP10120 Report writing and Digital Typography

T1 =

cos θ minus sin θ 0 δ

sin θ cos θ 0 ε

0 0 1 η

α β γ 1

In the LATEX code left[means lsquobig opening square

bracket pleasersquo ccccmeans lsquoan array with 4 columnsplease with the items in each column centredrsquo ampmeanslsquostart a new columnrsquo and means lsquostart a new rowrsquoYoursquoll notice that LATEX knows about greek letters itknows about most standard maths symbols too andalso the ways theyrsquore usually used

There are some symbols that you might need (forexample therefore which produces the usual threedots symbol there4) that are not part of standard LATEX Manysuch symbols are provided by the amssymb package ofsymbols compiled by the American Mathematical Soci-ety Details of the many symbols provided by this pack-age can be found online at

mirrormathkuedutex-archivefontsamsfontsdocamssymbpdf

To use these extra symbols you need to have usepackageamssymbin the document preamble

33

COMP10120 Report writing and Digital Typography

341 A longer piece of mathematics

We conclude this section with an example of a longerpiece of mathematics that shows how you might type-set a complete mathematical argument rather than asingle formula The example is Euclidrsquos proof of thefact that

radic2 is irrational Itrsquos an argument that has been

covered in COMP11120 and is an example of proof bycontradiction It starts by making the assumption thatit is not the case that

radic2 is irrational in other words that

we can find integers p and q withradic2 = pq

We can assume without losing anything that p andq have no common factors (Why)

radic2 = pq

qradic2 = p

2q2 = p2

This means that p2 is even from which we can also de-duce that p is even (Why)

This means that p = 2k for some k so

2q2 = (2k)2

there4 2q2 = 4k2

so q2 = 2k2

But this means that q2 and hence q is even Since p andq are both even we have a contradiction to our initialassumption so no such p and q exist

The way this is formatted is shown here

34

COMP10120 Report writing and Digital Typography

It starts by making the assumption that it is emphnot the casethat $sqrt2$ is irrational in other words that we can findintegers $p$ and $q$ with $sqrt2 = pq$

We can assume without losing anything that $p$ and $q$ haveemphno common factors (Why)

[beginarraylcl

sqrt2 amp = amp pq qsqrt2 amp = amp p 2q^2 amp = amp p^2

endarray]

This means that $p^2$ is even from which we can also deduce that $p$is even (Why)

This means that $p = 2k$ for some $k$ so ldots[beginarrayllcl

amp 2q^2 amp = amp (2k)^2 therefore amp 2q^2 amp = amp 4k^2 textso amp q^2 amp = amp 2k^2

endarray]

But this means that $q^2$ and hence $q$ is even Since $p$ and $q$are both even we have a contradiction to our initial assumptionso no such $p$ and $q$ exist

Notice the use of the array environment for gettingthings lined up You can find much more informationabout this on the web

LATEX really shines at typesetting mathematics and

35

COMP10120 Report writing and Digital Typography

it would take pages and pages to describe all the fea-tures Have a look at

enwikibooksorgwikiLaTeXMathematics

for a flavour

Exercise 5 Formatting mathematics

Now for an exercise that involves some mathematicsPlease create a file f-wtex which typesets the follow-ing piece of text and mathematics

There are many positive integer solutions tothe equation

x2 + y2 = z2

which can be rewritten as

z =radicx2 + y2

For example (3 4 5) or (5 12 13) Such solu-tions are called Pythagorean triples

However for higher powers the situation isvery different and we have-

Theorem Fermat-WilesFor all natural numbers n ge 3 there are no

36

COMP10120 Report writing and Digital Typography

integers x y z satisfying the equation

xn + yn = zn

35 Curriculum vitaie

There are several scenarios where using LATEX ratherthan other word processing software can be useful

bull typesetting mathematics yoursquove just read about

bull writing a technical document

bull your final year project peport

bull writing an article you want to get published

bull writing a Curriculum vitae CV

Wersquoll now look at CVrsquos briefly

Exercise 6 Curriculum vitae

Creating a professional document is especially impor-tant when you write your CV because how your CVlooks (not just the content) will determine if you are in-vited to interview for job you are applying for Thatcould be a summer internship next year a year long

37

COMP10120 Report writing and Digital Typography

placement after your second year or graduate positionafter you leave University

As well using a text-editor and compiling files fromthe command line other tools are available for editingLATEXWe will look at one of these overleafcom

Create a basic CV which describes you your edu-cation (including University) and any experience youhave or interesting projects that you may have doneYou can do this using httpsoverleafcom andchoosing the ready-made templates at httpswwwoverleafcomgallerytaggedcv

As you progress through University it is a good ideato keep your CV up to date and get feedback from asmany people as you can There will be opportunities todebug your CV later (See httpgitiomycv if youare interested) but yoursquoll need a ldquobeta releaserdquo (version10) of your CV to get started The best time to start thisprocess is now

36 Some optional extras

Exercise 7 Exploring more LATEX features (op-tional but easy)

This exercise reinforces some of the things yoursquove donealready but also introduces some features of LATEX that

38

COMP10120 Report writing and Digital Typography

will be new to you It is labelled as optional because itisnrsquot marked but we would recommend that you all tryit

Take a copy of the file optinfocoursesCOMP10120ex3latex-introtexand follow the instructions it contains You should readit before you process it with LATEX

Exercise 8 A neat directory listing (optionalmore challenging)

The fact that LATEX source files are just text makes it easyto have them generated by a program You are going toexploit this and use LATEX to produce a neat documentcontaining a listing of the files in any directory

Find how to create tables in LATEX tables using thetabular environment Make a LATEX document by handthat uses a table to neatly show the information aboutthe files in some (small) directory (as produced by ls

-l) Write a shell script called neat-ls that takes anargument which is the path name of a directory andproduces a LATEX document containing the above tablefor the given directory The script could also process theLATEX and display the resulting pdf file Finally find outabout the longtable package and change your script touse that instead

39

COMP10120 Report writing and Digital Typography

Exercise 9 A cleaning rota (optional evenmore challenging)

Now you will write a shell script called make-rota thatgenerates a house cleaning rota (Very handy for nextyear ) This is a table with columns such as KitchenBathroom and Lounge The rows will be weeks in theyear labelled with a date (eg always a Sunday) Theidea is that house mates can write their initials in theboxes promising to clean the corresponding room inthat particular week Start by making a sample tableby hand

Your script should take a single argument which isthe date of the first day of the first row eg102013(the US format for 20 Oct 13) The result will be a docu-ment that contains as many rows as fit on a single page(find out by experimenting)

The dates of each row should be generated from thefirst See the manual page for date to figure out howyou can generate a date that is a number of weeks anddays later than an existing one

361 Marking Scheme

You can view a copy of the marking scheme used bysubmit and labprint at

40

COMP10120 Report writing and Digital Typography

studentnetcsmanchesteracukugtlpmsphpunit=COMP10120ampex=ex3xml

37 Next steps

LATEX is a very powerful tool and it does take a littlegetting used to But itrsquos not as scary as it might initiallyseem and you should find that it doesnrsquot take long tolearn the common commands and techniques to makeyour documents well-structured and readable As youbecome more comfortable with the basics and under-stand the principles of typesetting finding out how todo more complex and sophisticated things is easymdashthere are hundreds of tutorials on the web

Donrsquot get carried away though and use the featuresjudiciously just because yoursquove found a cool new com-mand doesnrsquot mean that you should use it just to showoff your LATEX skills content and structure always trumpstypographic twiddlings4

4For example footnotes like this are for some reason a really tempting fea-ture to use in LATEX and in this document we have abused them mercilessly toillustrate a point Footnotes were originally a means for mechanical typeset-ters to insert comments corrections or additions to existing documents withouthaving to adjust the layout of a whole page and of course in digital typographythis is no longer necessary They can justifiably be used for citations (though itrsquosnot common to do so these days) and URLs if you donrsquot want these intrudinginto the body of your text And in some very very rare cases they can be usedas an aside to the main flow of the text (which is what has been done in this doc-ument) But this should be used sparingly If something is important to sayput it in the main body of your text If itrsquos not then perhaps you should thinkabout leaving it out completely or find some other way of including it Asking

41

COMP10120 Report writing and Digital Typography

371 Acknowledgements

Figure 38 is from the Wikipedia article on cheese

372 License

The text of this exercise is licensed under the terms ofthe Creative Commons Attribution 20 Generic (CC BY30) License

38 Background

What follows is additional contextual information aroundLATEX

LATEX was originally written by Leslie LamportW anAmerican computer scientist now working at MicrosoftResearch although its development has long been takenover by a world-wide LATEX community Itrsquos actuallybuilt on top of another system called TEX a computertypesetting system designed by one of the worldrsquos mostinfluential Computer Scientists Donald KnuthW of Stan-ford University Knuth has said that he designed TEX

the reader to look down at the bottom of a page to find out whether somethingis important or not is irritating and as yoursquove probably found out already oftenmeans you lose track of your reading position They also give the impressionthat the author isnrsquot clear about whether something is important or not whichis never good And long footnotes like this onemdashwhile LATEX will typeset themperfectly wellmdashare just plain silly Best avoid

42

COMP10120 Report writing and Digital Typography

for lsquothe creation of beautiful booksmdashand especially forbooks that contain a lot of mathematicsrsquo(D Knuth1984) Figure 34 shows what these eminent men looklike

So whatrsquos the purpose of LATEX Itrsquos purely a layerof software to make TEX easier to use in everyday sit-uations This is a good idea because although TEX isamazingly powerful it operates at a very low-level whichmakes it hard for non-expert users

Figure 34Don Knuth and Leslie Lamport

381 Pronunciation

The name TEX is intended by its creator to be pronouncedwith the final consonant as in the word loch or the nameBach but English speakers often pronounce it like thefirst syllable of technical The first syllable of LATEX is

43

COMP10120 Report writing and Digital Typography

pronounced as in rsquolayrsquo5

382 Why LATEX

Before we go any further why do we think LATEX is im-portant for youmdasha Computer Science studentmdashto knowabout Here are some reasons in no particular order

bull LATEX and TEX are superb examples of ComputerScience in action TEX was designed by Knuth fromfirst principlesmdashin other words from scratch TEXis actually a programming language and LATEX isa set of functions defined in the TEX language TheTEX lsquocompilerrsquo is written in WEBW a mixture ofdocumentation written in TeX and a PascalW sub-set in order to ensure portability it reads a TEXprogram and outputs documents TEX is completelyself-contained and designed to be portable to anycomputer architecture For example it implementsits own stackW and heapW (with garbage collectionW)and it does fixed-precision arithmeticW donrsquot worryif these terms donrsquot make much sense to you at themoment they soon will

5The Greek prefix lsquotexrsquo means lsquoartrsquo as well as lsquotechnologyrsquo so itrsquos a very nicelychosen name for a piece of software that produces such beautiful output Knuthexplained (D Knuth 1984) that one should lsquopronounce the X of TeX as a Greekchi not as an lsquoxrsquo so that TeX rhymes with the word blecchhhrsquo Wersquore not toosure that helps much unless you are confident in your pronunciation of theword lsquoblecchhrsquo Maybe itrsquos an American thing

44

COMP10120 Report writing and Digital Typography

bull LATEX is a new interesting way for you to thinkabout preparing documents

bull LATEX has a practical advantage for the writer inthat it helps you think more about what you wantto write rather than worrying about how it looks

bull LATEX is a powerful tool for professional scientificdocumentation and as a Computer Scientist youshould know about it

bull LATEX files are just plain text so can easily be cre-ated programatically For example the slides usedfor COMP16120 are generated automatically fromthe source of Johnrsquos book both are typeset usingLATEX The program labprint also produces itsoutput using LATEX using information drawn fromXMLW configuration files and ARCADE

bull Using LATEX is actually quite satisfying and thequality of its output may surprise you

In this lab session you are going to write severalshort documents using LATEX You could also write briefnotes in your logbook about how LATEX works and whatcommands you used inside the source of your docu-ments

45

COMP10120 Report writing and Digital Typography

383 Some history printing mathematics

Mathematics is hard to print on paper and on the Web(many websites resort to GIF or JPG images of mathsformulae which usually look horrible MathMLW pro-vides another approach but it is not yet widely used)

In the days before computers books and newspa-pers were printed with movable typeW made from lotsof little blocks of metal each with letters numbers andsymbols standing in relief which when inked left animpression on the paper (see Figure 35) The job ofthe printer (the printer here of course being a personnot a bit of electronics) was to gather together all theblocks in the right order between two horizontal stripsof wood to create a line of the document and then toassemble all those lines from top to bottom of a pageThus the term type settingW an incredible task whenyou think about it In the printerrsquos workshop by theway the blocks of metal were stored between jobs inwooden boxes called cases Letters like a b and c werestored in one case letters like A B and C were storedin a case sitting on top of that So a lower case and anupper case These terms may ring a bell

As technology progressed machines controlled bytypewriters would mechanically juggle the blocks intothe right order This conceptual model is the basis onwhich TEX operates Only now the metal blocks are

46

COMP10120 Report writing and Digital Typography

Figure 35On the left a piece of cast movable type in the Garamondfont On the right a case of cast metal type pieces andtypeset matter in a composing stick The text reads lsquoThequick brown fox jumps over the lazy dog and feels as if hewere in the seventh heaven of typography together with Her-mann Zapf the most famous artist of thersquo This document istypeset in a font called Palatino created by Hermann ZapfYou may have also seen rsquoZapf Dingbatsrsquo in the font lists ofvarious desktop applications Now you know why

little pieces of data arranged into data structuresThe one thing that traditional printers hated was

dealing with the typesetting of mathematics and theywould charge extra to do it It was incredibly fiddly toget the equations looking right they had to squeeze inextra bits of metal horizontally and vertically

When computers entered the printing world attemptsto print mathematics were limited by the printing tech-nology available It took a long time to reach the pointwhere computers could typeset mathematics beautifullyand that was the outstanding achievement of Knuthrsquos

47

COMP10120 Report writing and Digital Typography

TEXLetrsquos look at a quick example of the quality you get

from LATEX with a very simple formula that yoursquoll recog-nise

x =minusbplusmn

radicb2 minus 4ac

2aWersquoll revisit how LATEX typesets mathematics in Section 34

384 To WYSIWYG or not to WYSIWYG

Up until now you have probably used wordprocessingapplications such as Microsoft Word to create essaysletters and other (probably fairly short) documents Youmost likely know that the majority of modern wordprocessors use a paradigm called WYSIWYG or WhatYou See Is What You Get which means that you canmodify the visual style of the document yoursquore work-ing on by selecting the relevant bits and then choos-ing different attributes such as font size or colour usinga GUI In many ways this seems like such a sensibleand obvious way of doing things that you might bewondering why it even has a special name The rea-son is a historical one in the early days of comput-ing long before graphical window managers becamethe norm and when all you could display on screenwas fixed-width ASCII text in whatever the systemrsquos

48

COMP10120 Report writing and Digital Typography

default font was wordprocessors (eg Figure 36) onlyallowed you to format documents by using special se-quences of characters to cause particular effects Butthese effects were only visible when the document wasprinted So if you wanted a word to appear in boldtext in the wordprocessor you might write somethinglike [bold]hello world[bold] what you saw onscreen was not a direct reflection of what appeared onthe printed page If yoursquove written any HTML how-ever this process of marking up text may be familiarsee for example Figure 37 As computers moved todisplays able to draw things other than raw charac-ters on screen wordprocessors became capable of us-ing multiple fonts and styles as well as graphics anda new generation of applications appeared where whatyou saw on screen was an accurate reflection of how itwould appear when printed what you see (on screen)is what you get (on paper)

The huge advantage of WYSIWYG is that itrsquos reallyeasy to understand whatrsquos going on and most peoplecan create reasonably nicely formatted documents withrelatively little effort For short informal documentsone-off letters memos and such WYSIWYG works quitenicely But if yoursquove ever tried writing anything muchlonger or that includes images and tables you mayhave already started to see where the paradigm breaksdown For example if you write lsquoFigure 38 on page

49

COMP10120 Report writing and Digital Typography

Figure 36A screenshot of Wordperfect 51 running in Microsoft DOScirca 1989

51 shows a picture of some men looking at cheesersquo butthen later on edit your document to include some moretext at the start and a new picture of a some broccoli(as in Figure 39) yoursquod have to search through yourreport to find all mentions of lsquoFigure 38rsquo and lsquopage 51rsquoand manually update them to reflect the new number-ing This might be fine if you have two figures and fivepages but for a hundred-page report containing lots ofpictures you can see how this becomes tedious and er-ror prone very quickly

50

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 19: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

sectionReflection on Welcome WeeklabelwelcomeweekI spent most of welcome week getting to know my wayaround campus I should have made more effort to joinsocieties I think I must remember to get to theStudentsrsquo Union and take a look around there

subsectionThings I enjoyedEverything so far has been wonderful with the caveat Imentioned in Section refwelcomeweek

subsectionThings I didnrsquot enjoyIrsquove discovered that I donrsquot like soggy chips

The really useful thing about cross-referencing in LATEXis that yoursquoll get warnings when you compile your doc-ument if cross-references are undefined or used incor-rectly This means you donrsquot have to manually checkevery reference in your document to make sure itrsquos stillright You do however have to run LATEX twice forsimilar reasons to those given above

334 Figures and pictures

Including figures and pictures in your document is easyYou do it like this

beginfigure

26

COMP10120 Report writing and Digital Typography

Figure 33Some men possibly Dutch looking at cheeses

centerlineincludegraphics[width=10cm]imagesmen-and-cheesejpgcaptionSome men possibly Dutch looking at cheeseslabelfiguremenandcheesesendfigure

which is the code we used to create Figure 38 You canprobably see whatrsquos happening The command includegraphicsgets your image which can be PDF PNG JPG GIF orPostScript The beginfigureendfigurecode lsquowrapsrsquo up whatever picture yoursquore including andallows LATEX to treat it as an unbreakable floating thingthat it will position for you as best it can in the docu-ment while maintaining an overall nice typographicallayout This floating of figures can sometimes result inthe figure ending up in a place you didnrsquot expect but inmost cases LATEX will make the most sensible choice Itrsquos

27

COMP10120 Report writing and Digital Typography

possible to employ finer control over figure placementbut thatrsquos beyond the scope of this introduction

The includegraphics command is not built into core LATEX but is in an additional package whichneeds to be explicitly loaded We load this package byusing the command usepackagegraphicx in thedocument preamble ie after the documentclasscommand but before begindocument There arehundreds of such packages that extend LATEXrsquos func-tionality the lab scripts you are reading now use over30 of them

Exercise 3 Including images

Create a document imagetex that contains some text(maybe from rsquoLorem Ipsumrsquo) together with a figurecontaining an image of your choice perhaps the oneyou made in Intro Lab 2 like Steversquos Mr Noodle Thereshould also be a reference to the figure in the text Youshould first use the program convert

convert

(check its manpage) to create a PDF version of the image

Exercise 4 A reflection on your studies

Your first proper LATEX document will be a very briefreflection on your studies so far

Write a hand-crafted LATEX document called courses-reflectiontex

28

COMP10120 Report writing and Digital Typography

(exact name as usual please otherwise submitwill notwork) It will have the following structure

1 A table of contents

2 A brief paragraph saying what the document isabout

3 A section appropriately titled for one of your courseunits containing

bull a brief paragraph saying what the unit is about

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the most about the unit

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the least about the unit

A repeat of item 3 for each other unit you are study-ing These sections should appear in alphabeticalorder by course code (eg COMP10120)

After completing and successfully compiling and view-ing your document you should spell-check it as fol-lows

ispell courses-reflectiontex

29

COMP10120 Report writing and Digital Typography

Once you are completely satisfied with it produce ahard copy ready for marking

34 Typesetting Mathematics

Earlier we saw this formula

x =minusbplusmn

radicb2 minus 4ac

2aIt looks nice doesnrsquot it To tell LATEX to display thisyou have to type a bit of magic but itrsquos easily-learnedmagic To create such a formula in a WYSIWYG edi-tor there is also magic involved but it usually involvesa lot of mouse-clicking and remembering special keycombinations like rsquocontrol-thisrsquo and rsquoalt-thatrsquo In LATEXit doesnrsquot You simply type this

[ x = frac-b pm sqrtb^2-4ac2a ]

You can probably work out how most of this createsthe formula but it wonrsquot be obvious that the [ and ]symbols that enclose the formula mean lsquotypeset this asa displayed formula giving it some vertical space fromthe surrounding textrsquo If wersquod used ( and ) insteadto enclose the formula it would appear in-line like thisx = minusbplusmn

radicb2minus4ac2a It still looks very nice and observe

how itrsquos automatically been resized to fit and that the

30

COMP10120 Report writing and Digital Typography

lines of text have had their spacing changed a bit Thisall looks simple but the implementation inside LATEXand TEX is complex It involves parsing the descrip-tion of the formula to create a corresponding tree datastructure which is then recursively walked to workout the horizontal and vertical typographical spacingsneeded Yoursquoll meet these ideas in COMP11120 andCOMP26120 Algorithms and Imperative Programming

Herersquos another example taken from COMP27112Computer Graphics (itrsquos a lsquosimplersquo local illuminationmodel incorporating ambient diffuse and specular re-flection by multiple lights)

I = kaIa +

Msumi=1

Ipidprimei[kd(N middot Li) + ks(Ri middot V )n]

We write this in LATEX as follows

[ I = k_a I_a + sum_i=1^M fracI_p_idrsquo_i [ k_d(hatN cdot hatL_i)+ k_s(hatR_i cdot hatV)^n] ]

Try to match the LATEX commands with the formula dis-played above Yoursquoll see lots of curly brackets and thisexample illustrates their two uses in LATEX The firstis to provide an argument to a command for exam-ple hatN means lsquoapply the hat command to N rsquowhich creates N the vector N with a little hat on

31

COMP10120 Report writing and Digital Typography

The second use of curly brackets is to group thingstogether to avoid ambiguities In the example you cansee sum_i=1^M which creates a summation signand its lower and upper limits

sumMi=1 We wrap the

lower bound i=1 in curly brackets to group it into anindivisible unit If we were to omit the brackets writ-ing sum_i=1^M LATEX would then produce

sumi = 1M

which is not at all what we want (even LATEX canrsquot al-ways know what we really want)

One final example If we tell LATEX

[ T_1 = left[beginarraycccccos theta amp -sin theta amp 0 amp delta sin theta amp cos theta amp 0 amp epsilon 0 amp 0 amp 1 amp eta alpha amp beta amp gamma amp 1endarrayright] ]

wersquoll get a splendid matrix which expresses a particu-lar 3D geometrical transformation (Donrsquot worry if youdonrsquot recognise this yoursquoll be introduced to matrix no-tation in the latter part of COMP11120 MathematicalTechniques for Computer Science For now you can justtreat it as some mysterious maths)

32

COMP10120 Report writing and Digital Typography

T1 =

cos θ minus sin θ 0 δ

sin θ cos θ 0 ε

0 0 1 η

α β γ 1

In the LATEX code left[means lsquobig opening square

bracket pleasersquo ccccmeans lsquoan array with 4 columnsplease with the items in each column centredrsquo ampmeanslsquostart a new columnrsquo and means lsquostart a new rowrsquoYoursquoll notice that LATEX knows about greek letters itknows about most standard maths symbols too andalso the ways theyrsquore usually used

There are some symbols that you might need (forexample therefore which produces the usual threedots symbol there4) that are not part of standard LATEX Manysuch symbols are provided by the amssymb package ofsymbols compiled by the American Mathematical Soci-ety Details of the many symbols provided by this pack-age can be found online at

mirrormathkuedutex-archivefontsamsfontsdocamssymbpdf

To use these extra symbols you need to have usepackageamssymbin the document preamble

33

COMP10120 Report writing and Digital Typography

341 A longer piece of mathematics

We conclude this section with an example of a longerpiece of mathematics that shows how you might type-set a complete mathematical argument rather than asingle formula The example is Euclidrsquos proof of thefact that

radic2 is irrational Itrsquos an argument that has been

covered in COMP11120 and is an example of proof bycontradiction It starts by making the assumption thatit is not the case that

radic2 is irrational in other words that

we can find integers p and q withradic2 = pq

We can assume without losing anything that p andq have no common factors (Why)

radic2 = pq

qradic2 = p

2q2 = p2

This means that p2 is even from which we can also de-duce that p is even (Why)

This means that p = 2k for some k so

2q2 = (2k)2

there4 2q2 = 4k2

so q2 = 2k2

But this means that q2 and hence q is even Since p andq are both even we have a contradiction to our initialassumption so no such p and q exist

The way this is formatted is shown here

34

COMP10120 Report writing and Digital Typography

It starts by making the assumption that it is emphnot the casethat $sqrt2$ is irrational in other words that we can findintegers $p$ and $q$ with $sqrt2 = pq$

We can assume without losing anything that $p$ and $q$ haveemphno common factors (Why)

[beginarraylcl

sqrt2 amp = amp pq qsqrt2 amp = amp p 2q^2 amp = amp p^2

endarray]

This means that $p^2$ is even from which we can also deduce that $p$is even (Why)

This means that $p = 2k$ for some $k$ so ldots[beginarrayllcl

amp 2q^2 amp = amp (2k)^2 therefore amp 2q^2 amp = amp 4k^2 textso amp q^2 amp = amp 2k^2

endarray]

But this means that $q^2$ and hence $q$ is even Since $p$ and $q$are both even we have a contradiction to our initial assumptionso no such $p$ and $q$ exist

Notice the use of the array environment for gettingthings lined up You can find much more informationabout this on the web

LATEX really shines at typesetting mathematics and

35

COMP10120 Report writing and Digital Typography

it would take pages and pages to describe all the fea-tures Have a look at

enwikibooksorgwikiLaTeXMathematics

for a flavour

Exercise 5 Formatting mathematics

Now for an exercise that involves some mathematicsPlease create a file f-wtex which typesets the follow-ing piece of text and mathematics

There are many positive integer solutions tothe equation

x2 + y2 = z2

which can be rewritten as

z =radicx2 + y2

For example (3 4 5) or (5 12 13) Such solu-tions are called Pythagorean triples

However for higher powers the situation isvery different and we have-

Theorem Fermat-WilesFor all natural numbers n ge 3 there are no

36

COMP10120 Report writing and Digital Typography

integers x y z satisfying the equation

xn + yn = zn

35 Curriculum vitaie

There are several scenarios where using LATEX ratherthan other word processing software can be useful

bull typesetting mathematics yoursquove just read about

bull writing a technical document

bull your final year project peport

bull writing an article you want to get published

bull writing a Curriculum vitae CV

Wersquoll now look at CVrsquos briefly

Exercise 6 Curriculum vitae

Creating a professional document is especially impor-tant when you write your CV because how your CVlooks (not just the content) will determine if you are in-vited to interview for job you are applying for Thatcould be a summer internship next year a year long

37

COMP10120 Report writing and Digital Typography

placement after your second year or graduate positionafter you leave University

As well using a text-editor and compiling files fromthe command line other tools are available for editingLATEXWe will look at one of these overleafcom

Create a basic CV which describes you your edu-cation (including University) and any experience youhave or interesting projects that you may have doneYou can do this using httpsoverleafcom andchoosing the ready-made templates at httpswwwoverleafcomgallerytaggedcv

As you progress through University it is a good ideato keep your CV up to date and get feedback from asmany people as you can There will be opportunities todebug your CV later (See httpgitiomycv if youare interested) but yoursquoll need a ldquobeta releaserdquo (version10) of your CV to get started The best time to start thisprocess is now

36 Some optional extras

Exercise 7 Exploring more LATEX features (op-tional but easy)

This exercise reinforces some of the things yoursquove donealready but also introduces some features of LATEX that

38

COMP10120 Report writing and Digital Typography

will be new to you It is labelled as optional because itisnrsquot marked but we would recommend that you all tryit

Take a copy of the file optinfocoursesCOMP10120ex3latex-introtexand follow the instructions it contains You should readit before you process it with LATEX

Exercise 8 A neat directory listing (optionalmore challenging)

The fact that LATEX source files are just text makes it easyto have them generated by a program You are going toexploit this and use LATEX to produce a neat documentcontaining a listing of the files in any directory

Find how to create tables in LATEX tables using thetabular environment Make a LATEX document by handthat uses a table to neatly show the information aboutthe files in some (small) directory (as produced by ls

-l) Write a shell script called neat-ls that takes anargument which is the path name of a directory andproduces a LATEX document containing the above tablefor the given directory The script could also process theLATEX and display the resulting pdf file Finally find outabout the longtable package and change your script touse that instead

39

COMP10120 Report writing and Digital Typography

Exercise 9 A cleaning rota (optional evenmore challenging)

Now you will write a shell script called make-rota thatgenerates a house cleaning rota (Very handy for nextyear ) This is a table with columns such as KitchenBathroom and Lounge The rows will be weeks in theyear labelled with a date (eg always a Sunday) Theidea is that house mates can write their initials in theboxes promising to clean the corresponding room inthat particular week Start by making a sample tableby hand

Your script should take a single argument which isthe date of the first day of the first row eg102013(the US format for 20 Oct 13) The result will be a docu-ment that contains as many rows as fit on a single page(find out by experimenting)

The dates of each row should be generated from thefirst See the manual page for date to figure out howyou can generate a date that is a number of weeks anddays later than an existing one

361 Marking Scheme

You can view a copy of the marking scheme used bysubmit and labprint at

40

COMP10120 Report writing and Digital Typography

studentnetcsmanchesteracukugtlpmsphpunit=COMP10120ampex=ex3xml

37 Next steps

LATEX is a very powerful tool and it does take a littlegetting used to But itrsquos not as scary as it might initiallyseem and you should find that it doesnrsquot take long tolearn the common commands and techniques to makeyour documents well-structured and readable As youbecome more comfortable with the basics and under-stand the principles of typesetting finding out how todo more complex and sophisticated things is easymdashthere are hundreds of tutorials on the web

Donrsquot get carried away though and use the featuresjudiciously just because yoursquove found a cool new com-mand doesnrsquot mean that you should use it just to showoff your LATEX skills content and structure always trumpstypographic twiddlings4

4For example footnotes like this are for some reason a really tempting fea-ture to use in LATEX and in this document we have abused them mercilessly toillustrate a point Footnotes were originally a means for mechanical typeset-ters to insert comments corrections or additions to existing documents withouthaving to adjust the layout of a whole page and of course in digital typographythis is no longer necessary They can justifiably be used for citations (though itrsquosnot common to do so these days) and URLs if you donrsquot want these intrudinginto the body of your text And in some very very rare cases they can be usedas an aside to the main flow of the text (which is what has been done in this doc-ument) But this should be used sparingly If something is important to sayput it in the main body of your text If itrsquos not then perhaps you should thinkabout leaving it out completely or find some other way of including it Asking

41

COMP10120 Report writing and Digital Typography

371 Acknowledgements

Figure 38 is from the Wikipedia article on cheese

372 License

The text of this exercise is licensed under the terms ofthe Creative Commons Attribution 20 Generic (CC BY30) License

38 Background

What follows is additional contextual information aroundLATEX

LATEX was originally written by Leslie LamportW anAmerican computer scientist now working at MicrosoftResearch although its development has long been takenover by a world-wide LATEX community Itrsquos actuallybuilt on top of another system called TEX a computertypesetting system designed by one of the worldrsquos mostinfluential Computer Scientists Donald KnuthW of Stan-ford University Knuth has said that he designed TEX

the reader to look down at the bottom of a page to find out whether somethingis important or not is irritating and as yoursquove probably found out already oftenmeans you lose track of your reading position They also give the impressionthat the author isnrsquot clear about whether something is important or not whichis never good And long footnotes like this onemdashwhile LATEX will typeset themperfectly wellmdashare just plain silly Best avoid

42

COMP10120 Report writing and Digital Typography

for lsquothe creation of beautiful booksmdashand especially forbooks that contain a lot of mathematicsrsquo(D Knuth1984) Figure 34 shows what these eminent men looklike

So whatrsquos the purpose of LATEX Itrsquos purely a layerof software to make TEX easier to use in everyday sit-uations This is a good idea because although TEX isamazingly powerful it operates at a very low-level whichmakes it hard for non-expert users

Figure 34Don Knuth and Leslie Lamport

381 Pronunciation

The name TEX is intended by its creator to be pronouncedwith the final consonant as in the word loch or the nameBach but English speakers often pronounce it like thefirst syllable of technical The first syllable of LATEX is

43

COMP10120 Report writing and Digital Typography

pronounced as in rsquolayrsquo5

382 Why LATEX

Before we go any further why do we think LATEX is im-portant for youmdasha Computer Science studentmdashto knowabout Here are some reasons in no particular order

bull LATEX and TEX are superb examples of ComputerScience in action TEX was designed by Knuth fromfirst principlesmdashin other words from scratch TEXis actually a programming language and LATEX isa set of functions defined in the TEX language TheTEX lsquocompilerrsquo is written in WEBW a mixture ofdocumentation written in TeX and a PascalW sub-set in order to ensure portability it reads a TEXprogram and outputs documents TEX is completelyself-contained and designed to be portable to anycomputer architecture For example it implementsits own stackW and heapW (with garbage collectionW)and it does fixed-precision arithmeticW donrsquot worryif these terms donrsquot make much sense to you at themoment they soon will

5The Greek prefix lsquotexrsquo means lsquoartrsquo as well as lsquotechnologyrsquo so itrsquos a very nicelychosen name for a piece of software that produces such beautiful output Knuthexplained (D Knuth 1984) that one should lsquopronounce the X of TeX as a Greekchi not as an lsquoxrsquo so that TeX rhymes with the word blecchhhrsquo Wersquore not toosure that helps much unless you are confident in your pronunciation of theword lsquoblecchhrsquo Maybe itrsquos an American thing

44

COMP10120 Report writing and Digital Typography

bull LATEX is a new interesting way for you to thinkabout preparing documents

bull LATEX has a practical advantage for the writer inthat it helps you think more about what you wantto write rather than worrying about how it looks

bull LATEX is a powerful tool for professional scientificdocumentation and as a Computer Scientist youshould know about it

bull LATEX files are just plain text so can easily be cre-ated programatically For example the slides usedfor COMP16120 are generated automatically fromthe source of Johnrsquos book both are typeset usingLATEX The program labprint also produces itsoutput using LATEX using information drawn fromXMLW configuration files and ARCADE

bull Using LATEX is actually quite satisfying and thequality of its output may surprise you

In this lab session you are going to write severalshort documents using LATEX You could also write briefnotes in your logbook about how LATEX works and whatcommands you used inside the source of your docu-ments

45

COMP10120 Report writing and Digital Typography

383 Some history printing mathematics

Mathematics is hard to print on paper and on the Web(many websites resort to GIF or JPG images of mathsformulae which usually look horrible MathMLW pro-vides another approach but it is not yet widely used)

In the days before computers books and newspa-pers were printed with movable typeW made from lotsof little blocks of metal each with letters numbers andsymbols standing in relief which when inked left animpression on the paper (see Figure 35) The job ofthe printer (the printer here of course being a personnot a bit of electronics) was to gather together all theblocks in the right order between two horizontal stripsof wood to create a line of the document and then toassemble all those lines from top to bottom of a pageThus the term type settingW an incredible task whenyou think about it In the printerrsquos workshop by theway the blocks of metal were stored between jobs inwooden boxes called cases Letters like a b and c werestored in one case letters like A B and C were storedin a case sitting on top of that So a lower case and anupper case These terms may ring a bell

As technology progressed machines controlled bytypewriters would mechanically juggle the blocks intothe right order This conceptual model is the basis onwhich TEX operates Only now the metal blocks are

46

COMP10120 Report writing and Digital Typography

Figure 35On the left a piece of cast movable type in the Garamondfont On the right a case of cast metal type pieces andtypeset matter in a composing stick The text reads lsquoThequick brown fox jumps over the lazy dog and feels as if hewere in the seventh heaven of typography together with Her-mann Zapf the most famous artist of thersquo This document istypeset in a font called Palatino created by Hermann ZapfYou may have also seen rsquoZapf Dingbatsrsquo in the font lists ofvarious desktop applications Now you know why

little pieces of data arranged into data structuresThe one thing that traditional printers hated was

dealing with the typesetting of mathematics and theywould charge extra to do it It was incredibly fiddly toget the equations looking right they had to squeeze inextra bits of metal horizontally and vertically

When computers entered the printing world attemptsto print mathematics were limited by the printing tech-nology available It took a long time to reach the pointwhere computers could typeset mathematics beautifullyand that was the outstanding achievement of Knuthrsquos

47

COMP10120 Report writing and Digital Typography

TEXLetrsquos look at a quick example of the quality you get

from LATEX with a very simple formula that yoursquoll recog-nise

x =minusbplusmn

radicb2 minus 4ac

2aWersquoll revisit how LATEX typesets mathematics in Section 34

384 To WYSIWYG or not to WYSIWYG

Up until now you have probably used wordprocessingapplications such as Microsoft Word to create essaysletters and other (probably fairly short) documents Youmost likely know that the majority of modern wordprocessors use a paradigm called WYSIWYG or WhatYou See Is What You Get which means that you canmodify the visual style of the document yoursquore work-ing on by selecting the relevant bits and then choos-ing different attributes such as font size or colour usinga GUI In many ways this seems like such a sensibleand obvious way of doing things that you might bewondering why it even has a special name The rea-son is a historical one in the early days of comput-ing long before graphical window managers becamethe norm and when all you could display on screenwas fixed-width ASCII text in whatever the systemrsquos

48

COMP10120 Report writing and Digital Typography

default font was wordprocessors (eg Figure 36) onlyallowed you to format documents by using special se-quences of characters to cause particular effects Butthese effects were only visible when the document wasprinted So if you wanted a word to appear in boldtext in the wordprocessor you might write somethinglike [bold]hello world[bold] what you saw onscreen was not a direct reflection of what appeared onthe printed page If yoursquove written any HTML how-ever this process of marking up text may be familiarsee for example Figure 37 As computers moved todisplays able to draw things other than raw charac-ters on screen wordprocessors became capable of us-ing multiple fonts and styles as well as graphics anda new generation of applications appeared where whatyou saw on screen was an accurate reflection of how itwould appear when printed what you see (on screen)is what you get (on paper)

The huge advantage of WYSIWYG is that itrsquos reallyeasy to understand whatrsquos going on and most peoplecan create reasonably nicely formatted documents withrelatively little effort For short informal documentsone-off letters memos and such WYSIWYG works quitenicely But if yoursquove ever tried writing anything muchlonger or that includes images and tables you mayhave already started to see where the paradigm breaksdown For example if you write lsquoFigure 38 on page

49

COMP10120 Report writing and Digital Typography

Figure 36A screenshot of Wordperfect 51 running in Microsoft DOScirca 1989

51 shows a picture of some men looking at cheesersquo butthen later on edit your document to include some moretext at the start and a new picture of a some broccoli(as in Figure 39) yoursquod have to search through yourreport to find all mentions of lsquoFigure 38rsquo and lsquopage 51rsquoand manually update them to reflect the new number-ing This might be fine if you have two figures and fivepages but for a hundred-page report containing lots ofpictures you can see how this becomes tedious and er-ror prone very quickly

50

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 20: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

Figure 33Some men possibly Dutch looking at cheeses

centerlineincludegraphics[width=10cm]imagesmen-and-cheesejpgcaptionSome men possibly Dutch looking at cheeseslabelfiguremenandcheesesendfigure

which is the code we used to create Figure 38 You canprobably see whatrsquos happening The command includegraphicsgets your image which can be PDF PNG JPG GIF orPostScript The beginfigureendfigurecode lsquowrapsrsquo up whatever picture yoursquore including andallows LATEX to treat it as an unbreakable floating thingthat it will position for you as best it can in the docu-ment while maintaining an overall nice typographicallayout This floating of figures can sometimes result inthe figure ending up in a place you didnrsquot expect but inmost cases LATEX will make the most sensible choice Itrsquos

27

COMP10120 Report writing and Digital Typography

possible to employ finer control over figure placementbut thatrsquos beyond the scope of this introduction

The includegraphics command is not built into core LATEX but is in an additional package whichneeds to be explicitly loaded We load this package byusing the command usepackagegraphicx in thedocument preamble ie after the documentclasscommand but before begindocument There arehundreds of such packages that extend LATEXrsquos func-tionality the lab scripts you are reading now use over30 of them

Exercise 3 Including images

Create a document imagetex that contains some text(maybe from rsquoLorem Ipsumrsquo) together with a figurecontaining an image of your choice perhaps the oneyou made in Intro Lab 2 like Steversquos Mr Noodle Thereshould also be a reference to the figure in the text Youshould first use the program convert

convert

(check its manpage) to create a PDF version of the image

Exercise 4 A reflection on your studies

Your first proper LATEX document will be a very briefreflection on your studies so far

Write a hand-crafted LATEX document called courses-reflectiontex

28

COMP10120 Report writing and Digital Typography

(exact name as usual please otherwise submitwill notwork) It will have the following structure

1 A table of contents

2 A brief paragraph saying what the document isabout

3 A section appropriately titled for one of your courseunits containing

bull a brief paragraph saying what the unit is about

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the most about the unit

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the least about the unit

A repeat of item 3 for each other unit you are study-ing These sections should appear in alphabeticalorder by course code (eg COMP10120)

After completing and successfully compiling and view-ing your document you should spell-check it as fol-lows

ispell courses-reflectiontex

29

COMP10120 Report writing and Digital Typography

Once you are completely satisfied with it produce ahard copy ready for marking

34 Typesetting Mathematics

Earlier we saw this formula

x =minusbplusmn

radicb2 minus 4ac

2aIt looks nice doesnrsquot it To tell LATEX to display thisyou have to type a bit of magic but itrsquos easily-learnedmagic To create such a formula in a WYSIWYG edi-tor there is also magic involved but it usually involvesa lot of mouse-clicking and remembering special keycombinations like rsquocontrol-thisrsquo and rsquoalt-thatrsquo In LATEXit doesnrsquot You simply type this

[ x = frac-b pm sqrtb^2-4ac2a ]

You can probably work out how most of this createsthe formula but it wonrsquot be obvious that the [ and ]symbols that enclose the formula mean lsquotypeset this asa displayed formula giving it some vertical space fromthe surrounding textrsquo If wersquod used ( and ) insteadto enclose the formula it would appear in-line like thisx = minusbplusmn

radicb2minus4ac2a It still looks very nice and observe

how itrsquos automatically been resized to fit and that the

30

COMP10120 Report writing and Digital Typography

lines of text have had their spacing changed a bit Thisall looks simple but the implementation inside LATEXand TEX is complex It involves parsing the descrip-tion of the formula to create a corresponding tree datastructure which is then recursively walked to workout the horizontal and vertical typographical spacingsneeded Yoursquoll meet these ideas in COMP11120 andCOMP26120 Algorithms and Imperative Programming

Herersquos another example taken from COMP27112Computer Graphics (itrsquos a lsquosimplersquo local illuminationmodel incorporating ambient diffuse and specular re-flection by multiple lights)

I = kaIa +

Msumi=1

Ipidprimei[kd(N middot Li) + ks(Ri middot V )n]

We write this in LATEX as follows

[ I = k_a I_a + sum_i=1^M fracI_p_idrsquo_i [ k_d(hatN cdot hatL_i)+ k_s(hatR_i cdot hatV)^n] ]

Try to match the LATEX commands with the formula dis-played above Yoursquoll see lots of curly brackets and thisexample illustrates their two uses in LATEX The firstis to provide an argument to a command for exam-ple hatN means lsquoapply the hat command to N rsquowhich creates N the vector N with a little hat on

31

COMP10120 Report writing and Digital Typography

The second use of curly brackets is to group thingstogether to avoid ambiguities In the example you cansee sum_i=1^M which creates a summation signand its lower and upper limits

sumMi=1 We wrap the

lower bound i=1 in curly brackets to group it into anindivisible unit If we were to omit the brackets writ-ing sum_i=1^M LATEX would then produce

sumi = 1M

which is not at all what we want (even LATEX canrsquot al-ways know what we really want)

One final example If we tell LATEX

[ T_1 = left[beginarraycccccos theta amp -sin theta amp 0 amp delta sin theta amp cos theta amp 0 amp epsilon 0 amp 0 amp 1 amp eta alpha amp beta amp gamma amp 1endarrayright] ]

wersquoll get a splendid matrix which expresses a particu-lar 3D geometrical transformation (Donrsquot worry if youdonrsquot recognise this yoursquoll be introduced to matrix no-tation in the latter part of COMP11120 MathematicalTechniques for Computer Science For now you can justtreat it as some mysterious maths)

32

COMP10120 Report writing and Digital Typography

T1 =

cos θ minus sin θ 0 δ

sin θ cos θ 0 ε

0 0 1 η

α β γ 1

In the LATEX code left[means lsquobig opening square

bracket pleasersquo ccccmeans lsquoan array with 4 columnsplease with the items in each column centredrsquo ampmeanslsquostart a new columnrsquo and means lsquostart a new rowrsquoYoursquoll notice that LATEX knows about greek letters itknows about most standard maths symbols too andalso the ways theyrsquore usually used

There are some symbols that you might need (forexample therefore which produces the usual threedots symbol there4) that are not part of standard LATEX Manysuch symbols are provided by the amssymb package ofsymbols compiled by the American Mathematical Soci-ety Details of the many symbols provided by this pack-age can be found online at

mirrormathkuedutex-archivefontsamsfontsdocamssymbpdf

To use these extra symbols you need to have usepackageamssymbin the document preamble

33

COMP10120 Report writing and Digital Typography

341 A longer piece of mathematics

We conclude this section with an example of a longerpiece of mathematics that shows how you might type-set a complete mathematical argument rather than asingle formula The example is Euclidrsquos proof of thefact that

radic2 is irrational Itrsquos an argument that has been

covered in COMP11120 and is an example of proof bycontradiction It starts by making the assumption thatit is not the case that

radic2 is irrational in other words that

we can find integers p and q withradic2 = pq

We can assume without losing anything that p andq have no common factors (Why)

radic2 = pq

qradic2 = p

2q2 = p2

This means that p2 is even from which we can also de-duce that p is even (Why)

This means that p = 2k for some k so

2q2 = (2k)2

there4 2q2 = 4k2

so q2 = 2k2

But this means that q2 and hence q is even Since p andq are both even we have a contradiction to our initialassumption so no such p and q exist

The way this is formatted is shown here

34

COMP10120 Report writing and Digital Typography

It starts by making the assumption that it is emphnot the casethat $sqrt2$ is irrational in other words that we can findintegers $p$ and $q$ with $sqrt2 = pq$

We can assume without losing anything that $p$ and $q$ haveemphno common factors (Why)

[beginarraylcl

sqrt2 amp = amp pq qsqrt2 amp = amp p 2q^2 amp = amp p^2

endarray]

This means that $p^2$ is even from which we can also deduce that $p$is even (Why)

This means that $p = 2k$ for some $k$ so ldots[beginarrayllcl

amp 2q^2 amp = amp (2k)^2 therefore amp 2q^2 amp = amp 4k^2 textso amp q^2 amp = amp 2k^2

endarray]

But this means that $q^2$ and hence $q$ is even Since $p$ and $q$are both even we have a contradiction to our initial assumptionso no such $p$ and $q$ exist

Notice the use of the array environment for gettingthings lined up You can find much more informationabout this on the web

LATEX really shines at typesetting mathematics and

35

COMP10120 Report writing and Digital Typography

it would take pages and pages to describe all the fea-tures Have a look at

enwikibooksorgwikiLaTeXMathematics

for a flavour

Exercise 5 Formatting mathematics

Now for an exercise that involves some mathematicsPlease create a file f-wtex which typesets the follow-ing piece of text and mathematics

There are many positive integer solutions tothe equation

x2 + y2 = z2

which can be rewritten as

z =radicx2 + y2

For example (3 4 5) or (5 12 13) Such solu-tions are called Pythagorean triples

However for higher powers the situation isvery different and we have-

Theorem Fermat-WilesFor all natural numbers n ge 3 there are no

36

COMP10120 Report writing and Digital Typography

integers x y z satisfying the equation

xn + yn = zn

35 Curriculum vitaie

There are several scenarios where using LATEX ratherthan other word processing software can be useful

bull typesetting mathematics yoursquove just read about

bull writing a technical document

bull your final year project peport

bull writing an article you want to get published

bull writing a Curriculum vitae CV

Wersquoll now look at CVrsquos briefly

Exercise 6 Curriculum vitae

Creating a professional document is especially impor-tant when you write your CV because how your CVlooks (not just the content) will determine if you are in-vited to interview for job you are applying for Thatcould be a summer internship next year a year long

37

COMP10120 Report writing and Digital Typography

placement after your second year or graduate positionafter you leave University

As well using a text-editor and compiling files fromthe command line other tools are available for editingLATEXWe will look at one of these overleafcom

Create a basic CV which describes you your edu-cation (including University) and any experience youhave or interesting projects that you may have doneYou can do this using httpsoverleafcom andchoosing the ready-made templates at httpswwwoverleafcomgallerytaggedcv

As you progress through University it is a good ideato keep your CV up to date and get feedback from asmany people as you can There will be opportunities todebug your CV later (See httpgitiomycv if youare interested) but yoursquoll need a ldquobeta releaserdquo (version10) of your CV to get started The best time to start thisprocess is now

36 Some optional extras

Exercise 7 Exploring more LATEX features (op-tional but easy)

This exercise reinforces some of the things yoursquove donealready but also introduces some features of LATEX that

38

COMP10120 Report writing and Digital Typography

will be new to you It is labelled as optional because itisnrsquot marked but we would recommend that you all tryit

Take a copy of the file optinfocoursesCOMP10120ex3latex-introtexand follow the instructions it contains You should readit before you process it with LATEX

Exercise 8 A neat directory listing (optionalmore challenging)

The fact that LATEX source files are just text makes it easyto have them generated by a program You are going toexploit this and use LATEX to produce a neat documentcontaining a listing of the files in any directory

Find how to create tables in LATEX tables using thetabular environment Make a LATEX document by handthat uses a table to neatly show the information aboutthe files in some (small) directory (as produced by ls

-l) Write a shell script called neat-ls that takes anargument which is the path name of a directory andproduces a LATEX document containing the above tablefor the given directory The script could also process theLATEX and display the resulting pdf file Finally find outabout the longtable package and change your script touse that instead

39

COMP10120 Report writing and Digital Typography

Exercise 9 A cleaning rota (optional evenmore challenging)

Now you will write a shell script called make-rota thatgenerates a house cleaning rota (Very handy for nextyear ) This is a table with columns such as KitchenBathroom and Lounge The rows will be weeks in theyear labelled with a date (eg always a Sunday) Theidea is that house mates can write their initials in theboxes promising to clean the corresponding room inthat particular week Start by making a sample tableby hand

Your script should take a single argument which isthe date of the first day of the first row eg102013(the US format for 20 Oct 13) The result will be a docu-ment that contains as many rows as fit on a single page(find out by experimenting)

The dates of each row should be generated from thefirst See the manual page for date to figure out howyou can generate a date that is a number of weeks anddays later than an existing one

361 Marking Scheme

You can view a copy of the marking scheme used bysubmit and labprint at

40

COMP10120 Report writing and Digital Typography

studentnetcsmanchesteracukugtlpmsphpunit=COMP10120ampex=ex3xml

37 Next steps

LATEX is a very powerful tool and it does take a littlegetting used to But itrsquos not as scary as it might initiallyseem and you should find that it doesnrsquot take long tolearn the common commands and techniques to makeyour documents well-structured and readable As youbecome more comfortable with the basics and under-stand the principles of typesetting finding out how todo more complex and sophisticated things is easymdashthere are hundreds of tutorials on the web

Donrsquot get carried away though and use the featuresjudiciously just because yoursquove found a cool new com-mand doesnrsquot mean that you should use it just to showoff your LATEX skills content and structure always trumpstypographic twiddlings4

4For example footnotes like this are for some reason a really tempting fea-ture to use in LATEX and in this document we have abused them mercilessly toillustrate a point Footnotes were originally a means for mechanical typeset-ters to insert comments corrections or additions to existing documents withouthaving to adjust the layout of a whole page and of course in digital typographythis is no longer necessary They can justifiably be used for citations (though itrsquosnot common to do so these days) and URLs if you donrsquot want these intrudinginto the body of your text And in some very very rare cases they can be usedas an aside to the main flow of the text (which is what has been done in this doc-ument) But this should be used sparingly If something is important to sayput it in the main body of your text If itrsquos not then perhaps you should thinkabout leaving it out completely or find some other way of including it Asking

41

COMP10120 Report writing and Digital Typography

371 Acknowledgements

Figure 38 is from the Wikipedia article on cheese

372 License

The text of this exercise is licensed under the terms ofthe Creative Commons Attribution 20 Generic (CC BY30) License

38 Background

What follows is additional contextual information aroundLATEX

LATEX was originally written by Leslie LamportW anAmerican computer scientist now working at MicrosoftResearch although its development has long been takenover by a world-wide LATEX community Itrsquos actuallybuilt on top of another system called TEX a computertypesetting system designed by one of the worldrsquos mostinfluential Computer Scientists Donald KnuthW of Stan-ford University Knuth has said that he designed TEX

the reader to look down at the bottom of a page to find out whether somethingis important or not is irritating and as yoursquove probably found out already oftenmeans you lose track of your reading position They also give the impressionthat the author isnrsquot clear about whether something is important or not whichis never good And long footnotes like this onemdashwhile LATEX will typeset themperfectly wellmdashare just plain silly Best avoid

42

COMP10120 Report writing and Digital Typography

for lsquothe creation of beautiful booksmdashand especially forbooks that contain a lot of mathematicsrsquo(D Knuth1984) Figure 34 shows what these eminent men looklike

So whatrsquos the purpose of LATEX Itrsquos purely a layerof software to make TEX easier to use in everyday sit-uations This is a good idea because although TEX isamazingly powerful it operates at a very low-level whichmakes it hard for non-expert users

Figure 34Don Knuth and Leslie Lamport

381 Pronunciation

The name TEX is intended by its creator to be pronouncedwith the final consonant as in the word loch or the nameBach but English speakers often pronounce it like thefirst syllable of technical The first syllable of LATEX is

43

COMP10120 Report writing and Digital Typography

pronounced as in rsquolayrsquo5

382 Why LATEX

Before we go any further why do we think LATEX is im-portant for youmdasha Computer Science studentmdashto knowabout Here are some reasons in no particular order

bull LATEX and TEX are superb examples of ComputerScience in action TEX was designed by Knuth fromfirst principlesmdashin other words from scratch TEXis actually a programming language and LATEX isa set of functions defined in the TEX language TheTEX lsquocompilerrsquo is written in WEBW a mixture ofdocumentation written in TeX and a PascalW sub-set in order to ensure portability it reads a TEXprogram and outputs documents TEX is completelyself-contained and designed to be portable to anycomputer architecture For example it implementsits own stackW and heapW (with garbage collectionW)and it does fixed-precision arithmeticW donrsquot worryif these terms donrsquot make much sense to you at themoment they soon will

5The Greek prefix lsquotexrsquo means lsquoartrsquo as well as lsquotechnologyrsquo so itrsquos a very nicelychosen name for a piece of software that produces such beautiful output Knuthexplained (D Knuth 1984) that one should lsquopronounce the X of TeX as a Greekchi not as an lsquoxrsquo so that TeX rhymes with the word blecchhhrsquo Wersquore not toosure that helps much unless you are confident in your pronunciation of theword lsquoblecchhrsquo Maybe itrsquos an American thing

44

COMP10120 Report writing and Digital Typography

bull LATEX is a new interesting way for you to thinkabout preparing documents

bull LATEX has a practical advantage for the writer inthat it helps you think more about what you wantto write rather than worrying about how it looks

bull LATEX is a powerful tool for professional scientificdocumentation and as a Computer Scientist youshould know about it

bull LATEX files are just plain text so can easily be cre-ated programatically For example the slides usedfor COMP16120 are generated automatically fromthe source of Johnrsquos book both are typeset usingLATEX The program labprint also produces itsoutput using LATEX using information drawn fromXMLW configuration files and ARCADE

bull Using LATEX is actually quite satisfying and thequality of its output may surprise you

In this lab session you are going to write severalshort documents using LATEX You could also write briefnotes in your logbook about how LATEX works and whatcommands you used inside the source of your docu-ments

45

COMP10120 Report writing and Digital Typography

383 Some history printing mathematics

Mathematics is hard to print on paper and on the Web(many websites resort to GIF or JPG images of mathsformulae which usually look horrible MathMLW pro-vides another approach but it is not yet widely used)

In the days before computers books and newspa-pers were printed with movable typeW made from lotsof little blocks of metal each with letters numbers andsymbols standing in relief which when inked left animpression on the paper (see Figure 35) The job ofthe printer (the printer here of course being a personnot a bit of electronics) was to gather together all theblocks in the right order between two horizontal stripsof wood to create a line of the document and then toassemble all those lines from top to bottom of a pageThus the term type settingW an incredible task whenyou think about it In the printerrsquos workshop by theway the blocks of metal were stored between jobs inwooden boxes called cases Letters like a b and c werestored in one case letters like A B and C were storedin a case sitting on top of that So a lower case and anupper case These terms may ring a bell

As technology progressed machines controlled bytypewriters would mechanically juggle the blocks intothe right order This conceptual model is the basis onwhich TEX operates Only now the metal blocks are

46

COMP10120 Report writing and Digital Typography

Figure 35On the left a piece of cast movable type in the Garamondfont On the right a case of cast metal type pieces andtypeset matter in a composing stick The text reads lsquoThequick brown fox jumps over the lazy dog and feels as if hewere in the seventh heaven of typography together with Her-mann Zapf the most famous artist of thersquo This document istypeset in a font called Palatino created by Hermann ZapfYou may have also seen rsquoZapf Dingbatsrsquo in the font lists ofvarious desktop applications Now you know why

little pieces of data arranged into data structuresThe one thing that traditional printers hated was

dealing with the typesetting of mathematics and theywould charge extra to do it It was incredibly fiddly toget the equations looking right they had to squeeze inextra bits of metal horizontally and vertically

When computers entered the printing world attemptsto print mathematics were limited by the printing tech-nology available It took a long time to reach the pointwhere computers could typeset mathematics beautifullyand that was the outstanding achievement of Knuthrsquos

47

COMP10120 Report writing and Digital Typography

TEXLetrsquos look at a quick example of the quality you get

from LATEX with a very simple formula that yoursquoll recog-nise

x =minusbplusmn

radicb2 minus 4ac

2aWersquoll revisit how LATEX typesets mathematics in Section 34

384 To WYSIWYG or not to WYSIWYG

Up until now you have probably used wordprocessingapplications such as Microsoft Word to create essaysletters and other (probably fairly short) documents Youmost likely know that the majority of modern wordprocessors use a paradigm called WYSIWYG or WhatYou See Is What You Get which means that you canmodify the visual style of the document yoursquore work-ing on by selecting the relevant bits and then choos-ing different attributes such as font size or colour usinga GUI In many ways this seems like such a sensibleand obvious way of doing things that you might bewondering why it even has a special name The rea-son is a historical one in the early days of comput-ing long before graphical window managers becamethe norm and when all you could display on screenwas fixed-width ASCII text in whatever the systemrsquos

48

COMP10120 Report writing and Digital Typography

default font was wordprocessors (eg Figure 36) onlyallowed you to format documents by using special se-quences of characters to cause particular effects Butthese effects were only visible when the document wasprinted So if you wanted a word to appear in boldtext in the wordprocessor you might write somethinglike [bold]hello world[bold] what you saw onscreen was not a direct reflection of what appeared onthe printed page If yoursquove written any HTML how-ever this process of marking up text may be familiarsee for example Figure 37 As computers moved todisplays able to draw things other than raw charac-ters on screen wordprocessors became capable of us-ing multiple fonts and styles as well as graphics anda new generation of applications appeared where whatyou saw on screen was an accurate reflection of how itwould appear when printed what you see (on screen)is what you get (on paper)

The huge advantage of WYSIWYG is that itrsquos reallyeasy to understand whatrsquos going on and most peoplecan create reasonably nicely formatted documents withrelatively little effort For short informal documentsone-off letters memos and such WYSIWYG works quitenicely But if yoursquove ever tried writing anything muchlonger or that includes images and tables you mayhave already started to see where the paradigm breaksdown For example if you write lsquoFigure 38 on page

49

COMP10120 Report writing and Digital Typography

Figure 36A screenshot of Wordperfect 51 running in Microsoft DOScirca 1989

51 shows a picture of some men looking at cheesersquo butthen later on edit your document to include some moretext at the start and a new picture of a some broccoli(as in Figure 39) yoursquod have to search through yourreport to find all mentions of lsquoFigure 38rsquo and lsquopage 51rsquoand manually update them to reflect the new number-ing This might be fine if you have two figures and fivepages but for a hundred-page report containing lots ofpictures you can see how this becomes tedious and er-ror prone very quickly

50

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 21: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

possible to employ finer control over figure placementbut thatrsquos beyond the scope of this introduction

The includegraphics command is not built into core LATEX but is in an additional package whichneeds to be explicitly loaded We load this package byusing the command usepackagegraphicx in thedocument preamble ie after the documentclasscommand but before begindocument There arehundreds of such packages that extend LATEXrsquos func-tionality the lab scripts you are reading now use over30 of them

Exercise 3 Including images

Create a document imagetex that contains some text(maybe from rsquoLorem Ipsumrsquo) together with a figurecontaining an image of your choice perhaps the oneyou made in Intro Lab 2 like Steversquos Mr Noodle Thereshould also be a reference to the figure in the text Youshould first use the program convert

convert

(check its manpage) to create a PDF version of the image

Exercise 4 A reflection on your studies

Your first proper LATEX document will be a very briefreflection on your studies so far

Write a hand-crafted LATEX document called courses-reflectiontex

28

COMP10120 Report writing and Digital Typography

(exact name as usual please otherwise submitwill notwork) It will have the following structure

1 A table of contents

2 A brief paragraph saying what the document isabout

3 A section appropriately titled for one of your courseunits containing

bull a brief paragraph saying what the unit is about

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the most about the unit

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the least about the unit

A repeat of item 3 for each other unit you are study-ing These sections should appear in alphabeticalorder by course code (eg COMP10120)

After completing and successfully compiling and view-ing your document you should spell-check it as fol-lows

ispell courses-reflectiontex

29

COMP10120 Report writing and Digital Typography

Once you are completely satisfied with it produce ahard copy ready for marking

34 Typesetting Mathematics

Earlier we saw this formula

x =minusbplusmn

radicb2 minus 4ac

2aIt looks nice doesnrsquot it To tell LATEX to display thisyou have to type a bit of magic but itrsquos easily-learnedmagic To create such a formula in a WYSIWYG edi-tor there is also magic involved but it usually involvesa lot of mouse-clicking and remembering special keycombinations like rsquocontrol-thisrsquo and rsquoalt-thatrsquo In LATEXit doesnrsquot You simply type this

[ x = frac-b pm sqrtb^2-4ac2a ]

You can probably work out how most of this createsthe formula but it wonrsquot be obvious that the [ and ]symbols that enclose the formula mean lsquotypeset this asa displayed formula giving it some vertical space fromthe surrounding textrsquo If wersquod used ( and ) insteadto enclose the formula it would appear in-line like thisx = minusbplusmn

radicb2minus4ac2a It still looks very nice and observe

how itrsquos automatically been resized to fit and that the

30

COMP10120 Report writing and Digital Typography

lines of text have had their spacing changed a bit Thisall looks simple but the implementation inside LATEXand TEX is complex It involves parsing the descrip-tion of the formula to create a corresponding tree datastructure which is then recursively walked to workout the horizontal and vertical typographical spacingsneeded Yoursquoll meet these ideas in COMP11120 andCOMP26120 Algorithms and Imperative Programming

Herersquos another example taken from COMP27112Computer Graphics (itrsquos a lsquosimplersquo local illuminationmodel incorporating ambient diffuse and specular re-flection by multiple lights)

I = kaIa +

Msumi=1

Ipidprimei[kd(N middot Li) + ks(Ri middot V )n]

We write this in LATEX as follows

[ I = k_a I_a + sum_i=1^M fracI_p_idrsquo_i [ k_d(hatN cdot hatL_i)+ k_s(hatR_i cdot hatV)^n] ]

Try to match the LATEX commands with the formula dis-played above Yoursquoll see lots of curly brackets and thisexample illustrates their two uses in LATEX The firstis to provide an argument to a command for exam-ple hatN means lsquoapply the hat command to N rsquowhich creates N the vector N with a little hat on

31

COMP10120 Report writing and Digital Typography

The second use of curly brackets is to group thingstogether to avoid ambiguities In the example you cansee sum_i=1^M which creates a summation signand its lower and upper limits

sumMi=1 We wrap the

lower bound i=1 in curly brackets to group it into anindivisible unit If we were to omit the brackets writ-ing sum_i=1^M LATEX would then produce

sumi = 1M

which is not at all what we want (even LATEX canrsquot al-ways know what we really want)

One final example If we tell LATEX

[ T_1 = left[beginarraycccccos theta amp -sin theta amp 0 amp delta sin theta amp cos theta amp 0 amp epsilon 0 amp 0 amp 1 amp eta alpha amp beta amp gamma amp 1endarrayright] ]

wersquoll get a splendid matrix which expresses a particu-lar 3D geometrical transformation (Donrsquot worry if youdonrsquot recognise this yoursquoll be introduced to matrix no-tation in the latter part of COMP11120 MathematicalTechniques for Computer Science For now you can justtreat it as some mysterious maths)

32

COMP10120 Report writing and Digital Typography

T1 =

cos θ minus sin θ 0 δ

sin θ cos θ 0 ε

0 0 1 η

α β γ 1

In the LATEX code left[means lsquobig opening square

bracket pleasersquo ccccmeans lsquoan array with 4 columnsplease with the items in each column centredrsquo ampmeanslsquostart a new columnrsquo and means lsquostart a new rowrsquoYoursquoll notice that LATEX knows about greek letters itknows about most standard maths symbols too andalso the ways theyrsquore usually used

There are some symbols that you might need (forexample therefore which produces the usual threedots symbol there4) that are not part of standard LATEX Manysuch symbols are provided by the amssymb package ofsymbols compiled by the American Mathematical Soci-ety Details of the many symbols provided by this pack-age can be found online at

mirrormathkuedutex-archivefontsamsfontsdocamssymbpdf

To use these extra symbols you need to have usepackageamssymbin the document preamble

33

COMP10120 Report writing and Digital Typography

341 A longer piece of mathematics

We conclude this section with an example of a longerpiece of mathematics that shows how you might type-set a complete mathematical argument rather than asingle formula The example is Euclidrsquos proof of thefact that

radic2 is irrational Itrsquos an argument that has been

covered in COMP11120 and is an example of proof bycontradiction It starts by making the assumption thatit is not the case that

radic2 is irrational in other words that

we can find integers p and q withradic2 = pq

We can assume without losing anything that p andq have no common factors (Why)

radic2 = pq

qradic2 = p

2q2 = p2

This means that p2 is even from which we can also de-duce that p is even (Why)

This means that p = 2k for some k so

2q2 = (2k)2

there4 2q2 = 4k2

so q2 = 2k2

But this means that q2 and hence q is even Since p andq are both even we have a contradiction to our initialassumption so no such p and q exist

The way this is formatted is shown here

34

COMP10120 Report writing and Digital Typography

It starts by making the assumption that it is emphnot the casethat $sqrt2$ is irrational in other words that we can findintegers $p$ and $q$ with $sqrt2 = pq$

We can assume without losing anything that $p$ and $q$ haveemphno common factors (Why)

[beginarraylcl

sqrt2 amp = amp pq qsqrt2 amp = amp p 2q^2 amp = amp p^2

endarray]

This means that $p^2$ is even from which we can also deduce that $p$is even (Why)

This means that $p = 2k$ for some $k$ so ldots[beginarrayllcl

amp 2q^2 amp = amp (2k)^2 therefore amp 2q^2 amp = amp 4k^2 textso amp q^2 amp = amp 2k^2

endarray]

But this means that $q^2$ and hence $q$ is even Since $p$ and $q$are both even we have a contradiction to our initial assumptionso no such $p$ and $q$ exist

Notice the use of the array environment for gettingthings lined up You can find much more informationabout this on the web

LATEX really shines at typesetting mathematics and

35

COMP10120 Report writing and Digital Typography

it would take pages and pages to describe all the fea-tures Have a look at

enwikibooksorgwikiLaTeXMathematics

for a flavour

Exercise 5 Formatting mathematics

Now for an exercise that involves some mathematicsPlease create a file f-wtex which typesets the follow-ing piece of text and mathematics

There are many positive integer solutions tothe equation

x2 + y2 = z2

which can be rewritten as

z =radicx2 + y2

For example (3 4 5) or (5 12 13) Such solu-tions are called Pythagorean triples

However for higher powers the situation isvery different and we have-

Theorem Fermat-WilesFor all natural numbers n ge 3 there are no

36

COMP10120 Report writing and Digital Typography

integers x y z satisfying the equation

xn + yn = zn

35 Curriculum vitaie

There are several scenarios where using LATEX ratherthan other word processing software can be useful

bull typesetting mathematics yoursquove just read about

bull writing a technical document

bull your final year project peport

bull writing an article you want to get published

bull writing a Curriculum vitae CV

Wersquoll now look at CVrsquos briefly

Exercise 6 Curriculum vitae

Creating a professional document is especially impor-tant when you write your CV because how your CVlooks (not just the content) will determine if you are in-vited to interview for job you are applying for Thatcould be a summer internship next year a year long

37

COMP10120 Report writing and Digital Typography

placement after your second year or graduate positionafter you leave University

As well using a text-editor and compiling files fromthe command line other tools are available for editingLATEXWe will look at one of these overleafcom

Create a basic CV which describes you your edu-cation (including University) and any experience youhave or interesting projects that you may have doneYou can do this using httpsoverleafcom andchoosing the ready-made templates at httpswwwoverleafcomgallerytaggedcv

As you progress through University it is a good ideato keep your CV up to date and get feedback from asmany people as you can There will be opportunities todebug your CV later (See httpgitiomycv if youare interested) but yoursquoll need a ldquobeta releaserdquo (version10) of your CV to get started The best time to start thisprocess is now

36 Some optional extras

Exercise 7 Exploring more LATEX features (op-tional but easy)

This exercise reinforces some of the things yoursquove donealready but also introduces some features of LATEX that

38

COMP10120 Report writing and Digital Typography

will be new to you It is labelled as optional because itisnrsquot marked but we would recommend that you all tryit

Take a copy of the file optinfocoursesCOMP10120ex3latex-introtexand follow the instructions it contains You should readit before you process it with LATEX

Exercise 8 A neat directory listing (optionalmore challenging)

The fact that LATEX source files are just text makes it easyto have them generated by a program You are going toexploit this and use LATEX to produce a neat documentcontaining a listing of the files in any directory

Find how to create tables in LATEX tables using thetabular environment Make a LATEX document by handthat uses a table to neatly show the information aboutthe files in some (small) directory (as produced by ls

-l) Write a shell script called neat-ls that takes anargument which is the path name of a directory andproduces a LATEX document containing the above tablefor the given directory The script could also process theLATEX and display the resulting pdf file Finally find outabout the longtable package and change your script touse that instead

39

COMP10120 Report writing and Digital Typography

Exercise 9 A cleaning rota (optional evenmore challenging)

Now you will write a shell script called make-rota thatgenerates a house cleaning rota (Very handy for nextyear ) This is a table with columns such as KitchenBathroom and Lounge The rows will be weeks in theyear labelled with a date (eg always a Sunday) Theidea is that house mates can write their initials in theboxes promising to clean the corresponding room inthat particular week Start by making a sample tableby hand

Your script should take a single argument which isthe date of the first day of the first row eg102013(the US format for 20 Oct 13) The result will be a docu-ment that contains as many rows as fit on a single page(find out by experimenting)

The dates of each row should be generated from thefirst See the manual page for date to figure out howyou can generate a date that is a number of weeks anddays later than an existing one

361 Marking Scheme

You can view a copy of the marking scheme used bysubmit and labprint at

40

COMP10120 Report writing and Digital Typography

studentnetcsmanchesteracukugtlpmsphpunit=COMP10120ampex=ex3xml

37 Next steps

LATEX is a very powerful tool and it does take a littlegetting used to But itrsquos not as scary as it might initiallyseem and you should find that it doesnrsquot take long tolearn the common commands and techniques to makeyour documents well-structured and readable As youbecome more comfortable with the basics and under-stand the principles of typesetting finding out how todo more complex and sophisticated things is easymdashthere are hundreds of tutorials on the web

Donrsquot get carried away though and use the featuresjudiciously just because yoursquove found a cool new com-mand doesnrsquot mean that you should use it just to showoff your LATEX skills content and structure always trumpstypographic twiddlings4

4For example footnotes like this are for some reason a really tempting fea-ture to use in LATEX and in this document we have abused them mercilessly toillustrate a point Footnotes were originally a means for mechanical typeset-ters to insert comments corrections or additions to existing documents withouthaving to adjust the layout of a whole page and of course in digital typographythis is no longer necessary They can justifiably be used for citations (though itrsquosnot common to do so these days) and URLs if you donrsquot want these intrudinginto the body of your text And in some very very rare cases they can be usedas an aside to the main flow of the text (which is what has been done in this doc-ument) But this should be used sparingly If something is important to sayput it in the main body of your text If itrsquos not then perhaps you should thinkabout leaving it out completely or find some other way of including it Asking

41

COMP10120 Report writing and Digital Typography

371 Acknowledgements

Figure 38 is from the Wikipedia article on cheese

372 License

The text of this exercise is licensed under the terms ofthe Creative Commons Attribution 20 Generic (CC BY30) License

38 Background

What follows is additional contextual information aroundLATEX

LATEX was originally written by Leslie LamportW anAmerican computer scientist now working at MicrosoftResearch although its development has long been takenover by a world-wide LATEX community Itrsquos actuallybuilt on top of another system called TEX a computertypesetting system designed by one of the worldrsquos mostinfluential Computer Scientists Donald KnuthW of Stan-ford University Knuth has said that he designed TEX

the reader to look down at the bottom of a page to find out whether somethingis important or not is irritating and as yoursquove probably found out already oftenmeans you lose track of your reading position They also give the impressionthat the author isnrsquot clear about whether something is important or not whichis never good And long footnotes like this onemdashwhile LATEX will typeset themperfectly wellmdashare just plain silly Best avoid

42

COMP10120 Report writing and Digital Typography

for lsquothe creation of beautiful booksmdashand especially forbooks that contain a lot of mathematicsrsquo(D Knuth1984) Figure 34 shows what these eminent men looklike

So whatrsquos the purpose of LATEX Itrsquos purely a layerof software to make TEX easier to use in everyday sit-uations This is a good idea because although TEX isamazingly powerful it operates at a very low-level whichmakes it hard for non-expert users

Figure 34Don Knuth and Leslie Lamport

381 Pronunciation

The name TEX is intended by its creator to be pronouncedwith the final consonant as in the word loch or the nameBach but English speakers often pronounce it like thefirst syllable of technical The first syllable of LATEX is

43

COMP10120 Report writing and Digital Typography

pronounced as in rsquolayrsquo5

382 Why LATEX

Before we go any further why do we think LATEX is im-portant for youmdasha Computer Science studentmdashto knowabout Here are some reasons in no particular order

bull LATEX and TEX are superb examples of ComputerScience in action TEX was designed by Knuth fromfirst principlesmdashin other words from scratch TEXis actually a programming language and LATEX isa set of functions defined in the TEX language TheTEX lsquocompilerrsquo is written in WEBW a mixture ofdocumentation written in TeX and a PascalW sub-set in order to ensure portability it reads a TEXprogram and outputs documents TEX is completelyself-contained and designed to be portable to anycomputer architecture For example it implementsits own stackW and heapW (with garbage collectionW)and it does fixed-precision arithmeticW donrsquot worryif these terms donrsquot make much sense to you at themoment they soon will

5The Greek prefix lsquotexrsquo means lsquoartrsquo as well as lsquotechnologyrsquo so itrsquos a very nicelychosen name for a piece of software that produces such beautiful output Knuthexplained (D Knuth 1984) that one should lsquopronounce the X of TeX as a Greekchi not as an lsquoxrsquo so that TeX rhymes with the word blecchhhrsquo Wersquore not toosure that helps much unless you are confident in your pronunciation of theword lsquoblecchhrsquo Maybe itrsquos an American thing

44

COMP10120 Report writing and Digital Typography

bull LATEX is a new interesting way for you to thinkabout preparing documents

bull LATEX has a practical advantage for the writer inthat it helps you think more about what you wantto write rather than worrying about how it looks

bull LATEX is a powerful tool for professional scientificdocumentation and as a Computer Scientist youshould know about it

bull LATEX files are just plain text so can easily be cre-ated programatically For example the slides usedfor COMP16120 are generated automatically fromthe source of Johnrsquos book both are typeset usingLATEX The program labprint also produces itsoutput using LATEX using information drawn fromXMLW configuration files and ARCADE

bull Using LATEX is actually quite satisfying and thequality of its output may surprise you

In this lab session you are going to write severalshort documents using LATEX You could also write briefnotes in your logbook about how LATEX works and whatcommands you used inside the source of your docu-ments

45

COMP10120 Report writing and Digital Typography

383 Some history printing mathematics

Mathematics is hard to print on paper and on the Web(many websites resort to GIF or JPG images of mathsformulae which usually look horrible MathMLW pro-vides another approach but it is not yet widely used)

In the days before computers books and newspa-pers were printed with movable typeW made from lotsof little blocks of metal each with letters numbers andsymbols standing in relief which when inked left animpression on the paper (see Figure 35) The job ofthe printer (the printer here of course being a personnot a bit of electronics) was to gather together all theblocks in the right order between two horizontal stripsof wood to create a line of the document and then toassemble all those lines from top to bottom of a pageThus the term type settingW an incredible task whenyou think about it In the printerrsquos workshop by theway the blocks of metal were stored between jobs inwooden boxes called cases Letters like a b and c werestored in one case letters like A B and C were storedin a case sitting on top of that So a lower case and anupper case These terms may ring a bell

As technology progressed machines controlled bytypewriters would mechanically juggle the blocks intothe right order This conceptual model is the basis onwhich TEX operates Only now the metal blocks are

46

COMP10120 Report writing and Digital Typography

Figure 35On the left a piece of cast movable type in the Garamondfont On the right a case of cast metal type pieces andtypeset matter in a composing stick The text reads lsquoThequick brown fox jumps over the lazy dog and feels as if hewere in the seventh heaven of typography together with Her-mann Zapf the most famous artist of thersquo This document istypeset in a font called Palatino created by Hermann ZapfYou may have also seen rsquoZapf Dingbatsrsquo in the font lists ofvarious desktop applications Now you know why

little pieces of data arranged into data structuresThe one thing that traditional printers hated was

dealing with the typesetting of mathematics and theywould charge extra to do it It was incredibly fiddly toget the equations looking right they had to squeeze inextra bits of metal horizontally and vertically

When computers entered the printing world attemptsto print mathematics were limited by the printing tech-nology available It took a long time to reach the pointwhere computers could typeset mathematics beautifullyand that was the outstanding achievement of Knuthrsquos

47

COMP10120 Report writing and Digital Typography

TEXLetrsquos look at a quick example of the quality you get

from LATEX with a very simple formula that yoursquoll recog-nise

x =minusbplusmn

radicb2 minus 4ac

2aWersquoll revisit how LATEX typesets mathematics in Section 34

384 To WYSIWYG or not to WYSIWYG

Up until now you have probably used wordprocessingapplications such as Microsoft Word to create essaysletters and other (probably fairly short) documents Youmost likely know that the majority of modern wordprocessors use a paradigm called WYSIWYG or WhatYou See Is What You Get which means that you canmodify the visual style of the document yoursquore work-ing on by selecting the relevant bits and then choos-ing different attributes such as font size or colour usinga GUI In many ways this seems like such a sensibleand obvious way of doing things that you might bewondering why it even has a special name The rea-son is a historical one in the early days of comput-ing long before graphical window managers becamethe norm and when all you could display on screenwas fixed-width ASCII text in whatever the systemrsquos

48

COMP10120 Report writing and Digital Typography

default font was wordprocessors (eg Figure 36) onlyallowed you to format documents by using special se-quences of characters to cause particular effects Butthese effects were only visible when the document wasprinted So if you wanted a word to appear in boldtext in the wordprocessor you might write somethinglike [bold]hello world[bold] what you saw onscreen was not a direct reflection of what appeared onthe printed page If yoursquove written any HTML how-ever this process of marking up text may be familiarsee for example Figure 37 As computers moved todisplays able to draw things other than raw charac-ters on screen wordprocessors became capable of us-ing multiple fonts and styles as well as graphics anda new generation of applications appeared where whatyou saw on screen was an accurate reflection of how itwould appear when printed what you see (on screen)is what you get (on paper)

The huge advantage of WYSIWYG is that itrsquos reallyeasy to understand whatrsquos going on and most peoplecan create reasonably nicely formatted documents withrelatively little effort For short informal documentsone-off letters memos and such WYSIWYG works quitenicely But if yoursquove ever tried writing anything muchlonger or that includes images and tables you mayhave already started to see where the paradigm breaksdown For example if you write lsquoFigure 38 on page

49

COMP10120 Report writing and Digital Typography

Figure 36A screenshot of Wordperfect 51 running in Microsoft DOScirca 1989

51 shows a picture of some men looking at cheesersquo butthen later on edit your document to include some moretext at the start and a new picture of a some broccoli(as in Figure 39) yoursquod have to search through yourreport to find all mentions of lsquoFigure 38rsquo and lsquopage 51rsquoand manually update them to reflect the new number-ing This might be fine if you have two figures and fivepages but for a hundred-page report containing lots ofpictures you can see how this becomes tedious and er-ror prone very quickly

50

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 22: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

(exact name as usual please otherwise submitwill notwork) It will have the following structure

1 A table of contents

2 A brief paragraph saying what the document isabout

3 A section appropriately titled for one of your courseunits containing

bull a brief paragraph saying what the unit is about

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the most about the unit

bull A sub-section appropriately titled contain-ing an enumeration of the three things youlike the least about the unit

A repeat of item 3 for each other unit you are study-ing These sections should appear in alphabeticalorder by course code (eg COMP10120)

After completing and successfully compiling and view-ing your document you should spell-check it as fol-lows

ispell courses-reflectiontex

29

COMP10120 Report writing and Digital Typography

Once you are completely satisfied with it produce ahard copy ready for marking

34 Typesetting Mathematics

Earlier we saw this formula

x =minusbplusmn

radicb2 minus 4ac

2aIt looks nice doesnrsquot it To tell LATEX to display thisyou have to type a bit of magic but itrsquos easily-learnedmagic To create such a formula in a WYSIWYG edi-tor there is also magic involved but it usually involvesa lot of mouse-clicking and remembering special keycombinations like rsquocontrol-thisrsquo and rsquoalt-thatrsquo In LATEXit doesnrsquot You simply type this

[ x = frac-b pm sqrtb^2-4ac2a ]

You can probably work out how most of this createsthe formula but it wonrsquot be obvious that the [ and ]symbols that enclose the formula mean lsquotypeset this asa displayed formula giving it some vertical space fromthe surrounding textrsquo If wersquod used ( and ) insteadto enclose the formula it would appear in-line like thisx = minusbplusmn

radicb2minus4ac2a It still looks very nice and observe

how itrsquos automatically been resized to fit and that the

30

COMP10120 Report writing and Digital Typography

lines of text have had their spacing changed a bit Thisall looks simple but the implementation inside LATEXand TEX is complex It involves parsing the descrip-tion of the formula to create a corresponding tree datastructure which is then recursively walked to workout the horizontal and vertical typographical spacingsneeded Yoursquoll meet these ideas in COMP11120 andCOMP26120 Algorithms and Imperative Programming

Herersquos another example taken from COMP27112Computer Graphics (itrsquos a lsquosimplersquo local illuminationmodel incorporating ambient diffuse and specular re-flection by multiple lights)

I = kaIa +

Msumi=1

Ipidprimei[kd(N middot Li) + ks(Ri middot V )n]

We write this in LATEX as follows

[ I = k_a I_a + sum_i=1^M fracI_p_idrsquo_i [ k_d(hatN cdot hatL_i)+ k_s(hatR_i cdot hatV)^n] ]

Try to match the LATEX commands with the formula dis-played above Yoursquoll see lots of curly brackets and thisexample illustrates their two uses in LATEX The firstis to provide an argument to a command for exam-ple hatN means lsquoapply the hat command to N rsquowhich creates N the vector N with a little hat on

31

COMP10120 Report writing and Digital Typography

The second use of curly brackets is to group thingstogether to avoid ambiguities In the example you cansee sum_i=1^M which creates a summation signand its lower and upper limits

sumMi=1 We wrap the

lower bound i=1 in curly brackets to group it into anindivisible unit If we were to omit the brackets writ-ing sum_i=1^M LATEX would then produce

sumi = 1M

which is not at all what we want (even LATEX canrsquot al-ways know what we really want)

One final example If we tell LATEX

[ T_1 = left[beginarraycccccos theta amp -sin theta amp 0 amp delta sin theta amp cos theta amp 0 amp epsilon 0 amp 0 amp 1 amp eta alpha amp beta amp gamma amp 1endarrayright] ]

wersquoll get a splendid matrix which expresses a particu-lar 3D geometrical transformation (Donrsquot worry if youdonrsquot recognise this yoursquoll be introduced to matrix no-tation in the latter part of COMP11120 MathematicalTechniques for Computer Science For now you can justtreat it as some mysterious maths)

32

COMP10120 Report writing and Digital Typography

T1 =

cos θ minus sin θ 0 δ

sin θ cos θ 0 ε

0 0 1 η

α β γ 1

In the LATEX code left[means lsquobig opening square

bracket pleasersquo ccccmeans lsquoan array with 4 columnsplease with the items in each column centredrsquo ampmeanslsquostart a new columnrsquo and means lsquostart a new rowrsquoYoursquoll notice that LATEX knows about greek letters itknows about most standard maths symbols too andalso the ways theyrsquore usually used

There are some symbols that you might need (forexample therefore which produces the usual threedots symbol there4) that are not part of standard LATEX Manysuch symbols are provided by the amssymb package ofsymbols compiled by the American Mathematical Soci-ety Details of the many symbols provided by this pack-age can be found online at

mirrormathkuedutex-archivefontsamsfontsdocamssymbpdf

To use these extra symbols you need to have usepackageamssymbin the document preamble

33

COMP10120 Report writing and Digital Typography

341 A longer piece of mathematics

We conclude this section with an example of a longerpiece of mathematics that shows how you might type-set a complete mathematical argument rather than asingle formula The example is Euclidrsquos proof of thefact that

radic2 is irrational Itrsquos an argument that has been

covered in COMP11120 and is an example of proof bycontradiction It starts by making the assumption thatit is not the case that

radic2 is irrational in other words that

we can find integers p and q withradic2 = pq

We can assume without losing anything that p andq have no common factors (Why)

radic2 = pq

qradic2 = p

2q2 = p2

This means that p2 is even from which we can also de-duce that p is even (Why)

This means that p = 2k for some k so

2q2 = (2k)2

there4 2q2 = 4k2

so q2 = 2k2

But this means that q2 and hence q is even Since p andq are both even we have a contradiction to our initialassumption so no such p and q exist

The way this is formatted is shown here

34

COMP10120 Report writing and Digital Typography

It starts by making the assumption that it is emphnot the casethat $sqrt2$ is irrational in other words that we can findintegers $p$ and $q$ with $sqrt2 = pq$

We can assume without losing anything that $p$ and $q$ haveemphno common factors (Why)

[beginarraylcl

sqrt2 amp = amp pq qsqrt2 amp = amp p 2q^2 amp = amp p^2

endarray]

This means that $p^2$ is even from which we can also deduce that $p$is even (Why)

This means that $p = 2k$ for some $k$ so ldots[beginarrayllcl

amp 2q^2 amp = amp (2k)^2 therefore amp 2q^2 amp = amp 4k^2 textso amp q^2 amp = amp 2k^2

endarray]

But this means that $q^2$ and hence $q$ is even Since $p$ and $q$are both even we have a contradiction to our initial assumptionso no such $p$ and $q$ exist

Notice the use of the array environment for gettingthings lined up You can find much more informationabout this on the web

LATEX really shines at typesetting mathematics and

35

COMP10120 Report writing and Digital Typography

it would take pages and pages to describe all the fea-tures Have a look at

enwikibooksorgwikiLaTeXMathematics

for a flavour

Exercise 5 Formatting mathematics

Now for an exercise that involves some mathematicsPlease create a file f-wtex which typesets the follow-ing piece of text and mathematics

There are many positive integer solutions tothe equation

x2 + y2 = z2

which can be rewritten as

z =radicx2 + y2

For example (3 4 5) or (5 12 13) Such solu-tions are called Pythagorean triples

However for higher powers the situation isvery different and we have-

Theorem Fermat-WilesFor all natural numbers n ge 3 there are no

36

COMP10120 Report writing and Digital Typography

integers x y z satisfying the equation

xn + yn = zn

35 Curriculum vitaie

There are several scenarios where using LATEX ratherthan other word processing software can be useful

bull typesetting mathematics yoursquove just read about

bull writing a technical document

bull your final year project peport

bull writing an article you want to get published

bull writing a Curriculum vitae CV

Wersquoll now look at CVrsquos briefly

Exercise 6 Curriculum vitae

Creating a professional document is especially impor-tant when you write your CV because how your CVlooks (not just the content) will determine if you are in-vited to interview for job you are applying for Thatcould be a summer internship next year a year long

37

COMP10120 Report writing and Digital Typography

placement after your second year or graduate positionafter you leave University

As well using a text-editor and compiling files fromthe command line other tools are available for editingLATEXWe will look at one of these overleafcom

Create a basic CV which describes you your edu-cation (including University) and any experience youhave or interesting projects that you may have doneYou can do this using httpsoverleafcom andchoosing the ready-made templates at httpswwwoverleafcomgallerytaggedcv

As you progress through University it is a good ideato keep your CV up to date and get feedback from asmany people as you can There will be opportunities todebug your CV later (See httpgitiomycv if youare interested) but yoursquoll need a ldquobeta releaserdquo (version10) of your CV to get started The best time to start thisprocess is now

36 Some optional extras

Exercise 7 Exploring more LATEX features (op-tional but easy)

This exercise reinforces some of the things yoursquove donealready but also introduces some features of LATEX that

38

COMP10120 Report writing and Digital Typography

will be new to you It is labelled as optional because itisnrsquot marked but we would recommend that you all tryit

Take a copy of the file optinfocoursesCOMP10120ex3latex-introtexand follow the instructions it contains You should readit before you process it with LATEX

Exercise 8 A neat directory listing (optionalmore challenging)

The fact that LATEX source files are just text makes it easyto have them generated by a program You are going toexploit this and use LATEX to produce a neat documentcontaining a listing of the files in any directory

Find how to create tables in LATEX tables using thetabular environment Make a LATEX document by handthat uses a table to neatly show the information aboutthe files in some (small) directory (as produced by ls

-l) Write a shell script called neat-ls that takes anargument which is the path name of a directory andproduces a LATEX document containing the above tablefor the given directory The script could also process theLATEX and display the resulting pdf file Finally find outabout the longtable package and change your script touse that instead

39

COMP10120 Report writing and Digital Typography

Exercise 9 A cleaning rota (optional evenmore challenging)

Now you will write a shell script called make-rota thatgenerates a house cleaning rota (Very handy for nextyear ) This is a table with columns such as KitchenBathroom and Lounge The rows will be weeks in theyear labelled with a date (eg always a Sunday) Theidea is that house mates can write their initials in theboxes promising to clean the corresponding room inthat particular week Start by making a sample tableby hand

Your script should take a single argument which isthe date of the first day of the first row eg102013(the US format for 20 Oct 13) The result will be a docu-ment that contains as many rows as fit on a single page(find out by experimenting)

The dates of each row should be generated from thefirst See the manual page for date to figure out howyou can generate a date that is a number of weeks anddays later than an existing one

361 Marking Scheme

You can view a copy of the marking scheme used bysubmit and labprint at

40

COMP10120 Report writing and Digital Typography

studentnetcsmanchesteracukugtlpmsphpunit=COMP10120ampex=ex3xml

37 Next steps

LATEX is a very powerful tool and it does take a littlegetting used to But itrsquos not as scary as it might initiallyseem and you should find that it doesnrsquot take long tolearn the common commands and techniques to makeyour documents well-structured and readable As youbecome more comfortable with the basics and under-stand the principles of typesetting finding out how todo more complex and sophisticated things is easymdashthere are hundreds of tutorials on the web

Donrsquot get carried away though and use the featuresjudiciously just because yoursquove found a cool new com-mand doesnrsquot mean that you should use it just to showoff your LATEX skills content and structure always trumpstypographic twiddlings4

4For example footnotes like this are for some reason a really tempting fea-ture to use in LATEX and in this document we have abused them mercilessly toillustrate a point Footnotes were originally a means for mechanical typeset-ters to insert comments corrections or additions to existing documents withouthaving to adjust the layout of a whole page and of course in digital typographythis is no longer necessary They can justifiably be used for citations (though itrsquosnot common to do so these days) and URLs if you donrsquot want these intrudinginto the body of your text And in some very very rare cases they can be usedas an aside to the main flow of the text (which is what has been done in this doc-ument) But this should be used sparingly If something is important to sayput it in the main body of your text If itrsquos not then perhaps you should thinkabout leaving it out completely or find some other way of including it Asking

41

COMP10120 Report writing and Digital Typography

371 Acknowledgements

Figure 38 is from the Wikipedia article on cheese

372 License

The text of this exercise is licensed under the terms ofthe Creative Commons Attribution 20 Generic (CC BY30) License

38 Background

What follows is additional contextual information aroundLATEX

LATEX was originally written by Leslie LamportW anAmerican computer scientist now working at MicrosoftResearch although its development has long been takenover by a world-wide LATEX community Itrsquos actuallybuilt on top of another system called TEX a computertypesetting system designed by one of the worldrsquos mostinfluential Computer Scientists Donald KnuthW of Stan-ford University Knuth has said that he designed TEX

the reader to look down at the bottom of a page to find out whether somethingis important or not is irritating and as yoursquove probably found out already oftenmeans you lose track of your reading position They also give the impressionthat the author isnrsquot clear about whether something is important or not whichis never good And long footnotes like this onemdashwhile LATEX will typeset themperfectly wellmdashare just plain silly Best avoid

42

COMP10120 Report writing and Digital Typography

for lsquothe creation of beautiful booksmdashand especially forbooks that contain a lot of mathematicsrsquo(D Knuth1984) Figure 34 shows what these eminent men looklike

So whatrsquos the purpose of LATEX Itrsquos purely a layerof software to make TEX easier to use in everyday sit-uations This is a good idea because although TEX isamazingly powerful it operates at a very low-level whichmakes it hard for non-expert users

Figure 34Don Knuth and Leslie Lamport

381 Pronunciation

The name TEX is intended by its creator to be pronouncedwith the final consonant as in the word loch or the nameBach but English speakers often pronounce it like thefirst syllable of technical The first syllable of LATEX is

43

COMP10120 Report writing and Digital Typography

pronounced as in rsquolayrsquo5

382 Why LATEX

Before we go any further why do we think LATEX is im-portant for youmdasha Computer Science studentmdashto knowabout Here are some reasons in no particular order

bull LATEX and TEX are superb examples of ComputerScience in action TEX was designed by Knuth fromfirst principlesmdashin other words from scratch TEXis actually a programming language and LATEX isa set of functions defined in the TEX language TheTEX lsquocompilerrsquo is written in WEBW a mixture ofdocumentation written in TeX and a PascalW sub-set in order to ensure portability it reads a TEXprogram and outputs documents TEX is completelyself-contained and designed to be portable to anycomputer architecture For example it implementsits own stackW and heapW (with garbage collectionW)and it does fixed-precision arithmeticW donrsquot worryif these terms donrsquot make much sense to you at themoment they soon will

5The Greek prefix lsquotexrsquo means lsquoartrsquo as well as lsquotechnologyrsquo so itrsquos a very nicelychosen name for a piece of software that produces such beautiful output Knuthexplained (D Knuth 1984) that one should lsquopronounce the X of TeX as a Greekchi not as an lsquoxrsquo so that TeX rhymes with the word blecchhhrsquo Wersquore not toosure that helps much unless you are confident in your pronunciation of theword lsquoblecchhrsquo Maybe itrsquos an American thing

44

COMP10120 Report writing and Digital Typography

bull LATEX is a new interesting way for you to thinkabout preparing documents

bull LATEX has a practical advantage for the writer inthat it helps you think more about what you wantto write rather than worrying about how it looks

bull LATEX is a powerful tool for professional scientificdocumentation and as a Computer Scientist youshould know about it

bull LATEX files are just plain text so can easily be cre-ated programatically For example the slides usedfor COMP16120 are generated automatically fromthe source of Johnrsquos book both are typeset usingLATEX The program labprint also produces itsoutput using LATEX using information drawn fromXMLW configuration files and ARCADE

bull Using LATEX is actually quite satisfying and thequality of its output may surprise you

In this lab session you are going to write severalshort documents using LATEX You could also write briefnotes in your logbook about how LATEX works and whatcommands you used inside the source of your docu-ments

45

COMP10120 Report writing and Digital Typography

383 Some history printing mathematics

Mathematics is hard to print on paper and on the Web(many websites resort to GIF or JPG images of mathsformulae which usually look horrible MathMLW pro-vides another approach but it is not yet widely used)

In the days before computers books and newspa-pers were printed with movable typeW made from lotsof little blocks of metal each with letters numbers andsymbols standing in relief which when inked left animpression on the paper (see Figure 35) The job ofthe printer (the printer here of course being a personnot a bit of electronics) was to gather together all theblocks in the right order between two horizontal stripsof wood to create a line of the document and then toassemble all those lines from top to bottom of a pageThus the term type settingW an incredible task whenyou think about it In the printerrsquos workshop by theway the blocks of metal were stored between jobs inwooden boxes called cases Letters like a b and c werestored in one case letters like A B and C were storedin a case sitting on top of that So a lower case and anupper case These terms may ring a bell

As technology progressed machines controlled bytypewriters would mechanically juggle the blocks intothe right order This conceptual model is the basis onwhich TEX operates Only now the metal blocks are

46

COMP10120 Report writing and Digital Typography

Figure 35On the left a piece of cast movable type in the Garamondfont On the right a case of cast metal type pieces andtypeset matter in a composing stick The text reads lsquoThequick brown fox jumps over the lazy dog and feels as if hewere in the seventh heaven of typography together with Her-mann Zapf the most famous artist of thersquo This document istypeset in a font called Palatino created by Hermann ZapfYou may have also seen rsquoZapf Dingbatsrsquo in the font lists ofvarious desktop applications Now you know why

little pieces of data arranged into data structuresThe one thing that traditional printers hated was

dealing with the typesetting of mathematics and theywould charge extra to do it It was incredibly fiddly toget the equations looking right they had to squeeze inextra bits of metal horizontally and vertically

When computers entered the printing world attemptsto print mathematics were limited by the printing tech-nology available It took a long time to reach the pointwhere computers could typeset mathematics beautifullyand that was the outstanding achievement of Knuthrsquos

47

COMP10120 Report writing and Digital Typography

TEXLetrsquos look at a quick example of the quality you get

from LATEX with a very simple formula that yoursquoll recog-nise

x =minusbplusmn

radicb2 minus 4ac

2aWersquoll revisit how LATEX typesets mathematics in Section 34

384 To WYSIWYG or not to WYSIWYG

Up until now you have probably used wordprocessingapplications such as Microsoft Word to create essaysletters and other (probably fairly short) documents Youmost likely know that the majority of modern wordprocessors use a paradigm called WYSIWYG or WhatYou See Is What You Get which means that you canmodify the visual style of the document yoursquore work-ing on by selecting the relevant bits and then choos-ing different attributes such as font size or colour usinga GUI In many ways this seems like such a sensibleand obvious way of doing things that you might bewondering why it even has a special name The rea-son is a historical one in the early days of comput-ing long before graphical window managers becamethe norm and when all you could display on screenwas fixed-width ASCII text in whatever the systemrsquos

48

COMP10120 Report writing and Digital Typography

default font was wordprocessors (eg Figure 36) onlyallowed you to format documents by using special se-quences of characters to cause particular effects Butthese effects were only visible when the document wasprinted So if you wanted a word to appear in boldtext in the wordprocessor you might write somethinglike [bold]hello world[bold] what you saw onscreen was not a direct reflection of what appeared onthe printed page If yoursquove written any HTML how-ever this process of marking up text may be familiarsee for example Figure 37 As computers moved todisplays able to draw things other than raw charac-ters on screen wordprocessors became capable of us-ing multiple fonts and styles as well as graphics anda new generation of applications appeared where whatyou saw on screen was an accurate reflection of how itwould appear when printed what you see (on screen)is what you get (on paper)

The huge advantage of WYSIWYG is that itrsquos reallyeasy to understand whatrsquos going on and most peoplecan create reasonably nicely formatted documents withrelatively little effort For short informal documentsone-off letters memos and such WYSIWYG works quitenicely But if yoursquove ever tried writing anything muchlonger or that includes images and tables you mayhave already started to see where the paradigm breaksdown For example if you write lsquoFigure 38 on page

49

COMP10120 Report writing and Digital Typography

Figure 36A screenshot of Wordperfect 51 running in Microsoft DOScirca 1989

51 shows a picture of some men looking at cheesersquo butthen later on edit your document to include some moretext at the start and a new picture of a some broccoli(as in Figure 39) yoursquod have to search through yourreport to find all mentions of lsquoFigure 38rsquo and lsquopage 51rsquoand manually update them to reflect the new number-ing This might be fine if you have two figures and fivepages but for a hundred-page report containing lots ofpictures you can see how this becomes tedious and er-ror prone very quickly

50

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 23: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

Once you are completely satisfied with it produce ahard copy ready for marking

34 Typesetting Mathematics

Earlier we saw this formula

x =minusbplusmn

radicb2 minus 4ac

2aIt looks nice doesnrsquot it To tell LATEX to display thisyou have to type a bit of magic but itrsquos easily-learnedmagic To create such a formula in a WYSIWYG edi-tor there is also magic involved but it usually involvesa lot of mouse-clicking and remembering special keycombinations like rsquocontrol-thisrsquo and rsquoalt-thatrsquo In LATEXit doesnrsquot You simply type this

[ x = frac-b pm sqrtb^2-4ac2a ]

You can probably work out how most of this createsthe formula but it wonrsquot be obvious that the [ and ]symbols that enclose the formula mean lsquotypeset this asa displayed formula giving it some vertical space fromthe surrounding textrsquo If wersquod used ( and ) insteadto enclose the formula it would appear in-line like thisx = minusbplusmn

radicb2minus4ac2a It still looks very nice and observe

how itrsquos automatically been resized to fit and that the

30

COMP10120 Report writing and Digital Typography

lines of text have had their spacing changed a bit Thisall looks simple but the implementation inside LATEXand TEX is complex It involves parsing the descrip-tion of the formula to create a corresponding tree datastructure which is then recursively walked to workout the horizontal and vertical typographical spacingsneeded Yoursquoll meet these ideas in COMP11120 andCOMP26120 Algorithms and Imperative Programming

Herersquos another example taken from COMP27112Computer Graphics (itrsquos a lsquosimplersquo local illuminationmodel incorporating ambient diffuse and specular re-flection by multiple lights)

I = kaIa +

Msumi=1

Ipidprimei[kd(N middot Li) + ks(Ri middot V )n]

We write this in LATEX as follows

[ I = k_a I_a + sum_i=1^M fracI_p_idrsquo_i [ k_d(hatN cdot hatL_i)+ k_s(hatR_i cdot hatV)^n] ]

Try to match the LATEX commands with the formula dis-played above Yoursquoll see lots of curly brackets and thisexample illustrates their two uses in LATEX The firstis to provide an argument to a command for exam-ple hatN means lsquoapply the hat command to N rsquowhich creates N the vector N with a little hat on

31

COMP10120 Report writing and Digital Typography

The second use of curly brackets is to group thingstogether to avoid ambiguities In the example you cansee sum_i=1^M which creates a summation signand its lower and upper limits

sumMi=1 We wrap the

lower bound i=1 in curly brackets to group it into anindivisible unit If we were to omit the brackets writ-ing sum_i=1^M LATEX would then produce

sumi = 1M

which is not at all what we want (even LATEX canrsquot al-ways know what we really want)

One final example If we tell LATEX

[ T_1 = left[beginarraycccccos theta amp -sin theta amp 0 amp delta sin theta amp cos theta amp 0 amp epsilon 0 amp 0 amp 1 amp eta alpha amp beta amp gamma amp 1endarrayright] ]

wersquoll get a splendid matrix which expresses a particu-lar 3D geometrical transformation (Donrsquot worry if youdonrsquot recognise this yoursquoll be introduced to matrix no-tation in the latter part of COMP11120 MathematicalTechniques for Computer Science For now you can justtreat it as some mysterious maths)

32

COMP10120 Report writing and Digital Typography

T1 =

cos θ minus sin θ 0 δ

sin θ cos θ 0 ε

0 0 1 η

α β γ 1

In the LATEX code left[means lsquobig opening square

bracket pleasersquo ccccmeans lsquoan array with 4 columnsplease with the items in each column centredrsquo ampmeanslsquostart a new columnrsquo and means lsquostart a new rowrsquoYoursquoll notice that LATEX knows about greek letters itknows about most standard maths symbols too andalso the ways theyrsquore usually used

There are some symbols that you might need (forexample therefore which produces the usual threedots symbol there4) that are not part of standard LATEX Manysuch symbols are provided by the amssymb package ofsymbols compiled by the American Mathematical Soci-ety Details of the many symbols provided by this pack-age can be found online at

mirrormathkuedutex-archivefontsamsfontsdocamssymbpdf

To use these extra symbols you need to have usepackageamssymbin the document preamble

33

COMP10120 Report writing and Digital Typography

341 A longer piece of mathematics

We conclude this section with an example of a longerpiece of mathematics that shows how you might type-set a complete mathematical argument rather than asingle formula The example is Euclidrsquos proof of thefact that

radic2 is irrational Itrsquos an argument that has been

covered in COMP11120 and is an example of proof bycontradiction It starts by making the assumption thatit is not the case that

radic2 is irrational in other words that

we can find integers p and q withradic2 = pq

We can assume without losing anything that p andq have no common factors (Why)

radic2 = pq

qradic2 = p

2q2 = p2

This means that p2 is even from which we can also de-duce that p is even (Why)

This means that p = 2k for some k so

2q2 = (2k)2

there4 2q2 = 4k2

so q2 = 2k2

But this means that q2 and hence q is even Since p andq are both even we have a contradiction to our initialassumption so no such p and q exist

The way this is formatted is shown here

34

COMP10120 Report writing and Digital Typography

It starts by making the assumption that it is emphnot the casethat $sqrt2$ is irrational in other words that we can findintegers $p$ and $q$ with $sqrt2 = pq$

We can assume without losing anything that $p$ and $q$ haveemphno common factors (Why)

[beginarraylcl

sqrt2 amp = amp pq qsqrt2 amp = amp p 2q^2 amp = amp p^2

endarray]

This means that $p^2$ is even from which we can also deduce that $p$is even (Why)

This means that $p = 2k$ for some $k$ so ldots[beginarrayllcl

amp 2q^2 amp = amp (2k)^2 therefore amp 2q^2 amp = amp 4k^2 textso amp q^2 amp = amp 2k^2

endarray]

But this means that $q^2$ and hence $q$ is even Since $p$ and $q$are both even we have a contradiction to our initial assumptionso no such $p$ and $q$ exist

Notice the use of the array environment for gettingthings lined up You can find much more informationabout this on the web

LATEX really shines at typesetting mathematics and

35

COMP10120 Report writing and Digital Typography

it would take pages and pages to describe all the fea-tures Have a look at

enwikibooksorgwikiLaTeXMathematics

for a flavour

Exercise 5 Formatting mathematics

Now for an exercise that involves some mathematicsPlease create a file f-wtex which typesets the follow-ing piece of text and mathematics

There are many positive integer solutions tothe equation

x2 + y2 = z2

which can be rewritten as

z =radicx2 + y2

For example (3 4 5) or (5 12 13) Such solu-tions are called Pythagorean triples

However for higher powers the situation isvery different and we have-

Theorem Fermat-WilesFor all natural numbers n ge 3 there are no

36

COMP10120 Report writing and Digital Typography

integers x y z satisfying the equation

xn + yn = zn

35 Curriculum vitaie

There are several scenarios where using LATEX ratherthan other word processing software can be useful

bull typesetting mathematics yoursquove just read about

bull writing a technical document

bull your final year project peport

bull writing an article you want to get published

bull writing a Curriculum vitae CV

Wersquoll now look at CVrsquos briefly

Exercise 6 Curriculum vitae

Creating a professional document is especially impor-tant when you write your CV because how your CVlooks (not just the content) will determine if you are in-vited to interview for job you are applying for Thatcould be a summer internship next year a year long

37

COMP10120 Report writing and Digital Typography

placement after your second year or graduate positionafter you leave University

As well using a text-editor and compiling files fromthe command line other tools are available for editingLATEXWe will look at one of these overleafcom

Create a basic CV which describes you your edu-cation (including University) and any experience youhave or interesting projects that you may have doneYou can do this using httpsoverleafcom andchoosing the ready-made templates at httpswwwoverleafcomgallerytaggedcv

As you progress through University it is a good ideato keep your CV up to date and get feedback from asmany people as you can There will be opportunities todebug your CV later (See httpgitiomycv if youare interested) but yoursquoll need a ldquobeta releaserdquo (version10) of your CV to get started The best time to start thisprocess is now

36 Some optional extras

Exercise 7 Exploring more LATEX features (op-tional but easy)

This exercise reinforces some of the things yoursquove donealready but also introduces some features of LATEX that

38

COMP10120 Report writing and Digital Typography

will be new to you It is labelled as optional because itisnrsquot marked but we would recommend that you all tryit

Take a copy of the file optinfocoursesCOMP10120ex3latex-introtexand follow the instructions it contains You should readit before you process it with LATEX

Exercise 8 A neat directory listing (optionalmore challenging)

The fact that LATEX source files are just text makes it easyto have them generated by a program You are going toexploit this and use LATEX to produce a neat documentcontaining a listing of the files in any directory

Find how to create tables in LATEX tables using thetabular environment Make a LATEX document by handthat uses a table to neatly show the information aboutthe files in some (small) directory (as produced by ls

-l) Write a shell script called neat-ls that takes anargument which is the path name of a directory andproduces a LATEX document containing the above tablefor the given directory The script could also process theLATEX and display the resulting pdf file Finally find outabout the longtable package and change your script touse that instead

39

COMP10120 Report writing and Digital Typography

Exercise 9 A cleaning rota (optional evenmore challenging)

Now you will write a shell script called make-rota thatgenerates a house cleaning rota (Very handy for nextyear ) This is a table with columns such as KitchenBathroom and Lounge The rows will be weeks in theyear labelled with a date (eg always a Sunday) Theidea is that house mates can write their initials in theboxes promising to clean the corresponding room inthat particular week Start by making a sample tableby hand

Your script should take a single argument which isthe date of the first day of the first row eg102013(the US format for 20 Oct 13) The result will be a docu-ment that contains as many rows as fit on a single page(find out by experimenting)

The dates of each row should be generated from thefirst See the manual page for date to figure out howyou can generate a date that is a number of weeks anddays later than an existing one

361 Marking Scheme

You can view a copy of the marking scheme used bysubmit and labprint at

40

COMP10120 Report writing and Digital Typography

studentnetcsmanchesteracukugtlpmsphpunit=COMP10120ampex=ex3xml

37 Next steps

LATEX is a very powerful tool and it does take a littlegetting used to But itrsquos not as scary as it might initiallyseem and you should find that it doesnrsquot take long tolearn the common commands and techniques to makeyour documents well-structured and readable As youbecome more comfortable with the basics and under-stand the principles of typesetting finding out how todo more complex and sophisticated things is easymdashthere are hundreds of tutorials on the web

Donrsquot get carried away though and use the featuresjudiciously just because yoursquove found a cool new com-mand doesnrsquot mean that you should use it just to showoff your LATEX skills content and structure always trumpstypographic twiddlings4

4For example footnotes like this are for some reason a really tempting fea-ture to use in LATEX and in this document we have abused them mercilessly toillustrate a point Footnotes were originally a means for mechanical typeset-ters to insert comments corrections or additions to existing documents withouthaving to adjust the layout of a whole page and of course in digital typographythis is no longer necessary They can justifiably be used for citations (though itrsquosnot common to do so these days) and URLs if you donrsquot want these intrudinginto the body of your text And in some very very rare cases they can be usedas an aside to the main flow of the text (which is what has been done in this doc-ument) But this should be used sparingly If something is important to sayput it in the main body of your text If itrsquos not then perhaps you should thinkabout leaving it out completely or find some other way of including it Asking

41

COMP10120 Report writing and Digital Typography

371 Acknowledgements

Figure 38 is from the Wikipedia article on cheese

372 License

The text of this exercise is licensed under the terms ofthe Creative Commons Attribution 20 Generic (CC BY30) License

38 Background

What follows is additional contextual information aroundLATEX

LATEX was originally written by Leslie LamportW anAmerican computer scientist now working at MicrosoftResearch although its development has long been takenover by a world-wide LATEX community Itrsquos actuallybuilt on top of another system called TEX a computertypesetting system designed by one of the worldrsquos mostinfluential Computer Scientists Donald KnuthW of Stan-ford University Knuth has said that he designed TEX

the reader to look down at the bottom of a page to find out whether somethingis important or not is irritating and as yoursquove probably found out already oftenmeans you lose track of your reading position They also give the impressionthat the author isnrsquot clear about whether something is important or not whichis never good And long footnotes like this onemdashwhile LATEX will typeset themperfectly wellmdashare just plain silly Best avoid

42

COMP10120 Report writing and Digital Typography

for lsquothe creation of beautiful booksmdashand especially forbooks that contain a lot of mathematicsrsquo(D Knuth1984) Figure 34 shows what these eminent men looklike

So whatrsquos the purpose of LATEX Itrsquos purely a layerof software to make TEX easier to use in everyday sit-uations This is a good idea because although TEX isamazingly powerful it operates at a very low-level whichmakes it hard for non-expert users

Figure 34Don Knuth and Leslie Lamport

381 Pronunciation

The name TEX is intended by its creator to be pronouncedwith the final consonant as in the word loch or the nameBach but English speakers often pronounce it like thefirst syllable of technical The first syllable of LATEX is

43

COMP10120 Report writing and Digital Typography

pronounced as in rsquolayrsquo5

382 Why LATEX

Before we go any further why do we think LATEX is im-portant for youmdasha Computer Science studentmdashto knowabout Here are some reasons in no particular order

bull LATEX and TEX are superb examples of ComputerScience in action TEX was designed by Knuth fromfirst principlesmdashin other words from scratch TEXis actually a programming language and LATEX isa set of functions defined in the TEX language TheTEX lsquocompilerrsquo is written in WEBW a mixture ofdocumentation written in TeX and a PascalW sub-set in order to ensure portability it reads a TEXprogram and outputs documents TEX is completelyself-contained and designed to be portable to anycomputer architecture For example it implementsits own stackW and heapW (with garbage collectionW)and it does fixed-precision arithmeticW donrsquot worryif these terms donrsquot make much sense to you at themoment they soon will

5The Greek prefix lsquotexrsquo means lsquoartrsquo as well as lsquotechnologyrsquo so itrsquos a very nicelychosen name for a piece of software that produces such beautiful output Knuthexplained (D Knuth 1984) that one should lsquopronounce the X of TeX as a Greekchi not as an lsquoxrsquo so that TeX rhymes with the word blecchhhrsquo Wersquore not toosure that helps much unless you are confident in your pronunciation of theword lsquoblecchhrsquo Maybe itrsquos an American thing

44

COMP10120 Report writing and Digital Typography

bull LATEX is a new interesting way for you to thinkabout preparing documents

bull LATEX has a practical advantage for the writer inthat it helps you think more about what you wantto write rather than worrying about how it looks

bull LATEX is a powerful tool for professional scientificdocumentation and as a Computer Scientist youshould know about it

bull LATEX files are just plain text so can easily be cre-ated programatically For example the slides usedfor COMP16120 are generated automatically fromthe source of Johnrsquos book both are typeset usingLATEX The program labprint also produces itsoutput using LATEX using information drawn fromXMLW configuration files and ARCADE

bull Using LATEX is actually quite satisfying and thequality of its output may surprise you

In this lab session you are going to write severalshort documents using LATEX You could also write briefnotes in your logbook about how LATEX works and whatcommands you used inside the source of your docu-ments

45

COMP10120 Report writing and Digital Typography

383 Some history printing mathematics

Mathematics is hard to print on paper and on the Web(many websites resort to GIF or JPG images of mathsformulae which usually look horrible MathMLW pro-vides another approach but it is not yet widely used)

In the days before computers books and newspa-pers were printed with movable typeW made from lotsof little blocks of metal each with letters numbers andsymbols standing in relief which when inked left animpression on the paper (see Figure 35) The job ofthe printer (the printer here of course being a personnot a bit of electronics) was to gather together all theblocks in the right order between two horizontal stripsof wood to create a line of the document and then toassemble all those lines from top to bottom of a pageThus the term type settingW an incredible task whenyou think about it In the printerrsquos workshop by theway the blocks of metal were stored between jobs inwooden boxes called cases Letters like a b and c werestored in one case letters like A B and C were storedin a case sitting on top of that So a lower case and anupper case These terms may ring a bell

As technology progressed machines controlled bytypewriters would mechanically juggle the blocks intothe right order This conceptual model is the basis onwhich TEX operates Only now the metal blocks are

46

COMP10120 Report writing and Digital Typography

Figure 35On the left a piece of cast movable type in the Garamondfont On the right a case of cast metal type pieces andtypeset matter in a composing stick The text reads lsquoThequick brown fox jumps over the lazy dog and feels as if hewere in the seventh heaven of typography together with Her-mann Zapf the most famous artist of thersquo This document istypeset in a font called Palatino created by Hermann ZapfYou may have also seen rsquoZapf Dingbatsrsquo in the font lists ofvarious desktop applications Now you know why

little pieces of data arranged into data structuresThe one thing that traditional printers hated was

dealing with the typesetting of mathematics and theywould charge extra to do it It was incredibly fiddly toget the equations looking right they had to squeeze inextra bits of metal horizontally and vertically

When computers entered the printing world attemptsto print mathematics were limited by the printing tech-nology available It took a long time to reach the pointwhere computers could typeset mathematics beautifullyand that was the outstanding achievement of Knuthrsquos

47

COMP10120 Report writing and Digital Typography

TEXLetrsquos look at a quick example of the quality you get

from LATEX with a very simple formula that yoursquoll recog-nise

x =minusbplusmn

radicb2 minus 4ac

2aWersquoll revisit how LATEX typesets mathematics in Section 34

384 To WYSIWYG or not to WYSIWYG

Up until now you have probably used wordprocessingapplications such as Microsoft Word to create essaysletters and other (probably fairly short) documents Youmost likely know that the majority of modern wordprocessors use a paradigm called WYSIWYG or WhatYou See Is What You Get which means that you canmodify the visual style of the document yoursquore work-ing on by selecting the relevant bits and then choos-ing different attributes such as font size or colour usinga GUI In many ways this seems like such a sensibleand obvious way of doing things that you might bewondering why it even has a special name The rea-son is a historical one in the early days of comput-ing long before graphical window managers becamethe norm and when all you could display on screenwas fixed-width ASCII text in whatever the systemrsquos

48

COMP10120 Report writing and Digital Typography

default font was wordprocessors (eg Figure 36) onlyallowed you to format documents by using special se-quences of characters to cause particular effects Butthese effects were only visible when the document wasprinted So if you wanted a word to appear in boldtext in the wordprocessor you might write somethinglike [bold]hello world[bold] what you saw onscreen was not a direct reflection of what appeared onthe printed page If yoursquove written any HTML how-ever this process of marking up text may be familiarsee for example Figure 37 As computers moved todisplays able to draw things other than raw charac-ters on screen wordprocessors became capable of us-ing multiple fonts and styles as well as graphics anda new generation of applications appeared where whatyou saw on screen was an accurate reflection of how itwould appear when printed what you see (on screen)is what you get (on paper)

The huge advantage of WYSIWYG is that itrsquos reallyeasy to understand whatrsquos going on and most peoplecan create reasonably nicely formatted documents withrelatively little effort For short informal documentsone-off letters memos and such WYSIWYG works quitenicely But if yoursquove ever tried writing anything muchlonger or that includes images and tables you mayhave already started to see where the paradigm breaksdown For example if you write lsquoFigure 38 on page

49

COMP10120 Report writing and Digital Typography

Figure 36A screenshot of Wordperfect 51 running in Microsoft DOScirca 1989

51 shows a picture of some men looking at cheesersquo butthen later on edit your document to include some moretext at the start and a new picture of a some broccoli(as in Figure 39) yoursquod have to search through yourreport to find all mentions of lsquoFigure 38rsquo and lsquopage 51rsquoand manually update them to reflect the new number-ing This might be fine if you have two figures and fivepages but for a hundred-page report containing lots ofpictures you can see how this becomes tedious and er-ror prone very quickly

50

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 24: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

lines of text have had their spacing changed a bit Thisall looks simple but the implementation inside LATEXand TEX is complex It involves parsing the descrip-tion of the formula to create a corresponding tree datastructure which is then recursively walked to workout the horizontal and vertical typographical spacingsneeded Yoursquoll meet these ideas in COMP11120 andCOMP26120 Algorithms and Imperative Programming

Herersquos another example taken from COMP27112Computer Graphics (itrsquos a lsquosimplersquo local illuminationmodel incorporating ambient diffuse and specular re-flection by multiple lights)

I = kaIa +

Msumi=1

Ipidprimei[kd(N middot Li) + ks(Ri middot V )n]

We write this in LATEX as follows

[ I = k_a I_a + sum_i=1^M fracI_p_idrsquo_i [ k_d(hatN cdot hatL_i)+ k_s(hatR_i cdot hatV)^n] ]

Try to match the LATEX commands with the formula dis-played above Yoursquoll see lots of curly brackets and thisexample illustrates their two uses in LATEX The firstis to provide an argument to a command for exam-ple hatN means lsquoapply the hat command to N rsquowhich creates N the vector N with a little hat on

31

COMP10120 Report writing and Digital Typography

The second use of curly brackets is to group thingstogether to avoid ambiguities In the example you cansee sum_i=1^M which creates a summation signand its lower and upper limits

sumMi=1 We wrap the

lower bound i=1 in curly brackets to group it into anindivisible unit If we were to omit the brackets writ-ing sum_i=1^M LATEX would then produce

sumi = 1M

which is not at all what we want (even LATEX canrsquot al-ways know what we really want)

One final example If we tell LATEX

[ T_1 = left[beginarraycccccos theta amp -sin theta amp 0 amp delta sin theta amp cos theta amp 0 amp epsilon 0 amp 0 amp 1 amp eta alpha amp beta amp gamma amp 1endarrayright] ]

wersquoll get a splendid matrix which expresses a particu-lar 3D geometrical transformation (Donrsquot worry if youdonrsquot recognise this yoursquoll be introduced to matrix no-tation in the latter part of COMP11120 MathematicalTechniques for Computer Science For now you can justtreat it as some mysterious maths)

32

COMP10120 Report writing and Digital Typography

T1 =

cos θ minus sin θ 0 δ

sin θ cos θ 0 ε

0 0 1 η

α β γ 1

In the LATEX code left[means lsquobig opening square

bracket pleasersquo ccccmeans lsquoan array with 4 columnsplease with the items in each column centredrsquo ampmeanslsquostart a new columnrsquo and means lsquostart a new rowrsquoYoursquoll notice that LATEX knows about greek letters itknows about most standard maths symbols too andalso the ways theyrsquore usually used

There are some symbols that you might need (forexample therefore which produces the usual threedots symbol there4) that are not part of standard LATEX Manysuch symbols are provided by the amssymb package ofsymbols compiled by the American Mathematical Soci-ety Details of the many symbols provided by this pack-age can be found online at

mirrormathkuedutex-archivefontsamsfontsdocamssymbpdf

To use these extra symbols you need to have usepackageamssymbin the document preamble

33

COMP10120 Report writing and Digital Typography

341 A longer piece of mathematics

We conclude this section with an example of a longerpiece of mathematics that shows how you might type-set a complete mathematical argument rather than asingle formula The example is Euclidrsquos proof of thefact that

radic2 is irrational Itrsquos an argument that has been

covered in COMP11120 and is an example of proof bycontradiction It starts by making the assumption thatit is not the case that

radic2 is irrational in other words that

we can find integers p and q withradic2 = pq

We can assume without losing anything that p andq have no common factors (Why)

radic2 = pq

qradic2 = p

2q2 = p2

This means that p2 is even from which we can also de-duce that p is even (Why)

This means that p = 2k for some k so

2q2 = (2k)2

there4 2q2 = 4k2

so q2 = 2k2

But this means that q2 and hence q is even Since p andq are both even we have a contradiction to our initialassumption so no such p and q exist

The way this is formatted is shown here

34

COMP10120 Report writing and Digital Typography

It starts by making the assumption that it is emphnot the casethat $sqrt2$ is irrational in other words that we can findintegers $p$ and $q$ with $sqrt2 = pq$

We can assume without losing anything that $p$ and $q$ haveemphno common factors (Why)

[beginarraylcl

sqrt2 amp = amp pq qsqrt2 amp = amp p 2q^2 amp = amp p^2

endarray]

This means that $p^2$ is even from which we can also deduce that $p$is even (Why)

This means that $p = 2k$ for some $k$ so ldots[beginarrayllcl

amp 2q^2 amp = amp (2k)^2 therefore amp 2q^2 amp = amp 4k^2 textso amp q^2 amp = amp 2k^2

endarray]

But this means that $q^2$ and hence $q$ is even Since $p$ and $q$are both even we have a contradiction to our initial assumptionso no such $p$ and $q$ exist

Notice the use of the array environment for gettingthings lined up You can find much more informationabout this on the web

LATEX really shines at typesetting mathematics and

35

COMP10120 Report writing and Digital Typography

it would take pages and pages to describe all the fea-tures Have a look at

enwikibooksorgwikiLaTeXMathematics

for a flavour

Exercise 5 Formatting mathematics

Now for an exercise that involves some mathematicsPlease create a file f-wtex which typesets the follow-ing piece of text and mathematics

There are many positive integer solutions tothe equation

x2 + y2 = z2

which can be rewritten as

z =radicx2 + y2

For example (3 4 5) or (5 12 13) Such solu-tions are called Pythagorean triples

However for higher powers the situation isvery different and we have-

Theorem Fermat-WilesFor all natural numbers n ge 3 there are no

36

COMP10120 Report writing and Digital Typography

integers x y z satisfying the equation

xn + yn = zn

35 Curriculum vitaie

There are several scenarios where using LATEX ratherthan other word processing software can be useful

bull typesetting mathematics yoursquove just read about

bull writing a technical document

bull your final year project peport

bull writing an article you want to get published

bull writing a Curriculum vitae CV

Wersquoll now look at CVrsquos briefly

Exercise 6 Curriculum vitae

Creating a professional document is especially impor-tant when you write your CV because how your CVlooks (not just the content) will determine if you are in-vited to interview for job you are applying for Thatcould be a summer internship next year a year long

37

COMP10120 Report writing and Digital Typography

placement after your second year or graduate positionafter you leave University

As well using a text-editor and compiling files fromthe command line other tools are available for editingLATEXWe will look at one of these overleafcom

Create a basic CV which describes you your edu-cation (including University) and any experience youhave or interesting projects that you may have doneYou can do this using httpsoverleafcom andchoosing the ready-made templates at httpswwwoverleafcomgallerytaggedcv

As you progress through University it is a good ideato keep your CV up to date and get feedback from asmany people as you can There will be opportunities todebug your CV later (See httpgitiomycv if youare interested) but yoursquoll need a ldquobeta releaserdquo (version10) of your CV to get started The best time to start thisprocess is now

36 Some optional extras

Exercise 7 Exploring more LATEX features (op-tional but easy)

This exercise reinforces some of the things yoursquove donealready but also introduces some features of LATEX that

38

COMP10120 Report writing and Digital Typography

will be new to you It is labelled as optional because itisnrsquot marked but we would recommend that you all tryit

Take a copy of the file optinfocoursesCOMP10120ex3latex-introtexand follow the instructions it contains You should readit before you process it with LATEX

Exercise 8 A neat directory listing (optionalmore challenging)

The fact that LATEX source files are just text makes it easyto have them generated by a program You are going toexploit this and use LATEX to produce a neat documentcontaining a listing of the files in any directory

Find how to create tables in LATEX tables using thetabular environment Make a LATEX document by handthat uses a table to neatly show the information aboutthe files in some (small) directory (as produced by ls

-l) Write a shell script called neat-ls that takes anargument which is the path name of a directory andproduces a LATEX document containing the above tablefor the given directory The script could also process theLATEX and display the resulting pdf file Finally find outabout the longtable package and change your script touse that instead

39

COMP10120 Report writing and Digital Typography

Exercise 9 A cleaning rota (optional evenmore challenging)

Now you will write a shell script called make-rota thatgenerates a house cleaning rota (Very handy for nextyear ) This is a table with columns such as KitchenBathroom and Lounge The rows will be weeks in theyear labelled with a date (eg always a Sunday) Theidea is that house mates can write their initials in theboxes promising to clean the corresponding room inthat particular week Start by making a sample tableby hand

Your script should take a single argument which isthe date of the first day of the first row eg102013(the US format for 20 Oct 13) The result will be a docu-ment that contains as many rows as fit on a single page(find out by experimenting)

The dates of each row should be generated from thefirst See the manual page for date to figure out howyou can generate a date that is a number of weeks anddays later than an existing one

361 Marking Scheme

You can view a copy of the marking scheme used bysubmit and labprint at

40

COMP10120 Report writing and Digital Typography

studentnetcsmanchesteracukugtlpmsphpunit=COMP10120ampex=ex3xml

37 Next steps

LATEX is a very powerful tool and it does take a littlegetting used to But itrsquos not as scary as it might initiallyseem and you should find that it doesnrsquot take long tolearn the common commands and techniques to makeyour documents well-structured and readable As youbecome more comfortable with the basics and under-stand the principles of typesetting finding out how todo more complex and sophisticated things is easymdashthere are hundreds of tutorials on the web

Donrsquot get carried away though and use the featuresjudiciously just because yoursquove found a cool new com-mand doesnrsquot mean that you should use it just to showoff your LATEX skills content and structure always trumpstypographic twiddlings4

4For example footnotes like this are for some reason a really tempting fea-ture to use in LATEX and in this document we have abused them mercilessly toillustrate a point Footnotes were originally a means for mechanical typeset-ters to insert comments corrections or additions to existing documents withouthaving to adjust the layout of a whole page and of course in digital typographythis is no longer necessary They can justifiably be used for citations (though itrsquosnot common to do so these days) and URLs if you donrsquot want these intrudinginto the body of your text And in some very very rare cases they can be usedas an aside to the main flow of the text (which is what has been done in this doc-ument) But this should be used sparingly If something is important to sayput it in the main body of your text If itrsquos not then perhaps you should thinkabout leaving it out completely or find some other way of including it Asking

41

COMP10120 Report writing and Digital Typography

371 Acknowledgements

Figure 38 is from the Wikipedia article on cheese

372 License

The text of this exercise is licensed under the terms ofthe Creative Commons Attribution 20 Generic (CC BY30) License

38 Background

What follows is additional contextual information aroundLATEX

LATEX was originally written by Leslie LamportW anAmerican computer scientist now working at MicrosoftResearch although its development has long been takenover by a world-wide LATEX community Itrsquos actuallybuilt on top of another system called TEX a computertypesetting system designed by one of the worldrsquos mostinfluential Computer Scientists Donald KnuthW of Stan-ford University Knuth has said that he designed TEX

the reader to look down at the bottom of a page to find out whether somethingis important or not is irritating and as yoursquove probably found out already oftenmeans you lose track of your reading position They also give the impressionthat the author isnrsquot clear about whether something is important or not whichis never good And long footnotes like this onemdashwhile LATEX will typeset themperfectly wellmdashare just plain silly Best avoid

42

COMP10120 Report writing and Digital Typography

for lsquothe creation of beautiful booksmdashand especially forbooks that contain a lot of mathematicsrsquo(D Knuth1984) Figure 34 shows what these eminent men looklike

So whatrsquos the purpose of LATEX Itrsquos purely a layerof software to make TEX easier to use in everyday sit-uations This is a good idea because although TEX isamazingly powerful it operates at a very low-level whichmakes it hard for non-expert users

Figure 34Don Knuth and Leslie Lamport

381 Pronunciation

The name TEX is intended by its creator to be pronouncedwith the final consonant as in the word loch or the nameBach but English speakers often pronounce it like thefirst syllable of technical The first syllable of LATEX is

43

COMP10120 Report writing and Digital Typography

pronounced as in rsquolayrsquo5

382 Why LATEX

Before we go any further why do we think LATEX is im-portant for youmdasha Computer Science studentmdashto knowabout Here are some reasons in no particular order

bull LATEX and TEX are superb examples of ComputerScience in action TEX was designed by Knuth fromfirst principlesmdashin other words from scratch TEXis actually a programming language and LATEX isa set of functions defined in the TEX language TheTEX lsquocompilerrsquo is written in WEBW a mixture ofdocumentation written in TeX and a PascalW sub-set in order to ensure portability it reads a TEXprogram and outputs documents TEX is completelyself-contained and designed to be portable to anycomputer architecture For example it implementsits own stackW and heapW (with garbage collectionW)and it does fixed-precision arithmeticW donrsquot worryif these terms donrsquot make much sense to you at themoment they soon will

5The Greek prefix lsquotexrsquo means lsquoartrsquo as well as lsquotechnologyrsquo so itrsquos a very nicelychosen name for a piece of software that produces such beautiful output Knuthexplained (D Knuth 1984) that one should lsquopronounce the X of TeX as a Greekchi not as an lsquoxrsquo so that TeX rhymes with the word blecchhhrsquo Wersquore not toosure that helps much unless you are confident in your pronunciation of theword lsquoblecchhrsquo Maybe itrsquos an American thing

44

COMP10120 Report writing and Digital Typography

bull LATEX is a new interesting way for you to thinkabout preparing documents

bull LATEX has a practical advantage for the writer inthat it helps you think more about what you wantto write rather than worrying about how it looks

bull LATEX is a powerful tool for professional scientificdocumentation and as a Computer Scientist youshould know about it

bull LATEX files are just plain text so can easily be cre-ated programatically For example the slides usedfor COMP16120 are generated automatically fromthe source of Johnrsquos book both are typeset usingLATEX The program labprint also produces itsoutput using LATEX using information drawn fromXMLW configuration files and ARCADE

bull Using LATEX is actually quite satisfying and thequality of its output may surprise you

In this lab session you are going to write severalshort documents using LATEX You could also write briefnotes in your logbook about how LATEX works and whatcommands you used inside the source of your docu-ments

45

COMP10120 Report writing and Digital Typography

383 Some history printing mathematics

Mathematics is hard to print on paper and on the Web(many websites resort to GIF or JPG images of mathsformulae which usually look horrible MathMLW pro-vides another approach but it is not yet widely used)

In the days before computers books and newspa-pers were printed with movable typeW made from lotsof little blocks of metal each with letters numbers andsymbols standing in relief which when inked left animpression on the paper (see Figure 35) The job ofthe printer (the printer here of course being a personnot a bit of electronics) was to gather together all theblocks in the right order between two horizontal stripsof wood to create a line of the document and then toassemble all those lines from top to bottom of a pageThus the term type settingW an incredible task whenyou think about it In the printerrsquos workshop by theway the blocks of metal were stored between jobs inwooden boxes called cases Letters like a b and c werestored in one case letters like A B and C were storedin a case sitting on top of that So a lower case and anupper case These terms may ring a bell

As technology progressed machines controlled bytypewriters would mechanically juggle the blocks intothe right order This conceptual model is the basis onwhich TEX operates Only now the metal blocks are

46

COMP10120 Report writing and Digital Typography

Figure 35On the left a piece of cast movable type in the Garamondfont On the right a case of cast metal type pieces andtypeset matter in a composing stick The text reads lsquoThequick brown fox jumps over the lazy dog and feels as if hewere in the seventh heaven of typography together with Her-mann Zapf the most famous artist of thersquo This document istypeset in a font called Palatino created by Hermann ZapfYou may have also seen rsquoZapf Dingbatsrsquo in the font lists ofvarious desktop applications Now you know why

little pieces of data arranged into data structuresThe one thing that traditional printers hated was

dealing with the typesetting of mathematics and theywould charge extra to do it It was incredibly fiddly toget the equations looking right they had to squeeze inextra bits of metal horizontally and vertically

When computers entered the printing world attemptsto print mathematics were limited by the printing tech-nology available It took a long time to reach the pointwhere computers could typeset mathematics beautifullyand that was the outstanding achievement of Knuthrsquos

47

COMP10120 Report writing and Digital Typography

TEXLetrsquos look at a quick example of the quality you get

from LATEX with a very simple formula that yoursquoll recog-nise

x =minusbplusmn

radicb2 minus 4ac

2aWersquoll revisit how LATEX typesets mathematics in Section 34

384 To WYSIWYG or not to WYSIWYG

Up until now you have probably used wordprocessingapplications such as Microsoft Word to create essaysletters and other (probably fairly short) documents Youmost likely know that the majority of modern wordprocessors use a paradigm called WYSIWYG or WhatYou See Is What You Get which means that you canmodify the visual style of the document yoursquore work-ing on by selecting the relevant bits and then choos-ing different attributes such as font size or colour usinga GUI In many ways this seems like such a sensibleand obvious way of doing things that you might bewondering why it even has a special name The rea-son is a historical one in the early days of comput-ing long before graphical window managers becamethe norm and when all you could display on screenwas fixed-width ASCII text in whatever the systemrsquos

48

COMP10120 Report writing and Digital Typography

default font was wordprocessors (eg Figure 36) onlyallowed you to format documents by using special se-quences of characters to cause particular effects Butthese effects were only visible when the document wasprinted So if you wanted a word to appear in boldtext in the wordprocessor you might write somethinglike [bold]hello world[bold] what you saw onscreen was not a direct reflection of what appeared onthe printed page If yoursquove written any HTML how-ever this process of marking up text may be familiarsee for example Figure 37 As computers moved todisplays able to draw things other than raw charac-ters on screen wordprocessors became capable of us-ing multiple fonts and styles as well as graphics anda new generation of applications appeared where whatyou saw on screen was an accurate reflection of how itwould appear when printed what you see (on screen)is what you get (on paper)

The huge advantage of WYSIWYG is that itrsquos reallyeasy to understand whatrsquos going on and most peoplecan create reasonably nicely formatted documents withrelatively little effort For short informal documentsone-off letters memos and such WYSIWYG works quitenicely But if yoursquove ever tried writing anything muchlonger or that includes images and tables you mayhave already started to see where the paradigm breaksdown For example if you write lsquoFigure 38 on page

49

COMP10120 Report writing and Digital Typography

Figure 36A screenshot of Wordperfect 51 running in Microsoft DOScirca 1989

51 shows a picture of some men looking at cheesersquo butthen later on edit your document to include some moretext at the start and a new picture of a some broccoli(as in Figure 39) yoursquod have to search through yourreport to find all mentions of lsquoFigure 38rsquo and lsquopage 51rsquoand manually update them to reflect the new number-ing This might be fine if you have two figures and fivepages but for a hundred-page report containing lots ofpictures you can see how this becomes tedious and er-ror prone very quickly

50

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 25: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

The second use of curly brackets is to group thingstogether to avoid ambiguities In the example you cansee sum_i=1^M which creates a summation signand its lower and upper limits

sumMi=1 We wrap the

lower bound i=1 in curly brackets to group it into anindivisible unit If we were to omit the brackets writ-ing sum_i=1^M LATEX would then produce

sumi = 1M

which is not at all what we want (even LATEX canrsquot al-ways know what we really want)

One final example If we tell LATEX

[ T_1 = left[beginarraycccccos theta amp -sin theta amp 0 amp delta sin theta amp cos theta amp 0 amp epsilon 0 amp 0 amp 1 amp eta alpha amp beta amp gamma amp 1endarrayright] ]

wersquoll get a splendid matrix which expresses a particu-lar 3D geometrical transformation (Donrsquot worry if youdonrsquot recognise this yoursquoll be introduced to matrix no-tation in the latter part of COMP11120 MathematicalTechniques for Computer Science For now you can justtreat it as some mysterious maths)

32

COMP10120 Report writing and Digital Typography

T1 =

cos θ minus sin θ 0 δ

sin θ cos θ 0 ε

0 0 1 η

α β γ 1

In the LATEX code left[means lsquobig opening square

bracket pleasersquo ccccmeans lsquoan array with 4 columnsplease with the items in each column centredrsquo ampmeanslsquostart a new columnrsquo and means lsquostart a new rowrsquoYoursquoll notice that LATEX knows about greek letters itknows about most standard maths symbols too andalso the ways theyrsquore usually used

There are some symbols that you might need (forexample therefore which produces the usual threedots symbol there4) that are not part of standard LATEX Manysuch symbols are provided by the amssymb package ofsymbols compiled by the American Mathematical Soci-ety Details of the many symbols provided by this pack-age can be found online at

mirrormathkuedutex-archivefontsamsfontsdocamssymbpdf

To use these extra symbols you need to have usepackageamssymbin the document preamble

33

COMP10120 Report writing and Digital Typography

341 A longer piece of mathematics

We conclude this section with an example of a longerpiece of mathematics that shows how you might type-set a complete mathematical argument rather than asingle formula The example is Euclidrsquos proof of thefact that

radic2 is irrational Itrsquos an argument that has been

covered in COMP11120 and is an example of proof bycontradiction It starts by making the assumption thatit is not the case that

radic2 is irrational in other words that

we can find integers p and q withradic2 = pq

We can assume without losing anything that p andq have no common factors (Why)

radic2 = pq

qradic2 = p

2q2 = p2

This means that p2 is even from which we can also de-duce that p is even (Why)

This means that p = 2k for some k so

2q2 = (2k)2

there4 2q2 = 4k2

so q2 = 2k2

But this means that q2 and hence q is even Since p andq are both even we have a contradiction to our initialassumption so no such p and q exist

The way this is formatted is shown here

34

COMP10120 Report writing and Digital Typography

It starts by making the assumption that it is emphnot the casethat $sqrt2$ is irrational in other words that we can findintegers $p$ and $q$ with $sqrt2 = pq$

We can assume without losing anything that $p$ and $q$ haveemphno common factors (Why)

[beginarraylcl

sqrt2 amp = amp pq qsqrt2 amp = amp p 2q^2 amp = amp p^2

endarray]

This means that $p^2$ is even from which we can also deduce that $p$is even (Why)

This means that $p = 2k$ for some $k$ so ldots[beginarrayllcl

amp 2q^2 amp = amp (2k)^2 therefore amp 2q^2 amp = amp 4k^2 textso amp q^2 amp = amp 2k^2

endarray]

But this means that $q^2$ and hence $q$ is even Since $p$ and $q$are both even we have a contradiction to our initial assumptionso no such $p$ and $q$ exist

Notice the use of the array environment for gettingthings lined up You can find much more informationabout this on the web

LATEX really shines at typesetting mathematics and

35

COMP10120 Report writing and Digital Typography

it would take pages and pages to describe all the fea-tures Have a look at

enwikibooksorgwikiLaTeXMathematics

for a flavour

Exercise 5 Formatting mathematics

Now for an exercise that involves some mathematicsPlease create a file f-wtex which typesets the follow-ing piece of text and mathematics

There are many positive integer solutions tothe equation

x2 + y2 = z2

which can be rewritten as

z =radicx2 + y2

For example (3 4 5) or (5 12 13) Such solu-tions are called Pythagorean triples

However for higher powers the situation isvery different and we have-

Theorem Fermat-WilesFor all natural numbers n ge 3 there are no

36

COMP10120 Report writing and Digital Typography

integers x y z satisfying the equation

xn + yn = zn

35 Curriculum vitaie

There are several scenarios where using LATEX ratherthan other word processing software can be useful

bull typesetting mathematics yoursquove just read about

bull writing a technical document

bull your final year project peport

bull writing an article you want to get published

bull writing a Curriculum vitae CV

Wersquoll now look at CVrsquos briefly

Exercise 6 Curriculum vitae

Creating a professional document is especially impor-tant when you write your CV because how your CVlooks (not just the content) will determine if you are in-vited to interview for job you are applying for Thatcould be a summer internship next year a year long

37

COMP10120 Report writing and Digital Typography

placement after your second year or graduate positionafter you leave University

As well using a text-editor and compiling files fromthe command line other tools are available for editingLATEXWe will look at one of these overleafcom

Create a basic CV which describes you your edu-cation (including University) and any experience youhave or interesting projects that you may have doneYou can do this using httpsoverleafcom andchoosing the ready-made templates at httpswwwoverleafcomgallerytaggedcv

As you progress through University it is a good ideato keep your CV up to date and get feedback from asmany people as you can There will be opportunities todebug your CV later (See httpgitiomycv if youare interested) but yoursquoll need a ldquobeta releaserdquo (version10) of your CV to get started The best time to start thisprocess is now

36 Some optional extras

Exercise 7 Exploring more LATEX features (op-tional but easy)

This exercise reinforces some of the things yoursquove donealready but also introduces some features of LATEX that

38

COMP10120 Report writing and Digital Typography

will be new to you It is labelled as optional because itisnrsquot marked but we would recommend that you all tryit

Take a copy of the file optinfocoursesCOMP10120ex3latex-introtexand follow the instructions it contains You should readit before you process it with LATEX

Exercise 8 A neat directory listing (optionalmore challenging)

The fact that LATEX source files are just text makes it easyto have them generated by a program You are going toexploit this and use LATEX to produce a neat documentcontaining a listing of the files in any directory

Find how to create tables in LATEX tables using thetabular environment Make a LATEX document by handthat uses a table to neatly show the information aboutthe files in some (small) directory (as produced by ls

-l) Write a shell script called neat-ls that takes anargument which is the path name of a directory andproduces a LATEX document containing the above tablefor the given directory The script could also process theLATEX and display the resulting pdf file Finally find outabout the longtable package and change your script touse that instead

39

COMP10120 Report writing and Digital Typography

Exercise 9 A cleaning rota (optional evenmore challenging)

Now you will write a shell script called make-rota thatgenerates a house cleaning rota (Very handy for nextyear ) This is a table with columns such as KitchenBathroom and Lounge The rows will be weeks in theyear labelled with a date (eg always a Sunday) Theidea is that house mates can write their initials in theboxes promising to clean the corresponding room inthat particular week Start by making a sample tableby hand

Your script should take a single argument which isthe date of the first day of the first row eg102013(the US format for 20 Oct 13) The result will be a docu-ment that contains as many rows as fit on a single page(find out by experimenting)

The dates of each row should be generated from thefirst See the manual page for date to figure out howyou can generate a date that is a number of weeks anddays later than an existing one

361 Marking Scheme

You can view a copy of the marking scheme used bysubmit and labprint at

40

COMP10120 Report writing and Digital Typography

studentnetcsmanchesteracukugtlpmsphpunit=COMP10120ampex=ex3xml

37 Next steps

LATEX is a very powerful tool and it does take a littlegetting used to But itrsquos not as scary as it might initiallyseem and you should find that it doesnrsquot take long tolearn the common commands and techniques to makeyour documents well-structured and readable As youbecome more comfortable with the basics and under-stand the principles of typesetting finding out how todo more complex and sophisticated things is easymdashthere are hundreds of tutorials on the web

Donrsquot get carried away though and use the featuresjudiciously just because yoursquove found a cool new com-mand doesnrsquot mean that you should use it just to showoff your LATEX skills content and structure always trumpstypographic twiddlings4

4For example footnotes like this are for some reason a really tempting fea-ture to use in LATEX and in this document we have abused them mercilessly toillustrate a point Footnotes were originally a means for mechanical typeset-ters to insert comments corrections or additions to existing documents withouthaving to adjust the layout of a whole page and of course in digital typographythis is no longer necessary They can justifiably be used for citations (though itrsquosnot common to do so these days) and URLs if you donrsquot want these intrudinginto the body of your text And in some very very rare cases they can be usedas an aside to the main flow of the text (which is what has been done in this doc-ument) But this should be used sparingly If something is important to sayput it in the main body of your text If itrsquos not then perhaps you should thinkabout leaving it out completely or find some other way of including it Asking

41

COMP10120 Report writing and Digital Typography

371 Acknowledgements

Figure 38 is from the Wikipedia article on cheese

372 License

The text of this exercise is licensed under the terms ofthe Creative Commons Attribution 20 Generic (CC BY30) License

38 Background

What follows is additional contextual information aroundLATEX

LATEX was originally written by Leslie LamportW anAmerican computer scientist now working at MicrosoftResearch although its development has long been takenover by a world-wide LATEX community Itrsquos actuallybuilt on top of another system called TEX a computertypesetting system designed by one of the worldrsquos mostinfluential Computer Scientists Donald KnuthW of Stan-ford University Knuth has said that he designed TEX

the reader to look down at the bottom of a page to find out whether somethingis important or not is irritating and as yoursquove probably found out already oftenmeans you lose track of your reading position They also give the impressionthat the author isnrsquot clear about whether something is important or not whichis never good And long footnotes like this onemdashwhile LATEX will typeset themperfectly wellmdashare just plain silly Best avoid

42

COMP10120 Report writing and Digital Typography

for lsquothe creation of beautiful booksmdashand especially forbooks that contain a lot of mathematicsrsquo(D Knuth1984) Figure 34 shows what these eminent men looklike

So whatrsquos the purpose of LATEX Itrsquos purely a layerof software to make TEX easier to use in everyday sit-uations This is a good idea because although TEX isamazingly powerful it operates at a very low-level whichmakes it hard for non-expert users

Figure 34Don Knuth and Leslie Lamport

381 Pronunciation

The name TEX is intended by its creator to be pronouncedwith the final consonant as in the word loch or the nameBach but English speakers often pronounce it like thefirst syllable of technical The first syllable of LATEX is

43

COMP10120 Report writing and Digital Typography

pronounced as in rsquolayrsquo5

382 Why LATEX

Before we go any further why do we think LATEX is im-portant for youmdasha Computer Science studentmdashto knowabout Here are some reasons in no particular order

bull LATEX and TEX are superb examples of ComputerScience in action TEX was designed by Knuth fromfirst principlesmdashin other words from scratch TEXis actually a programming language and LATEX isa set of functions defined in the TEX language TheTEX lsquocompilerrsquo is written in WEBW a mixture ofdocumentation written in TeX and a PascalW sub-set in order to ensure portability it reads a TEXprogram and outputs documents TEX is completelyself-contained and designed to be portable to anycomputer architecture For example it implementsits own stackW and heapW (with garbage collectionW)and it does fixed-precision arithmeticW donrsquot worryif these terms donrsquot make much sense to you at themoment they soon will

5The Greek prefix lsquotexrsquo means lsquoartrsquo as well as lsquotechnologyrsquo so itrsquos a very nicelychosen name for a piece of software that produces such beautiful output Knuthexplained (D Knuth 1984) that one should lsquopronounce the X of TeX as a Greekchi not as an lsquoxrsquo so that TeX rhymes with the word blecchhhrsquo Wersquore not toosure that helps much unless you are confident in your pronunciation of theword lsquoblecchhrsquo Maybe itrsquos an American thing

44

COMP10120 Report writing and Digital Typography

bull LATEX is a new interesting way for you to thinkabout preparing documents

bull LATEX has a practical advantage for the writer inthat it helps you think more about what you wantto write rather than worrying about how it looks

bull LATEX is a powerful tool for professional scientificdocumentation and as a Computer Scientist youshould know about it

bull LATEX files are just plain text so can easily be cre-ated programatically For example the slides usedfor COMP16120 are generated automatically fromthe source of Johnrsquos book both are typeset usingLATEX The program labprint also produces itsoutput using LATEX using information drawn fromXMLW configuration files and ARCADE

bull Using LATEX is actually quite satisfying and thequality of its output may surprise you

In this lab session you are going to write severalshort documents using LATEX You could also write briefnotes in your logbook about how LATEX works and whatcommands you used inside the source of your docu-ments

45

COMP10120 Report writing and Digital Typography

383 Some history printing mathematics

Mathematics is hard to print on paper and on the Web(many websites resort to GIF or JPG images of mathsformulae which usually look horrible MathMLW pro-vides another approach but it is not yet widely used)

In the days before computers books and newspa-pers were printed with movable typeW made from lotsof little blocks of metal each with letters numbers andsymbols standing in relief which when inked left animpression on the paper (see Figure 35) The job ofthe printer (the printer here of course being a personnot a bit of electronics) was to gather together all theblocks in the right order between two horizontal stripsof wood to create a line of the document and then toassemble all those lines from top to bottom of a pageThus the term type settingW an incredible task whenyou think about it In the printerrsquos workshop by theway the blocks of metal were stored between jobs inwooden boxes called cases Letters like a b and c werestored in one case letters like A B and C were storedin a case sitting on top of that So a lower case and anupper case These terms may ring a bell

As technology progressed machines controlled bytypewriters would mechanically juggle the blocks intothe right order This conceptual model is the basis onwhich TEX operates Only now the metal blocks are

46

COMP10120 Report writing and Digital Typography

Figure 35On the left a piece of cast movable type in the Garamondfont On the right a case of cast metal type pieces andtypeset matter in a composing stick The text reads lsquoThequick brown fox jumps over the lazy dog and feels as if hewere in the seventh heaven of typography together with Her-mann Zapf the most famous artist of thersquo This document istypeset in a font called Palatino created by Hermann ZapfYou may have also seen rsquoZapf Dingbatsrsquo in the font lists ofvarious desktop applications Now you know why

little pieces of data arranged into data structuresThe one thing that traditional printers hated was

dealing with the typesetting of mathematics and theywould charge extra to do it It was incredibly fiddly toget the equations looking right they had to squeeze inextra bits of metal horizontally and vertically

When computers entered the printing world attemptsto print mathematics were limited by the printing tech-nology available It took a long time to reach the pointwhere computers could typeset mathematics beautifullyand that was the outstanding achievement of Knuthrsquos

47

COMP10120 Report writing and Digital Typography

TEXLetrsquos look at a quick example of the quality you get

from LATEX with a very simple formula that yoursquoll recog-nise

x =minusbplusmn

radicb2 minus 4ac

2aWersquoll revisit how LATEX typesets mathematics in Section 34

384 To WYSIWYG or not to WYSIWYG

Up until now you have probably used wordprocessingapplications such as Microsoft Word to create essaysletters and other (probably fairly short) documents Youmost likely know that the majority of modern wordprocessors use a paradigm called WYSIWYG or WhatYou See Is What You Get which means that you canmodify the visual style of the document yoursquore work-ing on by selecting the relevant bits and then choos-ing different attributes such as font size or colour usinga GUI In many ways this seems like such a sensibleand obvious way of doing things that you might bewondering why it even has a special name The rea-son is a historical one in the early days of comput-ing long before graphical window managers becamethe norm and when all you could display on screenwas fixed-width ASCII text in whatever the systemrsquos

48

COMP10120 Report writing and Digital Typography

default font was wordprocessors (eg Figure 36) onlyallowed you to format documents by using special se-quences of characters to cause particular effects Butthese effects were only visible when the document wasprinted So if you wanted a word to appear in boldtext in the wordprocessor you might write somethinglike [bold]hello world[bold] what you saw onscreen was not a direct reflection of what appeared onthe printed page If yoursquove written any HTML how-ever this process of marking up text may be familiarsee for example Figure 37 As computers moved todisplays able to draw things other than raw charac-ters on screen wordprocessors became capable of us-ing multiple fonts and styles as well as graphics anda new generation of applications appeared where whatyou saw on screen was an accurate reflection of how itwould appear when printed what you see (on screen)is what you get (on paper)

The huge advantage of WYSIWYG is that itrsquos reallyeasy to understand whatrsquos going on and most peoplecan create reasonably nicely formatted documents withrelatively little effort For short informal documentsone-off letters memos and such WYSIWYG works quitenicely But if yoursquove ever tried writing anything muchlonger or that includes images and tables you mayhave already started to see where the paradigm breaksdown For example if you write lsquoFigure 38 on page

49

COMP10120 Report writing and Digital Typography

Figure 36A screenshot of Wordperfect 51 running in Microsoft DOScirca 1989

51 shows a picture of some men looking at cheesersquo butthen later on edit your document to include some moretext at the start and a new picture of a some broccoli(as in Figure 39) yoursquod have to search through yourreport to find all mentions of lsquoFigure 38rsquo and lsquopage 51rsquoand manually update them to reflect the new number-ing This might be fine if you have two figures and fivepages but for a hundred-page report containing lots ofpictures you can see how this becomes tedious and er-ror prone very quickly

50

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 26: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

T1 =

cos θ minus sin θ 0 δ

sin θ cos θ 0 ε

0 0 1 η

α β γ 1

In the LATEX code left[means lsquobig opening square

bracket pleasersquo ccccmeans lsquoan array with 4 columnsplease with the items in each column centredrsquo ampmeanslsquostart a new columnrsquo and means lsquostart a new rowrsquoYoursquoll notice that LATEX knows about greek letters itknows about most standard maths symbols too andalso the ways theyrsquore usually used

There are some symbols that you might need (forexample therefore which produces the usual threedots symbol there4) that are not part of standard LATEX Manysuch symbols are provided by the amssymb package ofsymbols compiled by the American Mathematical Soci-ety Details of the many symbols provided by this pack-age can be found online at

mirrormathkuedutex-archivefontsamsfontsdocamssymbpdf

To use these extra symbols you need to have usepackageamssymbin the document preamble

33

COMP10120 Report writing and Digital Typography

341 A longer piece of mathematics

We conclude this section with an example of a longerpiece of mathematics that shows how you might type-set a complete mathematical argument rather than asingle formula The example is Euclidrsquos proof of thefact that

radic2 is irrational Itrsquos an argument that has been

covered in COMP11120 and is an example of proof bycontradiction It starts by making the assumption thatit is not the case that

radic2 is irrational in other words that

we can find integers p and q withradic2 = pq

We can assume without losing anything that p andq have no common factors (Why)

radic2 = pq

qradic2 = p

2q2 = p2

This means that p2 is even from which we can also de-duce that p is even (Why)

This means that p = 2k for some k so

2q2 = (2k)2

there4 2q2 = 4k2

so q2 = 2k2

But this means that q2 and hence q is even Since p andq are both even we have a contradiction to our initialassumption so no such p and q exist

The way this is formatted is shown here

34

COMP10120 Report writing and Digital Typography

It starts by making the assumption that it is emphnot the casethat $sqrt2$ is irrational in other words that we can findintegers $p$ and $q$ with $sqrt2 = pq$

We can assume without losing anything that $p$ and $q$ haveemphno common factors (Why)

[beginarraylcl

sqrt2 amp = amp pq qsqrt2 amp = amp p 2q^2 amp = amp p^2

endarray]

This means that $p^2$ is even from which we can also deduce that $p$is even (Why)

This means that $p = 2k$ for some $k$ so ldots[beginarrayllcl

amp 2q^2 amp = amp (2k)^2 therefore amp 2q^2 amp = amp 4k^2 textso amp q^2 amp = amp 2k^2

endarray]

But this means that $q^2$ and hence $q$ is even Since $p$ and $q$are both even we have a contradiction to our initial assumptionso no such $p$ and $q$ exist

Notice the use of the array environment for gettingthings lined up You can find much more informationabout this on the web

LATEX really shines at typesetting mathematics and

35

COMP10120 Report writing and Digital Typography

it would take pages and pages to describe all the fea-tures Have a look at

enwikibooksorgwikiLaTeXMathematics

for a flavour

Exercise 5 Formatting mathematics

Now for an exercise that involves some mathematicsPlease create a file f-wtex which typesets the follow-ing piece of text and mathematics

There are many positive integer solutions tothe equation

x2 + y2 = z2

which can be rewritten as

z =radicx2 + y2

For example (3 4 5) or (5 12 13) Such solu-tions are called Pythagorean triples

However for higher powers the situation isvery different and we have-

Theorem Fermat-WilesFor all natural numbers n ge 3 there are no

36

COMP10120 Report writing and Digital Typography

integers x y z satisfying the equation

xn + yn = zn

35 Curriculum vitaie

There are several scenarios where using LATEX ratherthan other word processing software can be useful

bull typesetting mathematics yoursquove just read about

bull writing a technical document

bull your final year project peport

bull writing an article you want to get published

bull writing a Curriculum vitae CV

Wersquoll now look at CVrsquos briefly

Exercise 6 Curriculum vitae

Creating a professional document is especially impor-tant when you write your CV because how your CVlooks (not just the content) will determine if you are in-vited to interview for job you are applying for Thatcould be a summer internship next year a year long

37

COMP10120 Report writing and Digital Typography

placement after your second year or graduate positionafter you leave University

As well using a text-editor and compiling files fromthe command line other tools are available for editingLATEXWe will look at one of these overleafcom

Create a basic CV which describes you your edu-cation (including University) and any experience youhave or interesting projects that you may have doneYou can do this using httpsoverleafcom andchoosing the ready-made templates at httpswwwoverleafcomgallerytaggedcv

As you progress through University it is a good ideato keep your CV up to date and get feedback from asmany people as you can There will be opportunities todebug your CV later (See httpgitiomycv if youare interested) but yoursquoll need a ldquobeta releaserdquo (version10) of your CV to get started The best time to start thisprocess is now

36 Some optional extras

Exercise 7 Exploring more LATEX features (op-tional but easy)

This exercise reinforces some of the things yoursquove donealready but also introduces some features of LATEX that

38

COMP10120 Report writing and Digital Typography

will be new to you It is labelled as optional because itisnrsquot marked but we would recommend that you all tryit

Take a copy of the file optinfocoursesCOMP10120ex3latex-introtexand follow the instructions it contains You should readit before you process it with LATEX

Exercise 8 A neat directory listing (optionalmore challenging)

The fact that LATEX source files are just text makes it easyto have them generated by a program You are going toexploit this and use LATEX to produce a neat documentcontaining a listing of the files in any directory

Find how to create tables in LATEX tables using thetabular environment Make a LATEX document by handthat uses a table to neatly show the information aboutthe files in some (small) directory (as produced by ls

-l) Write a shell script called neat-ls that takes anargument which is the path name of a directory andproduces a LATEX document containing the above tablefor the given directory The script could also process theLATEX and display the resulting pdf file Finally find outabout the longtable package and change your script touse that instead

39

COMP10120 Report writing and Digital Typography

Exercise 9 A cleaning rota (optional evenmore challenging)

Now you will write a shell script called make-rota thatgenerates a house cleaning rota (Very handy for nextyear ) This is a table with columns such as KitchenBathroom and Lounge The rows will be weeks in theyear labelled with a date (eg always a Sunday) Theidea is that house mates can write their initials in theboxes promising to clean the corresponding room inthat particular week Start by making a sample tableby hand

Your script should take a single argument which isthe date of the first day of the first row eg102013(the US format for 20 Oct 13) The result will be a docu-ment that contains as many rows as fit on a single page(find out by experimenting)

The dates of each row should be generated from thefirst See the manual page for date to figure out howyou can generate a date that is a number of weeks anddays later than an existing one

361 Marking Scheme

You can view a copy of the marking scheme used bysubmit and labprint at

40

COMP10120 Report writing and Digital Typography

studentnetcsmanchesteracukugtlpmsphpunit=COMP10120ampex=ex3xml

37 Next steps

LATEX is a very powerful tool and it does take a littlegetting used to But itrsquos not as scary as it might initiallyseem and you should find that it doesnrsquot take long tolearn the common commands and techniques to makeyour documents well-structured and readable As youbecome more comfortable with the basics and under-stand the principles of typesetting finding out how todo more complex and sophisticated things is easymdashthere are hundreds of tutorials on the web

Donrsquot get carried away though and use the featuresjudiciously just because yoursquove found a cool new com-mand doesnrsquot mean that you should use it just to showoff your LATEX skills content and structure always trumpstypographic twiddlings4

4For example footnotes like this are for some reason a really tempting fea-ture to use in LATEX and in this document we have abused them mercilessly toillustrate a point Footnotes were originally a means for mechanical typeset-ters to insert comments corrections or additions to existing documents withouthaving to adjust the layout of a whole page and of course in digital typographythis is no longer necessary They can justifiably be used for citations (though itrsquosnot common to do so these days) and URLs if you donrsquot want these intrudinginto the body of your text And in some very very rare cases they can be usedas an aside to the main flow of the text (which is what has been done in this doc-ument) But this should be used sparingly If something is important to sayput it in the main body of your text If itrsquos not then perhaps you should thinkabout leaving it out completely or find some other way of including it Asking

41

COMP10120 Report writing and Digital Typography

371 Acknowledgements

Figure 38 is from the Wikipedia article on cheese

372 License

The text of this exercise is licensed under the terms ofthe Creative Commons Attribution 20 Generic (CC BY30) License

38 Background

What follows is additional contextual information aroundLATEX

LATEX was originally written by Leslie LamportW anAmerican computer scientist now working at MicrosoftResearch although its development has long been takenover by a world-wide LATEX community Itrsquos actuallybuilt on top of another system called TEX a computertypesetting system designed by one of the worldrsquos mostinfluential Computer Scientists Donald KnuthW of Stan-ford University Knuth has said that he designed TEX

the reader to look down at the bottom of a page to find out whether somethingis important or not is irritating and as yoursquove probably found out already oftenmeans you lose track of your reading position They also give the impressionthat the author isnrsquot clear about whether something is important or not whichis never good And long footnotes like this onemdashwhile LATEX will typeset themperfectly wellmdashare just plain silly Best avoid

42

COMP10120 Report writing and Digital Typography

for lsquothe creation of beautiful booksmdashand especially forbooks that contain a lot of mathematicsrsquo(D Knuth1984) Figure 34 shows what these eminent men looklike

So whatrsquos the purpose of LATEX Itrsquos purely a layerof software to make TEX easier to use in everyday sit-uations This is a good idea because although TEX isamazingly powerful it operates at a very low-level whichmakes it hard for non-expert users

Figure 34Don Knuth and Leslie Lamport

381 Pronunciation

The name TEX is intended by its creator to be pronouncedwith the final consonant as in the word loch or the nameBach but English speakers often pronounce it like thefirst syllable of technical The first syllable of LATEX is

43

COMP10120 Report writing and Digital Typography

pronounced as in rsquolayrsquo5

382 Why LATEX

Before we go any further why do we think LATEX is im-portant for youmdasha Computer Science studentmdashto knowabout Here are some reasons in no particular order

bull LATEX and TEX are superb examples of ComputerScience in action TEX was designed by Knuth fromfirst principlesmdashin other words from scratch TEXis actually a programming language and LATEX isa set of functions defined in the TEX language TheTEX lsquocompilerrsquo is written in WEBW a mixture ofdocumentation written in TeX and a PascalW sub-set in order to ensure portability it reads a TEXprogram and outputs documents TEX is completelyself-contained and designed to be portable to anycomputer architecture For example it implementsits own stackW and heapW (with garbage collectionW)and it does fixed-precision arithmeticW donrsquot worryif these terms donrsquot make much sense to you at themoment they soon will

5The Greek prefix lsquotexrsquo means lsquoartrsquo as well as lsquotechnologyrsquo so itrsquos a very nicelychosen name for a piece of software that produces such beautiful output Knuthexplained (D Knuth 1984) that one should lsquopronounce the X of TeX as a Greekchi not as an lsquoxrsquo so that TeX rhymes with the word blecchhhrsquo Wersquore not toosure that helps much unless you are confident in your pronunciation of theword lsquoblecchhrsquo Maybe itrsquos an American thing

44

COMP10120 Report writing and Digital Typography

bull LATEX is a new interesting way for you to thinkabout preparing documents

bull LATEX has a practical advantage for the writer inthat it helps you think more about what you wantto write rather than worrying about how it looks

bull LATEX is a powerful tool for professional scientificdocumentation and as a Computer Scientist youshould know about it

bull LATEX files are just plain text so can easily be cre-ated programatically For example the slides usedfor COMP16120 are generated automatically fromthe source of Johnrsquos book both are typeset usingLATEX The program labprint also produces itsoutput using LATEX using information drawn fromXMLW configuration files and ARCADE

bull Using LATEX is actually quite satisfying and thequality of its output may surprise you

In this lab session you are going to write severalshort documents using LATEX You could also write briefnotes in your logbook about how LATEX works and whatcommands you used inside the source of your docu-ments

45

COMP10120 Report writing and Digital Typography

383 Some history printing mathematics

Mathematics is hard to print on paper and on the Web(many websites resort to GIF or JPG images of mathsformulae which usually look horrible MathMLW pro-vides another approach but it is not yet widely used)

In the days before computers books and newspa-pers were printed with movable typeW made from lotsof little blocks of metal each with letters numbers andsymbols standing in relief which when inked left animpression on the paper (see Figure 35) The job ofthe printer (the printer here of course being a personnot a bit of electronics) was to gather together all theblocks in the right order between two horizontal stripsof wood to create a line of the document and then toassemble all those lines from top to bottom of a pageThus the term type settingW an incredible task whenyou think about it In the printerrsquos workshop by theway the blocks of metal were stored between jobs inwooden boxes called cases Letters like a b and c werestored in one case letters like A B and C were storedin a case sitting on top of that So a lower case and anupper case These terms may ring a bell

As technology progressed machines controlled bytypewriters would mechanically juggle the blocks intothe right order This conceptual model is the basis onwhich TEX operates Only now the metal blocks are

46

COMP10120 Report writing and Digital Typography

Figure 35On the left a piece of cast movable type in the Garamondfont On the right a case of cast metal type pieces andtypeset matter in a composing stick The text reads lsquoThequick brown fox jumps over the lazy dog and feels as if hewere in the seventh heaven of typography together with Her-mann Zapf the most famous artist of thersquo This document istypeset in a font called Palatino created by Hermann ZapfYou may have also seen rsquoZapf Dingbatsrsquo in the font lists ofvarious desktop applications Now you know why

little pieces of data arranged into data structuresThe one thing that traditional printers hated was

dealing with the typesetting of mathematics and theywould charge extra to do it It was incredibly fiddly toget the equations looking right they had to squeeze inextra bits of metal horizontally and vertically

When computers entered the printing world attemptsto print mathematics were limited by the printing tech-nology available It took a long time to reach the pointwhere computers could typeset mathematics beautifullyand that was the outstanding achievement of Knuthrsquos

47

COMP10120 Report writing and Digital Typography

TEXLetrsquos look at a quick example of the quality you get

from LATEX with a very simple formula that yoursquoll recog-nise

x =minusbplusmn

radicb2 minus 4ac

2aWersquoll revisit how LATEX typesets mathematics in Section 34

384 To WYSIWYG or not to WYSIWYG

Up until now you have probably used wordprocessingapplications such as Microsoft Word to create essaysletters and other (probably fairly short) documents Youmost likely know that the majority of modern wordprocessors use a paradigm called WYSIWYG or WhatYou See Is What You Get which means that you canmodify the visual style of the document yoursquore work-ing on by selecting the relevant bits and then choos-ing different attributes such as font size or colour usinga GUI In many ways this seems like such a sensibleand obvious way of doing things that you might bewondering why it even has a special name The rea-son is a historical one in the early days of comput-ing long before graphical window managers becamethe norm and when all you could display on screenwas fixed-width ASCII text in whatever the systemrsquos

48

COMP10120 Report writing and Digital Typography

default font was wordprocessors (eg Figure 36) onlyallowed you to format documents by using special se-quences of characters to cause particular effects Butthese effects were only visible when the document wasprinted So if you wanted a word to appear in boldtext in the wordprocessor you might write somethinglike [bold]hello world[bold] what you saw onscreen was not a direct reflection of what appeared onthe printed page If yoursquove written any HTML how-ever this process of marking up text may be familiarsee for example Figure 37 As computers moved todisplays able to draw things other than raw charac-ters on screen wordprocessors became capable of us-ing multiple fonts and styles as well as graphics anda new generation of applications appeared where whatyou saw on screen was an accurate reflection of how itwould appear when printed what you see (on screen)is what you get (on paper)

The huge advantage of WYSIWYG is that itrsquos reallyeasy to understand whatrsquos going on and most peoplecan create reasonably nicely formatted documents withrelatively little effort For short informal documentsone-off letters memos and such WYSIWYG works quitenicely But if yoursquove ever tried writing anything muchlonger or that includes images and tables you mayhave already started to see where the paradigm breaksdown For example if you write lsquoFigure 38 on page

49

COMP10120 Report writing and Digital Typography

Figure 36A screenshot of Wordperfect 51 running in Microsoft DOScirca 1989

51 shows a picture of some men looking at cheesersquo butthen later on edit your document to include some moretext at the start and a new picture of a some broccoli(as in Figure 39) yoursquod have to search through yourreport to find all mentions of lsquoFigure 38rsquo and lsquopage 51rsquoand manually update them to reflect the new number-ing This might be fine if you have two figures and fivepages but for a hundred-page report containing lots ofpictures you can see how this becomes tedious and er-ror prone very quickly

50

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 27: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

341 A longer piece of mathematics

We conclude this section with an example of a longerpiece of mathematics that shows how you might type-set a complete mathematical argument rather than asingle formula The example is Euclidrsquos proof of thefact that

radic2 is irrational Itrsquos an argument that has been

covered in COMP11120 and is an example of proof bycontradiction It starts by making the assumption thatit is not the case that

radic2 is irrational in other words that

we can find integers p and q withradic2 = pq

We can assume without losing anything that p andq have no common factors (Why)

radic2 = pq

qradic2 = p

2q2 = p2

This means that p2 is even from which we can also de-duce that p is even (Why)

This means that p = 2k for some k so

2q2 = (2k)2

there4 2q2 = 4k2

so q2 = 2k2

But this means that q2 and hence q is even Since p andq are both even we have a contradiction to our initialassumption so no such p and q exist

The way this is formatted is shown here

34

COMP10120 Report writing and Digital Typography

It starts by making the assumption that it is emphnot the casethat $sqrt2$ is irrational in other words that we can findintegers $p$ and $q$ with $sqrt2 = pq$

We can assume without losing anything that $p$ and $q$ haveemphno common factors (Why)

[beginarraylcl

sqrt2 amp = amp pq qsqrt2 amp = amp p 2q^2 amp = amp p^2

endarray]

This means that $p^2$ is even from which we can also deduce that $p$is even (Why)

This means that $p = 2k$ for some $k$ so ldots[beginarrayllcl

amp 2q^2 amp = amp (2k)^2 therefore amp 2q^2 amp = amp 4k^2 textso amp q^2 amp = amp 2k^2

endarray]

But this means that $q^2$ and hence $q$ is even Since $p$ and $q$are both even we have a contradiction to our initial assumptionso no such $p$ and $q$ exist

Notice the use of the array environment for gettingthings lined up You can find much more informationabout this on the web

LATEX really shines at typesetting mathematics and

35

COMP10120 Report writing and Digital Typography

it would take pages and pages to describe all the fea-tures Have a look at

enwikibooksorgwikiLaTeXMathematics

for a flavour

Exercise 5 Formatting mathematics

Now for an exercise that involves some mathematicsPlease create a file f-wtex which typesets the follow-ing piece of text and mathematics

There are many positive integer solutions tothe equation

x2 + y2 = z2

which can be rewritten as

z =radicx2 + y2

For example (3 4 5) or (5 12 13) Such solu-tions are called Pythagorean triples

However for higher powers the situation isvery different and we have-

Theorem Fermat-WilesFor all natural numbers n ge 3 there are no

36

COMP10120 Report writing and Digital Typography

integers x y z satisfying the equation

xn + yn = zn

35 Curriculum vitaie

There are several scenarios where using LATEX ratherthan other word processing software can be useful

bull typesetting mathematics yoursquove just read about

bull writing a technical document

bull your final year project peport

bull writing an article you want to get published

bull writing a Curriculum vitae CV

Wersquoll now look at CVrsquos briefly

Exercise 6 Curriculum vitae

Creating a professional document is especially impor-tant when you write your CV because how your CVlooks (not just the content) will determine if you are in-vited to interview for job you are applying for Thatcould be a summer internship next year a year long

37

COMP10120 Report writing and Digital Typography

placement after your second year or graduate positionafter you leave University

As well using a text-editor and compiling files fromthe command line other tools are available for editingLATEXWe will look at one of these overleafcom

Create a basic CV which describes you your edu-cation (including University) and any experience youhave or interesting projects that you may have doneYou can do this using httpsoverleafcom andchoosing the ready-made templates at httpswwwoverleafcomgallerytaggedcv

As you progress through University it is a good ideato keep your CV up to date and get feedback from asmany people as you can There will be opportunities todebug your CV later (See httpgitiomycv if youare interested) but yoursquoll need a ldquobeta releaserdquo (version10) of your CV to get started The best time to start thisprocess is now

36 Some optional extras

Exercise 7 Exploring more LATEX features (op-tional but easy)

This exercise reinforces some of the things yoursquove donealready but also introduces some features of LATEX that

38

COMP10120 Report writing and Digital Typography

will be new to you It is labelled as optional because itisnrsquot marked but we would recommend that you all tryit

Take a copy of the file optinfocoursesCOMP10120ex3latex-introtexand follow the instructions it contains You should readit before you process it with LATEX

Exercise 8 A neat directory listing (optionalmore challenging)

The fact that LATEX source files are just text makes it easyto have them generated by a program You are going toexploit this and use LATEX to produce a neat documentcontaining a listing of the files in any directory

Find how to create tables in LATEX tables using thetabular environment Make a LATEX document by handthat uses a table to neatly show the information aboutthe files in some (small) directory (as produced by ls

-l) Write a shell script called neat-ls that takes anargument which is the path name of a directory andproduces a LATEX document containing the above tablefor the given directory The script could also process theLATEX and display the resulting pdf file Finally find outabout the longtable package and change your script touse that instead

39

COMP10120 Report writing and Digital Typography

Exercise 9 A cleaning rota (optional evenmore challenging)

Now you will write a shell script called make-rota thatgenerates a house cleaning rota (Very handy for nextyear ) This is a table with columns such as KitchenBathroom and Lounge The rows will be weeks in theyear labelled with a date (eg always a Sunday) Theidea is that house mates can write their initials in theboxes promising to clean the corresponding room inthat particular week Start by making a sample tableby hand

Your script should take a single argument which isthe date of the first day of the first row eg102013(the US format for 20 Oct 13) The result will be a docu-ment that contains as many rows as fit on a single page(find out by experimenting)

The dates of each row should be generated from thefirst See the manual page for date to figure out howyou can generate a date that is a number of weeks anddays later than an existing one

361 Marking Scheme

You can view a copy of the marking scheme used bysubmit and labprint at

40

COMP10120 Report writing and Digital Typography

studentnetcsmanchesteracukugtlpmsphpunit=COMP10120ampex=ex3xml

37 Next steps

LATEX is a very powerful tool and it does take a littlegetting used to But itrsquos not as scary as it might initiallyseem and you should find that it doesnrsquot take long tolearn the common commands and techniques to makeyour documents well-structured and readable As youbecome more comfortable with the basics and under-stand the principles of typesetting finding out how todo more complex and sophisticated things is easymdashthere are hundreds of tutorials on the web

Donrsquot get carried away though and use the featuresjudiciously just because yoursquove found a cool new com-mand doesnrsquot mean that you should use it just to showoff your LATEX skills content and structure always trumpstypographic twiddlings4

4For example footnotes like this are for some reason a really tempting fea-ture to use in LATEX and in this document we have abused them mercilessly toillustrate a point Footnotes were originally a means for mechanical typeset-ters to insert comments corrections or additions to existing documents withouthaving to adjust the layout of a whole page and of course in digital typographythis is no longer necessary They can justifiably be used for citations (though itrsquosnot common to do so these days) and URLs if you donrsquot want these intrudinginto the body of your text And in some very very rare cases they can be usedas an aside to the main flow of the text (which is what has been done in this doc-ument) But this should be used sparingly If something is important to sayput it in the main body of your text If itrsquos not then perhaps you should thinkabout leaving it out completely or find some other way of including it Asking

41

COMP10120 Report writing and Digital Typography

371 Acknowledgements

Figure 38 is from the Wikipedia article on cheese

372 License

The text of this exercise is licensed under the terms ofthe Creative Commons Attribution 20 Generic (CC BY30) License

38 Background

What follows is additional contextual information aroundLATEX

LATEX was originally written by Leslie LamportW anAmerican computer scientist now working at MicrosoftResearch although its development has long been takenover by a world-wide LATEX community Itrsquos actuallybuilt on top of another system called TEX a computertypesetting system designed by one of the worldrsquos mostinfluential Computer Scientists Donald KnuthW of Stan-ford University Knuth has said that he designed TEX

the reader to look down at the bottom of a page to find out whether somethingis important or not is irritating and as yoursquove probably found out already oftenmeans you lose track of your reading position They also give the impressionthat the author isnrsquot clear about whether something is important or not whichis never good And long footnotes like this onemdashwhile LATEX will typeset themperfectly wellmdashare just plain silly Best avoid

42

COMP10120 Report writing and Digital Typography

for lsquothe creation of beautiful booksmdashand especially forbooks that contain a lot of mathematicsrsquo(D Knuth1984) Figure 34 shows what these eminent men looklike

So whatrsquos the purpose of LATEX Itrsquos purely a layerof software to make TEX easier to use in everyday sit-uations This is a good idea because although TEX isamazingly powerful it operates at a very low-level whichmakes it hard for non-expert users

Figure 34Don Knuth and Leslie Lamport

381 Pronunciation

The name TEX is intended by its creator to be pronouncedwith the final consonant as in the word loch or the nameBach but English speakers often pronounce it like thefirst syllable of technical The first syllable of LATEX is

43

COMP10120 Report writing and Digital Typography

pronounced as in rsquolayrsquo5

382 Why LATEX

Before we go any further why do we think LATEX is im-portant for youmdasha Computer Science studentmdashto knowabout Here are some reasons in no particular order

bull LATEX and TEX are superb examples of ComputerScience in action TEX was designed by Knuth fromfirst principlesmdashin other words from scratch TEXis actually a programming language and LATEX isa set of functions defined in the TEX language TheTEX lsquocompilerrsquo is written in WEBW a mixture ofdocumentation written in TeX and a PascalW sub-set in order to ensure portability it reads a TEXprogram and outputs documents TEX is completelyself-contained and designed to be portable to anycomputer architecture For example it implementsits own stackW and heapW (with garbage collectionW)and it does fixed-precision arithmeticW donrsquot worryif these terms donrsquot make much sense to you at themoment they soon will

5The Greek prefix lsquotexrsquo means lsquoartrsquo as well as lsquotechnologyrsquo so itrsquos a very nicelychosen name for a piece of software that produces such beautiful output Knuthexplained (D Knuth 1984) that one should lsquopronounce the X of TeX as a Greekchi not as an lsquoxrsquo so that TeX rhymes with the word blecchhhrsquo Wersquore not toosure that helps much unless you are confident in your pronunciation of theword lsquoblecchhrsquo Maybe itrsquos an American thing

44

COMP10120 Report writing and Digital Typography

bull LATEX is a new interesting way for you to thinkabout preparing documents

bull LATEX has a practical advantage for the writer inthat it helps you think more about what you wantto write rather than worrying about how it looks

bull LATEX is a powerful tool for professional scientificdocumentation and as a Computer Scientist youshould know about it

bull LATEX files are just plain text so can easily be cre-ated programatically For example the slides usedfor COMP16120 are generated automatically fromthe source of Johnrsquos book both are typeset usingLATEX The program labprint also produces itsoutput using LATEX using information drawn fromXMLW configuration files and ARCADE

bull Using LATEX is actually quite satisfying and thequality of its output may surprise you

In this lab session you are going to write severalshort documents using LATEX You could also write briefnotes in your logbook about how LATEX works and whatcommands you used inside the source of your docu-ments

45

COMP10120 Report writing and Digital Typography

383 Some history printing mathematics

Mathematics is hard to print on paper and on the Web(many websites resort to GIF or JPG images of mathsformulae which usually look horrible MathMLW pro-vides another approach but it is not yet widely used)

In the days before computers books and newspa-pers were printed with movable typeW made from lotsof little blocks of metal each with letters numbers andsymbols standing in relief which when inked left animpression on the paper (see Figure 35) The job ofthe printer (the printer here of course being a personnot a bit of electronics) was to gather together all theblocks in the right order between two horizontal stripsof wood to create a line of the document and then toassemble all those lines from top to bottom of a pageThus the term type settingW an incredible task whenyou think about it In the printerrsquos workshop by theway the blocks of metal were stored between jobs inwooden boxes called cases Letters like a b and c werestored in one case letters like A B and C were storedin a case sitting on top of that So a lower case and anupper case These terms may ring a bell

As technology progressed machines controlled bytypewriters would mechanically juggle the blocks intothe right order This conceptual model is the basis onwhich TEX operates Only now the metal blocks are

46

COMP10120 Report writing and Digital Typography

Figure 35On the left a piece of cast movable type in the Garamondfont On the right a case of cast metal type pieces andtypeset matter in a composing stick The text reads lsquoThequick brown fox jumps over the lazy dog and feels as if hewere in the seventh heaven of typography together with Her-mann Zapf the most famous artist of thersquo This document istypeset in a font called Palatino created by Hermann ZapfYou may have also seen rsquoZapf Dingbatsrsquo in the font lists ofvarious desktop applications Now you know why

little pieces of data arranged into data structuresThe one thing that traditional printers hated was

dealing with the typesetting of mathematics and theywould charge extra to do it It was incredibly fiddly toget the equations looking right they had to squeeze inextra bits of metal horizontally and vertically

When computers entered the printing world attemptsto print mathematics were limited by the printing tech-nology available It took a long time to reach the pointwhere computers could typeset mathematics beautifullyand that was the outstanding achievement of Knuthrsquos

47

COMP10120 Report writing and Digital Typography

TEXLetrsquos look at a quick example of the quality you get

from LATEX with a very simple formula that yoursquoll recog-nise

x =minusbplusmn

radicb2 minus 4ac

2aWersquoll revisit how LATEX typesets mathematics in Section 34

384 To WYSIWYG or not to WYSIWYG

Up until now you have probably used wordprocessingapplications such as Microsoft Word to create essaysletters and other (probably fairly short) documents Youmost likely know that the majority of modern wordprocessors use a paradigm called WYSIWYG or WhatYou See Is What You Get which means that you canmodify the visual style of the document yoursquore work-ing on by selecting the relevant bits and then choos-ing different attributes such as font size or colour usinga GUI In many ways this seems like such a sensibleand obvious way of doing things that you might bewondering why it even has a special name The rea-son is a historical one in the early days of comput-ing long before graphical window managers becamethe norm and when all you could display on screenwas fixed-width ASCII text in whatever the systemrsquos

48

COMP10120 Report writing and Digital Typography

default font was wordprocessors (eg Figure 36) onlyallowed you to format documents by using special se-quences of characters to cause particular effects Butthese effects were only visible when the document wasprinted So if you wanted a word to appear in boldtext in the wordprocessor you might write somethinglike [bold]hello world[bold] what you saw onscreen was not a direct reflection of what appeared onthe printed page If yoursquove written any HTML how-ever this process of marking up text may be familiarsee for example Figure 37 As computers moved todisplays able to draw things other than raw charac-ters on screen wordprocessors became capable of us-ing multiple fonts and styles as well as graphics anda new generation of applications appeared where whatyou saw on screen was an accurate reflection of how itwould appear when printed what you see (on screen)is what you get (on paper)

The huge advantage of WYSIWYG is that itrsquos reallyeasy to understand whatrsquos going on and most peoplecan create reasonably nicely formatted documents withrelatively little effort For short informal documentsone-off letters memos and such WYSIWYG works quitenicely But if yoursquove ever tried writing anything muchlonger or that includes images and tables you mayhave already started to see where the paradigm breaksdown For example if you write lsquoFigure 38 on page

49

COMP10120 Report writing and Digital Typography

Figure 36A screenshot of Wordperfect 51 running in Microsoft DOScirca 1989

51 shows a picture of some men looking at cheesersquo butthen later on edit your document to include some moretext at the start and a new picture of a some broccoli(as in Figure 39) yoursquod have to search through yourreport to find all mentions of lsquoFigure 38rsquo and lsquopage 51rsquoand manually update them to reflect the new number-ing This might be fine if you have two figures and fivepages but for a hundred-page report containing lots ofpictures you can see how this becomes tedious and er-ror prone very quickly

50

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 28: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

It starts by making the assumption that it is emphnot the casethat $sqrt2$ is irrational in other words that we can findintegers $p$ and $q$ with $sqrt2 = pq$

We can assume without losing anything that $p$ and $q$ haveemphno common factors (Why)

[beginarraylcl

sqrt2 amp = amp pq qsqrt2 amp = amp p 2q^2 amp = amp p^2

endarray]

This means that $p^2$ is even from which we can also deduce that $p$is even (Why)

This means that $p = 2k$ for some $k$ so ldots[beginarrayllcl

amp 2q^2 amp = amp (2k)^2 therefore amp 2q^2 amp = amp 4k^2 textso amp q^2 amp = amp 2k^2

endarray]

But this means that $q^2$ and hence $q$ is even Since $p$ and $q$are both even we have a contradiction to our initial assumptionso no such $p$ and $q$ exist

Notice the use of the array environment for gettingthings lined up You can find much more informationabout this on the web

LATEX really shines at typesetting mathematics and

35

COMP10120 Report writing and Digital Typography

it would take pages and pages to describe all the fea-tures Have a look at

enwikibooksorgwikiLaTeXMathematics

for a flavour

Exercise 5 Formatting mathematics

Now for an exercise that involves some mathematicsPlease create a file f-wtex which typesets the follow-ing piece of text and mathematics

There are many positive integer solutions tothe equation

x2 + y2 = z2

which can be rewritten as

z =radicx2 + y2

For example (3 4 5) or (5 12 13) Such solu-tions are called Pythagorean triples

However for higher powers the situation isvery different and we have-

Theorem Fermat-WilesFor all natural numbers n ge 3 there are no

36

COMP10120 Report writing and Digital Typography

integers x y z satisfying the equation

xn + yn = zn

35 Curriculum vitaie

There are several scenarios where using LATEX ratherthan other word processing software can be useful

bull typesetting mathematics yoursquove just read about

bull writing a technical document

bull your final year project peport

bull writing an article you want to get published

bull writing a Curriculum vitae CV

Wersquoll now look at CVrsquos briefly

Exercise 6 Curriculum vitae

Creating a professional document is especially impor-tant when you write your CV because how your CVlooks (not just the content) will determine if you are in-vited to interview for job you are applying for Thatcould be a summer internship next year a year long

37

COMP10120 Report writing and Digital Typography

placement after your second year or graduate positionafter you leave University

As well using a text-editor and compiling files fromthe command line other tools are available for editingLATEXWe will look at one of these overleafcom

Create a basic CV which describes you your edu-cation (including University) and any experience youhave or interesting projects that you may have doneYou can do this using httpsoverleafcom andchoosing the ready-made templates at httpswwwoverleafcomgallerytaggedcv

As you progress through University it is a good ideato keep your CV up to date and get feedback from asmany people as you can There will be opportunities todebug your CV later (See httpgitiomycv if youare interested) but yoursquoll need a ldquobeta releaserdquo (version10) of your CV to get started The best time to start thisprocess is now

36 Some optional extras

Exercise 7 Exploring more LATEX features (op-tional but easy)

This exercise reinforces some of the things yoursquove donealready but also introduces some features of LATEX that

38

COMP10120 Report writing and Digital Typography

will be new to you It is labelled as optional because itisnrsquot marked but we would recommend that you all tryit

Take a copy of the file optinfocoursesCOMP10120ex3latex-introtexand follow the instructions it contains You should readit before you process it with LATEX

Exercise 8 A neat directory listing (optionalmore challenging)

The fact that LATEX source files are just text makes it easyto have them generated by a program You are going toexploit this and use LATEX to produce a neat documentcontaining a listing of the files in any directory

Find how to create tables in LATEX tables using thetabular environment Make a LATEX document by handthat uses a table to neatly show the information aboutthe files in some (small) directory (as produced by ls

-l) Write a shell script called neat-ls that takes anargument which is the path name of a directory andproduces a LATEX document containing the above tablefor the given directory The script could also process theLATEX and display the resulting pdf file Finally find outabout the longtable package and change your script touse that instead

39

COMP10120 Report writing and Digital Typography

Exercise 9 A cleaning rota (optional evenmore challenging)

Now you will write a shell script called make-rota thatgenerates a house cleaning rota (Very handy for nextyear ) This is a table with columns such as KitchenBathroom and Lounge The rows will be weeks in theyear labelled with a date (eg always a Sunday) Theidea is that house mates can write their initials in theboxes promising to clean the corresponding room inthat particular week Start by making a sample tableby hand

Your script should take a single argument which isthe date of the first day of the first row eg102013(the US format for 20 Oct 13) The result will be a docu-ment that contains as many rows as fit on a single page(find out by experimenting)

The dates of each row should be generated from thefirst See the manual page for date to figure out howyou can generate a date that is a number of weeks anddays later than an existing one

361 Marking Scheme

You can view a copy of the marking scheme used bysubmit and labprint at

40

COMP10120 Report writing and Digital Typography

studentnetcsmanchesteracukugtlpmsphpunit=COMP10120ampex=ex3xml

37 Next steps

LATEX is a very powerful tool and it does take a littlegetting used to But itrsquos not as scary as it might initiallyseem and you should find that it doesnrsquot take long tolearn the common commands and techniques to makeyour documents well-structured and readable As youbecome more comfortable with the basics and under-stand the principles of typesetting finding out how todo more complex and sophisticated things is easymdashthere are hundreds of tutorials on the web

Donrsquot get carried away though and use the featuresjudiciously just because yoursquove found a cool new com-mand doesnrsquot mean that you should use it just to showoff your LATEX skills content and structure always trumpstypographic twiddlings4

4For example footnotes like this are for some reason a really tempting fea-ture to use in LATEX and in this document we have abused them mercilessly toillustrate a point Footnotes were originally a means for mechanical typeset-ters to insert comments corrections or additions to existing documents withouthaving to adjust the layout of a whole page and of course in digital typographythis is no longer necessary They can justifiably be used for citations (though itrsquosnot common to do so these days) and URLs if you donrsquot want these intrudinginto the body of your text And in some very very rare cases they can be usedas an aside to the main flow of the text (which is what has been done in this doc-ument) But this should be used sparingly If something is important to sayput it in the main body of your text If itrsquos not then perhaps you should thinkabout leaving it out completely or find some other way of including it Asking

41

COMP10120 Report writing and Digital Typography

371 Acknowledgements

Figure 38 is from the Wikipedia article on cheese

372 License

The text of this exercise is licensed under the terms ofthe Creative Commons Attribution 20 Generic (CC BY30) License

38 Background

What follows is additional contextual information aroundLATEX

LATEX was originally written by Leslie LamportW anAmerican computer scientist now working at MicrosoftResearch although its development has long been takenover by a world-wide LATEX community Itrsquos actuallybuilt on top of another system called TEX a computertypesetting system designed by one of the worldrsquos mostinfluential Computer Scientists Donald KnuthW of Stan-ford University Knuth has said that he designed TEX

the reader to look down at the bottom of a page to find out whether somethingis important or not is irritating and as yoursquove probably found out already oftenmeans you lose track of your reading position They also give the impressionthat the author isnrsquot clear about whether something is important or not whichis never good And long footnotes like this onemdashwhile LATEX will typeset themperfectly wellmdashare just plain silly Best avoid

42

COMP10120 Report writing and Digital Typography

for lsquothe creation of beautiful booksmdashand especially forbooks that contain a lot of mathematicsrsquo(D Knuth1984) Figure 34 shows what these eminent men looklike

So whatrsquos the purpose of LATEX Itrsquos purely a layerof software to make TEX easier to use in everyday sit-uations This is a good idea because although TEX isamazingly powerful it operates at a very low-level whichmakes it hard for non-expert users

Figure 34Don Knuth and Leslie Lamport

381 Pronunciation

The name TEX is intended by its creator to be pronouncedwith the final consonant as in the word loch or the nameBach but English speakers often pronounce it like thefirst syllable of technical The first syllable of LATEX is

43

COMP10120 Report writing and Digital Typography

pronounced as in rsquolayrsquo5

382 Why LATEX

Before we go any further why do we think LATEX is im-portant for youmdasha Computer Science studentmdashto knowabout Here are some reasons in no particular order

bull LATEX and TEX are superb examples of ComputerScience in action TEX was designed by Knuth fromfirst principlesmdashin other words from scratch TEXis actually a programming language and LATEX isa set of functions defined in the TEX language TheTEX lsquocompilerrsquo is written in WEBW a mixture ofdocumentation written in TeX and a PascalW sub-set in order to ensure portability it reads a TEXprogram and outputs documents TEX is completelyself-contained and designed to be portable to anycomputer architecture For example it implementsits own stackW and heapW (with garbage collectionW)and it does fixed-precision arithmeticW donrsquot worryif these terms donrsquot make much sense to you at themoment they soon will

5The Greek prefix lsquotexrsquo means lsquoartrsquo as well as lsquotechnologyrsquo so itrsquos a very nicelychosen name for a piece of software that produces such beautiful output Knuthexplained (D Knuth 1984) that one should lsquopronounce the X of TeX as a Greekchi not as an lsquoxrsquo so that TeX rhymes with the word blecchhhrsquo Wersquore not toosure that helps much unless you are confident in your pronunciation of theword lsquoblecchhrsquo Maybe itrsquos an American thing

44

COMP10120 Report writing and Digital Typography

bull LATEX is a new interesting way for you to thinkabout preparing documents

bull LATEX has a practical advantage for the writer inthat it helps you think more about what you wantto write rather than worrying about how it looks

bull LATEX is a powerful tool for professional scientificdocumentation and as a Computer Scientist youshould know about it

bull LATEX files are just plain text so can easily be cre-ated programatically For example the slides usedfor COMP16120 are generated automatically fromthe source of Johnrsquos book both are typeset usingLATEX The program labprint also produces itsoutput using LATEX using information drawn fromXMLW configuration files and ARCADE

bull Using LATEX is actually quite satisfying and thequality of its output may surprise you

In this lab session you are going to write severalshort documents using LATEX You could also write briefnotes in your logbook about how LATEX works and whatcommands you used inside the source of your docu-ments

45

COMP10120 Report writing and Digital Typography

383 Some history printing mathematics

Mathematics is hard to print on paper and on the Web(many websites resort to GIF or JPG images of mathsformulae which usually look horrible MathMLW pro-vides another approach but it is not yet widely used)

In the days before computers books and newspa-pers were printed with movable typeW made from lotsof little blocks of metal each with letters numbers andsymbols standing in relief which when inked left animpression on the paper (see Figure 35) The job ofthe printer (the printer here of course being a personnot a bit of electronics) was to gather together all theblocks in the right order between two horizontal stripsof wood to create a line of the document and then toassemble all those lines from top to bottom of a pageThus the term type settingW an incredible task whenyou think about it In the printerrsquos workshop by theway the blocks of metal were stored between jobs inwooden boxes called cases Letters like a b and c werestored in one case letters like A B and C were storedin a case sitting on top of that So a lower case and anupper case These terms may ring a bell

As technology progressed machines controlled bytypewriters would mechanically juggle the blocks intothe right order This conceptual model is the basis onwhich TEX operates Only now the metal blocks are

46

COMP10120 Report writing and Digital Typography

Figure 35On the left a piece of cast movable type in the Garamondfont On the right a case of cast metal type pieces andtypeset matter in a composing stick The text reads lsquoThequick brown fox jumps over the lazy dog and feels as if hewere in the seventh heaven of typography together with Her-mann Zapf the most famous artist of thersquo This document istypeset in a font called Palatino created by Hermann ZapfYou may have also seen rsquoZapf Dingbatsrsquo in the font lists ofvarious desktop applications Now you know why

little pieces of data arranged into data structuresThe one thing that traditional printers hated was

dealing with the typesetting of mathematics and theywould charge extra to do it It was incredibly fiddly toget the equations looking right they had to squeeze inextra bits of metal horizontally and vertically

When computers entered the printing world attemptsto print mathematics were limited by the printing tech-nology available It took a long time to reach the pointwhere computers could typeset mathematics beautifullyand that was the outstanding achievement of Knuthrsquos

47

COMP10120 Report writing and Digital Typography

TEXLetrsquos look at a quick example of the quality you get

from LATEX with a very simple formula that yoursquoll recog-nise

x =minusbplusmn

radicb2 minus 4ac

2aWersquoll revisit how LATEX typesets mathematics in Section 34

384 To WYSIWYG or not to WYSIWYG

Up until now you have probably used wordprocessingapplications such as Microsoft Word to create essaysletters and other (probably fairly short) documents Youmost likely know that the majority of modern wordprocessors use a paradigm called WYSIWYG or WhatYou See Is What You Get which means that you canmodify the visual style of the document yoursquore work-ing on by selecting the relevant bits and then choos-ing different attributes such as font size or colour usinga GUI In many ways this seems like such a sensibleand obvious way of doing things that you might bewondering why it even has a special name The rea-son is a historical one in the early days of comput-ing long before graphical window managers becamethe norm and when all you could display on screenwas fixed-width ASCII text in whatever the systemrsquos

48

COMP10120 Report writing and Digital Typography

default font was wordprocessors (eg Figure 36) onlyallowed you to format documents by using special se-quences of characters to cause particular effects Butthese effects were only visible when the document wasprinted So if you wanted a word to appear in boldtext in the wordprocessor you might write somethinglike [bold]hello world[bold] what you saw onscreen was not a direct reflection of what appeared onthe printed page If yoursquove written any HTML how-ever this process of marking up text may be familiarsee for example Figure 37 As computers moved todisplays able to draw things other than raw charac-ters on screen wordprocessors became capable of us-ing multiple fonts and styles as well as graphics anda new generation of applications appeared where whatyou saw on screen was an accurate reflection of how itwould appear when printed what you see (on screen)is what you get (on paper)

The huge advantage of WYSIWYG is that itrsquos reallyeasy to understand whatrsquos going on and most peoplecan create reasonably nicely formatted documents withrelatively little effort For short informal documentsone-off letters memos and such WYSIWYG works quitenicely But if yoursquove ever tried writing anything muchlonger or that includes images and tables you mayhave already started to see where the paradigm breaksdown For example if you write lsquoFigure 38 on page

49

COMP10120 Report writing and Digital Typography

Figure 36A screenshot of Wordperfect 51 running in Microsoft DOScirca 1989

51 shows a picture of some men looking at cheesersquo butthen later on edit your document to include some moretext at the start and a new picture of a some broccoli(as in Figure 39) yoursquod have to search through yourreport to find all mentions of lsquoFigure 38rsquo and lsquopage 51rsquoand manually update them to reflect the new number-ing This might be fine if you have two figures and fivepages but for a hundred-page report containing lots ofpictures you can see how this becomes tedious and er-ror prone very quickly

50

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 29: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

it would take pages and pages to describe all the fea-tures Have a look at

enwikibooksorgwikiLaTeXMathematics

for a flavour

Exercise 5 Formatting mathematics

Now for an exercise that involves some mathematicsPlease create a file f-wtex which typesets the follow-ing piece of text and mathematics

There are many positive integer solutions tothe equation

x2 + y2 = z2

which can be rewritten as

z =radicx2 + y2

For example (3 4 5) or (5 12 13) Such solu-tions are called Pythagorean triples

However for higher powers the situation isvery different and we have-

Theorem Fermat-WilesFor all natural numbers n ge 3 there are no

36

COMP10120 Report writing and Digital Typography

integers x y z satisfying the equation

xn + yn = zn

35 Curriculum vitaie

There are several scenarios where using LATEX ratherthan other word processing software can be useful

bull typesetting mathematics yoursquove just read about

bull writing a technical document

bull your final year project peport

bull writing an article you want to get published

bull writing a Curriculum vitae CV

Wersquoll now look at CVrsquos briefly

Exercise 6 Curriculum vitae

Creating a professional document is especially impor-tant when you write your CV because how your CVlooks (not just the content) will determine if you are in-vited to interview for job you are applying for Thatcould be a summer internship next year a year long

37

COMP10120 Report writing and Digital Typography

placement after your second year or graduate positionafter you leave University

As well using a text-editor and compiling files fromthe command line other tools are available for editingLATEXWe will look at one of these overleafcom

Create a basic CV which describes you your edu-cation (including University) and any experience youhave or interesting projects that you may have doneYou can do this using httpsoverleafcom andchoosing the ready-made templates at httpswwwoverleafcomgallerytaggedcv

As you progress through University it is a good ideato keep your CV up to date and get feedback from asmany people as you can There will be opportunities todebug your CV later (See httpgitiomycv if youare interested) but yoursquoll need a ldquobeta releaserdquo (version10) of your CV to get started The best time to start thisprocess is now

36 Some optional extras

Exercise 7 Exploring more LATEX features (op-tional but easy)

This exercise reinforces some of the things yoursquove donealready but also introduces some features of LATEX that

38

COMP10120 Report writing and Digital Typography

will be new to you It is labelled as optional because itisnrsquot marked but we would recommend that you all tryit

Take a copy of the file optinfocoursesCOMP10120ex3latex-introtexand follow the instructions it contains You should readit before you process it with LATEX

Exercise 8 A neat directory listing (optionalmore challenging)

The fact that LATEX source files are just text makes it easyto have them generated by a program You are going toexploit this and use LATEX to produce a neat documentcontaining a listing of the files in any directory

Find how to create tables in LATEX tables using thetabular environment Make a LATEX document by handthat uses a table to neatly show the information aboutthe files in some (small) directory (as produced by ls

-l) Write a shell script called neat-ls that takes anargument which is the path name of a directory andproduces a LATEX document containing the above tablefor the given directory The script could also process theLATEX and display the resulting pdf file Finally find outabout the longtable package and change your script touse that instead

39

COMP10120 Report writing and Digital Typography

Exercise 9 A cleaning rota (optional evenmore challenging)

Now you will write a shell script called make-rota thatgenerates a house cleaning rota (Very handy for nextyear ) This is a table with columns such as KitchenBathroom and Lounge The rows will be weeks in theyear labelled with a date (eg always a Sunday) Theidea is that house mates can write their initials in theboxes promising to clean the corresponding room inthat particular week Start by making a sample tableby hand

Your script should take a single argument which isthe date of the first day of the first row eg102013(the US format for 20 Oct 13) The result will be a docu-ment that contains as many rows as fit on a single page(find out by experimenting)

The dates of each row should be generated from thefirst See the manual page for date to figure out howyou can generate a date that is a number of weeks anddays later than an existing one

361 Marking Scheme

You can view a copy of the marking scheme used bysubmit and labprint at

40

COMP10120 Report writing and Digital Typography

studentnetcsmanchesteracukugtlpmsphpunit=COMP10120ampex=ex3xml

37 Next steps

LATEX is a very powerful tool and it does take a littlegetting used to But itrsquos not as scary as it might initiallyseem and you should find that it doesnrsquot take long tolearn the common commands and techniques to makeyour documents well-structured and readable As youbecome more comfortable with the basics and under-stand the principles of typesetting finding out how todo more complex and sophisticated things is easymdashthere are hundreds of tutorials on the web

Donrsquot get carried away though and use the featuresjudiciously just because yoursquove found a cool new com-mand doesnrsquot mean that you should use it just to showoff your LATEX skills content and structure always trumpstypographic twiddlings4

4For example footnotes like this are for some reason a really tempting fea-ture to use in LATEX and in this document we have abused them mercilessly toillustrate a point Footnotes were originally a means for mechanical typeset-ters to insert comments corrections or additions to existing documents withouthaving to adjust the layout of a whole page and of course in digital typographythis is no longer necessary They can justifiably be used for citations (though itrsquosnot common to do so these days) and URLs if you donrsquot want these intrudinginto the body of your text And in some very very rare cases they can be usedas an aside to the main flow of the text (which is what has been done in this doc-ument) But this should be used sparingly If something is important to sayput it in the main body of your text If itrsquos not then perhaps you should thinkabout leaving it out completely or find some other way of including it Asking

41

COMP10120 Report writing and Digital Typography

371 Acknowledgements

Figure 38 is from the Wikipedia article on cheese

372 License

The text of this exercise is licensed under the terms ofthe Creative Commons Attribution 20 Generic (CC BY30) License

38 Background

What follows is additional contextual information aroundLATEX

LATEX was originally written by Leslie LamportW anAmerican computer scientist now working at MicrosoftResearch although its development has long been takenover by a world-wide LATEX community Itrsquos actuallybuilt on top of another system called TEX a computertypesetting system designed by one of the worldrsquos mostinfluential Computer Scientists Donald KnuthW of Stan-ford University Knuth has said that he designed TEX

the reader to look down at the bottom of a page to find out whether somethingis important or not is irritating and as yoursquove probably found out already oftenmeans you lose track of your reading position They also give the impressionthat the author isnrsquot clear about whether something is important or not whichis never good And long footnotes like this onemdashwhile LATEX will typeset themperfectly wellmdashare just plain silly Best avoid

42

COMP10120 Report writing and Digital Typography

for lsquothe creation of beautiful booksmdashand especially forbooks that contain a lot of mathematicsrsquo(D Knuth1984) Figure 34 shows what these eminent men looklike

So whatrsquos the purpose of LATEX Itrsquos purely a layerof software to make TEX easier to use in everyday sit-uations This is a good idea because although TEX isamazingly powerful it operates at a very low-level whichmakes it hard for non-expert users

Figure 34Don Knuth and Leslie Lamport

381 Pronunciation

The name TEX is intended by its creator to be pronouncedwith the final consonant as in the word loch or the nameBach but English speakers often pronounce it like thefirst syllable of technical The first syllable of LATEX is

43

COMP10120 Report writing and Digital Typography

pronounced as in rsquolayrsquo5

382 Why LATEX

Before we go any further why do we think LATEX is im-portant for youmdasha Computer Science studentmdashto knowabout Here are some reasons in no particular order

bull LATEX and TEX are superb examples of ComputerScience in action TEX was designed by Knuth fromfirst principlesmdashin other words from scratch TEXis actually a programming language and LATEX isa set of functions defined in the TEX language TheTEX lsquocompilerrsquo is written in WEBW a mixture ofdocumentation written in TeX and a PascalW sub-set in order to ensure portability it reads a TEXprogram and outputs documents TEX is completelyself-contained and designed to be portable to anycomputer architecture For example it implementsits own stackW and heapW (with garbage collectionW)and it does fixed-precision arithmeticW donrsquot worryif these terms donrsquot make much sense to you at themoment they soon will

5The Greek prefix lsquotexrsquo means lsquoartrsquo as well as lsquotechnologyrsquo so itrsquos a very nicelychosen name for a piece of software that produces such beautiful output Knuthexplained (D Knuth 1984) that one should lsquopronounce the X of TeX as a Greekchi not as an lsquoxrsquo so that TeX rhymes with the word blecchhhrsquo Wersquore not toosure that helps much unless you are confident in your pronunciation of theword lsquoblecchhrsquo Maybe itrsquos an American thing

44

COMP10120 Report writing and Digital Typography

bull LATEX is a new interesting way for you to thinkabout preparing documents

bull LATEX has a practical advantage for the writer inthat it helps you think more about what you wantto write rather than worrying about how it looks

bull LATEX is a powerful tool for professional scientificdocumentation and as a Computer Scientist youshould know about it

bull LATEX files are just plain text so can easily be cre-ated programatically For example the slides usedfor COMP16120 are generated automatically fromthe source of Johnrsquos book both are typeset usingLATEX The program labprint also produces itsoutput using LATEX using information drawn fromXMLW configuration files and ARCADE

bull Using LATEX is actually quite satisfying and thequality of its output may surprise you

In this lab session you are going to write severalshort documents using LATEX You could also write briefnotes in your logbook about how LATEX works and whatcommands you used inside the source of your docu-ments

45

COMP10120 Report writing and Digital Typography

383 Some history printing mathematics

Mathematics is hard to print on paper and on the Web(many websites resort to GIF or JPG images of mathsformulae which usually look horrible MathMLW pro-vides another approach but it is not yet widely used)

In the days before computers books and newspa-pers were printed with movable typeW made from lotsof little blocks of metal each with letters numbers andsymbols standing in relief which when inked left animpression on the paper (see Figure 35) The job ofthe printer (the printer here of course being a personnot a bit of electronics) was to gather together all theblocks in the right order between two horizontal stripsof wood to create a line of the document and then toassemble all those lines from top to bottom of a pageThus the term type settingW an incredible task whenyou think about it In the printerrsquos workshop by theway the blocks of metal were stored between jobs inwooden boxes called cases Letters like a b and c werestored in one case letters like A B and C were storedin a case sitting on top of that So a lower case and anupper case These terms may ring a bell

As technology progressed machines controlled bytypewriters would mechanically juggle the blocks intothe right order This conceptual model is the basis onwhich TEX operates Only now the metal blocks are

46

COMP10120 Report writing and Digital Typography

Figure 35On the left a piece of cast movable type in the Garamondfont On the right a case of cast metal type pieces andtypeset matter in a composing stick The text reads lsquoThequick brown fox jumps over the lazy dog and feels as if hewere in the seventh heaven of typography together with Her-mann Zapf the most famous artist of thersquo This document istypeset in a font called Palatino created by Hermann ZapfYou may have also seen rsquoZapf Dingbatsrsquo in the font lists ofvarious desktop applications Now you know why

little pieces of data arranged into data structuresThe one thing that traditional printers hated was

dealing with the typesetting of mathematics and theywould charge extra to do it It was incredibly fiddly toget the equations looking right they had to squeeze inextra bits of metal horizontally and vertically

When computers entered the printing world attemptsto print mathematics were limited by the printing tech-nology available It took a long time to reach the pointwhere computers could typeset mathematics beautifullyand that was the outstanding achievement of Knuthrsquos

47

COMP10120 Report writing and Digital Typography

TEXLetrsquos look at a quick example of the quality you get

from LATEX with a very simple formula that yoursquoll recog-nise

x =minusbplusmn

radicb2 minus 4ac

2aWersquoll revisit how LATEX typesets mathematics in Section 34

384 To WYSIWYG or not to WYSIWYG

Up until now you have probably used wordprocessingapplications such as Microsoft Word to create essaysletters and other (probably fairly short) documents Youmost likely know that the majority of modern wordprocessors use a paradigm called WYSIWYG or WhatYou See Is What You Get which means that you canmodify the visual style of the document yoursquore work-ing on by selecting the relevant bits and then choos-ing different attributes such as font size or colour usinga GUI In many ways this seems like such a sensibleand obvious way of doing things that you might bewondering why it even has a special name The rea-son is a historical one in the early days of comput-ing long before graphical window managers becamethe norm and when all you could display on screenwas fixed-width ASCII text in whatever the systemrsquos

48

COMP10120 Report writing and Digital Typography

default font was wordprocessors (eg Figure 36) onlyallowed you to format documents by using special se-quences of characters to cause particular effects Butthese effects were only visible when the document wasprinted So if you wanted a word to appear in boldtext in the wordprocessor you might write somethinglike [bold]hello world[bold] what you saw onscreen was not a direct reflection of what appeared onthe printed page If yoursquove written any HTML how-ever this process of marking up text may be familiarsee for example Figure 37 As computers moved todisplays able to draw things other than raw charac-ters on screen wordprocessors became capable of us-ing multiple fonts and styles as well as graphics anda new generation of applications appeared where whatyou saw on screen was an accurate reflection of how itwould appear when printed what you see (on screen)is what you get (on paper)

The huge advantage of WYSIWYG is that itrsquos reallyeasy to understand whatrsquos going on and most peoplecan create reasonably nicely formatted documents withrelatively little effort For short informal documentsone-off letters memos and such WYSIWYG works quitenicely But if yoursquove ever tried writing anything muchlonger or that includes images and tables you mayhave already started to see where the paradigm breaksdown For example if you write lsquoFigure 38 on page

49

COMP10120 Report writing and Digital Typography

Figure 36A screenshot of Wordperfect 51 running in Microsoft DOScirca 1989

51 shows a picture of some men looking at cheesersquo butthen later on edit your document to include some moretext at the start and a new picture of a some broccoli(as in Figure 39) yoursquod have to search through yourreport to find all mentions of lsquoFigure 38rsquo and lsquopage 51rsquoand manually update them to reflect the new number-ing This might be fine if you have two figures and fivepages but for a hundred-page report containing lots ofpictures you can see how this becomes tedious and er-ror prone very quickly

50

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 30: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

integers x y z satisfying the equation

xn + yn = zn

35 Curriculum vitaie

There are several scenarios where using LATEX ratherthan other word processing software can be useful

bull typesetting mathematics yoursquove just read about

bull writing a technical document

bull your final year project peport

bull writing an article you want to get published

bull writing a Curriculum vitae CV

Wersquoll now look at CVrsquos briefly

Exercise 6 Curriculum vitae

Creating a professional document is especially impor-tant when you write your CV because how your CVlooks (not just the content) will determine if you are in-vited to interview for job you are applying for Thatcould be a summer internship next year a year long

37

COMP10120 Report writing and Digital Typography

placement after your second year or graduate positionafter you leave University

As well using a text-editor and compiling files fromthe command line other tools are available for editingLATEXWe will look at one of these overleafcom

Create a basic CV which describes you your edu-cation (including University) and any experience youhave or interesting projects that you may have doneYou can do this using httpsoverleafcom andchoosing the ready-made templates at httpswwwoverleafcomgallerytaggedcv

As you progress through University it is a good ideato keep your CV up to date and get feedback from asmany people as you can There will be opportunities todebug your CV later (See httpgitiomycv if youare interested) but yoursquoll need a ldquobeta releaserdquo (version10) of your CV to get started The best time to start thisprocess is now

36 Some optional extras

Exercise 7 Exploring more LATEX features (op-tional but easy)

This exercise reinforces some of the things yoursquove donealready but also introduces some features of LATEX that

38

COMP10120 Report writing and Digital Typography

will be new to you It is labelled as optional because itisnrsquot marked but we would recommend that you all tryit

Take a copy of the file optinfocoursesCOMP10120ex3latex-introtexand follow the instructions it contains You should readit before you process it with LATEX

Exercise 8 A neat directory listing (optionalmore challenging)

The fact that LATEX source files are just text makes it easyto have them generated by a program You are going toexploit this and use LATEX to produce a neat documentcontaining a listing of the files in any directory

Find how to create tables in LATEX tables using thetabular environment Make a LATEX document by handthat uses a table to neatly show the information aboutthe files in some (small) directory (as produced by ls

-l) Write a shell script called neat-ls that takes anargument which is the path name of a directory andproduces a LATEX document containing the above tablefor the given directory The script could also process theLATEX and display the resulting pdf file Finally find outabout the longtable package and change your script touse that instead

39

COMP10120 Report writing and Digital Typography

Exercise 9 A cleaning rota (optional evenmore challenging)

Now you will write a shell script called make-rota thatgenerates a house cleaning rota (Very handy for nextyear ) This is a table with columns such as KitchenBathroom and Lounge The rows will be weeks in theyear labelled with a date (eg always a Sunday) Theidea is that house mates can write their initials in theboxes promising to clean the corresponding room inthat particular week Start by making a sample tableby hand

Your script should take a single argument which isthe date of the first day of the first row eg102013(the US format for 20 Oct 13) The result will be a docu-ment that contains as many rows as fit on a single page(find out by experimenting)

The dates of each row should be generated from thefirst See the manual page for date to figure out howyou can generate a date that is a number of weeks anddays later than an existing one

361 Marking Scheme

You can view a copy of the marking scheme used bysubmit and labprint at

40

COMP10120 Report writing and Digital Typography

studentnetcsmanchesteracukugtlpmsphpunit=COMP10120ampex=ex3xml

37 Next steps

LATEX is a very powerful tool and it does take a littlegetting used to But itrsquos not as scary as it might initiallyseem and you should find that it doesnrsquot take long tolearn the common commands and techniques to makeyour documents well-structured and readable As youbecome more comfortable with the basics and under-stand the principles of typesetting finding out how todo more complex and sophisticated things is easymdashthere are hundreds of tutorials on the web

Donrsquot get carried away though and use the featuresjudiciously just because yoursquove found a cool new com-mand doesnrsquot mean that you should use it just to showoff your LATEX skills content and structure always trumpstypographic twiddlings4

4For example footnotes like this are for some reason a really tempting fea-ture to use in LATEX and in this document we have abused them mercilessly toillustrate a point Footnotes were originally a means for mechanical typeset-ters to insert comments corrections or additions to existing documents withouthaving to adjust the layout of a whole page and of course in digital typographythis is no longer necessary They can justifiably be used for citations (though itrsquosnot common to do so these days) and URLs if you donrsquot want these intrudinginto the body of your text And in some very very rare cases they can be usedas an aside to the main flow of the text (which is what has been done in this doc-ument) But this should be used sparingly If something is important to sayput it in the main body of your text If itrsquos not then perhaps you should thinkabout leaving it out completely or find some other way of including it Asking

41

COMP10120 Report writing and Digital Typography

371 Acknowledgements

Figure 38 is from the Wikipedia article on cheese

372 License

The text of this exercise is licensed under the terms ofthe Creative Commons Attribution 20 Generic (CC BY30) License

38 Background

What follows is additional contextual information aroundLATEX

LATEX was originally written by Leslie LamportW anAmerican computer scientist now working at MicrosoftResearch although its development has long been takenover by a world-wide LATEX community Itrsquos actuallybuilt on top of another system called TEX a computertypesetting system designed by one of the worldrsquos mostinfluential Computer Scientists Donald KnuthW of Stan-ford University Knuth has said that he designed TEX

the reader to look down at the bottom of a page to find out whether somethingis important or not is irritating and as yoursquove probably found out already oftenmeans you lose track of your reading position They also give the impressionthat the author isnrsquot clear about whether something is important or not whichis never good And long footnotes like this onemdashwhile LATEX will typeset themperfectly wellmdashare just plain silly Best avoid

42

COMP10120 Report writing and Digital Typography

for lsquothe creation of beautiful booksmdashand especially forbooks that contain a lot of mathematicsrsquo(D Knuth1984) Figure 34 shows what these eminent men looklike

So whatrsquos the purpose of LATEX Itrsquos purely a layerof software to make TEX easier to use in everyday sit-uations This is a good idea because although TEX isamazingly powerful it operates at a very low-level whichmakes it hard for non-expert users

Figure 34Don Knuth and Leslie Lamport

381 Pronunciation

The name TEX is intended by its creator to be pronouncedwith the final consonant as in the word loch or the nameBach but English speakers often pronounce it like thefirst syllable of technical The first syllable of LATEX is

43

COMP10120 Report writing and Digital Typography

pronounced as in rsquolayrsquo5

382 Why LATEX

Before we go any further why do we think LATEX is im-portant for youmdasha Computer Science studentmdashto knowabout Here are some reasons in no particular order

bull LATEX and TEX are superb examples of ComputerScience in action TEX was designed by Knuth fromfirst principlesmdashin other words from scratch TEXis actually a programming language and LATEX isa set of functions defined in the TEX language TheTEX lsquocompilerrsquo is written in WEBW a mixture ofdocumentation written in TeX and a PascalW sub-set in order to ensure portability it reads a TEXprogram and outputs documents TEX is completelyself-contained and designed to be portable to anycomputer architecture For example it implementsits own stackW and heapW (with garbage collectionW)and it does fixed-precision arithmeticW donrsquot worryif these terms donrsquot make much sense to you at themoment they soon will

5The Greek prefix lsquotexrsquo means lsquoartrsquo as well as lsquotechnologyrsquo so itrsquos a very nicelychosen name for a piece of software that produces such beautiful output Knuthexplained (D Knuth 1984) that one should lsquopronounce the X of TeX as a Greekchi not as an lsquoxrsquo so that TeX rhymes with the word blecchhhrsquo Wersquore not toosure that helps much unless you are confident in your pronunciation of theword lsquoblecchhrsquo Maybe itrsquos an American thing

44

COMP10120 Report writing and Digital Typography

bull LATEX is a new interesting way for you to thinkabout preparing documents

bull LATEX has a practical advantage for the writer inthat it helps you think more about what you wantto write rather than worrying about how it looks

bull LATEX is a powerful tool for professional scientificdocumentation and as a Computer Scientist youshould know about it

bull LATEX files are just plain text so can easily be cre-ated programatically For example the slides usedfor COMP16120 are generated automatically fromthe source of Johnrsquos book both are typeset usingLATEX The program labprint also produces itsoutput using LATEX using information drawn fromXMLW configuration files and ARCADE

bull Using LATEX is actually quite satisfying and thequality of its output may surprise you

In this lab session you are going to write severalshort documents using LATEX You could also write briefnotes in your logbook about how LATEX works and whatcommands you used inside the source of your docu-ments

45

COMP10120 Report writing and Digital Typography

383 Some history printing mathematics

Mathematics is hard to print on paper and on the Web(many websites resort to GIF or JPG images of mathsformulae which usually look horrible MathMLW pro-vides another approach but it is not yet widely used)

In the days before computers books and newspa-pers were printed with movable typeW made from lotsof little blocks of metal each with letters numbers andsymbols standing in relief which when inked left animpression on the paper (see Figure 35) The job ofthe printer (the printer here of course being a personnot a bit of electronics) was to gather together all theblocks in the right order between two horizontal stripsof wood to create a line of the document and then toassemble all those lines from top to bottom of a pageThus the term type settingW an incredible task whenyou think about it In the printerrsquos workshop by theway the blocks of metal were stored between jobs inwooden boxes called cases Letters like a b and c werestored in one case letters like A B and C were storedin a case sitting on top of that So a lower case and anupper case These terms may ring a bell

As technology progressed machines controlled bytypewriters would mechanically juggle the blocks intothe right order This conceptual model is the basis onwhich TEX operates Only now the metal blocks are

46

COMP10120 Report writing and Digital Typography

Figure 35On the left a piece of cast movable type in the Garamondfont On the right a case of cast metal type pieces andtypeset matter in a composing stick The text reads lsquoThequick brown fox jumps over the lazy dog and feels as if hewere in the seventh heaven of typography together with Her-mann Zapf the most famous artist of thersquo This document istypeset in a font called Palatino created by Hermann ZapfYou may have also seen rsquoZapf Dingbatsrsquo in the font lists ofvarious desktop applications Now you know why

little pieces of data arranged into data structuresThe one thing that traditional printers hated was

dealing with the typesetting of mathematics and theywould charge extra to do it It was incredibly fiddly toget the equations looking right they had to squeeze inextra bits of metal horizontally and vertically

When computers entered the printing world attemptsto print mathematics were limited by the printing tech-nology available It took a long time to reach the pointwhere computers could typeset mathematics beautifullyand that was the outstanding achievement of Knuthrsquos

47

COMP10120 Report writing and Digital Typography

TEXLetrsquos look at a quick example of the quality you get

from LATEX with a very simple formula that yoursquoll recog-nise

x =minusbplusmn

radicb2 minus 4ac

2aWersquoll revisit how LATEX typesets mathematics in Section 34

384 To WYSIWYG or not to WYSIWYG

Up until now you have probably used wordprocessingapplications such as Microsoft Word to create essaysletters and other (probably fairly short) documents Youmost likely know that the majority of modern wordprocessors use a paradigm called WYSIWYG or WhatYou See Is What You Get which means that you canmodify the visual style of the document yoursquore work-ing on by selecting the relevant bits and then choos-ing different attributes such as font size or colour usinga GUI In many ways this seems like such a sensibleand obvious way of doing things that you might bewondering why it even has a special name The rea-son is a historical one in the early days of comput-ing long before graphical window managers becamethe norm and when all you could display on screenwas fixed-width ASCII text in whatever the systemrsquos

48

COMP10120 Report writing and Digital Typography

default font was wordprocessors (eg Figure 36) onlyallowed you to format documents by using special se-quences of characters to cause particular effects Butthese effects were only visible when the document wasprinted So if you wanted a word to appear in boldtext in the wordprocessor you might write somethinglike [bold]hello world[bold] what you saw onscreen was not a direct reflection of what appeared onthe printed page If yoursquove written any HTML how-ever this process of marking up text may be familiarsee for example Figure 37 As computers moved todisplays able to draw things other than raw charac-ters on screen wordprocessors became capable of us-ing multiple fonts and styles as well as graphics anda new generation of applications appeared where whatyou saw on screen was an accurate reflection of how itwould appear when printed what you see (on screen)is what you get (on paper)

The huge advantage of WYSIWYG is that itrsquos reallyeasy to understand whatrsquos going on and most peoplecan create reasonably nicely formatted documents withrelatively little effort For short informal documentsone-off letters memos and such WYSIWYG works quitenicely But if yoursquove ever tried writing anything muchlonger or that includes images and tables you mayhave already started to see where the paradigm breaksdown For example if you write lsquoFigure 38 on page

49

COMP10120 Report writing and Digital Typography

Figure 36A screenshot of Wordperfect 51 running in Microsoft DOScirca 1989

51 shows a picture of some men looking at cheesersquo butthen later on edit your document to include some moretext at the start and a new picture of a some broccoli(as in Figure 39) yoursquod have to search through yourreport to find all mentions of lsquoFigure 38rsquo and lsquopage 51rsquoand manually update them to reflect the new number-ing This might be fine if you have two figures and fivepages but for a hundred-page report containing lots ofpictures you can see how this becomes tedious and er-ror prone very quickly

50

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 31: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

placement after your second year or graduate positionafter you leave University

As well using a text-editor and compiling files fromthe command line other tools are available for editingLATEXWe will look at one of these overleafcom

Create a basic CV which describes you your edu-cation (including University) and any experience youhave or interesting projects that you may have doneYou can do this using httpsoverleafcom andchoosing the ready-made templates at httpswwwoverleafcomgallerytaggedcv

As you progress through University it is a good ideato keep your CV up to date and get feedback from asmany people as you can There will be opportunities todebug your CV later (See httpgitiomycv if youare interested) but yoursquoll need a ldquobeta releaserdquo (version10) of your CV to get started The best time to start thisprocess is now

36 Some optional extras

Exercise 7 Exploring more LATEX features (op-tional but easy)

This exercise reinforces some of the things yoursquove donealready but also introduces some features of LATEX that

38

COMP10120 Report writing and Digital Typography

will be new to you It is labelled as optional because itisnrsquot marked but we would recommend that you all tryit

Take a copy of the file optinfocoursesCOMP10120ex3latex-introtexand follow the instructions it contains You should readit before you process it with LATEX

Exercise 8 A neat directory listing (optionalmore challenging)

The fact that LATEX source files are just text makes it easyto have them generated by a program You are going toexploit this and use LATEX to produce a neat documentcontaining a listing of the files in any directory

Find how to create tables in LATEX tables using thetabular environment Make a LATEX document by handthat uses a table to neatly show the information aboutthe files in some (small) directory (as produced by ls

-l) Write a shell script called neat-ls that takes anargument which is the path name of a directory andproduces a LATEX document containing the above tablefor the given directory The script could also process theLATEX and display the resulting pdf file Finally find outabout the longtable package and change your script touse that instead

39

COMP10120 Report writing and Digital Typography

Exercise 9 A cleaning rota (optional evenmore challenging)

Now you will write a shell script called make-rota thatgenerates a house cleaning rota (Very handy for nextyear ) This is a table with columns such as KitchenBathroom and Lounge The rows will be weeks in theyear labelled with a date (eg always a Sunday) Theidea is that house mates can write their initials in theboxes promising to clean the corresponding room inthat particular week Start by making a sample tableby hand

Your script should take a single argument which isthe date of the first day of the first row eg102013(the US format for 20 Oct 13) The result will be a docu-ment that contains as many rows as fit on a single page(find out by experimenting)

The dates of each row should be generated from thefirst See the manual page for date to figure out howyou can generate a date that is a number of weeks anddays later than an existing one

361 Marking Scheme

You can view a copy of the marking scheme used bysubmit and labprint at

40

COMP10120 Report writing and Digital Typography

studentnetcsmanchesteracukugtlpmsphpunit=COMP10120ampex=ex3xml

37 Next steps

LATEX is a very powerful tool and it does take a littlegetting used to But itrsquos not as scary as it might initiallyseem and you should find that it doesnrsquot take long tolearn the common commands and techniques to makeyour documents well-structured and readable As youbecome more comfortable with the basics and under-stand the principles of typesetting finding out how todo more complex and sophisticated things is easymdashthere are hundreds of tutorials on the web

Donrsquot get carried away though and use the featuresjudiciously just because yoursquove found a cool new com-mand doesnrsquot mean that you should use it just to showoff your LATEX skills content and structure always trumpstypographic twiddlings4

4For example footnotes like this are for some reason a really tempting fea-ture to use in LATEX and in this document we have abused them mercilessly toillustrate a point Footnotes were originally a means for mechanical typeset-ters to insert comments corrections or additions to existing documents withouthaving to adjust the layout of a whole page and of course in digital typographythis is no longer necessary They can justifiably be used for citations (though itrsquosnot common to do so these days) and URLs if you donrsquot want these intrudinginto the body of your text And in some very very rare cases they can be usedas an aside to the main flow of the text (which is what has been done in this doc-ument) But this should be used sparingly If something is important to sayput it in the main body of your text If itrsquos not then perhaps you should thinkabout leaving it out completely or find some other way of including it Asking

41

COMP10120 Report writing and Digital Typography

371 Acknowledgements

Figure 38 is from the Wikipedia article on cheese

372 License

The text of this exercise is licensed under the terms ofthe Creative Commons Attribution 20 Generic (CC BY30) License

38 Background

What follows is additional contextual information aroundLATEX

LATEX was originally written by Leslie LamportW anAmerican computer scientist now working at MicrosoftResearch although its development has long been takenover by a world-wide LATEX community Itrsquos actuallybuilt on top of another system called TEX a computertypesetting system designed by one of the worldrsquos mostinfluential Computer Scientists Donald KnuthW of Stan-ford University Knuth has said that he designed TEX

the reader to look down at the bottom of a page to find out whether somethingis important or not is irritating and as yoursquove probably found out already oftenmeans you lose track of your reading position They also give the impressionthat the author isnrsquot clear about whether something is important or not whichis never good And long footnotes like this onemdashwhile LATEX will typeset themperfectly wellmdashare just plain silly Best avoid

42

COMP10120 Report writing and Digital Typography

for lsquothe creation of beautiful booksmdashand especially forbooks that contain a lot of mathematicsrsquo(D Knuth1984) Figure 34 shows what these eminent men looklike

So whatrsquos the purpose of LATEX Itrsquos purely a layerof software to make TEX easier to use in everyday sit-uations This is a good idea because although TEX isamazingly powerful it operates at a very low-level whichmakes it hard for non-expert users

Figure 34Don Knuth and Leslie Lamport

381 Pronunciation

The name TEX is intended by its creator to be pronouncedwith the final consonant as in the word loch or the nameBach but English speakers often pronounce it like thefirst syllable of technical The first syllable of LATEX is

43

COMP10120 Report writing and Digital Typography

pronounced as in rsquolayrsquo5

382 Why LATEX

Before we go any further why do we think LATEX is im-portant for youmdasha Computer Science studentmdashto knowabout Here are some reasons in no particular order

bull LATEX and TEX are superb examples of ComputerScience in action TEX was designed by Knuth fromfirst principlesmdashin other words from scratch TEXis actually a programming language and LATEX isa set of functions defined in the TEX language TheTEX lsquocompilerrsquo is written in WEBW a mixture ofdocumentation written in TeX and a PascalW sub-set in order to ensure portability it reads a TEXprogram and outputs documents TEX is completelyself-contained and designed to be portable to anycomputer architecture For example it implementsits own stackW and heapW (with garbage collectionW)and it does fixed-precision arithmeticW donrsquot worryif these terms donrsquot make much sense to you at themoment they soon will

5The Greek prefix lsquotexrsquo means lsquoartrsquo as well as lsquotechnologyrsquo so itrsquos a very nicelychosen name for a piece of software that produces such beautiful output Knuthexplained (D Knuth 1984) that one should lsquopronounce the X of TeX as a Greekchi not as an lsquoxrsquo so that TeX rhymes with the word blecchhhrsquo Wersquore not toosure that helps much unless you are confident in your pronunciation of theword lsquoblecchhrsquo Maybe itrsquos an American thing

44

COMP10120 Report writing and Digital Typography

bull LATEX is a new interesting way for you to thinkabout preparing documents

bull LATEX has a practical advantage for the writer inthat it helps you think more about what you wantto write rather than worrying about how it looks

bull LATEX is a powerful tool for professional scientificdocumentation and as a Computer Scientist youshould know about it

bull LATEX files are just plain text so can easily be cre-ated programatically For example the slides usedfor COMP16120 are generated automatically fromthe source of Johnrsquos book both are typeset usingLATEX The program labprint also produces itsoutput using LATEX using information drawn fromXMLW configuration files and ARCADE

bull Using LATEX is actually quite satisfying and thequality of its output may surprise you

In this lab session you are going to write severalshort documents using LATEX You could also write briefnotes in your logbook about how LATEX works and whatcommands you used inside the source of your docu-ments

45

COMP10120 Report writing and Digital Typography

383 Some history printing mathematics

Mathematics is hard to print on paper and on the Web(many websites resort to GIF or JPG images of mathsformulae which usually look horrible MathMLW pro-vides another approach but it is not yet widely used)

In the days before computers books and newspa-pers were printed with movable typeW made from lotsof little blocks of metal each with letters numbers andsymbols standing in relief which when inked left animpression on the paper (see Figure 35) The job ofthe printer (the printer here of course being a personnot a bit of electronics) was to gather together all theblocks in the right order between two horizontal stripsof wood to create a line of the document and then toassemble all those lines from top to bottom of a pageThus the term type settingW an incredible task whenyou think about it In the printerrsquos workshop by theway the blocks of metal were stored between jobs inwooden boxes called cases Letters like a b and c werestored in one case letters like A B and C were storedin a case sitting on top of that So a lower case and anupper case These terms may ring a bell

As technology progressed machines controlled bytypewriters would mechanically juggle the blocks intothe right order This conceptual model is the basis onwhich TEX operates Only now the metal blocks are

46

COMP10120 Report writing and Digital Typography

Figure 35On the left a piece of cast movable type in the Garamondfont On the right a case of cast metal type pieces andtypeset matter in a composing stick The text reads lsquoThequick brown fox jumps over the lazy dog and feels as if hewere in the seventh heaven of typography together with Her-mann Zapf the most famous artist of thersquo This document istypeset in a font called Palatino created by Hermann ZapfYou may have also seen rsquoZapf Dingbatsrsquo in the font lists ofvarious desktop applications Now you know why

little pieces of data arranged into data structuresThe one thing that traditional printers hated was

dealing with the typesetting of mathematics and theywould charge extra to do it It was incredibly fiddly toget the equations looking right they had to squeeze inextra bits of metal horizontally and vertically

When computers entered the printing world attemptsto print mathematics were limited by the printing tech-nology available It took a long time to reach the pointwhere computers could typeset mathematics beautifullyand that was the outstanding achievement of Knuthrsquos

47

COMP10120 Report writing and Digital Typography

TEXLetrsquos look at a quick example of the quality you get

from LATEX with a very simple formula that yoursquoll recog-nise

x =minusbplusmn

radicb2 minus 4ac

2aWersquoll revisit how LATEX typesets mathematics in Section 34

384 To WYSIWYG or not to WYSIWYG

Up until now you have probably used wordprocessingapplications such as Microsoft Word to create essaysletters and other (probably fairly short) documents Youmost likely know that the majority of modern wordprocessors use a paradigm called WYSIWYG or WhatYou See Is What You Get which means that you canmodify the visual style of the document yoursquore work-ing on by selecting the relevant bits and then choos-ing different attributes such as font size or colour usinga GUI In many ways this seems like such a sensibleand obvious way of doing things that you might bewondering why it even has a special name The rea-son is a historical one in the early days of comput-ing long before graphical window managers becamethe norm and when all you could display on screenwas fixed-width ASCII text in whatever the systemrsquos

48

COMP10120 Report writing and Digital Typography

default font was wordprocessors (eg Figure 36) onlyallowed you to format documents by using special se-quences of characters to cause particular effects Butthese effects were only visible when the document wasprinted So if you wanted a word to appear in boldtext in the wordprocessor you might write somethinglike [bold]hello world[bold] what you saw onscreen was not a direct reflection of what appeared onthe printed page If yoursquove written any HTML how-ever this process of marking up text may be familiarsee for example Figure 37 As computers moved todisplays able to draw things other than raw charac-ters on screen wordprocessors became capable of us-ing multiple fonts and styles as well as graphics anda new generation of applications appeared where whatyou saw on screen was an accurate reflection of how itwould appear when printed what you see (on screen)is what you get (on paper)

The huge advantage of WYSIWYG is that itrsquos reallyeasy to understand whatrsquos going on and most peoplecan create reasonably nicely formatted documents withrelatively little effort For short informal documentsone-off letters memos and such WYSIWYG works quitenicely But if yoursquove ever tried writing anything muchlonger or that includes images and tables you mayhave already started to see where the paradigm breaksdown For example if you write lsquoFigure 38 on page

49

COMP10120 Report writing and Digital Typography

Figure 36A screenshot of Wordperfect 51 running in Microsoft DOScirca 1989

51 shows a picture of some men looking at cheesersquo butthen later on edit your document to include some moretext at the start and a new picture of a some broccoli(as in Figure 39) yoursquod have to search through yourreport to find all mentions of lsquoFigure 38rsquo and lsquopage 51rsquoand manually update them to reflect the new number-ing This might be fine if you have two figures and fivepages but for a hundred-page report containing lots ofpictures you can see how this becomes tedious and er-ror prone very quickly

50

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 32: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

will be new to you It is labelled as optional because itisnrsquot marked but we would recommend that you all tryit

Take a copy of the file optinfocoursesCOMP10120ex3latex-introtexand follow the instructions it contains You should readit before you process it with LATEX

Exercise 8 A neat directory listing (optionalmore challenging)

The fact that LATEX source files are just text makes it easyto have them generated by a program You are going toexploit this and use LATEX to produce a neat documentcontaining a listing of the files in any directory

Find how to create tables in LATEX tables using thetabular environment Make a LATEX document by handthat uses a table to neatly show the information aboutthe files in some (small) directory (as produced by ls

-l) Write a shell script called neat-ls that takes anargument which is the path name of a directory andproduces a LATEX document containing the above tablefor the given directory The script could also process theLATEX and display the resulting pdf file Finally find outabout the longtable package and change your script touse that instead

39

COMP10120 Report writing and Digital Typography

Exercise 9 A cleaning rota (optional evenmore challenging)

Now you will write a shell script called make-rota thatgenerates a house cleaning rota (Very handy for nextyear ) This is a table with columns such as KitchenBathroom and Lounge The rows will be weeks in theyear labelled with a date (eg always a Sunday) Theidea is that house mates can write their initials in theboxes promising to clean the corresponding room inthat particular week Start by making a sample tableby hand

Your script should take a single argument which isthe date of the first day of the first row eg102013(the US format for 20 Oct 13) The result will be a docu-ment that contains as many rows as fit on a single page(find out by experimenting)

The dates of each row should be generated from thefirst See the manual page for date to figure out howyou can generate a date that is a number of weeks anddays later than an existing one

361 Marking Scheme

You can view a copy of the marking scheme used bysubmit and labprint at

40

COMP10120 Report writing and Digital Typography

studentnetcsmanchesteracukugtlpmsphpunit=COMP10120ampex=ex3xml

37 Next steps

LATEX is a very powerful tool and it does take a littlegetting used to But itrsquos not as scary as it might initiallyseem and you should find that it doesnrsquot take long tolearn the common commands and techniques to makeyour documents well-structured and readable As youbecome more comfortable with the basics and under-stand the principles of typesetting finding out how todo more complex and sophisticated things is easymdashthere are hundreds of tutorials on the web

Donrsquot get carried away though and use the featuresjudiciously just because yoursquove found a cool new com-mand doesnrsquot mean that you should use it just to showoff your LATEX skills content and structure always trumpstypographic twiddlings4

4For example footnotes like this are for some reason a really tempting fea-ture to use in LATEX and in this document we have abused them mercilessly toillustrate a point Footnotes were originally a means for mechanical typeset-ters to insert comments corrections or additions to existing documents withouthaving to adjust the layout of a whole page and of course in digital typographythis is no longer necessary They can justifiably be used for citations (though itrsquosnot common to do so these days) and URLs if you donrsquot want these intrudinginto the body of your text And in some very very rare cases they can be usedas an aside to the main flow of the text (which is what has been done in this doc-ument) But this should be used sparingly If something is important to sayput it in the main body of your text If itrsquos not then perhaps you should thinkabout leaving it out completely or find some other way of including it Asking

41

COMP10120 Report writing and Digital Typography

371 Acknowledgements

Figure 38 is from the Wikipedia article on cheese

372 License

The text of this exercise is licensed under the terms ofthe Creative Commons Attribution 20 Generic (CC BY30) License

38 Background

What follows is additional contextual information aroundLATEX

LATEX was originally written by Leslie LamportW anAmerican computer scientist now working at MicrosoftResearch although its development has long been takenover by a world-wide LATEX community Itrsquos actuallybuilt on top of another system called TEX a computertypesetting system designed by one of the worldrsquos mostinfluential Computer Scientists Donald KnuthW of Stan-ford University Knuth has said that he designed TEX

the reader to look down at the bottom of a page to find out whether somethingis important or not is irritating and as yoursquove probably found out already oftenmeans you lose track of your reading position They also give the impressionthat the author isnrsquot clear about whether something is important or not whichis never good And long footnotes like this onemdashwhile LATEX will typeset themperfectly wellmdashare just plain silly Best avoid

42

COMP10120 Report writing and Digital Typography

for lsquothe creation of beautiful booksmdashand especially forbooks that contain a lot of mathematicsrsquo(D Knuth1984) Figure 34 shows what these eminent men looklike

So whatrsquos the purpose of LATEX Itrsquos purely a layerof software to make TEX easier to use in everyday sit-uations This is a good idea because although TEX isamazingly powerful it operates at a very low-level whichmakes it hard for non-expert users

Figure 34Don Knuth and Leslie Lamport

381 Pronunciation

The name TEX is intended by its creator to be pronouncedwith the final consonant as in the word loch or the nameBach but English speakers often pronounce it like thefirst syllable of technical The first syllable of LATEX is

43

COMP10120 Report writing and Digital Typography

pronounced as in rsquolayrsquo5

382 Why LATEX

Before we go any further why do we think LATEX is im-portant for youmdasha Computer Science studentmdashto knowabout Here are some reasons in no particular order

bull LATEX and TEX are superb examples of ComputerScience in action TEX was designed by Knuth fromfirst principlesmdashin other words from scratch TEXis actually a programming language and LATEX isa set of functions defined in the TEX language TheTEX lsquocompilerrsquo is written in WEBW a mixture ofdocumentation written in TeX and a PascalW sub-set in order to ensure portability it reads a TEXprogram and outputs documents TEX is completelyself-contained and designed to be portable to anycomputer architecture For example it implementsits own stackW and heapW (with garbage collectionW)and it does fixed-precision arithmeticW donrsquot worryif these terms donrsquot make much sense to you at themoment they soon will

5The Greek prefix lsquotexrsquo means lsquoartrsquo as well as lsquotechnologyrsquo so itrsquos a very nicelychosen name for a piece of software that produces such beautiful output Knuthexplained (D Knuth 1984) that one should lsquopronounce the X of TeX as a Greekchi not as an lsquoxrsquo so that TeX rhymes with the word blecchhhrsquo Wersquore not toosure that helps much unless you are confident in your pronunciation of theword lsquoblecchhrsquo Maybe itrsquos an American thing

44

COMP10120 Report writing and Digital Typography

bull LATEX is a new interesting way for you to thinkabout preparing documents

bull LATEX has a practical advantage for the writer inthat it helps you think more about what you wantto write rather than worrying about how it looks

bull LATEX is a powerful tool for professional scientificdocumentation and as a Computer Scientist youshould know about it

bull LATEX files are just plain text so can easily be cre-ated programatically For example the slides usedfor COMP16120 are generated automatically fromthe source of Johnrsquos book both are typeset usingLATEX The program labprint also produces itsoutput using LATEX using information drawn fromXMLW configuration files and ARCADE

bull Using LATEX is actually quite satisfying and thequality of its output may surprise you

In this lab session you are going to write severalshort documents using LATEX You could also write briefnotes in your logbook about how LATEX works and whatcommands you used inside the source of your docu-ments

45

COMP10120 Report writing and Digital Typography

383 Some history printing mathematics

Mathematics is hard to print on paper and on the Web(many websites resort to GIF or JPG images of mathsformulae which usually look horrible MathMLW pro-vides another approach but it is not yet widely used)

In the days before computers books and newspa-pers were printed with movable typeW made from lotsof little blocks of metal each with letters numbers andsymbols standing in relief which when inked left animpression on the paper (see Figure 35) The job ofthe printer (the printer here of course being a personnot a bit of electronics) was to gather together all theblocks in the right order between two horizontal stripsof wood to create a line of the document and then toassemble all those lines from top to bottom of a pageThus the term type settingW an incredible task whenyou think about it In the printerrsquos workshop by theway the blocks of metal were stored between jobs inwooden boxes called cases Letters like a b and c werestored in one case letters like A B and C were storedin a case sitting on top of that So a lower case and anupper case These terms may ring a bell

As technology progressed machines controlled bytypewriters would mechanically juggle the blocks intothe right order This conceptual model is the basis onwhich TEX operates Only now the metal blocks are

46

COMP10120 Report writing and Digital Typography

Figure 35On the left a piece of cast movable type in the Garamondfont On the right a case of cast metal type pieces andtypeset matter in a composing stick The text reads lsquoThequick brown fox jumps over the lazy dog and feels as if hewere in the seventh heaven of typography together with Her-mann Zapf the most famous artist of thersquo This document istypeset in a font called Palatino created by Hermann ZapfYou may have also seen rsquoZapf Dingbatsrsquo in the font lists ofvarious desktop applications Now you know why

little pieces of data arranged into data structuresThe one thing that traditional printers hated was

dealing with the typesetting of mathematics and theywould charge extra to do it It was incredibly fiddly toget the equations looking right they had to squeeze inextra bits of metal horizontally and vertically

When computers entered the printing world attemptsto print mathematics were limited by the printing tech-nology available It took a long time to reach the pointwhere computers could typeset mathematics beautifullyand that was the outstanding achievement of Knuthrsquos

47

COMP10120 Report writing and Digital Typography

TEXLetrsquos look at a quick example of the quality you get

from LATEX with a very simple formula that yoursquoll recog-nise

x =minusbplusmn

radicb2 minus 4ac

2aWersquoll revisit how LATEX typesets mathematics in Section 34

384 To WYSIWYG or not to WYSIWYG

Up until now you have probably used wordprocessingapplications such as Microsoft Word to create essaysletters and other (probably fairly short) documents Youmost likely know that the majority of modern wordprocessors use a paradigm called WYSIWYG or WhatYou See Is What You Get which means that you canmodify the visual style of the document yoursquore work-ing on by selecting the relevant bits and then choos-ing different attributes such as font size or colour usinga GUI In many ways this seems like such a sensibleand obvious way of doing things that you might bewondering why it even has a special name The rea-son is a historical one in the early days of comput-ing long before graphical window managers becamethe norm and when all you could display on screenwas fixed-width ASCII text in whatever the systemrsquos

48

COMP10120 Report writing and Digital Typography

default font was wordprocessors (eg Figure 36) onlyallowed you to format documents by using special se-quences of characters to cause particular effects Butthese effects were only visible when the document wasprinted So if you wanted a word to appear in boldtext in the wordprocessor you might write somethinglike [bold]hello world[bold] what you saw onscreen was not a direct reflection of what appeared onthe printed page If yoursquove written any HTML how-ever this process of marking up text may be familiarsee for example Figure 37 As computers moved todisplays able to draw things other than raw charac-ters on screen wordprocessors became capable of us-ing multiple fonts and styles as well as graphics anda new generation of applications appeared where whatyou saw on screen was an accurate reflection of how itwould appear when printed what you see (on screen)is what you get (on paper)

The huge advantage of WYSIWYG is that itrsquos reallyeasy to understand whatrsquos going on and most peoplecan create reasonably nicely formatted documents withrelatively little effort For short informal documentsone-off letters memos and such WYSIWYG works quitenicely But if yoursquove ever tried writing anything muchlonger or that includes images and tables you mayhave already started to see where the paradigm breaksdown For example if you write lsquoFigure 38 on page

49

COMP10120 Report writing and Digital Typography

Figure 36A screenshot of Wordperfect 51 running in Microsoft DOScirca 1989

51 shows a picture of some men looking at cheesersquo butthen later on edit your document to include some moretext at the start and a new picture of a some broccoli(as in Figure 39) yoursquod have to search through yourreport to find all mentions of lsquoFigure 38rsquo and lsquopage 51rsquoand manually update them to reflect the new number-ing This might be fine if you have two figures and fivepages but for a hundred-page report containing lots ofpictures you can see how this becomes tedious and er-ror prone very quickly

50

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 33: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

Exercise 9 A cleaning rota (optional evenmore challenging)

Now you will write a shell script called make-rota thatgenerates a house cleaning rota (Very handy for nextyear ) This is a table with columns such as KitchenBathroom and Lounge The rows will be weeks in theyear labelled with a date (eg always a Sunday) Theidea is that house mates can write their initials in theboxes promising to clean the corresponding room inthat particular week Start by making a sample tableby hand

Your script should take a single argument which isthe date of the first day of the first row eg102013(the US format for 20 Oct 13) The result will be a docu-ment that contains as many rows as fit on a single page(find out by experimenting)

The dates of each row should be generated from thefirst See the manual page for date to figure out howyou can generate a date that is a number of weeks anddays later than an existing one

361 Marking Scheme

You can view a copy of the marking scheme used bysubmit and labprint at

40

COMP10120 Report writing and Digital Typography

studentnetcsmanchesteracukugtlpmsphpunit=COMP10120ampex=ex3xml

37 Next steps

LATEX is a very powerful tool and it does take a littlegetting used to But itrsquos not as scary as it might initiallyseem and you should find that it doesnrsquot take long tolearn the common commands and techniques to makeyour documents well-structured and readable As youbecome more comfortable with the basics and under-stand the principles of typesetting finding out how todo more complex and sophisticated things is easymdashthere are hundreds of tutorials on the web

Donrsquot get carried away though and use the featuresjudiciously just because yoursquove found a cool new com-mand doesnrsquot mean that you should use it just to showoff your LATEX skills content and structure always trumpstypographic twiddlings4

4For example footnotes like this are for some reason a really tempting fea-ture to use in LATEX and in this document we have abused them mercilessly toillustrate a point Footnotes were originally a means for mechanical typeset-ters to insert comments corrections or additions to existing documents withouthaving to adjust the layout of a whole page and of course in digital typographythis is no longer necessary They can justifiably be used for citations (though itrsquosnot common to do so these days) and URLs if you donrsquot want these intrudinginto the body of your text And in some very very rare cases they can be usedas an aside to the main flow of the text (which is what has been done in this doc-ument) But this should be used sparingly If something is important to sayput it in the main body of your text If itrsquos not then perhaps you should thinkabout leaving it out completely or find some other way of including it Asking

41

COMP10120 Report writing and Digital Typography

371 Acknowledgements

Figure 38 is from the Wikipedia article on cheese

372 License

The text of this exercise is licensed under the terms ofthe Creative Commons Attribution 20 Generic (CC BY30) License

38 Background

What follows is additional contextual information aroundLATEX

LATEX was originally written by Leslie LamportW anAmerican computer scientist now working at MicrosoftResearch although its development has long been takenover by a world-wide LATEX community Itrsquos actuallybuilt on top of another system called TEX a computertypesetting system designed by one of the worldrsquos mostinfluential Computer Scientists Donald KnuthW of Stan-ford University Knuth has said that he designed TEX

the reader to look down at the bottom of a page to find out whether somethingis important or not is irritating and as yoursquove probably found out already oftenmeans you lose track of your reading position They also give the impressionthat the author isnrsquot clear about whether something is important or not whichis never good And long footnotes like this onemdashwhile LATEX will typeset themperfectly wellmdashare just plain silly Best avoid

42

COMP10120 Report writing and Digital Typography

for lsquothe creation of beautiful booksmdashand especially forbooks that contain a lot of mathematicsrsquo(D Knuth1984) Figure 34 shows what these eminent men looklike

So whatrsquos the purpose of LATEX Itrsquos purely a layerof software to make TEX easier to use in everyday sit-uations This is a good idea because although TEX isamazingly powerful it operates at a very low-level whichmakes it hard for non-expert users

Figure 34Don Knuth and Leslie Lamport

381 Pronunciation

The name TEX is intended by its creator to be pronouncedwith the final consonant as in the word loch or the nameBach but English speakers often pronounce it like thefirst syllable of technical The first syllable of LATEX is

43

COMP10120 Report writing and Digital Typography

pronounced as in rsquolayrsquo5

382 Why LATEX

Before we go any further why do we think LATEX is im-portant for youmdasha Computer Science studentmdashto knowabout Here are some reasons in no particular order

bull LATEX and TEX are superb examples of ComputerScience in action TEX was designed by Knuth fromfirst principlesmdashin other words from scratch TEXis actually a programming language and LATEX isa set of functions defined in the TEX language TheTEX lsquocompilerrsquo is written in WEBW a mixture ofdocumentation written in TeX and a PascalW sub-set in order to ensure portability it reads a TEXprogram and outputs documents TEX is completelyself-contained and designed to be portable to anycomputer architecture For example it implementsits own stackW and heapW (with garbage collectionW)and it does fixed-precision arithmeticW donrsquot worryif these terms donrsquot make much sense to you at themoment they soon will

5The Greek prefix lsquotexrsquo means lsquoartrsquo as well as lsquotechnologyrsquo so itrsquos a very nicelychosen name for a piece of software that produces such beautiful output Knuthexplained (D Knuth 1984) that one should lsquopronounce the X of TeX as a Greekchi not as an lsquoxrsquo so that TeX rhymes with the word blecchhhrsquo Wersquore not toosure that helps much unless you are confident in your pronunciation of theword lsquoblecchhrsquo Maybe itrsquos an American thing

44

COMP10120 Report writing and Digital Typography

bull LATEX is a new interesting way for you to thinkabout preparing documents

bull LATEX has a practical advantage for the writer inthat it helps you think more about what you wantto write rather than worrying about how it looks

bull LATEX is a powerful tool for professional scientificdocumentation and as a Computer Scientist youshould know about it

bull LATEX files are just plain text so can easily be cre-ated programatically For example the slides usedfor COMP16120 are generated automatically fromthe source of Johnrsquos book both are typeset usingLATEX The program labprint also produces itsoutput using LATEX using information drawn fromXMLW configuration files and ARCADE

bull Using LATEX is actually quite satisfying and thequality of its output may surprise you

In this lab session you are going to write severalshort documents using LATEX You could also write briefnotes in your logbook about how LATEX works and whatcommands you used inside the source of your docu-ments

45

COMP10120 Report writing and Digital Typography

383 Some history printing mathematics

Mathematics is hard to print on paper and on the Web(many websites resort to GIF or JPG images of mathsformulae which usually look horrible MathMLW pro-vides another approach but it is not yet widely used)

In the days before computers books and newspa-pers were printed with movable typeW made from lotsof little blocks of metal each with letters numbers andsymbols standing in relief which when inked left animpression on the paper (see Figure 35) The job ofthe printer (the printer here of course being a personnot a bit of electronics) was to gather together all theblocks in the right order between two horizontal stripsof wood to create a line of the document and then toassemble all those lines from top to bottom of a pageThus the term type settingW an incredible task whenyou think about it In the printerrsquos workshop by theway the blocks of metal were stored between jobs inwooden boxes called cases Letters like a b and c werestored in one case letters like A B and C were storedin a case sitting on top of that So a lower case and anupper case These terms may ring a bell

As technology progressed machines controlled bytypewriters would mechanically juggle the blocks intothe right order This conceptual model is the basis onwhich TEX operates Only now the metal blocks are

46

COMP10120 Report writing and Digital Typography

Figure 35On the left a piece of cast movable type in the Garamondfont On the right a case of cast metal type pieces andtypeset matter in a composing stick The text reads lsquoThequick brown fox jumps over the lazy dog and feels as if hewere in the seventh heaven of typography together with Her-mann Zapf the most famous artist of thersquo This document istypeset in a font called Palatino created by Hermann ZapfYou may have also seen rsquoZapf Dingbatsrsquo in the font lists ofvarious desktop applications Now you know why

little pieces of data arranged into data structuresThe one thing that traditional printers hated was

dealing with the typesetting of mathematics and theywould charge extra to do it It was incredibly fiddly toget the equations looking right they had to squeeze inextra bits of metal horizontally and vertically

When computers entered the printing world attemptsto print mathematics were limited by the printing tech-nology available It took a long time to reach the pointwhere computers could typeset mathematics beautifullyand that was the outstanding achievement of Knuthrsquos

47

COMP10120 Report writing and Digital Typography

TEXLetrsquos look at a quick example of the quality you get

from LATEX with a very simple formula that yoursquoll recog-nise

x =minusbplusmn

radicb2 minus 4ac

2aWersquoll revisit how LATEX typesets mathematics in Section 34

384 To WYSIWYG or not to WYSIWYG

Up until now you have probably used wordprocessingapplications such as Microsoft Word to create essaysletters and other (probably fairly short) documents Youmost likely know that the majority of modern wordprocessors use a paradigm called WYSIWYG or WhatYou See Is What You Get which means that you canmodify the visual style of the document yoursquore work-ing on by selecting the relevant bits and then choos-ing different attributes such as font size or colour usinga GUI In many ways this seems like such a sensibleand obvious way of doing things that you might bewondering why it even has a special name The rea-son is a historical one in the early days of comput-ing long before graphical window managers becamethe norm and when all you could display on screenwas fixed-width ASCII text in whatever the systemrsquos

48

COMP10120 Report writing and Digital Typography

default font was wordprocessors (eg Figure 36) onlyallowed you to format documents by using special se-quences of characters to cause particular effects Butthese effects were only visible when the document wasprinted So if you wanted a word to appear in boldtext in the wordprocessor you might write somethinglike [bold]hello world[bold] what you saw onscreen was not a direct reflection of what appeared onthe printed page If yoursquove written any HTML how-ever this process of marking up text may be familiarsee for example Figure 37 As computers moved todisplays able to draw things other than raw charac-ters on screen wordprocessors became capable of us-ing multiple fonts and styles as well as graphics anda new generation of applications appeared where whatyou saw on screen was an accurate reflection of how itwould appear when printed what you see (on screen)is what you get (on paper)

The huge advantage of WYSIWYG is that itrsquos reallyeasy to understand whatrsquos going on and most peoplecan create reasonably nicely formatted documents withrelatively little effort For short informal documentsone-off letters memos and such WYSIWYG works quitenicely But if yoursquove ever tried writing anything muchlonger or that includes images and tables you mayhave already started to see where the paradigm breaksdown For example if you write lsquoFigure 38 on page

49

COMP10120 Report writing and Digital Typography

Figure 36A screenshot of Wordperfect 51 running in Microsoft DOScirca 1989

51 shows a picture of some men looking at cheesersquo butthen later on edit your document to include some moretext at the start and a new picture of a some broccoli(as in Figure 39) yoursquod have to search through yourreport to find all mentions of lsquoFigure 38rsquo and lsquopage 51rsquoand manually update them to reflect the new number-ing This might be fine if you have two figures and fivepages but for a hundred-page report containing lots ofpictures you can see how this becomes tedious and er-ror prone very quickly

50

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 34: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

studentnetcsmanchesteracukugtlpmsphpunit=COMP10120ampex=ex3xml

37 Next steps

LATEX is a very powerful tool and it does take a littlegetting used to But itrsquos not as scary as it might initiallyseem and you should find that it doesnrsquot take long tolearn the common commands and techniques to makeyour documents well-structured and readable As youbecome more comfortable with the basics and under-stand the principles of typesetting finding out how todo more complex and sophisticated things is easymdashthere are hundreds of tutorials on the web

Donrsquot get carried away though and use the featuresjudiciously just because yoursquove found a cool new com-mand doesnrsquot mean that you should use it just to showoff your LATEX skills content and structure always trumpstypographic twiddlings4

4For example footnotes like this are for some reason a really tempting fea-ture to use in LATEX and in this document we have abused them mercilessly toillustrate a point Footnotes were originally a means for mechanical typeset-ters to insert comments corrections or additions to existing documents withouthaving to adjust the layout of a whole page and of course in digital typographythis is no longer necessary They can justifiably be used for citations (though itrsquosnot common to do so these days) and URLs if you donrsquot want these intrudinginto the body of your text And in some very very rare cases they can be usedas an aside to the main flow of the text (which is what has been done in this doc-ument) But this should be used sparingly If something is important to sayput it in the main body of your text If itrsquos not then perhaps you should thinkabout leaving it out completely or find some other way of including it Asking

41

COMP10120 Report writing and Digital Typography

371 Acknowledgements

Figure 38 is from the Wikipedia article on cheese

372 License

The text of this exercise is licensed under the terms ofthe Creative Commons Attribution 20 Generic (CC BY30) License

38 Background

What follows is additional contextual information aroundLATEX

LATEX was originally written by Leslie LamportW anAmerican computer scientist now working at MicrosoftResearch although its development has long been takenover by a world-wide LATEX community Itrsquos actuallybuilt on top of another system called TEX a computertypesetting system designed by one of the worldrsquos mostinfluential Computer Scientists Donald KnuthW of Stan-ford University Knuth has said that he designed TEX

the reader to look down at the bottom of a page to find out whether somethingis important or not is irritating and as yoursquove probably found out already oftenmeans you lose track of your reading position They also give the impressionthat the author isnrsquot clear about whether something is important or not whichis never good And long footnotes like this onemdashwhile LATEX will typeset themperfectly wellmdashare just plain silly Best avoid

42

COMP10120 Report writing and Digital Typography

for lsquothe creation of beautiful booksmdashand especially forbooks that contain a lot of mathematicsrsquo(D Knuth1984) Figure 34 shows what these eminent men looklike

So whatrsquos the purpose of LATEX Itrsquos purely a layerof software to make TEX easier to use in everyday sit-uations This is a good idea because although TEX isamazingly powerful it operates at a very low-level whichmakes it hard for non-expert users

Figure 34Don Knuth and Leslie Lamport

381 Pronunciation

The name TEX is intended by its creator to be pronouncedwith the final consonant as in the word loch or the nameBach but English speakers often pronounce it like thefirst syllable of technical The first syllable of LATEX is

43

COMP10120 Report writing and Digital Typography

pronounced as in rsquolayrsquo5

382 Why LATEX

Before we go any further why do we think LATEX is im-portant for youmdasha Computer Science studentmdashto knowabout Here are some reasons in no particular order

bull LATEX and TEX are superb examples of ComputerScience in action TEX was designed by Knuth fromfirst principlesmdashin other words from scratch TEXis actually a programming language and LATEX isa set of functions defined in the TEX language TheTEX lsquocompilerrsquo is written in WEBW a mixture ofdocumentation written in TeX and a PascalW sub-set in order to ensure portability it reads a TEXprogram and outputs documents TEX is completelyself-contained and designed to be portable to anycomputer architecture For example it implementsits own stackW and heapW (with garbage collectionW)and it does fixed-precision arithmeticW donrsquot worryif these terms donrsquot make much sense to you at themoment they soon will

5The Greek prefix lsquotexrsquo means lsquoartrsquo as well as lsquotechnologyrsquo so itrsquos a very nicelychosen name for a piece of software that produces such beautiful output Knuthexplained (D Knuth 1984) that one should lsquopronounce the X of TeX as a Greekchi not as an lsquoxrsquo so that TeX rhymes with the word blecchhhrsquo Wersquore not toosure that helps much unless you are confident in your pronunciation of theword lsquoblecchhrsquo Maybe itrsquos an American thing

44

COMP10120 Report writing and Digital Typography

bull LATEX is a new interesting way for you to thinkabout preparing documents

bull LATEX has a practical advantage for the writer inthat it helps you think more about what you wantto write rather than worrying about how it looks

bull LATEX is a powerful tool for professional scientificdocumentation and as a Computer Scientist youshould know about it

bull LATEX files are just plain text so can easily be cre-ated programatically For example the slides usedfor COMP16120 are generated automatically fromthe source of Johnrsquos book both are typeset usingLATEX The program labprint also produces itsoutput using LATEX using information drawn fromXMLW configuration files and ARCADE

bull Using LATEX is actually quite satisfying and thequality of its output may surprise you

In this lab session you are going to write severalshort documents using LATEX You could also write briefnotes in your logbook about how LATEX works and whatcommands you used inside the source of your docu-ments

45

COMP10120 Report writing and Digital Typography

383 Some history printing mathematics

Mathematics is hard to print on paper and on the Web(many websites resort to GIF or JPG images of mathsformulae which usually look horrible MathMLW pro-vides another approach but it is not yet widely used)

In the days before computers books and newspa-pers were printed with movable typeW made from lotsof little blocks of metal each with letters numbers andsymbols standing in relief which when inked left animpression on the paper (see Figure 35) The job ofthe printer (the printer here of course being a personnot a bit of electronics) was to gather together all theblocks in the right order between two horizontal stripsof wood to create a line of the document and then toassemble all those lines from top to bottom of a pageThus the term type settingW an incredible task whenyou think about it In the printerrsquos workshop by theway the blocks of metal were stored between jobs inwooden boxes called cases Letters like a b and c werestored in one case letters like A B and C were storedin a case sitting on top of that So a lower case and anupper case These terms may ring a bell

As technology progressed machines controlled bytypewriters would mechanically juggle the blocks intothe right order This conceptual model is the basis onwhich TEX operates Only now the metal blocks are

46

COMP10120 Report writing and Digital Typography

Figure 35On the left a piece of cast movable type in the Garamondfont On the right a case of cast metal type pieces andtypeset matter in a composing stick The text reads lsquoThequick brown fox jumps over the lazy dog and feels as if hewere in the seventh heaven of typography together with Her-mann Zapf the most famous artist of thersquo This document istypeset in a font called Palatino created by Hermann ZapfYou may have also seen rsquoZapf Dingbatsrsquo in the font lists ofvarious desktop applications Now you know why

little pieces of data arranged into data structuresThe one thing that traditional printers hated was

dealing with the typesetting of mathematics and theywould charge extra to do it It was incredibly fiddly toget the equations looking right they had to squeeze inextra bits of metal horizontally and vertically

When computers entered the printing world attemptsto print mathematics were limited by the printing tech-nology available It took a long time to reach the pointwhere computers could typeset mathematics beautifullyand that was the outstanding achievement of Knuthrsquos

47

COMP10120 Report writing and Digital Typography

TEXLetrsquos look at a quick example of the quality you get

from LATEX with a very simple formula that yoursquoll recog-nise

x =minusbplusmn

radicb2 minus 4ac

2aWersquoll revisit how LATEX typesets mathematics in Section 34

384 To WYSIWYG or not to WYSIWYG

Up until now you have probably used wordprocessingapplications such as Microsoft Word to create essaysletters and other (probably fairly short) documents Youmost likely know that the majority of modern wordprocessors use a paradigm called WYSIWYG or WhatYou See Is What You Get which means that you canmodify the visual style of the document yoursquore work-ing on by selecting the relevant bits and then choos-ing different attributes such as font size or colour usinga GUI In many ways this seems like such a sensibleand obvious way of doing things that you might bewondering why it even has a special name The rea-son is a historical one in the early days of comput-ing long before graphical window managers becamethe norm and when all you could display on screenwas fixed-width ASCII text in whatever the systemrsquos

48

COMP10120 Report writing and Digital Typography

default font was wordprocessors (eg Figure 36) onlyallowed you to format documents by using special se-quences of characters to cause particular effects Butthese effects were only visible when the document wasprinted So if you wanted a word to appear in boldtext in the wordprocessor you might write somethinglike [bold]hello world[bold] what you saw onscreen was not a direct reflection of what appeared onthe printed page If yoursquove written any HTML how-ever this process of marking up text may be familiarsee for example Figure 37 As computers moved todisplays able to draw things other than raw charac-ters on screen wordprocessors became capable of us-ing multiple fonts and styles as well as graphics anda new generation of applications appeared where whatyou saw on screen was an accurate reflection of how itwould appear when printed what you see (on screen)is what you get (on paper)

The huge advantage of WYSIWYG is that itrsquos reallyeasy to understand whatrsquos going on and most peoplecan create reasonably nicely formatted documents withrelatively little effort For short informal documentsone-off letters memos and such WYSIWYG works quitenicely But if yoursquove ever tried writing anything muchlonger or that includes images and tables you mayhave already started to see where the paradigm breaksdown For example if you write lsquoFigure 38 on page

49

COMP10120 Report writing and Digital Typography

Figure 36A screenshot of Wordperfect 51 running in Microsoft DOScirca 1989

51 shows a picture of some men looking at cheesersquo butthen later on edit your document to include some moretext at the start and a new picture of a some broccoli(as in Figure 39) yoursquod have to search through yourreport to find all mentions of lsquoFigure 38rsquo and lsquopage 51rsquoand manually update them to reflect the new number-ing This might be fine if you have two figures and fivepages but for a hundred-page report containing lots ofpictures you can see how this becomes tedious and er-ror prone very quickly

50

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 35: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

371 Acknowledgements

Figure 38 is from the Wikipedia article on cheese

372 License

The text of this exercise is licensed under the terms ofthe Creative Commons Attribution 20 Generic (CC BY30) License

38 Background

What follows is additional contextual information aroundLATEX

LATEX was originally written by Leslie LamportW anAmerican computer scientist now working at MicrosoftResearch although its development has long been takenover by a world-wide LATEX community Itrsquos actuallybuilt on top of another system called TEX a computertypesetting system designed by one of the worldrsquos mostinfluential Computer Scientists Donald KnuthW of Stan-ford University Knuth has said that he designed TEX

the reader to look down at the bottom of a page to find out whether somethingis important or not is irritating and as yoursquove probably found out already oftenmeans you lose track of your reading position They also give the impressionthat the author isnrsquot clear about whether something is important or not whichis never good And long footnotes like this onemdashwhile LATEX will typeset themperfectly wellmdashare just plain silly Best avoid

42

COMP10120 Report writing and Digital Typography

for lsquothe creation of beautiful booksmdashand especially forbooks that contain a lot of mathematicsrsquo(D Knuth1984) Figure 34 shows what these eminent men looklike

So whatrsquos the purpose of LATEX Itrsquos purely a layerof software to make TEX easier to use in everyday sit-uations This is a good idea because although TEX isamazingly powerful it operates at a very low-level whichmakes it hard for non-expert users

Figure 34Don Knuth and Leslie Lamport

381 Pronunciation

The name TEX is intended by its creator to be pronouncedwith the final consonant as in the word loch or the nameBach but English speakers often pronounce it like thefirst syllable of technical The first syllable of LATEX is

43

COMP10120 Report writing and Digital Typography

pronounced as in rsquolayrsquo5

382 Why LATEX

Before we go any further why do we think LATEX is im-portant for youmdasha Computer Science studentmdashto knowabout Here are some reasons in no particular order

bull LATEX and TEX are superb examples of ComputerScience in action TEX was designed by Knuth fromfirst principlesmdashin other words from scratch TEXis actually a programming language and LATEX isa set of functions defined in the TEX language TheTEX lsquocompilerrsquo is written in WEBW a mixture ofdocumentation written in TeX and a PascalW sub-set in order to ensure portability it reads a TEXprogram and outputs documents TEX is completelyself-contained and designed to be portable to anycomputer architecture For example it implementsits own stackW and heapW (with garbage collectionW)and it does fixed-precision arithmeticW donrsquot worryif these terms donrsquot make much sense to you at themoment they soon will

5The Greek prefix lsquotexrsquo means lsquoartrsquo as well as lsquotechnologyrsquo so itrsquos a very nicelychosen name for a piece of software that produces such beautiful output Knuthexplained (D Knuth 1984) that one should lsquopronounce the X of TeX as a Greekchi not as an lsquoxrsquo so that TeX rhymes with the word blecchhhrsquo Wersquore not toosure that helps much unless you are confident in your pronunciation of theword lsquoblecchhrsquo Maybe itrsquos an American thing

44

COMP10120 Report writing and Digital Typography

bull LATEX is a new interesting way for you to thinkabout preparing documents

bull LATEX has a practical advantage for the writer inthat it helps you think more about what you wantto write rather than worrying about how it looks

bull LATEX is a powerful tool for professional scientificdocumentation and as a Computer Scientist youshould know about it

bull LATEX files are just plain text so can easily be cre-ated programatically For example the slides usedfor COMP16120 are generated automatically fromthe source of Johnrsquos book both are typeset usingLATEX The program labprint also produces itsoutput using LATEX using information drawn fromXMLW configuration files and ARCADE

bull Using LATEX is actually quite satisfying and thequality of its output may surprise you

In this lab session you are going to write severalshort documents using LATEX You could also write briefnotes in your logbook about how LATEX works and whatcommands you used inside the source of your docu-ments

45

COMP10120 Report writing and Digital Typography

383 Some history printing mathematics

Mathematics is hard to print on paper and on the Web(many websites resort to GIF or JPG images of mathsformulae which usually look horrible MathMLW pro-vides another approach but it is not yet widely used)

In the days before computers books and newspa-pers were printed with movable typeW made from lotsof little blocks of metal each with letters numbers andsymbols standing in relief which when inked left animpression on the paper (see Figure 35) The job ofthe printer (the printer here of course being a personnot a bit of electronics) was to gather together all theblocks in the right order between two horizontal stripsof wood to create a line of the document and then toassemble all those lines from top to bottom of a pageThus the term type settingW an incredible task whenyou think about it In the printerrsquos workshop by theway the blocks of metal were stored between jobs inwooden boxes called cases Letters like a b and c werestored in one case letters like A B and C were storedin a case sitting on top of that So a lower case and anupper case These terms may ring a bell

As technology progressed machines controlled bytypewriters would mechanically juggle the blocks intothe right order This conceptual model is the basis onwhich TEX operates Only now the metal blocks are

46

COMP10120 Report writing and Digital Typography

Figure 35On the left a piece of cast movable type in the Garamondfont On the right a case of cast metal type pieces andtypeset matter in a composing stick The text reads lsquoThequick brown fox jumps over the lazy dog and feels as if hewere in the seventh heaven of typography together with Her-mann Zapf the most famous artist of thersquo This document istypeset in a font called Palatino created by Hermann ZapfYou may have also seen rsquoZapf Dingbatsrsquo in the font lists ofvarious desktop applications Now you know why

little pieces of data arranged into data structuresThe one thing that traditional printers hated was

dealing with the typesetting of mathematics and theywould charge extra to do it It was incredibly fiddly toget the equations looking right they had to squeeze inextra bits of metal horizontally and vertically

When computers entered the printing world attemptsto print mathematics were limited by the printing tech-nology available It took a long time to reach the pointwhere computers could typeset mathematics beautifullyand that was the outstanding achievement of Knuthrsquos

47

COMP10120 Report writing and Digital Typography

TEXLetrsquos look at a quick example of the quality you get

from LATEX with a very simple formula that yoursquoll recog-nise

x =minusbplusmn

radicb2 minus 4ac

2aWersquoll revisit how LATEX typesets mathematics in Section 34

384 To WYSIWYG or not to WYSIWYG

Up until now you have probably used wordprocessingapplications such as Microsoft Word to create essaysletters and other (probably fairly short) documents Youmost likely know that the majority of modern wordprocessors use a paradigm called WYSIWYG or WhatYou See Is What You Get which means that you canmodify the visual style of the document yoursquore work-ing on by selecting the relevant bits and then choos-ing different attributes such as font size or colour usinga GUI In many ways this seems like such a sensibleand obvious way of doing things that you might bewondering why it even has a special name The rea-son is a historical one in the early days of comput-ing long before graphical window managers becamethe norm and when all you could display on screenwas fixed-width ASCII text in whatever the systemrsquos

48

COMP10120 Report writing and Digital Typography

default font was wordprocessors (eg Figure 36) onlyallowed you to format documents by using special se-quences of characters to cause particular effects Butthese effects were only visible when the document wasprinted So if you wanted a word to appear in boldtext in the wordprocessor you might write somethinglike [bold]hello world[bold] what you saw onscreen was not a direct reflection of what appeared onthe printed page If yoursquove written any HTML how-ever this process of marking up text may be familiarsee for example Figure 37 As computers moved todisplays able to draw things other than raw charac-ters on screen wordprocessors became capable of us-ing multiple fonts and styles as well as graphics anda new generation of applications appeared where whatyou saw on screen was an accurate reflection of how itwould appear when printed what you see (on screen)is what you get (on paper)

The huge advantage of WYSIWYG is that itrsquos reallyeasy to understand whatrsquos going on and most peoplecan create reasonably nicely formatted documents withrelatively little effort For short informal documentsone-off letters memos and such WYSIWYG works quitenicely But if yoursquove ever tried writing anything muchlonger or that includes images and tables you mayhave already started to see where the paradigm breaksdown For example if you write lsquoFigure 38 on page

49

COMP10120 Report writing and Digital Typography

Figure 36A screenshot of Wordperfect 51 running in Microsoft DOScirca 1989

51 shows a picture of some men looking at cheesersquo butthen later on edit your document to include some moretext at the start and a new picture of a some broccoli(as in Figure 39) yoursquod have to search through yourreport to find all mentions of lsquoFigure 38rsquo and lsquopage 51rsquoand manually update them to reflect the new number-ing This might be fine if you have two figures and fivepages but for a hundred-page report containing lots ofpictures you can see how this becomes tedious and er-ror prone very quickly

50

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 36: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

for lsquothe creation of beautiful booksmdashand especially forbooks that contain a lot of mathematicsrsquo(D Knuth1984) Figure 34 shows what these eminent men looklike

So whatrsquos the purpose of LATEX Itrsquos purely a layerof software to make TEX easier to use in everyday sit-uations This is a good idea because although TEX isamazingly powerful it operates at a very low-level whichmakes it hard for non-expert users

Figure 34Don Knuth and Leslie Lamport

381 Pronunciation

The name TEX is intended by its creator to be pronouncedwith the final consonant as in the word loch or the nameBach but English speakers often pronounce it like thefirst syllable of technical The first syllable of LATEX is

43

COMP10120 Report writing and Digital Typography

pronounced as in rsquolayrsquo5

382 Why LATEX

Before we go any further why do we think LATEX is im-portant for youmdasha Computer Science studentmdashto knowabout Here are some reasons in no particular order

bull LATEX and TEX are superb examples of ComputerScience in action TEX was designed by Knuth fromfirst principlesmdashin other words from scratch TEXis actually a programming language and LATEX isa set of functions defined in the TEX language TheTEX lsquocompilerrsquo is written in WEBW a mixture ofdocumentation written in TeX and a PascalW sub-set in order to ensure portability it reads a TEXprogram and outputs documents TEX is completelyself-contained and designed to be portable to anycomputer architecture For example it implementsits own stackW and heapW (with garbage collectionW)and it does fixed-precision arithmeticW donrsquot worryif these terms donrsquot make much sense to you at themoment they soon will

5The Greek prefix lsquotexrsquo means lsquoartrsquo as well as lsquotechnologyrsquo so itrsquos a very nicelychosen name for a piece of software that produces such beautiful output Knuthexplained (D Knuth 1984) that one should lsquopronounce the X of TeX as a Greekchi not as an lsquoxrsquo so that TeX rhymes with the word blecchhhrsquo Wersquore not toosure that helps much unless you are confident in your pronunciation of theword lsquoblecchhrsquo Maybe itrsquos an American thing

44

COMP10120 Report writing and Digital Typography

bull LATEX is a new interesting way for you to thinkabout preparing documents

bull LATEX has a practical advantage for the writer inthat it helps you think more about what you wantto write rather than worrying about how it looks

bull LATEX is a powerful tool for professional scientificdocumentation and as a Computer Scientist youshould know about it

bull LATEX files are just plain text so can easily be cre-ated programatically For example the slides usedfor COMP16120 are generated automatically fromthe source of Johnrsquos book both are typeset usingLATEX The program labprint also produces itsoutput using LATEX using information drawn fromXMLW configuration files and ARCADE

bull Using LATEX is actually quite satisfying and thequality of its output may surprise you

In this lab session you are going to write severalshort documents using LATEX You could also write briefnotes in your logbook about how LATEX works and whatcommands you used inside the source of your docu-ments

45

COMP10120 Report writing and Digital Typography

383 Some history printing mathematics

Mathematics is hard to print on paper and on the Web(many websites resort to GIF or JPG images of mathsformulae which usually look horrible MathMLW pro-vides another approach but it is not yet widely used)

In the days before computers books and newspa-pers were printed with movable typeW made from lotsof little blocks of metal each with letters numbers andsymbols standing in relief which when inked left animpression on the paper (see Figure 35) The job ofthe printer (the printer here of course being a personnot a bit of electronics) was to gather together all theblocks in the right order between two horizontal stripsof wood to create a line of the document and then toassemble all those lines from top to bottom of a pageThus the term type settingW an incredible task whenyou think about it In the printerrsquos workshop by theway the blocks of metal were stored between jobs inwooden boxes called cases Letters like a b and c werestored in one case letters like A B and C were storedin a case sitting on top of that So a lower case and anupper case These terms may ring a bell

As technology progressed machines controlled bytypewriters would mechanically juggle the blocks intothe right order This conceptual model is the basis onwhich TEX operates Only now the metal blocks are

46

COMP10120 Report writing and Digital Typography

Figure 35On the left a piece of cast movable type in the Garamondfont On the right a case of cast metal type pieces andtypeset matter in a composing stick The text reads lsquoThequick brown fox jumps over the lazy dog and feels as if hewere in the seventh heaven of typography together with Her-mann Zapf the most famous artist of thersquo This document istypeset in a font called Palatino created by Hermann ZapfYou may have also seen rsquoZapf Dingbatsrsquo in the font lists ofvarious desktop applications Now you know why

little pieces of data arranged into data structuresThe one thing that traditional printers hated was

dealing with the typesetting of mathematics and theywould charge extra to do it It was incredibly fiddly toget the equations looking right they had to squeeze inextra bits of metal horizontally and vertically

When computers entered the printing world attemptsto print mathematics were limited by the printing tech-nology available It took a long time to reach the pointwhere computers could typeset mathematics beautifullyand that was the outstanding achievement of Knuthrsquos

47

COMP10120 Report writing and Digital Typography

TEXLetrsquos look at a quick example of the quality you get

from LATEX with a very simple formula that yoursquoll recog-nise

x =minusbplusmn

radicb2 minus 4ac

2aWersquoll revisit how LATEX typesets mathematics in Section 34

384 To WYSIWYG or not to WYSIWYG

Up until now you have probably used wordprocessingapplications such as Microsoft Word to create essaysletters and other (probably fairly short) documents Youmost likely know that the majority of modern wordprocessors use a paradigm called WYSIWYG or WhatYou See Is What You Get which means that you canmodify the visual style of the document yoursquore work-ing on by selecting the relevant bits and then choos-ing different attributes such as font size or colour usinga GUI In many ways this seems like such a sensibleand obvious way of doing things that you might bewondering why it even has a special name The rea-son is a historical one in the early days of comput-ing long before graphical window managers becamethe norm and when all you could display on screenwas fixed-width ASCII text in whatever the systemrsquos

48

COMP10120 Report writing and Digital Typography

default font was wordprocessors (eg Figure 36) onlyallowed you to format documents by using special se-quences of characters to cause particular effects Butthese effects were only visible when the document wasprinted So if you wanted a word to appear in boldtext in the wordprocessor you might write somethinglike [bold]hello world[bold] what you saw onscreen was not a direct reflection of what appeared onthe printed page If yoursquove written any HTML how-ever this process of marking up text may be familiarsee for example Figure 37 As computers moved todisplays able to draw things other than raw charac-ters on screen wordprocessors became capable of us-ing multiple fonts and styles as well as graphics anda new generation of applications appeared where whatyou saw on screen was an accurate reflection of how itwould appear when printed what you see (on screen)is what you get (on paper)

The huge advantage of WYSIWYG is that itrsquos reallyeasy to understand whatrsquos going on and most peoplecan create reasonably nicely formatted documents withrelatively little effort For short informal documentsone-off letters memos and such WYSIWYG works quitenicely But if yoursquove ever tried writing anything muchlonger or that includes images and tables you mayhave already started to see where the paradigm breaksdown For example if you write lsquoFigure 38 on page

49

COMP10120 Report writing and Digital Typography

Figure 36A screenshot of Wordperfect 51 running in Microsoft DOScirca 1989

51 shows a picture of some men looking at cheesersquo butthen later on edit your document to include some moretext at the start and a new picture of a some broccoli(as in Figure 39) yoursquod have to search through yourreport to find all mentions of lsquoFigure 38rsquo and lsquopage 51rsquoand manually update them to reflect the new number-ing This might be fine if you have two figures and fivepages but for a hundred-page report containing lots ofpictures you can see how this becomes tedious and er-ror prone very quickly

50

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 37: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

pronounced as in rsquolayrsquo5

382 Why LATEX

Before we go any further why do we think LATEX is im-portant for youmdasha Computer Science studentmdashto knowabout Here are some reasons in no particular order

bull LATEX and TEX are superb examples of ComputerScience in action TEX was designed by Knuth fromfirst principlesmdashin other words from scratch TEXis actually a programming language and LATEX isa set of functions defined in the TEX language TheTEX lsquocompilerrsquo is written in WEBW a mixture ofdocumentation written in TeX and a PascalW sub-set in order to ensure portability it reads a TEXprogram and outputs documents TEX is completelyself-contained and designed to be portable to anycomputer architecture For example it implementsits own stackW and heapW (with garbage collectionW)and it does fixed-precision arithmeticW donrsquot worryif these terms donrsquot make much sense to you at themoment they soon will

5The Greek prefix lsquotexrsquo means lsquoartrsquo as well as lsquotechnologyrsquo so itrsquos a very nicelychosen name for a piece of software that produces such beautiful output Knuthexplained (D Knuth 1984) that one should lsquopronounce the X of TeX as a Greekchi not as an lsquoxrsquo so that TeX rhymes with the word blecchhhrsquo Wersquore not toosure that helps much unless you are confident in your pronunciation of theword lsquoblecchhrsquo Maybe itrsquos an American thing

44

COMP10120 Report writing and Digital Typography

bull LATEX is a new interesting way for you to thinkabout preparing documents

bull LATEX has a practical advantage for the writer inthat it helps you think more about what you wantto write rather than worrying about how it looks

bull LATEX is a powerful tool for professional scientificdocumentation and as a Computer Scientist youshould know about it

bull LATEX files are just plain text so can easily be cre-ated programatically For example the slides usedfor COMP16120 are generated automatically fromthe source of Johnrsquos book both are typeset usingLATEX The program labprint also produces itsoutput using LATEX using information drawn fromXMLW configuration files and ARCADE

bull Using LATEX is actually quite satisfying and thequality of its output may surprise you

In this lab session you are going to write severalshort documents using LATEX You could also write briefnotes in your logbook about how LATEX works and whatcommands you used inside the source of your docu-ments

45

COMP10120 Report writing and Digital Typography

383 Some history printing mathematics

Mathematics is hard to print on paper and on the Web(many websites resort to GIF or JPG images of mathsformulae which usually look horrible MathMLW pro-vides another approach but it is not yet widely used)

In the days before computers books and newspa-pers were printed with movable typeW made from lotsof little blocks of metal each with letters numbers andsymbols standing in relief which when inked left animpression on the paper (see Figure 35) The job ofthe printer (the printer here of course being a personnot a bit of electronics) was to gather together all theblocks in the right order between two horizontal stripsof wood to create a line of the document and then toassemble all those lines from top to bottom of a pageThus the term type settingW an incredible task whenyou think about it In the printerrsquos workshop by theway the blocks of metal were stored between jobs inwooden boxes called cases Letters like a b and c werestored in one case letters like A B and C were storedin a case sitting on top of that So a lower case and anupper case These terms may ring a bell

As technology progressed machines controlled bytypewriters would mechanically juggle the blocks intothe right order This conceptual model is the basis onwhich TEX operates Only now the metal blocks are

46

COMP10120 Report writing and Digital Typography

Figure 35On the left a piece of cast movable type in the Garamondfont On the right a case of cast metal type pieces andtypeset matter in a composing stick The text reads lsquoThequick brown fox jumps over the lazy dog and feels as if hewere in the seventh heaven of typography together with Her-mann Zapf the most famous artist of thersquo This document istypeset in a font called Palatino created by Hermann ZapfYou may have also seen rsquoZapf Dingbatsrsquo in the font lists ofvarious desktop applications Now you know why

little pieces of data arranged into data structuresThe one thing that traditional printers hated was

dealing with the typesetting of mathematics and theywould charge extra to do it It was incredibly fiddly toget the equations looking right they had to squeeze inextra bits of metal horizontally and vertically

When computers entered the printing world attemptsto print mathematics were limited by the printing tech-nology available It took a long time to reach the pointwhere computers could typeset mathematics beautifullyand that was the outstanding achievement of Knuthrsquos

47

COMP10120 Report writing and Digital Typography

TEXLetrsquos look at a quick example of the quality you get

from LATEX with a very simple formula that yoursquoll recog-nise

x =minusbplusmn

radicb2 minus 4ac

2aWersquoll revisit how LATEX typesets mathematics in Section 34

384 To WYSIWYG or not to WYSIWYG

Up until now you have probably used wordprocessingapplications such as Microsoft Word to create essaysletters and other (probably fairly short) documents Youmost likely know that the majority of modern wordprocessors use a paradigm called WYSIWYG or WhatYou See Is What You Get which means that you canmodify the visual style of the document yoursquore work-ing on by selecting the relevant bits and then choos-ing different attributes such as font size or colour usinga GUI In many ways this seems like such a sensibleand obvious way of doing things that you might bewondering why it even has a special name The rea-son is a historical one in the early days of comput-ing long before graphical window managers becamethe norm and when all you could display on screenwas fixed-width ASCII text in whatever the systemrsquos

48

COMP10120 Report writing and Digital Typography

default font was wordprocessors (eg Figure 36) onlyallowed you to format documents by using special se-quences of characters to cause particular effects Butthese effects were only visible when the document wasprinted So if you wanted a word to appear in boldtext in the wordprocessor you might write somethinglike [bold]hello world[bold] what you saw onscreen was not a direct reflection of what appeared onthe printed page If yoursquove written any HTML how-ever this process of marking up text may be familiarsee for example Figure 37 As computers moved todisplays able to draw things other than raw charac-ters on screen wordprocessors became capable of us-ing multiple fonts and styles as well as graphics anda new generation of applications appeared where whatyou saw on screen was an accurate reflection of how itwould appear when printed what you see (on screen)is what you get (on paper)

The huge advantage of WYSIWYG is that itrsquos reallyeasy to understand whatrsquos going on and most peoplecan create reasonably nicely formatted documents withrelatively little effort For short informal documentsone-off letters memos and such WYSIWYG works quitenicely But if yoursquove ever tried writing anything muchlonger or that includes images and tables you mayhave already started to see where the paradigm breaksdown For example if you write lsquoFigure 38 on page

49

COMP10120 Report writing and Digital Typography

Figure 36A screenshot of Wordperfect 51 running in Microsoft DOScirca 1989

51 shows a picture of some men looking at cheesersquo butthen later on edit your document to include some moretext at the start and a new picture of a some broccoli(as in Figure 39) yoursquod have to search through yourreport to find all mentions of lsquoFigure 38rsquo and lsquopage 51rsquoand manually update them to reflect the new number-ing This might be fine if you have two figures and fivepages but for a hundred-page report containing lots ofpictures you can see how this becomes tedious and er-ror prone very quickly

50

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 38: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

bull LATEX is a new interesting way for you to thinkabout preparing documents

bull LATEX has a practical advantage for the writer inthat it helps you think more about what you wantto write rather than worrying about how it looks

bull LATEX is a powerful tool for professional scientificdocumentation and as a Computer Scientist youshould know about it

bull LATEX files are just plain text so can easily be cre-ated programatically For example the slides usedfor COMP16120 are generated automatically fromthe source of Johnrsquos book both are typeset usingLATEX The program labprint also produces itsoutput using LATEX using information drawn fromXMLW configuration files and ARCADE

bull Using LATEX is actually quite satisfying and thequality of its output may surprise you

In this lab session you are going to write severalshort documents using LATEX You could also write briefnotes in your logbook about how LATEX works and whatcommands you used inside the source of your docu-ments

45

COMP10120 Report writing and Digital Typography

383 Some history printing mathematics

Mathematics is hard to print on paper and on the Web(many websites resort to GIF or JPG images of mathsformulae which usually look horrible MathMLW pro-vides another approach but it is not yet widely used)

In the days before computers books and newspa-pers were printed with movable typeW made from lotsof little blocks of metal each with letters numbers andsymbols standing in relief which when inked left animpression on the paper (see Figure 35) The job ofthe printer (the printer here of course being a personnot a bit of electronics) was to gather together all theblocks in the right order between two horizontal stripsof wood to create a line of the document and then toassemble all those lines from top to bottom of a pageThus the term type settingW an incredible task whenyou think about it In the printerrsquos workshop by theway the blocks of metal were stored between jobs inwooden boxes called cases Letters like a b and c werestored in one case letters like A B and C were storedin a case sitting on top of that So a lower case and anupper case These terms may ring a bell

As technology progressed machines controlled bytypewriters would mechanically juggle the blocks intothe right order This conceptual model is the basis onwhich TEX operates Only now the metal blocks are

46

COMP10120 Report writing and Digital Typography

Figure 35On the left a piece of cast movable type in the Garamondfont On the right a case of cast metal type pieces andtypeset matter in a composing stick The text reads lsquoThequick brown fox jumps over the lazy dog and feels as if hewere in the seventh heaven of typography together with Her-mann Zapf the most famous artist of thersquo This document istypeset in a font called Palatino created by Hermann ZapfYou may have also seen rsquoZapf Dingbatsrsquo in the font lists ofvarious desktop applications Now you know why

little pieces of data arranged into data structuresThe one thing that traditional printers hated was

dealing with the typesetting of mathematics and theywould charge extra to do it It was incredibly fiddly toget the equations looking right they had to squeeze inextra bits of metal horizontally and vertically

When computers entered the printing world attemptsto print mathematics were limited by the printing tech-nology available It took a long time to reach the pointwhere computers could typeset mathematics beautifullyand that was the outstanding achievement of Knuthrsquos

47

COMP10120 Report writing and Digital Typography

TEXLetrsquos look at a quick example of the quality you get

from LATEX with a very simple formula that yoursquoll recog-nise

x =minusbplusmn

radicb2 minus 4ac

2aWersquoll revisit how LATEX typesets mathematics in Section 34

384 To WYSIWYG or not to WYSIWYG

Up until now you have probably used wordprocessingapplications such as Microsoft Word to create essaysletters and other (probably fairly short) documents Youmost likely know that the majority of modern wordprocessors use a paradigm called WYSIWYG or WhatYou See Is What You Get which means that you canmodify the visual style of the document yoursquore work-ing on by selecting the relevant bits and then choos-ing different attributes such as font size or colour usinga GUI In many ways this seems like such a sensibleand obvious way of doing things that you might bewondering why it even has a special name The rea-son is a historical one in the early days of comput-ing long before graphical window managers becamethe norm and when all you could display on screenwas fixed-width ASCII text in whatever the systemrsquos

48

COMP10120 Report writing and Digital Typography

default font was wordprocessors (eg Figure 36) onlyallowed you to format documents by using special se-quences of characters to cause particular effects Butthese effects were only visible when the document wasprinted So if you wanted a word to appear in boldtext in the wordprocessor you might write somethinglike [bold]hello world[bold] what you saw onscreen was not a direct reflection of what appeared onthe printed page If yoursquove written any HTML how-ever this process of marking up text may be familiarsee for example Figure 37 As computers moved todisplays able to draw things other than raw charac-ters on screen wordprocessors became capable of us-ing multiple fonts and styles as well as graphics anda new generation of applications appeared where whatyou saw on screen was an accurate reflection of how itwould appear when printed what you see (on screen)is what you get (on paper)

The huge advantage of WYSIWYG is that itrsquos reallyeasy to understand whatrsquos going on and most peoplecan create reasonably nicely formatted documents withrelatively little effort For short informal documentsone-off letters memos and such WYSIWYG works quitenicely But if yoursquove ever tried writing anything muchlonger or that includes images and tables you mayhave already started to see where the paradigm breaksdown For example if you write lsquoFigure 38 on page

49

COMP10120 Report writing and Digital Typography

Figure 36A screenshot of Wordperfect 51 running in Microsoft DOScirca 1989

51 shows a picture of some men looking at cheesersquo butthen later on edit your document to include some moretext at the start and a new picture of a some broccoli(as in Figure 39) yoursquod have to search through yourreport to find all mentions of lsquoFigure 38rsquo and lsquopage 51rsquoand manually update them to reflect the new number-ing This might be fine if you have two figures and fivepages but for a hundred-page report containing lots ofpictures you can see how this becomes tedious and er-ror prone very quickly

50

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 39: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

383 Some history printing mathematics

Mathematics is hard to print on paper and on the Web(many websites resort to GIF or JPG images of mathsformulae which usually look horrible MathMLW pro-vides another approach but it is not yet widely used)

In the days before computers books and newspa-pers were printed with movable typeW made from lotsof little blocks of metal each with letters numbers andsymbols standing in relief which when inked left animpression on the paper (see Figure 35) The job ofthe printer (the printer here of course being a personnot a bit of electronics) was to gather together all theblocks in the right order between two horizontal stripsof wood to create a line of the document and then toassemble all those lines from top to bottom of a pageThus the term type settingW an incredible task whenyou think about it In the printerrsquos workshop by theway the blocks of metal were stored between jobs inwooden boxes called cases Letters like a b and c werestored in one case letters like A B and C were storedin a case sitting on top of that So a lower case and anupper case These terms may ring a bell

As technology progressed machines controlled bytypewriters would mechanically juggle the blocks intothe right order This conceptual model is the basis onwhich TEX operates Only now the metal blocks are

46

COMP10120 Report writing and Digital Typography

Figure 35On the left a piece of cast movable type in the Garamondfont On the right a case of cast metal type pieces andtypeset matter in a composing stick The text reads lsquoThequick brown fox jumps over the lazy dog and feels as if hewere in the seventh heaven of typography together with Her-mann Zapf the most famous artist of thersquo This document istypeset in a font called Palatino created by Hermann ZapfYou may have also seen rsquoZapf Dingbatsrsquo in the font lists ofvarious desktop applications Now you know why

little pieces of data arranged into data structuresThe one thing that traditional printers hated was

dealing with the typesetting of mathematics and theywould charge extra to do it It was incredibly fiddly toget the equations looking right they had to squeeze inextra bits of metal horizontally and vertically

When computers entered the printing world attemptsto print mathematics were limited by the printing tech-nology available It took a long time to reach the pointwhere computers could typeset mathematics beautifullyand that was the outstanding achievement of Knuthrsquos

47

COMP10120 Report writing and Digital Typography

TEXLetrsquos look at a quick example of the quality you get

from LATEX with a very simple formula that yoursquoll recog-nise

x =minusbplusmn

radicb2 minus 4ac

2aWersquoll revisit how LATEX typesets mathematics in Section 34

384 To WYSIWYG or not to WYSIWYG

Up until now you have probably used wordprocessingapplications such as Microsoft Word to create essaysletters and other (probably fairly short) documents Youmost likely know that the majority of modern wordprocessors use a paradigm called WYSIWYG or WhatYou See Is What You Get which means that you canmodify the visual style of the document yoursquore work-ing on by selecting the relevant bits and then choos-ing different attributes such as font size or colour usinga GUI In many ways this seems like such a sensibleand obvious way of doing things that you might bewondering why it even has a special name The rea-son is a historical one in the early days of comput-ing long before graphical window managers becamethe norm and when all you could display on screenwas fixed-width ASCII text in whatever the systemrsquos

48

COMP10120 Report writing and Digital Typography

default font was wordprocessors (eg Figure 36) onlyallowed you to format documents by using special se-quences of characters to cause particular effects Butthese effects were only visible when the document wasprinted So if you wanted a word to appear in boldtext in the wordprocessor you might write somethinglike [bold]hello world[bold] what you saw onscreen was not a direct reflection of what appeared onthe printed page If yoursquove written any HTML how-ever this process of marking up text may be familiarsee for example Figure 37 As computers moved todisplays able to draw things other than raw charac-ters on screen wordprocessors became capable of us-ing multiple fonts and styles as well as graphics anda new generation of applications appeared where whatyou saw on screen was an accurate reflection of how itwould appear when printed what you see (on screen)is what you get (on paper)

The huge advantage of WYSIWYG is that itrsquos reallyeasy to understand whatrsquos going on and most peoplecan create reasonably nicely formatted documents withrelatively little effort For short informal documentsone-off letters memos and such WYSIWYG works quitenicely But if yoursquove ever tried writing anything muchlonger or that includes images and tables you mayhave already started to see where the paradigm breaksdown For example if you write lsquoFigure 38 on page

49

COMP10120 Report writing and Digital Typography

Figure 36A screenshot of Wordperfect 51 running in Microsoft DOScirca 1989

51 shows a picture of some men looking at cheesersquo butthen later on edit your document to include some moretext at the start and a new picture of a some broccoli(as in Figure 39) yoursquod have to search through yourreport to find all mentions of lsquoFigure 38rsquo and lsquopage 51rsquoand manually update them to reflect the new number-ing This might be fine if you have two figures and fivepages but for a hundred-page report containing lots ofpictures you can see how this becomes tedious and er-ror prone very quickly

50

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 40: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

Figure 35On the left a piece of cast movable type in the Garamondfont On the right a case of cast metal type pieces andtypeset matter in a composing stick The text reads lsquoThequick brown fox jumps over the lazy dog and feels as if hewere in the seventh heaven of typography together with Her-mann Zapf the most famous artist of thersquo This document istypeset in a font called Palatino created by Hermann ZapfYou may have also seen rsquoZapf Dingbatsrsquo in the font lists ofvarious desktop applications Now you know why

little pieces of data arranged into data structuresThe one thing that traditional printers hated was

dealing with the typesetting of mathematics and theywould charge extra to do it It was incredibly fiddly toget the equations looking right they had to squeeze inextra bits of metal horizontally and vertically

When computers entered the printing world attemptsto print mathematics were limited by the printing tech-nology available It took a long time to reach the pointwhere computers could typeset mathematics beautifullyand that was the outstanding achievement of Knuthrsquos

47

COMP10120 Report writing and Digital Typography

TEXLetrsquos look at a quick example of the quality you get

from LATEX with a very simple formula that yoursquoll recog-nise

x =minusbplusmn

radicb2 minus 4ac

2aWersquoll revisit how LATEX typesets mathematics in Section 34

384 To WYSIWYG or not to WYSIWYG

Up until now you have probably used wordprocessingapplications such as Microsoft Word to create essaysletters and other (probably fairly short) documents Youmost likely know that the majority of modern wordprocessors use a paradigm called WYSIWYG or WhatYou See Is What You Get which means that you canmodify the visual style of the document yoursquore work-ing on by selecting the relevant bits and then choos-ing different attributes such as font size or colour usinga GUI In many ways this seems like such a sensibleand obvious way of doing things that you might bewondering why it even has a special name The rea-son is a historical one in the early days of comput-ing long before graphical window managers becamethe norm and when all you could display on screenwas fixed-width ASCII text in whatever the systemrsquos

48

COMP10120 Report writing and Digital Typography

default font was wordprocessors (eg Figure 36) onlyallowed you to format documents by using special se-quences of characters to cause particular effects Butthese effects were only visible when the document wasprinted So if you wanted a word to appear in boldtext in the wordprocessor you might write somethinglike [bold]hello world[bold] what you saw onscreen was not a direct reflection of what appeared onthe printed page If yoursquove written any HTML how-ever this process of marking up text may be familiarsee for example Figure 37 As computers moved todisplays able to draw things other than raw charac-ters on screen wordprocessors became capable of us-ing multiple fonts and styles as well as graphics anda new generation of applications appeared where whatyou saw on screen was an accurate reflection of how itwould appear when printed what you see (on screen)is what you get (on paper)

The huge advantage of WYSIWYG is that itrsquos reallyeasy to understand whatrsquos going on and most peoplecan create reasonably nicely formatted documents withrelatively little effort For short informal documentsone-off letters memos and such WYSIWYG works quitenicely But if yoursquove ever tried writing anything muchlonger or that includes images and tables you mayhave already started to see where the paradigm breaksdown For example if you write lsquoFigure 38 on page

49

COMP10120 Report writing and Digital Typography

Figure 36A screenshot of Wordperfect 51 running in Microsoft DOScirca 1989

51 shows a picture of some men looking at cheesersquo butthen later on edit your document to include some moretext at the start and a new picture of a some broccoli(as in Figure 39) yoursquod have to search through yourreport to find all mentions of lsquoFigure 38rsquo and lsquopage 51rsquoand manually update them to reflect the new number-ing This might be fine if you have two figures and fivepages but for a hundred-page report containing lots ofpictures you can see how this becomes tedious and er-ror prone very quickly

50

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 41: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

TEXLetrsquos look at a quick example of the quality you get

from LATEX with a very simple formula that yoursquoll recog-nise

x =minusbplusmn

radicb2 minus 4ac

2aWersquoll revisit how LATEX typesets mathematics in Section 34

384 To WYSIWYG or not to WYSIWYG

Up until now you have probably used wordprocessingapplications such as Microsoft Word to create essaysletters and other (probably fairly short) documents Youmost likely know that the majority of modern wordprocessors use a paradigm called WYSIWYG or WhatYou See Is What You Get which means that you canmodify the visual style of the document yoursquore work-ing on by selecting the relevant bits and then choos-ing different attributes such as font size or colour usinga GUI In many ways this seems like such a sensibleand obvious way of doing things that you might bewondering why it even has a special name The rea-son is a historical one in the early days of comput-ing long before graphical window managers becamethe norm and when all you could display on screenwas fixed-width ASCII text in whatever the systemrsquos

48

COMP10120 Report writing and Digital Typography

default font was wordprocessors (eg Figure 36) onlyallowed you to format documents by using special se-quences of characters to cause particular effects Butthese effects were only visible when the document wasprinted So if you wanted a word to appear in boldtext in the wordprocessor you might write somethinglike [bold]hello world[bold] what you saw onscreen was not a direct reflection of what appeared onthe printed page If yoursquove written any HTML how-ever this process of marking up text may be familiarsee for example Figure 37 As computers moved todisplays able to draw things other than raw charac-ters on screen wordprocessors became capable of us-ing multiple fonts and styles as well as graphics anda new generation of applications appeared where whatyou saw on screen was an accurate reflection of how itwould appear when printed what you see (on screen)is what you get (on paper)

The huge advantage of WYSIWYG is that itrsquos reallyeasy to understand whatrsquos going on and most peoplecan create reasonably nicely formatted documents withrelatively little effort For short informal documentsone-off letters memos and such WYSIWYG works quitenicely But if yoursquove ever tried writing anything muchlonger or that includes images and tables you mayhave already started to see where the paradigm breaksdown For example if you write lsquoFigure 38 on page

49

COMP10120 Report writing and Digital Typography

Figure 36A screenshot of Wordperfect 51 running in Microsoft DOScirca 1989

51 shows a picture of some men looking at cheesersquo butthen later on edit your document to include some moretext at the start and a new picture of a some broccoli(as in Figure 39) yoursquod have to search through yourreport to find all mentions of lsquoFigure 38rsquo and lsquopage 51rsquoand manually update them to reflect the new number-ing This might be fine if you have two figures and fivepages but for a hundred-page report containing lots ofpictures you can see how this becomes tedious and er-ror prone very quickly

50

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 42: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

default font was wordprocessors (eg Figure 36) onlyallowed you to format documents by using special se-quences of characters to cause particular effects Butthese effects were only visible when the document wasprinted So if you wanted a word to appear in boldtext in the wordprocessor you might write somethinglike [bold]hello world[bold] what you saw onscreen was not a direct reflection of what appeared onthe printed page If yoursquove written any HTML how-ever this process of marking up text may be familiarsee for example Figure 37 As computers moved todisplays able to draw things other than raw charac-ters on screen wordprocessors became capable of us-ing multiple fonts and styles as well as graphics anda new generation of applications appeared where whatyou saw on screen was an accurate reflection of how itwould appear when printed what you see (on screen)is what you get (on paper)

The huge advantage of WYSIWYG is that itrsquos reallyeasy to understand whatrsquos going on and most peoplecan create reasonably nicely formatted documents withrelatively little effort For short informal documentsone-off letters memos and such WYSIWYG works quitenicely But if yoursquove ever tried writing anything muchlonger or that includes images and tables you mayhave already started to see where the paradigm breaksdown For example if you write lsquoFigure 38 on page

49

COMP10120 Report writing and Digital Typography

Figure 36A screenshot of Wordperfect 51 running in Microsoft DOScirca 1989

51 shows a picture of some men looking at cheesersquo butthen later on edit your document to include some moretext at the start and a new picture of a some broccoli(as in Figure 39) yoursquod have to search through yourreport to find all mentions of lsquoFigure 38rsquo and lsquopage 51rsquoand manually update them to reflect the new number-ing This might be fine if you have two figures and fivepages but for a hundred-page report containing lots ofpictures you can see how this becomes tedious and er-ror prone very quickly

50

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 43: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

Figure 36A screenshot of Wordperfect 51 running in Microsoft DOScirca 1989

51 shows a picture of some men looking at cheesersquo butthen later on edit your document to include some moretext at the start and a new picture of a some broccoli(as in Figure 39) yoursquod have to search through yourreport to find all mentions of lsquoFigure 38rsquo and lsquopage 51rsquoand manually update them to reflect the new number-ing This might be fine if you have two figures and fivepages but for a hundred-page report containing lots ofpictures you can see how this becomes tedious and er-ror prone very quickly

50

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 44: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

documentclassarticlebegindocumenttextbfHello worldenddocument

(a)

lthtmlgtltbodygt

ltbgtHello worldltbgtltbodygt

lthtmlgt

(b)Figure 37Examples of the words lsquohello worldrsquo in bold text typeset (a)LATEX and (b) HTML

Figure 38Some men possibly Dutch looking at cheeses

51

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 45: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

Figure 39Some broccoli

385 Style and content

The other thing about WYSIWYG is that it puts you en-tirely in control of the visual layout and style of yourarticle and this isnrsquot necessarily a good thing for tworeasons First it means that instead of focusing on thecontent and structure of what yoursquore writing it makesit easy to get distracted by tinkering with the layoutand style And although layout and style are of courseimportant if you want to create a professional-lookingdocument they are definitely always secondary to con-tent and structure Second it means that you are wellentirely in control of the visual layout and style of yourarticle And although it might not be obvious up-frontsuch control is not necessarily a good thing unless youreally know what yoursquore doing (and unless you are a

52

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 46: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

talented graphic designer with a deep understandingof typography you almost certainly donrsquot6) Creatingdocuments that are aesthetically pleasing and easy toread is rather a specialist skill with its origins goingall the way back to Caxtonrsquos invention of the printingpress in the fifteenth century Over the years typogra-phers have honed their skills arriving at complex rulesand heuristics that determine the optimum number ofcharacters on a line ideal relative and absolute fontsizes spacings margins figure placement and so onthat lead to attractivemdashand most importantlymdashreadabledocuments You could of course learn all these rulesand make sure you implement them manually usingyour favourite WYSIWG editor but thatrsquos not what aComputer Science degree is about The LATEX systemimplements many of these rules making decisions foryou about the best way to lay your document out onthe page This allows you to concentrate on creatinggood quality content safe in the knowledge that LATEXwill do a good job of presenting it for you The ideaof separating out content from presentation is some-thing yoursquoll encounter many times during your studiesof Computer Science Yoursquoll see it again in a fairly obvi-ous way soon when you come to writing some HTMLand CSS in Phase 3 of this course unit but the con-

6Donrsquot take this personally wersquore in the same boat If you think that thisdocument is nicely formatted thatrsquos all down to LATEX not us

53

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 47: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

cept of distinguishing between a model and a view willreappear in increasingly subtle ways throughout yourdegree

386 The right tool for the right job

To avoid any misunderstanding we are not at all tryingto claim that LATEX is lsquobetterrsquo than Word (or similar) justthat itrsquos lsquodifferentrsquo in fact lsquoextremely differentrsquo both inits capabilties and its conceptual model One of the keyskills that any professional needs to learn is to be able tochoose the right tool for the right job If yoursquore going toopen a coconut yoursquoll probably use a corkscrew not apneumatic drill Similarly if yoursquore writing a quick let-ter or making a DO NOT DISTURB sign yoursquoll prob-ably want to use a quick WYSIWYG tool like WordIf however yoursquore writing a technical document per-haps with some maths or a 3rd Year Project Report oran article you want to get published then yoursquoll prob-ably want LATEX You might see analogies with pro-gramming heremdashand which languages are best suitedto which jobs

387 Summing up

The downside of using a non-WYSIWYG system suchas LATEX is that there is rather more to understand and

54

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 48: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

master before you can get going You will have proba-bly spotted that this is a recurring pattern to performcertain tasks we often have the choice between two ap-proaches the first (in this case the WYSIWYG way) al-lows you to get going straight away as a novice butdoesnrsquot allow us to grow much expertise to get betterand faster and as you try to do more complex thingsyou discover problems and limitations that are hard toovercome the second is inherently more powerful butrequires you to invest time and effort before you canget started Wordprocessors and file browsers fall intothe former category LATEX and use of the command lineinto the latter

By the time you get to write your third year projectreport you will almost certainly want to use LATEX In-deed that might well be the point at which you willgain the most benefit from it throughout your studieshere What you do not want is to be having to learnLATEX at that pointndashit will be challenging enough with-out that extra burden So we are embarking you on aprogramme of learning LATEX more gradually

388 Fire And Ice

Fire and Ice by Robert Frost

55

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 49: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

Some say the world will end in fireSome say in iceFrom what Irsquove tasted of desireI hold with those who favor fireBut if it had to perish twiceI think I know enough of hateTo say that for destruction iceIs also greatAnd would suffice

389 Search Terms

dots per inch resolution contrast LED LCD CRT e-ink emissive versus reflective anti aliasing reading inlight dark environments annotating doodling view-ing angles brightness levels of colour

use google google scholar ACM digital libraryKindle iPad eInk retina display

3810 Acknowledgements

The images in Figure 34 are from Wikimedia Commonsvia the Wikipedia articles on Knuth and Lamport andare in the public domain Figure 36 is from Wikime-dia Commons via the Wikipedia article on WordPer-fect and is in the public domain Figure 39 also viaWikimedia Commons is reproduced with the permis-

56

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 50: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

sion of its creator Fir0002Flagstaffotos under the termsof the GNU Free Documentation License Figure 35 is acombination of images by Daniel Ullrich and Willi Hei-delbach both from Wikipedia and both released underthe GNU Free Documentation License

References

C Dickens (1852) Bleak House Bradbury amp Evans

D Knuth (1984) The TeXbook Addison-Wesley ISBN 0-201-13448-9

mdash (1999) Digital Typography Cambridge University PressISBN 1575860104

F M Liang (Aug 1983) ldquoWord Hy-phen-a-tion by Com-pu-terrdquo PhD thesis Department of Computer Sci-ence Stanford University

Knuth Donald E and Michael F Plass (1981) ldquoBreak-ing paragraphs into linesrdquo In Software Practice andExperience 1111 pp 1119ndash1184 ISSN 1097-024X DOI101002spe4380111102

M A Tinker (1963) Legibility of Print Iowa State Uni-versity Press ISBN 978-0813824505

57

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements
Page 51: Report writing and Digital Typographystudentnet.cs.manchester.ac.uk/ugt/COMP10120/labscripts/101lab3 … · 1If you have been carried away with the sheer excitement and joy of learning

COMP10120 Report writing and Digital Typography

R Bringhurst (1992) The Elements of Typographic StyleHartley amp Marks Publishers ISBN 0-88179-110-5

R Frost (1924) New Hampshire A poem with notes andgrace notes Henry Holt and Company

58

  • Report writing and Digital Typography
    • Introduction
    • Getting started
      • Exercise 1 A closer look
      • Exercise 2 A larger example
        • Common formatting features
          • Enumerated and bulleted lists
          • Changing the appearance of text
          • Cross referencing
          • Figures and pictures
          • Exercise 3 Including images
          • Exercise 4 A reflection on your studies
            • Typesetting Mathematics
              • A longer piece of mathematics
              • Exercise 5 Formatting mathematics
                • Curriculum vitaie
                  • Exercise 6 Curriculum vitae
                    • Some optional extras
                      • Exercise 7 Exploring more LaTeX features (optional but easy)
                      • Exercise 8 A neat directory listing (optional more challenging)
                      • Exercise 9 A cleaning rota (optional even more challenging)
                      • Marking Scheme
                        • Next steps
                          • Acknowledgements
                          • License
                            • Background
                              • Pronunciation
                              • Why LaTeX
                              • Some history printing mathematics
                              • To WYSIWYG or not to WYSIWYG
                              • Style and content
                              • The right tool for the right job
                              • Summing up
                              • Fire And Ice
                              • Search Terms
                              • Acknowledgements