Writing in LaTeX under Windows or Linux
Writing in LaTeX under Windows or Linux
Writing in LaTeX under Windows or Linux
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
<strong>Writ<strong>in</strong>g</strong> <strong>in</strong> <strong>LaTeX</strong> <strong>under</strong> W<strong>in</strong>dows <strong>or</strong> L<strong>in</strong>uxEric ReesNovember 16, 2007Although a beta version, this document is free f<strong>or</strong> use and copy<strong>in</strong>g, absolutelynot warranteed f<strong>or</strong> any purpose whatsoever, should not be restrictedfrom free distribution, and is provided <strong>in</strong> the hope it is useful. Credit is dueto the programmers of the freely available L A TEX and L<strong>in</strong>ux.1 AbstractHere are some notes I wrote after sett<strong>in</strong>g up L<strong>in</strong>ux (Fed<strong>or</strong>a C<strong>or</strong>e 5) on aDell Optiplex Gs240 PC (krond<strong>or</strong>) and then <strong>in</strong>stall<strong>in</strong>g a Latex distribution(TeXLive2007) and an IDE f<strong>or</strong> Latex (Texmaker). The subjects are as follows:1. Abstract2. Advantages of L A TEX3. L<strong>in</strong>ux. Obta<strong>in</strong><strong>in</strong>g and <strong>in</strong>stall<strong>in</strong>g a L<strong>in</strong>ux Distribution (Fed<strong>or</strong>a C<strong>or</strong>e 5,also 8)4. Unix. Basic <strong>in</strong>f<strong>or</strong>mation on Unix (L<strong>in</strong>ux) file system.5. L A TEX. Obta<strong>in</strong><strong>in</strong>g and Install<strong>in</strong>g a L A TEX distribution (TeXLive here,but MikTeX is possible). TeXLive has several collections of the Latexfiles on one CD <strong>or</strong> DVD, and can be <strong>in</strong>stalled to (has b<strong>in</strong>aries f<strong>or</strong>) aW<strong>in</strong>dows (w<strong>in</strong>32) platf<strong>or</strong>m, l<strong>in</strong>ux on several types of computer (<strong>in</strong>telx86 PCs, i386 and x86 64 are common as of 2007) and MacOS.6. Texmaker. An IDE (‘Integrated Design Environment’) f<strong>or</strong> produc<strong>in</strong>gthe <strong>in</strong>put files of the f<strong>or</strong>m ‘article.tex’ that will then be converted to‘article.pdf’ <strong>or</strong> ‘article.ps.’ Such IDEs <strong>in</strong>clude Texmaker (W<strong>in</strong>32 andL<strong>in</strong>ux), Kile (L<strong>in</strong>ux), and Emacs (multiple platf<strong>or</strong>ms).7. Some notes on the use of L A TEX1
2 TeX and <strong>LaTeX</strong>. Contents of a modern distribution.TEX is a compiler that reads a pla<strong>in</strong> text <strong>in</strong>put file, f<strong>or</strong> example this-guide.tex,and converts it to a pr<strong>in</strong>table page <strong>or</strong> another standard output such as thisguide.pdf.The auth<strong>or</strong> must write <strong>in</strong>to the <strong>in</strong>put file all of the f<strong>or</strong>matt<strong>in</strong>g thatis <strong>in</strong>tended f<strong>or</strong> the f<strong>in</strong>al page. But there are a vast number of default optionsso that head<strong>in</strong>gs and other environments such as captions will automaticallybe set <strong>in</strong> a fixed style. This saves the auth<strong>or</strong> from manually sett<strong>in</strong>g everyparagraph to have the c<strong>or</strong>rect number of free l<strong>in</strong>es follow<strong>in</strong>g it, etc.TEX is not a WYSIWIG <strong>in</strong>terface - not a w<strong>or</strong>d process<strong>or</strong> that displays thepage <strong>in</strong> real-time as it will be pr<strong>in</strong>ted. TEX produces f<strong>or</strong>matted documentsfrom an <strong>in</strong>put file of pla<strong>in</strong> text - a ‘recipe.’ So the obvious disadvantage isthat you have to compile the document each time you want to see a visualupdate of the pr<strong>in</strong>ted page. The advantage is that the the computer neednot hold the entire document <strong>in</strong> mem<strong>or</strong>y and juggle an arbitrary amountof typesett<strong>in</strong>g after every w<strong>or</strong>d. Hence TeX can be stable when handl<strong>in</strong>glarge documents. S<strong>in</strong>ce TEX handles choices of font size (etc.) it sets outdocuments <strong>in</strong> a very unif<strong>or</strong>m style, which can save a lot of user eff<strong>or</strong>t <strong>in</strong>sett<strong>in</strong>g section spac<strong>in</strong>gs and title styles.TEX is a compiler. It is implemented on many different platf<strong>or</strong>ms: onewould use a tex.exe on a W<strong>in</strong>32 platf<strong>or</strong>m (98–XP), and on L<strong>in</strong>ux the executablewould probably be called just tex (L<strong>in</strong>ux is a Unix system and willhandle files without extensions).2.1 Difference between L A TEX and TEXTEX is an extremely stable compiler f<strong>or</strong> convert<strong>in</strong>g a descriptive <strong>in</strong>put file thatyou have written (eg article.tex) <strong>in</strong>to a neatly f<strong>or</strong>matted document (eg. article.pdf).TeX is essentially a program that <strong>in</strong>terprets text and <strong>in</strong>structions <strong>in</strong>a typographically c<strong>or</strong>rect way, then breaks down the process of typesett<strong>in</strong>g<strong>in</strong>to a task of shuffl<strong>in</strong>g boxes of text around a page.L A TEX is another compiler, which <strong>in</strong>c<strong>or</strong>p<strong>or</strong>ates the c<strong>or</strong>e TeX program butalso allows additional program modules to be called. Technically L A TEX isa Tur<strong>in</strong>g-complete programm<strong>in</strong>g language (can perf<strong>or</strong>m any programm<strong>in</strong>gfunction) although it is f<strong>or</strong> typesett<strong>in</strong>g. Documents can be typeset <strong>in</strong> TEX,but they may as well be typeset <strong>under</strong> L A TEX f<strong>or</strong> extra functionality. F<strong>or</strong>example L A TEX will construct a Table of Contents from your section <strong>or</strong> chapterhead<strong>in</strong>gs (etc.) and then get TEX to typeset that at the beg<strong>in</strong>n<strong>in</strong>g of thedocument (<strong>or</strong> elsewhere).2
2.2 Advantages of L A TEX over w<strong>or</strong>d process<strong>or</strong>sS<strong>in</strong>ce the L A TEX compiler only has to skim through the text <strong>in</strong>put file once,convert<strong>in</strong>g it to typeset pages as it goes, it does not need to bear the entiredocument <strong>in</strong> mem<strong>or</strong>y. Theref<strong>or</strong>e it is stable when handl<strong>in</strong>g larger documents.Cross-referenc<strong>in</strong>g is also much easier f<strong>or</strong> this s<strong>or</strong>t of program. I suggest thebenefits of L A TEX are:• Freely available• Exists f<strong>or</strong> many platf<strong>or</strong>ms, <strong>in</strong>clud<strong>in</strong>g: W<strong>in</strong>32, L<strong>in</strong>ux <strong>in</strong> various chipsets,MacOS. LiveTeX now supp<strong>or</strong>ts all of these from 1 DVD.• Stable f<strong>or</strong> large documents• F<strong>or</strong>ces a standard f<strong>or</strong>mat across entire document (spac<strong>in</strong>g between sections,font size f<strong>or</strong> environments such as titles, subsitles, captions, etc.)• Supp<strong>or</strong>ts graphics (preferably <strong>in</strong> .eps f<strong>or</strong>mat) and can accurately placethese objects• Most document f<strong>or</strong>mats already have stylesheets to supp<strong>or</strong>t them (journalarticles, theses...)• Cross references figure caption and other sections us<strong>in</strong>g tags• Bibtex can manage citations automatically• Many plug-<strong>in</strong> modules exist on CTAN. Extra modules provide functions<strong>in</strong>clud<strong>in</strong>g: l<strong>in</strong>e-number<strong>in</strong>g, figures with text flow<strong>in</strong>g around them (a bitunstable), typesett<strong>in</strong>g of chess boards...3 Install<strong>in</strong>g L<strong>in</strong>ux - Fed<strong>or</strong>a C<strong>or</strong>e 5Modern PCs should be able to boot from the CD <strong>or</strong> DVD drive. Hence the<strong>in</strong>stallation discs f<strong>or</strong> modern distributions of L<strong>in</strong>ux are typically sets of 5CDs, <strong>or</strong> 1 DVD. A basic recipe f<strong>or</strong> <strong>in</strong>stall<strong>in</strong>g l<strong>in</strong>ux is:1. You will need a PC that is suitable f<strong>or</strong> conversion to l<strong>in</strong>ux. It is possibleto partition the hard drive to boot <strong>in</strong> a choice of operat<strong>in</strong>g systems,but simpler to put down a s<strong>in</strong>gle l<strong>in</strong>ux partition.3
2. Obta<strong>in</strong> Installation CDs. The UK academic mirr<strong>or</strong> page is now supplied<strong>in</strong>stead by the university of Kent (s<strong>in</strong>ce July 2007). The UniversityCambridge Unix Supp<strong>or</strong>t page has a mirr<strong>or</strong> server with many l<strong>in</strong>uxdistributions:http://www.mirr<strong>or</strong>.ac.ukhttp://www.cam.ac.uk/csSeek<strong>in</strong>g “l<strong>in</strong>ux fed<strong>or</strong>a” should be sufficient to f<strong>in</strong>d a distribution. Burnthe CD images to CD (do not copy the images as data, but burn theimage – double click<strong>in</strong>g on the image.iso file <strong>in</strong> XP should be sufficientto get CD-burn<strong>in</strong>g software to <strong>under</strong>stand this). Optionally confirmthe .iso files are err<strong>or</strong> free by compar<strong>in</strong>g the checksum of the image filewith the published value that should be advertised by the mirr<strong>or</strong>.3. F<strong>or</strong> Fed<strong>or</strong>a C<strong>or</strong>e 5 (and higher), feed the first <strong>in</strong>stallation CD <strong>in</strong>to theCD drive of the PC. Press F12 to br<strong>in</strong>g up the boot menu from the BIOS(the startup screen may specify another F-key to br<strong>in</strong>g up the bootmenu). Tell it to boot from CD (<strong>or</strong> DVD). This should be sufficientto beg<strong>in</strong> ‘Anaconda.’ the <strong>in</strong>stallation <strong>in</strong>terface f<strong>or</strong> l<strong>in</strong>ux. Anacondahas a graphical <strong>in</strong>terface that you can select by hitt<strong>in</strong>g enter when it<strong>in</strong>structs you to do so. Anaconda can also <strong>in</strong>stall via a command l<strong>in</strong>e<strong>in</strong>terface, suitable f<strong>or</strong> <strong>in</strong>stall<strong>in</strong>g by remote over a netw<strong>or</strong>k – to use this,type ‘l<strong>in</strong>ux-text’ and hit enter. Verify the <strong>in</strong>tegrity of the CD mediabef<strong>or</strong>e their first use, by follow<strong>in</strong>g on-screen <strong>in</strong>structions.4. Follow Anaconda’s <strong>in</strong>structions. You will need to choose a passw<strong>or</strong>df<strong>or</strong> the ‘root user’ of the mach<strong>in</strong>e. Also select the applications youwant <strong>in</strong>stalled with the operat<strong>in</strong>g system. Options <strong>in</strong>clude the KDEdesktop environment <strong>in</strong>stead of Gnome, and programm<strong>in</strong>g tools suchas Eclipse.3.1 Partition<strong>in</strong>g the hard discAs an advanced option, Anaconda will let you ign<strong>or</strong>e the default layout onthe hard disc and specify partitions. The basic partitions on a hard disc(example size 80 GB) are:/boot physical 0.1 GBLVM physical 79.9 GBthe LVM (logical volume management) partition, native to l<strong>in</strong>ux,4
is logically split <strong>in</strong>to/ LogVol00 79.4 GBswap LogVol01 512 MBThe ‘/’ partition is the root partition. It may be sensible to have a separate‘/home’ and ‘/’ partition. Upgrad<strong>in</strong>g the operat<strong>in</strong>g system is then easier,as a new OS may be written onto ‘/’ without affect<strong>in</strong>g personal data st<strong>or</strong>ed<strong>in</strong>‘/home’3.2 Keyboards etcWhen Anaconda requests a keyboard type, the UK english keyboard has:" on Shift+2@ on Shift+’A pound sign, ^A£4 The UNIX Direct<strong>or</strong>y StructureL<strong>in</strong>ux implements the same file system as Unix (obviously, s<strong>in</strong>ce L<strong>in</strong>ux isessentially a modern implementation of Unix, Posix-compliant etc.). So thefile system spreads out from the root with various direct<strong>or</strong>ies, of which someimp<strong>or</strong>tant ones are://b<strong>in</strong>/etc/home/media/root/usr/usr/local4.1 b<strong>in</strong>Low-level, fundamental b<strong>in</strong>aries are st<strong>or</strong>ed <strong>in</strong> the b<strong>in</strong>. Awk, grep, and catare examples of these.4.2 etcHigher level than the b<strong>in</strong>. Etc <strong>in</strong>cludes such files as “profile,” an <strong>in</strong>itialisationfile read as part of the startup of any shell called by users other than root. So5
edit<strong>in</strong>g this allows extra PATHs to be specified from which other executablesmay be called. But this can ru<strong>in</strong> a system if done wrong (Nov 2007). T<strong>or</strong>epair a broken system, boot from a rescue CD, and try replac<strong>in</strong>g the editedfile with its f<strong>or</strong>mer self (produced automatically by l<strong>in</strong>ux):>cd /mnt/sysfiles/etc>mv profile~ profile<strong>or</strong>>rm profile>cp profile~ profile4.3 homeThe preferred location f<strong>or</strong> the personal files of each user4.4 mediaA m<strong>or</strong>e modern direct<strong>or</strong>y. CDs and USB mem<strong>or</strong>y sticks may be automaticallymounted <strong>in</strong> “media.”4.5 mntExtra file systems may be mounted here, f<strong>or</strong> read and write access. In lessautomated systems, a CD might have to be mounted explicitely by the user,and this is where it would typically be attached to the filesystem.4.6 rootThe home direct<strong>or</strong>y of the root user. Does not necessarily conta<strong>in</strong> anyth<strong>in</strong>g.4.7 usrPrograms and applications are st<strong>or</strong>ed here.4.8 usr/localNew packages (such as texlive) are n<strong>or</strong>mally <strong>in</strong>stalled to this direct<strong>or</strong>y.6
5 Obta<strong>in</strong><strong>in</strong>g and Install<strong>in</strong>g a L A TEXdistributionTeXLive is probably the best distribution of a <strong>LaTeX</strong> package. Inf<strong>or</strong>mationon TeXLive can be found at:http://www.tug.<strong>or</strong>g/texlive/To get the disc, either copy someone’s TeXLive DVD <strong>or</strong> CD, <strong>or</strong> downloadthe zipped DVD image – named someth<strong>in</strong>g like:texlive2007-live-20070212.iso.zipUnzip and burn to DVD. The DVD is preferred s<strong>in</strong>ce it is not compressedcan be run ’live’ from the DVD drive without <strong>in</strong>stall<strong>in</strong>g, can also be directly<strong>in</strong>stalled, and has supp<strong>or</strong>t f<strong>or</strong> m<strong>or</strong>e system architectures. However the CD(which is compressed and can only be used to <strong>in</strong>stall the tex distribution,not run live from the DVD drive) is needed f<strong>or</strong> mach<strong>in</strong>es with an old drivethat can’t read DVDs. Beware full <strong>in</strong>stallation on XP takes 3 h+ (probablytranslat<strong>in</strong>g file f<strong>or</strong>mat) but only 10 m<strong>in</strong> on L<strong>in</strong>ux (FC 5+).F<strong>or</strong> W<strong>in</strong>dows, the <strong>in</strong>staller should autoplay and run a graphical <strong>in</strong>stall<strong>in</strong>terface.F<strong>or</strong> L<strong>in</strong>ux go to the top folder on the DVD, f<strong>or</strong> example:>cd /media/cdrom0>cd /media/TeXLive>m<strong>or</strong>e README.EN>sh <strong>in</strong>stall-tl.sh>i<strong>or</strong>If the <strong>in</strong>staller does not suggest the c<strong>or</strong>rect <strong>in</strong>stall type automatically, runother options bef<strong>or</strong>e enter<strong>in</strong>g ‘i’. The readme file will be previewed when youtype the “m<strong>or</strong>e” command, and expla<strong>in</strong>s most options. ‘l’ may be of use t<strong>or</strong>estrict the excessive number of languages that are supp<strong>or</strong>ted by default.Set the PATH, so L<strong>in</strong>ux can <strong>in</strong>voke tex commands. Either type this atthe term<strong>in</strong>al, <strong>or</strong> add it to /etc/profile (f<strong>or</strong> all users except root). In Fed<strong>or</strong>a8, I successfully appended this to the end of /etc/bashrc. Bashrc seemsless general than profile, but still allows programs (texmaker) to call thecommand “latex” (f<strong>or</strong> example) without us<strong>in</strong>g the entire path.# Ejr tries to append the path to texlivePATH=/usr/local/texlive/2007/b<strong>in</strong>/i386-l<strong>in</strong>ux:\$PATH; exp<strong>or</strong>t PATH7
The comment follow<strong>in</strong>g # above should not strictly be necessary.The follow<strong>in</strong>g PATH <strong>in</strong>struction, when appended to /etc/profile, w<strong>or</strong>kedonce <strong>in</strong> Fed<strong>or</strong>a 5, but caused critical damage to Fed<strong>or</strong>a 8. Some implicitlook<strong>in</strong>g <strong>in</strong> the b<strong>in</strong> direct<strong>or</strong>y must have been caused at some stage, perhapsby a term<strong>in</strong>al command dur<strong>in</strong>g <strong>in</strong>stallation that I did not <strong>under</strong>stand. DoNOT append it to profile, and do not use it - just note the risk!DO NOT USE:PATH=/usr/local/texlive/2007/i386-l<strong>in</strong>ux:\$PATH; exp<strong>or</strong>t PATHAfter sett<strong>in</strong>g the PATH, l<strong>in</strong>ux can call the executables <strong>in</strong> the specifieddirect<strong>or</strong>y from anywhere. You should immediately use one of these executables,texconfig, to ensure the paper size (A4 etc.) is set to your satisfaction.At a term<strong>in</strong>al type:>texconfig6 Obta<strong>in</strong><strong>in</strong>g, Install<strong>in</strong>g, and Configur<strong>in</strong>g TexmakerGo to:http://www.xm1math.net/texmaker/download.htmlF<strong>or</strong> w<strong>in</strong>dows, get the <strong>in</strong>staller executable which can then be run directly(double click) to <strong>in</strong>stall the texmaker program.texmakerw<strong>in</strong>32_<strong>in</strong>stall.exeF<strong>or</strong> L<strong>in</strong>ux, grab the texmaker l<strong>in</strong>ux <strong>in</strong>staller (this is currently f<strong>or</strong> commoni386 32 bit chipset PCs).• Copy this file to the l<strong>in</strong>ux PC, probably to /usr/local• Run the <strong>in</strong>staller as root, us<strong>in</strong>g the command:>./texmaker_l<strong>in</strong>ux_<strong>in</strong>staller• “You may have to make the program executable bef<strong>or</strong>e runn<strong>in</strong>g it.” Ifound this cryptic clue on the website I grabbed the Texmaker Installerfrom. It may mean that you should add ‘.sh’ as a file extension to thefile, but I was able to run it from the term<strong>in</strong>al without do<strong>in</strong>g this.8
The texmaker <strong>in</strong>staller should launch its own graphic <strong>in</strong>staller, which is extremelyquick.In Fed<strong>or</strong>a, Texmaker is added to ‘Office’ <strong>in</strong> the ma<strong>in</strong> menu. It can alsobe found at:/usr/share/texmaker/texmaker.desktopand <strong>in</strong>/usr/share/applications6.1 Configur<strong>in</strong>g Texmaker f<strong>or</strong> w<strong>in</strong>dowsStart the texmaker program. Go toOptions: Configure Texmaker.The executable files f<strong>or</strong> each of the 12 commands (<strong>LaTeX</strong>, dvips, etc.) musthave their location specified <strong>in</strong> the field next to their name, so that Texmakercan call f<strong>or</strong> the executables to run. The executables are likely to be <strong>in</strong> alocation like:C:texlive/2007/b<strong>in</strong>/w<strong>in</strong>32Some functions are required to get useful output (latex, dvips and gsview, <strong>or</strong>pdflatex and pdfread). bibtex is basically vital if bibliographies are used. Inan older MikTeX distribution, I found that bibtex8.exe w<strong>or</strong>ks but bibtex.exedoes not.Ghostscript may have to be <strong>in</strong>stalled to read postscript files, and I havenot yet found gsview <strong>in</strong> the texlive distribution, so some s<strong>or</strong>t of ps readermight have to be found. Alternatively you could compile to pdf and readthose <strong>in</strong>stead.6.2 Configur<strong>in</strong>g Texmaker f<strong>or</strong> L<strong>in</strong>uxAga<strong>in</strong> go to:Options: Configure TexmakerAs long as you have c<strong>or</strong>rectly added the direct<strong>or</strong>y, with<strong>in</strong> TeXLive that conta<strong>in</strong>sthe l<strong>in</strong>ux executables, to the PATH, then it should just w<strong>or</strong>k if youhave the names of the functions typed <strong>in</strong>to the fields. As long as they areon the path, these executables can be called from a term<strong>in</strong>al regardless ofcurrent direct<strong>or</strong>y and they can also be called by programs such as texmaker.The follow<strong>in</strong>g files are found <strong>in</strong> the texlive/2007 direct<strong>or</strong>y we added above:9
latexdvipsbibtexmake<strong>in</strong>dexxdvipdflatexdvipdfmmpostThe follow<strong>in</strong>g file from texlive/2007/b<strong>in</strong>/i386-l<strong>in</strong>ux is not named c<strong>or</strong>rectlyacc<strong>or</strong>d<strong>in</strong>g to the default name <strong>in</strong> texmaker (which calls it ps2pdf):pstopdfThe follow<strong>in</strong>g programs are available directly on Fed<strong>or</strong>a 5 and 8 (probablyneed<strong>in</strong>g the K desktop environment f<strong>or</strong> kpdf):gskpdf7 <strong>Writ<strong>in</strong>g</strong> Documents <strong>in</strong> L A TEXSome notes that are not obviously available <strong>in</strong> the “Sh<strong>or</strong>t Introduction toL A TEX.”7.1 Special CharactersThe special pr<strong>in</strong>t<strong>in</strong>g characters that control the L A TEX markup are: backslash(command w<strong>or</strong>ds), hash (?), dollar (maths mode), percent (comments),ampersand (?), tilde, <strong>under</strong>sc<strong>or</strong>e (math subscript), hat (math superscript),and swirly brackets (envelopes commands). They are mostly typeset us<strong>in</strong>g\backslash, \$ and so on, although the verbatim environment allows themto be spooled directly from the source to the target page. To avoid a spaceafter the character, <strong>in</strong> pla<strong>in</strong> text try:\_{}next w<strong>or</strong>d\<strong>LaTeX</strong>{} space as brackets conclude function@ <strong>in</strong> bibtex. Bibtex uses the strong delimiter @ with the consequencethat you can never write a n<strong>or</strong>mal email address <strong>in</strong> bibtex, not even <strong>in</strong> acomment (@comment). The @ symbol would be assumed to start a newbibligraphical entry (which would surely be misf<strong>or</strong>matted if you carried on10
writ<strong>in</strong>g regardless). The use of a strong delimiter means that bibtex willrecover f<strong>or</strong>m this mistake once it reaches the next entry, but it loses thecurrent entry.11