LaTeX Cookbook - Stefan Kottwitz - E-Book

LaTeX Cookbook E-Book

Stefan Kottwitz

0,0
29,99 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

LaTeX is a high-quality typesetting software and is very popular, especially among scientists. Its programming language gives you full control over every aspect of your documents, no matter how complex they are. LaTeX's huge amount of customizable templates and supporting packages cover most aspects of writing with embedded typographic expertise.
With this book you will learn to leverage the capabilities of the latest document classes and explore the functionalities of the newest packages. The book starts with examples of common document types. It provides you with samples for tuning text design, using fonts, embedding images, and creating legible tables. Common document parts such as the bibliography, glossary, and index are covered, with LaTeX's modern approach.You will learn how to create excellent graphics directly within LaTeX, including diagrams and plots quickly and easily.
Finally, you will discover how to use the new engines XeTeX and LuaTeX for advanced programming and calculating with LaTeX. The example-driven approach of this book is sure to increase your productivity.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 405

Veröffentlichungsjahr: 2015

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

LaTeX Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why Subscribe?
Free Access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Sections
Getting ready
How to do it…
How it works…
There's more…
See also
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. The Variety of Document Types
Introduction
Getting ready
TeX and LaTeX distributions
LaTeX editors
Writing a short text
How to do it...
How it works...
See also
Writing a thesis
Getting ready
How to do it...
How it works...
There's more...
Changing the input encoding
Getting a right-justified table of contents
Changing the margins
Modifying the layout of captions
Centering displayed equations
See also
Designing a book
How to do it...
How it works...
There's more...
Changing the page layout
Designing a title page
Adding a cover page
Changing the document class
See also
Creating a presentation
How to do it...
How it works...
There's more...
Using short titles and names
Uncovering information piecewise
Splitting frames in columns
Showing an outline for each section
Removing the navigation symbols
Changing the font
Changing the color
Loading a theme from the Internet
Providing a handout
See also
Designing a curriculum vitae
Getting ready
How to do it...
How it works...
See also
Writing a letter
How to do it...
How it works...
There's more...
Separating paragraphs
Changing the signature
Adding enclosures
Producing a leaflet
How to do it...
How it works...
There's more...
Fold marks and cut lines
Adjusting the margins
Adding a background image
Changing the sectioning font
Creating a large poster
How to do it...
How it works...
There's more...
2. Tuning the Text
Introduction
Inputting accented characters
How to do it...
How it works...
There's more...
Improving justification and hyphenation
How to do it...
How it works...
Converting numbers to words
How to do it...
How it works...
There's more...
Multilingual support
Gender
Enumerated lists
Putting text into a colorful box
How to do it...
How it works...
There's more...
Visualizing the layout
How to do it...
How it works...
There's more...
Using geometry
Examining the page layout details
Visualizing boxes of letters and symbols
How to do it...
How it works...
Typesetting in a grid
How to do it...
How it works...
There's more...
Absolute positioning of text
How to do it...
How it works...
There's more...
Starting a paragraph with an over-sized letter
How to do it...
How it works...
There's more...
Changing the drop cap size
Coloring the initial
Fitting text to a shape
How to do it...
How it works...
There's more...
Further shapes
Cutting out shapes
Creating a pull quote
How to do it...
How it works...
There's more...
3. Adjusting Fonts
Introduction
Basic font commands
There's more...
Choosing a font for a document
Getting ready
How to do it...
There's more...
Latin Modern
Kepler fonts
Font combinations
Locally switching to a different font
How to do it...
A command for changing the font
An environment for changing the font
How it works...
There's more...
Importing just a single symbol from a font family
Getting ready
How to do it...
How it works...
Writing bold mathematical symbols
How to do it...
How it works...
There's more...
Standard LaTeX
AMS-LaTeX and amsmath
Comparing bm and amsmath
Getting the sans serif mathematics font
How to do it...
How it works...
There's more...
An alternative approach
Sans serif fonts with direct math support
Arev Sans
Kepler fonts
Writing double stroke letters as if on a blackboard
How to do it...
How it works...
There's more...
Enabling the searching and copying of ligatures
How to do it...
How it works...
There's more...
Suppressing ligatures
How to do it...
How it works...
Adding a contour
How to do it...
How it works...
See also
4. Working with Images
Introduction
Including images with optimal quality
Getting ready
How to do it...
How it works...
Automating image positioning
How to do it...
How it works...
There's more
Limiting the floating figures and tables
Fixing the position of a figure
See also
Manipulating images
How to do it...
Adding a frame to an image
How to do it...
How it works...
Cutting an image to get rounded corners
How to do it...
How it works...
There's more...
Shaping an image like a circle
How to do it...
How it works...
There's more...
Drawing over an image
How to do it…
How it works...
Aligning images
How to do it...
How it works...
Arranging images in a grid
How to do it...
How it works...
Stacking images
How to do it...
How it works...
5. Beautiful Designs
Introduction
Adding a background image
How to do it...
How it works...
There's more...
Creating beautiful ornaments
Getting ready
How to do it...
How it works...
There's more...
Preparing pretty headings
How to do it...
How it works...
Producing a calendar
How to do it...
How it works...
Mimicking keys and menu items
How to do it...
How it works...
6. Designing Tables
Introduction
Creating a legible table
How to do it...
How it works...
There's more...
Adding footnotes to a table
How to do it...
How it works...
Aligning numeric data
How to do it...
How it works...
There's more...
Coloring a table
How to do it...
How it works...
Merging cells
How to do it...
How it works...
There's more...
Splitting a cell diagonally
How to do it...
How it works...
Adding shape, shading, and transparency
How to do it...
How it works...
There's more...
Numbering table rows automatically
Adding styles to rows and columns
Importing data from files
How to do it...
How it works...
7. Contents, Indexes, and Bibliographies
Introduction
Tuning a table of contents, lists of figures, and tables
How to do it...
Automatic correction of widths
Printing a flat table of contents
Getting KOMA-Script like-sans-serif headings
How it works...
There's more...
Creating a bibliography
How to do it...
How it works...
There's more...
Adding a glossary
How to do it...
How it works...
Creating a list of acronyms
How to do it...
How it works...
Producing an index
How to do it...
How it works...
There's more...
8. Getting the Most out of the PDF
Introduction
Adding hyperlinks
How to do it...
How it works...
There's more...
Inserting custom hyperlinks
Linking to a place within the document
Linking to labeled objects
Linking to the Internet
Changing the color and shape of the hyperlinks
Getting backreferences in the bibliography
Hyperlinking index entries
Adding metadata
How to do it...
How it works...
There's more...
Adding copyright information
How to do it...
How it works...
There's more...
Inserting comments
How to do it...
How it works...
Producing fillable forms
How to do it...
How it works...
Optimizing the output for e-book readers
How to do it...
How it works...
There's more...
Removing white margins
Getting ready
How to do it...
How it works...
There's more...
Combining PDF files
How to do it...
How it works...
Creating an animation
How to do it...
How it works...
9. Creating Graphics
Introduction
Getting ready
Building smart diagrams
How to do it...
How it works...
There's more...
Circular diagrams
Bubble diagrams
Constellation diagrams
Descriptive diagrams
Priority descriptive diagrams
Animating a diagram
Further customization
Constructing a flowchart
How it works...
Building a tree
How to do it...
How it works...
There's more...
Creating a decision tree
Building a bar chart
How to do it...
How it works...
Drawing a pie chart
How to do it...
How it works...
There's more...
Square charts
Polar area charts
Cloud charts
Drawing a Venn diagram
How to do it...
How it works...
Putting thoughts in a mind map
How to do it...
How it works...
Generating a timeline
Getting ready
How to do it...
How it works...
10. Advanced Mathematics
Introduction
Quick-start for beginners
How to do it...
How it works...
Math styles
Greek letters
Math symbols
Squares and fractions
There's more...
Subscripts and superscripts
Operators
Numbering and referencing equations
Writing multiline formulas with alignment
Aligning at the relation symbol
Centering a block of equations
Adjusting numbering
Fine-tuning math formulas
Getting ready
How to do it...
How it works...
Automatic line-breaking in equations
How to do it...
How it works....
Highlighting in a formula
How to do it...
How it works...
There's more...
Stating definitions and theorems
How to do it...
How it works...
There's more...
Adjusting the numbering
An alternative theorem package
Additional theorem tools
Drawing commutative diagrams
How to do it...
How it works....
There's more...
Plotting functions in two dimensions
How to do it...
How it works...
There's more...
Adding ticks and grids
Reducing axes
Plotting in polar coordinates
Plotting in three dimensions
How to do it...
How it works...
There's more...
Reducing axes
Drawing geometry pictures
How to do it...
How it works....
Defining points
Calculating points
Drawing objects
Printing labels
There's more...
Doing calculations
How to do it...
How it works....
See also
11. Science and Technology
Introduction
Typesetting an algorithm
How to do it...
How it works...
There's more...
Printing a code listing
How to do it...
How it works...
There's more...
Application in graph theory
How to do it...
How it works...
Writing physical quantities with units
How to do it...
How it works...
Writing chemical formulae
How to do it...
How it works...
There's more...
Drawing molecules
How to do it...
How it works...
There's more...
Drawing rings
Naming molecules
Using building blocks
Applying TikZ options
Using ready-drawn carbohydrates
Representing atoms
How to do it...
How it works...
Drawing electrical circuits
How to do it...
How it works...
See also
12. Getting Support on the Internet
Introduction
Exploring online LaTeX resources
How to do it...
Software archives and catalogues
User groups
Web forums and discussion groups
Frequently Asked Questions
There's more...
Using web forums
How to do it...
How it works...
There's more...
Framing a really good question
How to do it...
Creating a minimal example
How to do it...
There's more...
Index

LaTeX Cookbook

LaTeX Cookbook

Copyright © 2015 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

First published: October 2015

Production reference: 1231015

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham B3 2PB, UK.

ISBN 978-1-78439-514-8

www.packtpub.com

Credits

Author

Stefan Kottwitz

Reviewers

Brandon Amos

Jan Baier

Commissioning Editor

Usha Iyer

Acquisition Editor

Sonali Vernekar

Content Development Editor

Athira Laji

Technical Editor

Abhishek R. Kotian

Copy Editor

Brandt D'mello

Project Coordinator

Harshal Ved

Proofreader

Safis Editing

Indexer

Monica Ajmera Mehta

Production Coordinator

Conidon Miranda

Cover Work

Conidon Miranda

About the Author

Stefan Kottwitz studied mathematics in Jena and Hamburg. He worked as an IT administrator and communication officer onboard cruise ships for AIDA Cruises and for Hapag-Lloyd Cruises. Following 10 years of sailing around the world, he worked for the next few years specializing in network infrastructure and IT security. In 2014, he became a consultant for Lufthansa Systems. Currently, he works for Lufthansa Industry Solutions and designs and implements networks for new cruise ships.

In between contracts, he worked as a freelance programmer and typography designer. For many years, he has been providing LaTeX support on online forums. He maintains the web forums LaTeX-Community.org and goLaTeX.de, the TeX gallery site TeXample.net, the Q&A sites TeXwelt.de and TeXnique.fr, the TeXdoc.net service and the server for the UK TeX FAQ. He is a moderator of the TeX Stack Exchange site and on matheplanet.com.

He publishes ideas and news from the TeX world on his personal blog at TeXblog.net.

Before this book, he authored LaTeX Beginner's Guide, by Packt Publishing in 2011.

About the Reviewers

Brandon Amos is a PhD student at Carnegie Mellon University with research interests in machine learning and computer vision. He is a Linux and LaTeX enthusiast and actively releases research and hobby projects on the open source community at http://github.com/bamos.

Jan Baier is a young system engineer and administrator from the Czech Republic. He holds a master's degree in computer science from the Czech Technical University, Prague. In his spare time, he teaches Unix/Linux basics. He is a cofounder of amagical.net, a company that focuses on delivering information systems to small and medium companies. He tries to boldly go where no one has gone before, and he believes in the true power of open source.

www.PacktPub.com

Support files, eBooks, discount offers, and more

For support files and downloads related to your book, please visit www.PacktPub.com.

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.

At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

https://www2.packtpub.com/books/subscription/packtlib

Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.

Why Subscribe?

Fully searchable across every book published by PacktCopy and paste, print, and bookmark contentOn demand and accessible via a web browser

Free Access for Packt account holders

If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view 9 entirely free books. Simply use your login credentials for immediate access.

Preface

LaTeX is a high-quality typesetting software and is very popular, especially among scientists. Its programming language gives you full control over every aspect of your documents, no matter how complex they are. LaTeX's large number of customizable templates and supporting packages cover most aspects of writing with embedded typographic expertise.

With this book, you will learn to leverage the capabilities of the latest document classes and explore the functionalities of the newest packages.

This book starts with examples of common document types. It provides samples for tuning text design, using fonts, embedding images, and creating legible tables. Common parts of the document such as the bibliography, glossary, and index are covered with LaTeX's modern approach.

You will learn how to create excellent graphics directly within LaTeX; this includes creating diagrams and plots quickly and easily.

Finally, the book shows the application of LaTeX in various scientific fields.

The example-driven approach of this book is sure to increase your productivity.

What this book covers

Chapter 1, The Variety of Document Types, introduces you to the different types of documents and covers how LaTeX can be used for for any document type such as a thesis, a book, a CV, a presentation, a flyer, and a large poster.

Chapter 2, Tuning the Text, focuses on customizing text details in the documents. We will start with some very useful basics, covering some helpful things. We will end the chapter with recipes that show off what LaTeX can do beyond rectangular paragraphs.

Chapter 3, Adjusting Fonts, helps you to choose fonts globally, and demonstrates how to adjust them within the document.

Chapter 4, Working with Images, contains some recipes for including, positioning, and manipulating images within LaTeX. After discussing the quality aspects, you will get to know about the concept of floating figures for automated positioning to give well-balanced text heights on pages.

Chapter 5, Beautiful Designs, helps you in adding background images, creating beautiful ornaments, adding pretty headings, producing a calendar, and inserting symbols for computer keys and menu items.

Chapter 6, Designing Tables, helps you to create good-looking tables. Specifically, it covers creating a legible table, aligning numeric data, adding colors, shape, shading, and transparency merging and splitting cells, and reading in table data from external files.

Chapter 7, Contents, Indexes, and Bibliographies, provides recipes for quickly starting and customizing the table of contents, lists of of figures and tables, bibliographies, glossaries, and indexes.

Chapter 8, Getting the Most out of the PDF, explores the capabilities of PDF, such as metadata, PDF comments, and fillable forms. You will see how to combine PDF files, how to crop margins, and how to optimize the output for e-books.

Chapter 9, Creating Graphics, contains recipes to create impressive graphics. We will start off using modern packages for various purposes to create complete and useable graphics, such as various kinds of diagrams and charts.

Chapter 10, Advanced Mathematics, explores one of the classic strong points of LaTeX—its excellent quality in typesetting formulas. That's why LaTeX is the most used writing software in mathematics. When it comes to formulas, other sciences benefit from it as well.

Chapter 11, Science and Technology, deals with other sciences such as chemistry, physics, computer science, and technologies such as electronics. This chapter will be an overview, showing how LaTeX can be used in various fields using specific recipes.

Chapter 12, Getting Support on the Internet, starts with a guide to the most useful Internet resources for LaTeX. This chapter will show you how to get help from the TeX online communities.

What you need for this book

The software that you need here is TeX Live, version 2015 or later, or MiKTeX, version 2.9 or later. It is recommendable to also install a LaTeX editor. The introduction in Chapter 1 will explain, where to get the TeX software and editors. The Chapter 12 will guide you to further Internet resources.

An important tool is texdoc. It opens manuals and further documentation for you. texdoc is contained in TeX Live. MiKTeX provides a similar tool with the same name. texdoc is called at in Command Prompt by typing texdoc keyword. For packages and bundles, the keyword is usually just the name.

All the code examples in this book can be downloaded as described later in the section Customer support. So, you don't need to type the code, neither to do copy & paste. That's why we could split the codes into snippets to explain them step by step.

Who this book is for

If you already know the basics of LaTeX and if you'd like to get quick and efficient solutions to your problems, this is the perfect book for you. If you are an advanced reader, you can use this book's example-driven format to take your skillset to the next level. Some familiarity with the basic syntax of LaTeX and how to use the editor of your choice for compiling is required.

Sections

In this book, you will find several headings that appear frequently (Getting ready, How to do it, How it works, There's more, and See also).

To give clear instructions on how to complete a recipe, we use these sections as follows:

Getting ready

This section tells you what to expect in the recipe, and describes how to set up any software or any preliminary settings required for the recipe.

How to do it…

This section contains the steps required to follow the recipe.

How it works…

This section usually consists of a detailed explanation of what happened in the previous section.

There's more…

This section consists of additional information about the recipe in order to make the reader more knowledgeable about the recipe.

See also

This section provides helpful links to other useful information for the recipe.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "Write a mathematical equation using the equation environment."

A block of code is set as follows:

\begin{document} \frenchspacing \raggedbottom \selectlanguage{american} \pagenumbering{roman} \pagestyle{plain}

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Click on browse files to have filler images and a sample file."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail <[email protected]>, and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at <[email protected]> with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at <[email protected]>, and we will do our best to address the problem.

Chapter 1. The Variety of Document Types

Documents can vary in size, format, sectioning, and design in general. You can use LaTeX for any document type. In this chapter, you will find recipes for different kinds of documents.

We will specifically cover the following topics:

Writing a short textWriting a thesisDesigning a bookCreating a presentationDesigning a curriculum vitaeWriting a letterProducing a leafletCreating a large poster

Introduction

LaTeX has been around for many years. Over time, developers and authors have contributed a lot of extensions to the LaTeX code base.

These extensions include the following:

Document class: This is a style file which is the frame of your document. It usually comes with meaningful default settings that can be changed via options when loading it. Its macros can be customized by the \renewcommand command. It often provides commands for authors to modify settings.Package: This is a style file with a specific purpose that can be loaded in addition to the document class. Packages can be combined. Most of the time, we load many packages using the \usepackage command.Bundle: This is a set of closely related packages or classes. In our first recipe, Writing a short text, you will get to know some bundles.Template: This is a document filled with dummy text, which you can use it as a starting point, and just fill in your own headings, texts, formulas, and images. We will take a look at a template in our second recipe, Writing a thesis.

These add-ons are incredibly valuable! They are one of the reasons for the enduring success of LaTeX. We all agree that learning LaTeX can be hard with its steep learning curve. However, if you don't reinvent the wheel, and start with a good template or class and a quality set of packages, you can quickly achieve great results.

The purpose of this book is to assist you in this regard.

Getting ready

To be able to work with LaTeX, you need install the following on your computer:

TeX and LaTeX software, which are together called TeX distributionA LaTeX editor, although you can use any text editorA PDF viewer to view the final output

If you already have these installed, great! In that case, you can skip the next paragraphs and immediately proceed to the first recipe.

A PDF reader is probably already installed on your computer, such as the Foxit Reader, the Adobe Reader or the Preview app on the Mac. Furthermore, most editors come with an integrated PDF previewer. So, let's take a look at the TeX software and editors.

TeX and LaTeX distributions

There are collections of TeX and LaTeX software that are ready to use and easy to install. Their websites provide information on installing and updating them. You may choose the download site for your system:

TeX Live: At http://tug.org/texlive/, you can find download information and installation instructions for the cross-platform TeX distribution that runs on Windows, Linux, Mac OS X, and other Unix systems. It is supported by the TeX Users Group (TUG).MacTeX: This is based on TeX Live and has been significantly customized for Mac OS X. The basic information is available at http://www.tug.org/mactex/.MiKTeX: The download and documentation of that Windows-specific distribution can be found at http://www.miktex.org/.proTeXt: This is for Windows only, and it is derived from MiKTeX, but proTeXt is more user-friendly during installation. Its home page can be found at http://www.tug.org/protext/.

I recommend that you choose MacTeX if you have a Mac; otherwise, I recommend using TeX Live, since the support by the TUG is especially good.

Describing the setup is beyond the scope of this book. For TeX Live, you can find a step-by-step explanation with screenshots in the LaTeX Beginner's Guide by Packt Publishing. Generally, when you visit Internet addresses of the TeX distributions listed above, you can find detailed setup instructions.

Finally, on Linux, such as Ubuntu, Debian, Red Hat, Fedora, and SUSE versions, there's usually a TeX Live-based software package available via the operating system repositories. While it's usually not as up-to-date as an installation done via the TeX Live website or a TeX Live DVD, it's very easy to install using the Linux package manager, which you use to install any software usually.

LaTeX editors

There are many LaTeX editors, from small and quick to very feature-rich editors. The TeX distributions already provide the fine editor TeXworks, which I use. It can be set up together with TeX or with a package manager on Linux, and it can be downloaded from http://www.tug.org/texworks/.

I have a collection of the links to LaTeX editors and additional software on my blog, http://texblog.net/latex-link-archive/distribution-editor-viewer/, where you may look for alternative editors, which run on your operating system.

Additionally, there are pure online LaTeX editors, which run in a web browser, so you can use them even on tablets and smartphones. The most noticeable LaTeX editors are as follows:

https://www.overleaf.com, with real-time collaborative editing and a rich text modes which renders headings, equations and further formatting directly in the editorhttps://www.sharelatex.com, also with real-time collaboration and revision history for tracking changes

If you need any help in setting up and using LaTeX or any other editor, you can visit a LaTeX web forum. In Chapter 12, Getting Support on the Internet, you can find links to these forums and see and how to use them. You can also find me on those forums.

If you would like to get help in learning LaTeX, you may take a look at LaTeX Beginner's Guide at https://www.packtpub.com/hardware-and-creative/latex-beginners-guide.

Once you have done the installation, you can launch the editor and start with a LaTeX recipe.

Writing a short text

While LaTeX is great for big documents, it's just as useful for smaller ones, and you get all the features to work with. Writing down homework or producing a seminar handout, for example, doesn't need book-like chapters, and the layout would not be very spacious. So we will choose a document class that suits the task at hand best.

There are class bundles that cover commonly used document types. Every LaTeX installation contains the base bundle with standard classes. There are class files for articles, books, reports, letters, and more. It is stable stuff; it has not really been changed for many years. If you don't care about the latest style, this can be sufficient. It would even run on a ten-year-old LaTeX installation.

In this recipe, we will use a class of the KOMA-Script bundle. This is a set of classes that were originally designed with the aim of replacing the standard classes and providing more features. In contrast to the rather static base bundle, KOMA-Script has been extensively developed during recent years. It became feature-rich and got an excellent user interface. Parts of its functionality are provided in packages that can be used together with other classes as well. You can identify KOMA-Script classes and packages by the prefix scr. This prefix stands for script, which was the initial name of this bundle.

How to do it...

We will start with a complete small document, already using various features. This can be your template, into which you can add your own text later on.

While we go through the document step by step, you may open the complete code directly with your editor, so you don't need to type it. It is contained in the code bundle available at the book's page https://www.packtpub.com and at the book's page http://latex-cookbook.net. Perform the following steps to create a small document:

Start with a document class. We will use the KOMA-Script class scrartcl, with A4 paper size, a base font size of 12 pt, and interparagraph spacing instead of the default paragraph indentation:
\documentclass[paper=a4,oneside,fontsize=12pt, parskip=full]{scrartcl}
Begin the document:
\begin{document}
Let LaTeX print a table of contents using this command:
\tableofcontents
Start a section without numbering:
\addsec{Introduction}
Add some text:
This document will be our starting point for simple documents. It is suitable for a single page or up to a couple of dozen pages. The text will be divided into sections.
Start an automatically numbered section with text:
\section{The first section} This first text will contain
Add a bulleted list using an itemize environment. Each list item starts with \item. Using \ref{label}, we will refer to labels, which we will create later:
\begin{itemize} \item a table of contents, \item a bulleted list, \item headings and some text and math in section, \item referencing such as to section \ref{sec:maths} and equation (\ref{eq:integral}). \end{itemize}
Continue with text and start another numbered section:
We can use this document as a template for filling in our own content. \section{Some maths}
Set a label so that we can refer to this point whenever we want to refer to this section:
\label{sec:maths}
Continue with the text. We will start using some mathematical expressions in the text. We mark this by enclosing them in parentheses with a prefixing backslash, that is, \( … \).
When we write a scientific or technical document, we usually include math formulas. To get a brief glimpse of the look of maths, we will look at an integral approximation of a function \( f(x) \) as a sum with weights \( w_i \):
Write a mathematical equation using the equation environment. Again, place a label by using the following commands:
\begin{equation} \label{eq:integral} \int_a^b f(x)\,\mathrm{d}x \approx (b-a) \sum_{i=0}^n w_i f(x_i) \end{equation}
End the document:
\end{document}
Compile the document. The first page of the output will look like this:

How it works...

In the first line, we loaded the document class scrartcl. In square brackets, we set options for specifying an A4 paper size with one-sided printing and a font size of 12 pt. Finally, we chose to have a full line between paragraphs in the output so that we can easily distinguish paragraphs.

Note

The default setting is no space between paragraphs and a small indentation at the beginning of each paragraph. Uncheck the parskip option to see it. We chose a paragraph skip because many people are used to it when working with e-mails, while indentation costs line space, which is a precious resource on small electronic devices.

Without further ado, we began the text with a table of contents. While numbered sections are started by the \section command, we can start unnumbered sections by using the starred version \section*. However, we used the KOMA-Script command \addsec for the first unnumbered section. That's because, in contrast with \section*, the \addsec command generates an entry in the table of contents.

An empty line tells LaTeX to make a paragraph break.

As bulleted lists are a good way to clearly present points, we used an itemize environment for this. All environments start with the \begin command and are ended with the \end command.

Tip

If you would like to have a numbered list, use the enumerate environment.

An equation environment has been used to display a formula that is automatically numbered. We used the \label command to set an invisible anchor mark so we could refer to it using its label name by the \ref command and get the equation number in the output.

Tip

Choosing label identifiers:

It is a good practice to use prefixes to identify kinds of labels, such as eq:name for equations, fig:name for figures, tab:name for tables, and so on. Avoid special characters in names, such as accented alphabets.

Small formulas within text lines have been enclosed in \( ... \), which provides inline math mode. Dollar symbols, $ ... $, can be used instead of \( ... \), which makes typing easier. However, the use of parentheses makes it easier to understand where the math mode starts and where it ends, which may be beneficial when many math expressions are scattered throughout the text.

For further information on math typesetting, refer to Chapter 10, Advanced Mathematics, specifically to the recipe Finetuning a formula.

See also

The part of the document before the \begin{document} command is called the preamble. It contains global settings. By adding a few lines to our document preamble, we can improve our document and modify the general appearance. Chapter 2, Tuning the Text, starts with additions that are beneficial for small documents as well. They enable the direct input of accented characters and unicode symbols, and they improve justification and hyphenation.

In Chapter 3, Adjusting Fonts, you can find recipes for changing the fonts of either the whole document or of certain elements.

For further customization tasks, such as modifying page layout, and adding a title page, refer to the recipe Designing a book in the current chapter. We will take a look at such settings on the occasion of a book example.

Writing a thesis

When you plan to write a large document like a thesis, you have two choices: either choose a ready-made template, or set up your own document environment. If you have got limited time and need to start off with your thesis fast, a template can come to the rescue.

Beware of outdated and questionable templates found somewhere on the Internet. Look first at the date and at user opinions, such as on web forums. The age of a template is not a problem by itself, as LaTeX can run it the same way when it's been written. However, as LaTeX has developed, better solutions have come up over time. Legacy code may not benefit from it.

Some universities provide their own templates. That may be ok, because requirements would be met for sure; just check if it can be improved; for example, by replacing an obsolete package with its recommended successors.

A very good source for checking the quality of a template is the guide to obsolete commands and packages in LaTeX2e, which is also called l2tabu. You can open the English version by typing the texdoc l2tabuen command in Command Prompt, or by visiting http://texdoc.net/pkg/l2tabuen.

To be clear, the LaTeX base is stable and solid, but there are changes in community-contributed packages.

In the previous recipe, Writing a short text, we took the bottom-up approach and built a document from scratch, adding what we desired. Now we will go top-down; let's use and understand a complete template, removing what we don't need.

As we need to choose a template now, let's take a real gem. The ClassicThesis package by Prof. André Miede is a thesis template of very good quality. The design follows the classic guide to writing, The Elements of Typographic Style by Robert Bringhurst, we will see some particular points later in this recipe. Its implementation is thoughtful and modern. Originally written in 2006, it's maintained today as well, and shipped with TeX distributions.

Even if you would not use this specific template later, it shows how we can organize a large document.

Getting ready

Though the ClassicThesis package may already be installed in your TeX system, named classicthesis.sty, the whole template is an archive of files that should go into your working directory.

Download the ClassicThesis archive from CTAN by visiting http://www.ctan.org/tex-archive/macros/latex/contrib/classicthesis/.

Instead of fetching single files, choose to download it as a .zip file. Unzip it to where you keep your personal documents, in its own directory. This directory will be your thesis directory.

This package provides a ready-made structured filesystem of the main document, style file, settings file, and document parts such as the abstract and foreword, and also chapters in dedicated files. You can edit all files and fill in your own text.

The ClassicThesis.tex file is the main document. Its filler text is the template's manual; this allows us to compile the template immediately for looking at the output design. By compiling, you can also verify that your TeX installation can handle additional packages if you need to install any.

How to do it...

After unzipping, your directory will have the following structure:

Now follow these steps:

Rename or copy the file ClassicThesis.tex; choose your own name, such as MyThesis.tex, but keep it in the same directory.Open the main document, that is, MyThesis.tex, and look around to get a feeling of the document structure. Compile it for testing at least twice to get the correct referencing so you would know that this starting point works.You can review and edit the settings in the main file, MyThesis.tex, and in the configuration file, classicthesis-config.tex. Over the course of the following pages, we will examine their content.Open the existing .tex files, such as Abstract.tex and Chapter01.tex, with your editor. Remove the filler text and type in your own text. Add further chapter files as needed, and include them in the main file, MyThesis.tex, using the \include command. The structure is given; the technical part of the editing is like cloning files and copying lines, all you need to focus on is the actual thesis content now.

Don't worry if the font or margins don't please you yet. You can change the layout at any time. Let's take a closer look now, and then you will know how.

How it works...

We will take a look at the functional lines of the main file, MyThesis.tex.

The document preamble is as follows:

\documentclass[ twoside,openright,titlepage, numbers=noenddot,headinclude, footinclude=true,cleardoublepage=empty, BCOR=5mm,paper=a4,fontsize=11pt, ngerman,american,% ]{scrreprt} \input{classicthesis-config}

The template is built on the KOMA-Script class, scrreprt. KOMA-Script as a LaTeX bundle is described in this chapter's first recipe, Writing a short text.

You can change the preset options to those you need, such as the font size or binding correction BCOR. There are many class options for adjusting the layout; you can read about them in the KOMA-Script manual. Type texdocscrguien in Command prompt, or visit http://texdoc.net/pkg/scrguien. We will discuss some of them in depth in our next recipe, Designing a book.

Loading of packages and all the remaining settings is done in a single file, classicthesis-config.tex. We will look at it later in this recipe.

The document body starts with the following commands:

\begin{document} \frenchspacing \raggedbottom \selectlanguage{american} \pagenumbering{roman} \pagestyle{plain}

The \frenchspacing line means that there's a single space following the punctuation after a sentence. Before the twentieth century, people stuffed extra space between sentences. LaTeX does this by default, or you can enter the \nonfrenchspacing line. The language is set to American English. Actually, you would need the \selectlanguage line only if you need to switch between languages for correct hyphenation.

We start with Roman page numbers. The plain page style means that we have no page headers for now, while page numbers are centered in the page footer.

Then, we look at the front matter, which is the part of the document where the formal parts before the actual content go:

\include{FrontBackmatter/DirtyTitlepage} \include{FrontBackmatter/Titlepage} \include{FrontBackmatter/Titleback} \cleardoublepage\include{FrontBackmatter/Dedication} %\cleardoublepage\include{FrontBackmatter/Foreword} \cleardoublepage\include{FrontBackmatter/Abstract} \cleardoublepage\include{FrontBackmatter/Publication} \cleardoublepage\include{FrontBackmatter/Acknowledgments} \pagestyle{scrheadings} \cleardoublepage\include{FrontBackmatter/Contents}

Each commonly-required part of the front matter has its own file. Just edit the file as you need it, comment out by inserting a % symbol at the beginning of a line, or remove what you don't need. The \cleardoublepage line ends a page, but also ensures that the next page starts on the right-hand side. This can mean inserting an empty page if necessary; that is, a double page break. This will not happen if you change the twoside option to oneside, so you can keep the \cleardoublepage line, which will act like a \clearpage command when the oneside option is set.

Finally, we got the main matter:

\pagenumbering{arabic} %\setcounter{page}{90} % use \cleardoublepage here to avoid problems with pdfbookmark \cleardoublepage \part{Some Kind of Manual} \include{Chapters/Chapter01} \cleardoublepage \ctparttext{You can put some informational part preamble text here...} \part{The Showcase} \include{Chapters/Chapter02} \include{Chapters/Chapter03}

In the main matter, we use Arabic page numbers. The \pagenumbering line resets the page number to 0.

The thesis is divided into parts. Each one is split into chapters. You can omit the \part lines if you want your highest sectioning level to be the chapter level.

In the Chapters subdirectory, each chapter has its own .tex file; so, you can easily handle a large amount of text. Furthermore, you can use the \includeonly command to compile just the selected chapters for speeding up writing.

Finally, the main document ends with the back matter:

\appendix \cleardoublepage \part{Appendix} \include{Chapters/Chapter0A} %******************************************************************** % Other Stuff in the Back %******************************************************* \cleardoublepage\include{FrontBackmatter/Bibliography} \cleardoublepage\include{FrontBackmatter/Colophon} \cleardoublepage\include{FrontBackmatter/Declaration} \end{document}

The command \appendix resets the sectioning counters and changes them to alphabetic numbering, that is, the following chapters will be numbered A, B, and so on. Like in the front matter, the parts of the appendix are divided into several files.

Let's take a look at the configuration file. Open the classicthesis-config.tex file. The whole thing would take too much space in the book, so let's just take a look at some sample lines:

\newcommand{\myTitle}{A Classic Thesis Style\xspace} \newcommand{\myName}{Andr\'e Miede\xspace} \newcommand{\myUni}{Put data here\xspace} \newcommand{\myLocation}{Darmstadt\xspace} \newcommand{\myTime}{August 2012\xspace}

Here, you can fill in your own data. Besides being printed on the title page, this data will be used as metadata for the generated PDF document. There are more supported macros here, such as \mySubtitle, \myProf, and many more. The \xspace takes care of proper spacing after such a macro; that is, it inserts a space when there's no punctuation mark following it.

There's more...

As mentioned, this template contains design decisions inspired by the book The Elements of Typographical Style by Robert Bringhurst. The most notable design decisions are as follows:

It doesn't use bold fonts, but rather uses small caps or italics elegantly to emphasize what's important.The text body is not very wide and this allows it to be read comfortably without needing the eyes to jump too far from the end of the line to the beginning of the next line. So, we have wide margins, which can be used for notes.The table of contents is not stretched to get right-aligned page numbers. To quote the author, "Is your reader interested in the page number or does she/he want to sum the numbers up?". That's why the page number follows the title.

Explore the classicthesis-config.tex file further to make modifications. Like in the previous recipe, we apply document-wide changes within the preamble, and here, we do it in this file.

We will now take a look at the selected lines of that configuration file.

Changing the input encoding

You might have noticed that special characters, such as accented characters, don't work directly in the input. Scroll to this line:

\PassOptionsToPackage{latin9}{inputenc} \usepackage{inputenc}

This is another way of setting the input encoding. Refer to the recipe Inputting accented characters in Chapter 2, Tuning the Text, to understand the topic of encoding. Here, you should change the latin9 option to utf8 if you wish to use an UTF-8-capable system and editor. The latin9 option is typically used by older editors on Windows. There are other encodings. If you would need another one, use texdoc inputenc, or visit http://texdoc.net/pkg/inputenc to take a look at the available options.

Getting a right-justified table of contents

The design is not set in stone, you may adjust it all. If you would like to see the page numbers in the table of contents right aligned, set a single option. Look at the very beginning of the classicthesis-config.tex file:

\PassOptionsToPackage{eulerchapternumbers,listings,drafting,% pdfspacing,%floatperchapter,%linedheaders,% subfig,beramono,eulermath,parts}{classicthesis}

Here, you can find the options for the actual classicthesis package. Simply add the dottedtoc option to this comma separated list. These options, among others, are documented in the template's manual. You can open it by typing texdocclassicthesis in Command Prompt, or at http://texdoc.net/pkg/classicthesis. (editor: please apply inline code formatting correctly, and URL formatting)

Changing the margins

To fulfill requirements of page margins or to implement your own layout ideas, you can specify exact page dimensions by loading the geometry package. Consider the following example:

\usepackage[inner=1.5cm,outer=3cm,top=2cm,bottom=2cm, bindingoffset=5mm]{geometry}

Here, you can also provide a value for the space that you leave for the binding and all margins you like. It's good practice to have a visible inner margin set to half the value of the outer margin, because margins will be added in the middle. For single-sided printing, with the oneside option, use left=... and right=... for the defining the margins instead of inner and outer.

Place such a line at the end of the classicthesis-config.tex file so that it will override the original settings.

Modifying the layout of captions

In the classicthesis-config.tex file, you can change the appearance of captions of figures and tables:

\usepackage{caption} \captionsetup{format=hang,font=small}

The template loads the caption package. It provides a lot of features for fine-tuning captions. For now, the caption texts are indented so they will hang under the first line, and they will have a smaller font size than the normal text. By adding simple options, you can further adjust the appearance; for example, by adding the labelfont=it line, you can get italicized caption labels. Refer to the caption manual to learn more. As usual, you can open it via texdoccaption or at http://texdoc.net/pkg/caption.

Note

While the caption