Document Preparation for Researchers Using Latex
Total Page:16
File Type:pdf, Size:1020Kb
Documents: Document preparation for researchers using LaTeX Table of Contents 1 Introduction 1 1.1 Course background 1 1.2 Course aims and content 1 1.3 This document 1 1.4 Getting started 1 2 Exercises 3 2.1 Before you start 3 2.2 Texmaker 3 2.3 LATEX 5 2.3.1 Compiling LATEX files 6 2.3.2 Viewing LATEX files 6 2.4 Introductory Exercises 7 2.4.1 A simple example 7 2.4.2 A longer document 8 2.5 Typesetting Text 9 2.6 Version control 10 2.7 Typesetting Mathematics 10 2.8 Advanced features 12 2.8.1 Cross references 12 2.8.2 Including pictures 13 2.8.3 Bibliographies 13 3 Helpful Hints 15 3.1 Special Characters 15 3.2 Dashes and Hyphens 15 3.3 Quotation Marks 15 3.4 Accents and Special Characters 16 3.5 List of Mathematical Symbols 16 4 Answers 23 4.1 Acknowledgements 32 References 33 Not So Short Introduction 34 Slides 187 Chapter 1 Introduction Course background LATEX is a document preparation system that produces far better-looking output than any word processor. It is ideal for producing well-structured documents particularly those containing scientific formulae, mathematical proofs or computer programs, without getting bogged down in design. Course aims and content The course provides an introduction to LATEX using Texmaker. The following topics are covered. • A brief history of LATEX. • Creating a simple LATEX document. • Adding chapters and sections. • Lists and tables. • Typesetting mathematical equations. • Using cross–references, including images, and creating bibliographies. This document The document contains all the information you will need to get you started using LATEX. • Exercises. • Typesetting special characters or Helpful Hints. • The answers to the exercises. • The Not So Short Introduction to LATEX – a widely used guide. • The slides. Getting started Begin by reading Chapter 2 for instructions on how to get started. 1 Chapter 2 Exercises Before you start These exercises aim to illustrate particular features of LATEX. They start very gradually by asking you to create and view a simple document and then move on to more complex examples. If at any time you can’t work out how to produce a particular effect then do consult the answers in Chapter 4, page 23, or ask. Texmaker We will be using Texmaker to create, edit, compile and view LATEX files. To start Texmaker go to Start | All Programs | Texmaker. A window like Figure 2.1 should appear. Figure 2.1: Texmaker: Start–up screen If your screen does not look exactly like this window then look at the View menu and make sure 3 CHAPTER 2. EXERCISES that these items are checked: • Structure • Messages / Log File • PDF Viewer • List of opened files Once Texmaker is correct, find the Run (F6) drop down menu box to the right of PDFLaTeX . See what other options there are. Find the following buttons: • View PDF (F7) • Find (Ctrl+F) • Replace (Ctrl+R) • Save (Ctrl+S) The keyboard shortcuts are included after each command. These buttons are used for building and viewing LATEX documents. Most of the other buttons are used for particular LATEX commands. See if you can find some of these: • Bold • Italic • Left • Part/Chapter/Section • Relation symbols • Greek Letters Have a look at the View menu to open different Texmaker screens. Make sure that • Messages / Log files • List of opened files are both checked. Now you have explored the Texmaker it is time to start using LATEX. Files to download Please download these three files for use during this practical. Browse to http://www.stats.ox.ac.uk/pub/susan/oucs_latex/ and save the three files i. sample.tex ii. panic.png iii. test.bib in your home folder. To be really organised you could create a new folder to keep them in. This booklet can also be downloaded if you want to see an online version of the exercises. 2018-05-14 12:42 4 Rev: 417 2.3. LATEX LATEX Go to File | Open. and open sample.tex. You should see a screen like Figure 2.2. Note that some Figure 2.2: Texmaker: Opening an example file. of the text on the screen (not on this printed page!) is highlighted in different colours. This helps to locate errors. Let’s look at some of the significant lines in the sample.tex file. All LATEX files begin with a \documentclass declaration. \documentclass[12pt,a4paper]{article} The syntax of LATEX commands is consistent. A command begins with a \ (a backslash), is altered by options contained in [. ] (square brackets) and is defined by what’s contained within {. } (curly brackets). The optional arguments contained in [. ] are: 12pt the font size a4paper the paper size The necessary argument contained in {. } is: article defines the type or class of document Conventionally the article class is used for shorter documents and the report class for longer dissertations. Other options include book and letter. Note that everything that appears on a line after a % is a comment and is ignored. The main body of a document – that is the information that you want people to read – begins with \begin{document} and is always ended by Rev: 417 5 2018-05-14 12:42 CHAPTER 2. EXERCISES \end{document} The information has been divided into sections with the commands \section{Simple Text} and \subsection{A Warning or Two} When the file is compiled these sections and subsections will be numbered automatically. Various formatting commands are embedded within the text. For example \emph is used to italicise text and \textbf for bold text. Compiling LATEX files Figure 2.3: A successful LATEX compilation Once you have a finished editing your file it should saved and be compiled. To compile your file click on the light grey arrow by PDFLaTeX . See Figure 2.3 for an example. A small digression on debugging. When LATEX finds errors it shows a line number near where it thinks the error has has been found. If you look at the bottom of the Texmaker screen window, a block of red text will appear, with an error message and a line number. If you click on this text, then you should be taken to the location of the error in the edit window. Viewing LATEX files To look at the compiled version of the file click on the light grey arrow next to View PDF . A new window should open which looks similar to Figure 2.4. It should show a formatted version of the file. Alternatively Quick Build will both compile your .tex file and preview it as long as you have done one PDFLaTeX first. 2018-05-14 12:42 6 Rev: 417 2.4. INTRODUCTORY EXERCISES Figure 2.4: The preview window Introductory Exercises The following exercises are designed to show many features of LATEX. A simple example . Exercise 1 We are now going to input, compile and view a simple LATEX file. Use File | New. and enter these lines \documentclass{article} \begin{document} \section{Introduction} Hello there. Goodbye now. \end{document} in the editing window. Use the File | Save As. menu to save the file as new.tex. It is very important that the file has a .tex suffix. To use the auto-completion feature in Texmaker use the TAB key. Click on the light grey arrow to the left of PDFLaTex to compile the file, or use F6. You should see a compiled version of the file. Now change the file so that it contains a mistake – perhaps by replacing ‘section’ by ‘sektion’ or leaving out the closing } after \begin{document. Now compile the file again and see what happens. Depending on the error you have introduced you may see something like this: ! Undefined control sequence. l.3 \sektion Rev: 417 7 2018-05-14 12:42 CHAPTER 2. EXERCISES {Introduction} or like this: Runaway argument? {document Hello there. ! Paragraph ended before \begin was complete. <to be read again> \par l.4 Can you see the red text in the lower window? This shows that there is an error. Clicking on the error should take you to the place in the edit window where the error was found. Figure 2.5: Texmaker: Locating errors A longer document This exercise uses the sample .tex file which you will have downloaded. Exercise 2 Open the sample.tex file in Texmaker and then compile and view the file. Now we are going to make some changes this file. Remember that you will need to save the file and compile each time you make changes. 1. Change documentclass from article to report and then to book. You might want to include \chapter{Introduction} immediately after \begin{document} 2. Change the documentclass font size option from 12pt to 11pt . 3. Add \usepackage{parskip} to the preamble. How does the paragraph formatting change? 4. Add \usepackage{times} to the preamble. The font should now look different. 5. Change the text colour from red to green. Remember that you will need to include \usepackage{color} in the preamble if it is not already there. 6. Swap the emphasised and bold text. 2018-05-14 12:42 8 Rev: 417 2.5. TYPESETTING TEXT Typesetting Text . Exercise 3 We will now typeset some simple sentences. Included in this document is The Not So Short Introduction to LATEX2e which we will be using for reference for the rest of these exercises. See Chapter 2 Typesetting Text of The Not So Short Introduction for more information. Look at Chapter 3 Helpful Hints, page 15. It contains instructions on how to typeset many characters used in the exercises below.