% This is part of the source code for "LaTeX for Complete Novices" % It includes some code that was used to generate other formats of % this tutorial that aren't included in this distribution. That code % will be skipped by the current class settings. % arara: pdflatex % arara: bibtex % arara: makeglossaries % arara: pdflatex % arara: makeglossaries % arara: pdflatex % arara: makeindex: { style: novices-index.ist } % arara: pdflatex % arara: pdflatex % arara: pdflatex % arara: pdflatex % arara: makeindex: { style: novices-index.ist } % arara: pdflatex % Multiple pdflatex runs are required to ensure the flow frame switches occur % correctly before and after the summary and index \documentclass[report]{novices} \usepackage{fancybox} \usepackage{tikz} \usetikzlibrary{shapes} \usetikzlibrary{decorations.pathmorphing} \usepackage{caption,subcaption} \usepackage{makeidx} \usepackage{alltt} \usepackage{amsmath} \usepackage{amsfonts} \usepackage{graphicx} \usepackage{rotating} \usepackage{booktabs} \usepackage{pifont} \usepackage{cmap} \usepackage[utf8]{inputenc} \usepackage[math]{anttor} \usepackage{libris} \renewcommand*{\ttdefault}{txtt} \newcommand*{\docdate}{\formatdate{25}{9}{2012}} \authordetails{1970}{Talbot}{Nicola L.~C.} \title[LaTeX for Complete Novices]{\LaTeX\ for Complete Novices} \version{1.4} \edition{1} \volume{1} \series{The Dickimaw \LaTeX\ Series} \seriesurl{http://www.dickimaw-books.com/latex/} \affiliation {Dickimaw Books} {http://www.dickimaw-books.com/} {Saxlingham Nethergate} \keywords{LaTeX,beginners,introduction,typesetting} \subject{LaTeX} \date{\docdate} \html{\input{htmlonly}} \makeindex \makeglossaries \input{keywords} \input{glsentries} \newacr{ctan}{CTAN} {the Comprehensive \TeX\ Archive Network} {http://mirror.ctan.org/} \newacr{tug}{TUG}% {\TeX\ User Group}% {http://tug.org/} \newacr{uktug}{UK TUG}% {UK \TeX\ User Group}% {http://uk.tug.org/} \newacr{ukfaq}{UK FAQ}% {UK List of \TeX\ Frequently Asked Questions}% {http://www.tex.ac.uk/faq} \newacrx{tds}{TDS}{\TeX\ Directory Structure} \newacrnocite{gui}{GUI}{graphical user interface} \definecolor{midgray}{gray}{0.4} \indexpreamble{\latexhtml{Page numbers}{Locations} in \textit{italic} indicate the primary reference. \latexhtml{Page numbers}{Locations} in \textbf{bold} indicate the entry definition in the summary.} \newcommand{\xtableref}[1]{\objectref{Table}{#1}} % \figconts[graphics opts]{image}{caption}{label} \newcommand{\figconts}[4][]{% \begin{makeimage}\end{makeimage}\figuretop{#4} \centering \incPgfOrGraphics[#1]{#2}% #3% caption \label{#4}% } \newcommand{\latexbook}{\emph{\LaTeX: A Document Preparation System}~\cite{lamport94}} \newcommand{\latexcomp}{\emph{The \LaTeX\ Companion}~\cite{goossens94}} \newcommand{\latexguide}{\emph{A Guide to \LaTeX}~\cite{kopka95}} \newcommand{\latexgraphic}{\emph{The \LaTeX\ Graphics Companion}~\cite{goossens97}} \newcommand{\latexweb}{\emph{The \LaTeX\ Web Companion}~\cite{goossens99}} \newcommand{\baseurl}{http://www.dickimaw-books.com} \newcommand{\packageurl}{\baseurl/latex/packages} \newcommand{\exerciseurl}{\baseurl/latex/novices/html/exercises} \newcommand{\pderiv}[2]{\frac{\partial #1}{\partial #2}} \newcommand{\e}{\mathrm{e}} \newcommand{\koma}{KOMA-Script} \newcommand*{\backcovertext}{If you choose to buy a copy of this book, Dickimaw Books asks for your support through buying the Dickimaw Books edition to help cover costs.} \copyrighttext{% Copyright \textcopyright\ 2004 Nicola L.~C. Talbot Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and one Back-Cover Text: \dq{\backcovertext} A copy of the license is included in the section entitled \htmlref{\dq{GNU Free Documentation License}}{sec:fdl}. \doifnotbook {% The base URL for this document is: \url{\baseurl/latex/novices/} }% } \renewcommand{\glossaryname}{Summary} \begin{document} \maketitle \frontmatter \setcounter{tocdepth}{2} \setnode{contents} \tableofcontents \setnode{listoffigures} \listoffigures \setnode{listoftables} \listoftables \setnode{listofexercises} \listofexercises \mainmatter %%%%%%%%%%%%%%%% INTRODUCTION %%%%%%%%%%%%%%%%%%%%%%%%%%%% \setnode{introduction} \chapter{Introduction} \label{ch:intro} The aim of this book is to introduce \LaTeX\ to a non-technical person. \LaTeX\ is excellent for producing professional looking documents, however it is a \emph{language} not a word processor\faq{Why is TeX not a WYSIWYG system?}{notWYSIWYG}, so it can take a bit of getting used to, particularly if you have never had any experience using programming languages. \LaTeX\ does take a while to learn, so why should you use it? Here are a few reasons but it is not an exhaustive list: \LaTeX\ is far better at typesetting mathematical equations than word processors. I~wrote my Ph.D. thesis back in the days of \LaTeX2.09 (the old version of \LaTeX) and given the high quantity of mathematics that I~had to typeset, it would have taken me considerably longer to write it in a word processor, and the resulting document wouldn't have looked nearly as good. Even Microsoft have acknowledged \glsterm{tex}'s high-quality mathematical typography~\cite{sargentiii}. \xminisec{Example:} Here's an equation taken from some kernel survival analysis: \begin{result}[latexintromaths.html] \newcommand{\me}{\mathrm{e}} \newcommand{\pfrac}[2]{\frac{\partial #1}{\partial #2}} \[ \pfrac{^2\mathcal{L}}{{z_i^\rho}^2} = -\pfrac{\rho_i}{z_i^\rho}\left(\pfrac{v_i}{\rho_i}\frac{\me^{v_i}}{1-\me^{v_i}} +v_i\frac{\me^{v_i}\pfrac{v_i}{\rho_i}(1-\me^{v_i})+\me^{2v_i}\pfrac{v_i}{\rho_i}}{(1-\me^{v_i})^2}\right) \] \end{result} (You can find out how to create this equation \latexhtml{on page~\pageref{introeq} in \sectionref{sec:delimiters}}{\htmlref{later}{introeq}}.) That's all very well and good if you want to typeset some equations, but if your work doesn't involve maths, does that mean that \LaTeX\ is not for you? Although I~am a mathematician, I~have written plenty of documents with no maths in at all, including prose, poetry, newsletters, posters and brochures, but I~still opt for \LaTeX\ because using \LaTeX\ ensures consistent formatting, and the style of the document can be completely changed by simply using a different \glsterm{cls}, or loading additional \htmlref{packages}{sec:packages}. This means that I~can concentrate on writing the document, rather than worrying about how it will look. It also means that if, after having written a 200 page document, I~then find that I~need to change all the figure captions so that they are labelled \dq{Fig} instead of \dq{Figure}, all I~need to do is edit a single line, rather than going through 200 pages to individually edit every single figure caption.\footnote{Sure, you could use a search and replace function, but a sweeping replace-all can have unexpected side effects. For example, your document may include the sentence, \dq{Figures from the last quarter showed improvement}, which would get changed to, \dq{Figs from the last quarter showed improvement}.} Serious fiction writers are taught never to remind the reader that they're reading a book. Poor formatting is just as much a reminder of this as authorial intrusion. \LaTeX\ makes it very easy to cross-reference chapters, sections, equations, figures, tables etc, and it also makes it very easy to generate a table of contents, list of figures, list of tables, index, glossary\footnote{Glossaries are covered in \latexthesis.}\ and bibliography. You don't need to worry about numbering anything, as this is done automatically, which means that you can insert new sections or swap sections around without having to worry about updating all the section numbering etc. Furthermore, if you use \BiBTeX\footnote{Automating bibliographies is covered in \latexthesis.}\ in combination with \LaTeX, and you have, say, 100 or more citations, it doesn't matter if you are then told that the citations have to be re-ordered (say, in order of citation rather than alphabetically). All that is required is a minor edit to change the appropriate style file rather than ploughing through the entire document changing all the citations by hand. When you are editing a document using a word processor, the word processor has to work out how to reformat the document every time you type something. If you have a large document with a great many inserted objects (such as figures and equations), the response to keyboard input can become very slow. You may find that after typing a few words you will have to wait until the computer catches up before you can see what you have typed. With \LaTeX\ you type in your code using an ordinary text editor. The document doesn't get formatted until you pass it to \LaTeX, which means that you are not slowed down by constant reformatting. Lastly, there's the fact that \LaTeX\ follows certain typographical rules, so you can leave most of the typesetting to \LaTeX. You rarely need to worry about minor things such as \glstext{intersentencespacing}. The default is English spacing, but if you have a publisher who disapproves of this, you can switch if off with a single command. (See \sectionref{sec:intersentencespacing}.) \LaTeX\ will also automatically deal with f-ligatures.\footnote{Ligatures can be suppressed using the \isty{microtype} package if necessary} That is, if any of the following combination of letters are found: \texttt{fl}, \texttt{ffl}, \texttt{ff}, \texttt{fi}, \texttt{ffi}, they will automatically be converted into the corresponding ligatures: % Using CMR as the ligatures are more noticeable than with anttor. % make latex2html convert this text into an image \makeimg{fl ligature}{\cmr{fl}}, \makeimg{ffl ligature}{\cmr{ffl}}, \makeimg{ff ligature}{\cmr{ff}}, \makeimg{fi ligature}{\cmr{fi}}, \makeimg{ffi ligature}{\cmr{ffi}}. Note the difference between \makeimg{fl-ligature u ffi-ligature e r}{\cmr{fluffier}} (2 ligatures) and \makeimg{fluffier}{\cmr{f{}l{}uf{}f{}i{}er}} (no ligatures). These points may seem minor but they all contribute towards the impact of the entire document. When writing technical documents, the presentation as well as the content is important. All too often examiners or referees are put off reading a document because it is badly formatted. This provokes an immediate negative reaction and provides little desire to look favourably upon your work. To give you an idea of what you can do with \LaTeX, this book was written in \LaTeX.\footnote{The source code is available at \url{\baseurl/latex/novices/}, but it really is \emph{not} the place to start if you are a beginner, as it contains \LaTeX\ and \glsterm{perl} code beyond the scope of this tutorial.} The PDF versions (including \ifbookorother{this}{the} paperback version) were generated using PDF\LaTeX\ and \appname{makeindex} and the HTML version was generated using the \latexhtml {\LaTeX2HTML\footnote{\url{http://www.latex2html.org/}}}% {\htmladdnormallink{\LaTeX2HTML}{http://www.latex2html.org/}}% \faq{Conversion from (La)TeX to HTML}{LaTeX2HTML} converter. For more reasons as to why you might want to use \LaTeX\ instead of a word processor, have a look at \ifbookorother {\url{http://www.ctan.org/what_is_tex.html\#whytex}.}% {\htmladdnormallink{Why TeX?}{http://www.ctan.org/what_is_tex.html\#whytex}} \setnode{texdoc} \section{Class and Package Documentation} \label{sec:texdoc} There are hundreds of \htmlref{classes}{sec:cls} and \htmlref{packages}{sec:packages} available on \gls{ctan}. These are made available by many volunteers. Some provide detailed documentation to accompany their contribution, while others only provide a few notes in a README file or comments in the source files. This book only provides an introductory look at a small selection of these contributions. If you want further details on how to use a particular class or package you should check the documentation that accompanies it. You can use the \iappname{texdoc} application to search for the documentation. This is a command line application, which means you need a terminal or command prompt (see \sectionref{sec:terminal}). To use \appname{texdoc}, you need to type (at the command prompt) \appname{texdoc} followed by a space followed by the name of the class or package you want information about. For example, to read the \icls{memoir} documentation, type the following at the \htmlref{command prompt}{sec:terminal} (press the return/enter key \enter\ at the end of the line): \begin{verbatim} texdoc memoir \end{verbatim} Some packages come with more than one set of documentation. For example, the \isty{glossaries} package comes with the main user manual, a short guide for beginners and the documented code for advanced users. Just doing \begin{verbatim} texdoc glossaries \end{verbatim} will display the advanced documented code. To list all available documentation for a package, use the \texttt{-l} option: \begin{verbatim} texdoc -l glossaries \end{verbatim} Then type the number corresponding to the file you want to view. If you can remember the file name (for example \texttt{glossaries-user}) you can type that next time you want to view it: \begin{verbatim} texdoc glossaries-user \end{verbatim} There is also a \glsterm{perl}/Tk-based \gls{gui} called \iappname{texdoctk}, which is distributed with \texdistro{TeX~Live}, that you can use instead of \appname{texdoc} if you can't work out how to use a \glsterm{terminal} or prefer a \gls*{gui} approach. Failing that, you can also check on \gls{ctan} using the URL \texttt{ctan.org\slash pkg\slash}\meta{name}, where \meta{name} is the name of the package or class. For example, if you want to look up the documentation for the \icls{memoir} package, you can find it at \url{http://ctan.org/pkg/memoir} or go to \url{http://mirror.ctan.org/} and search for the package or class. Another alternative recently made available is to use the URL \texttt{texdoc.net\slash pkg\slash}\meta{name}. For example, \url{http://texdoc.net/pkg/memoir} will fetch the documentation for the \icls{memoir} class. However, it's better to use \appname{texdoc} or \appname{texdoctk} to read the documentation installed with the class or package on your computer to ensure it matches the installed class or package version. Note that it is important to remember that the \glsterm{tex} world is mostly supported by volunteers. \gls{ctan} itself is maintained by a very small group (currently two people). It's not like a commercial company with 24/7 support and hundreds of paid employees constantly updating the software. At its core, \TeX\ is a community effort. While some volunteers actively maintain and update their classes or packages, some people move on to other things and stop maintaining their work. Occasionally, if the class or package is popular, someone else might take over maintenance. There is no dedicated helpdesk to go to, but there are many ways of getting help, see \appendixref{ch:help} \setnode{overview} \section{Overview} This document is structured as follows: \begin{description} \item[\chapterref{ch:def}] defines terms that will be used throughout this document. I strongly suggest that you look through this \latexhtml{chapter}{section} before you start so that you understand the terminology used in this document. At the very least, you should read the first part that details how corresponding input and output is displayed in this document\dash you need to understand the difference between \dq{input} (source code) and \dq{output} (how the source code will appear in the typeset document).\html{ Note that it is not always possible to reproduce an exact replica of the output in the HTML version, so if in doubt, look at one of the PDF versions instead, which can be downloaded from this book's \htmladdnormallink{home page}{../index.html}.} \item[\chapterref{ch:tex2pdf}] details the software that you will need to use \LaTeX\ and describes how to use the software. \item[\chapterref{ch:simpledoc}] shows you how to create a very basic document. \item[\chapterref{ch:sections}] shows you how to create chapters and other sectional units so that you end up with a fully structured document. \item[\chapterref{ch:graphicx}] shows you how to include external image files and how to scale and rotate text. \item[\chapterref{ch:floats}] describes how to create figures and tables. \item[\chapterref{ch:newcom}] describes how to define your own commands, and redefine existing commands. \item[\chapterref{ch:maths}] describes how to typeset mathematics. \item[\chapterref{ch:newenv}] describes how to define new environments. \item[\chapterref{ch:counters}] discusses how numbers are stored in counters, how to change their values, and how to define your own counter. \item[\appendixref{ch:installsty}] shows you how to download and install additional packages that weren't installed with your \TeX\ distribution. \item[\appendixref{ch:errors}] documents possible errors you may encounter, and gives advice on how to fix them. \item[\appendixref{ch:help}] gives pointers on where to go for help. \end{description} Throughout this document there are pointers to related topics in the \gls{ukfaq}. \latexhtml{These are displayed in the margin in square brackets, as illustrated on the \ifbookorother{\ifthispageodd{right}{left}}{right}.}{% These are displayed in the text like this:}% \faq{What is LaTeX?}{latex} You may find these resources useful in answering related questions that are not covered in this book. \begin{latexonly} \doifbook{% To find the resources, go to \url{http://www.tex.ac.uk/faq} and either look for the question title in the list, or enter a keyword in the search field.% } This book and associated files, including solutions to the exercises, are available on-line at: \url{\baseurl/latex/novices/}. \doifnotbook {% The links in this document are colour-coded: internal links are blue, external links are magenta. }% \end{latexonly} \setnode{reading} \section{Recommended Reading} This document is designed as an introductory text, not a comprehensive guide. For further reading try some of the following\faq{Books on LaTeX}{latex-books}: \latexbook\ is the user guide and reference manual for \LaTeX, and is a good basic text for anyone starting out, however it doesn't cover AMS\TeX\faq{What are the AMS packages?}{AMSpkg}, so anyone who needs to typeset more than basic mathematics may prefer either \latexguide\ or \latexcomp. Both these books cover AMS\TeX, \iBiBTeX\ and \appname{makeindex}. In the same series as \emph{The \LaTeX\ Companion}, there is also \latexgraphic\ which details how to illustrate documents with \LaTeX\ and PostScript, including a chapter on colour (coloured text, background, tables and slides). This is recommended to anyone who is contemplating heavy use of graphics, but you do need a basic knowledge of \LaTeX\ before delving into it. The final book in the \dq{Companion} series which you may find useful is \latexweb. This is recommended for those interested in creating documents for the web, either as HTML or PDF. It details how to convert \LaTeX\ documents into HTML using various applications such as \appname{LaTeX2HTML} and \appname{TeX4ht}, and how to create PDF documents using \iPDFLaTeX\faq{What is PDFTeX?}{whatpdftex}, including how to create active links within your document using the \isty{hyperref} package. There are two new \LaTeX\ books that I haven't read but have been recommended to me: \emph{\LaTeX\ Beginner's Guide}~\cite{kottwitz} and \emph{\LaTeX\ and Friends}~\cite{vandongen}. Note that the \gls{uktug} has a 25\% book discount scheme for members. See \url{http://uk.tug.org/membership} for more details of that and other associated benefits. If you're not in the UK, have a look at \url{http://www.tug.org/usergroups.html} to see if there is a local user group in your area. There is also a wealth of \LaTeX-related information on the Internet\faq{How to get help}{gethelp}. \reportlinebreak\Gls{ctan} is a good place to start. You can check the on-line catalogue~\cite{texcat} for information about available software and, as mentioned earlier, there is also the list of \htmladdnormallink{frequently asked questions}{http://www.tex.ac.uk/faq} which I~recommend you try if you have any queries. See also \appendixref{ch:help} %%%%%%%%%%%%%%%%%%%%%%%%% DEFINITIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \setnode{definitions} \printkeywords \html{\input{novices.hkls}} \glsaddall[types=keywords] %%%%%%%%%%%%%%%%%%%%%% SOURCE TO PDF %%%%%%%%%%%%%%%%%%%%%%%%%% \setnode{fromsource2output} \chapter{From Source Code to Typeset Output} \label{ch:tex2pdf} Every time you want to create or edit a \LaTeX\ document, there are three basic steps you will always need to follow: \begin{enumerate} \item\label{itm:step1} Write or edit the \gls{source}. \item\label{itm:step2} Pass the source code to the \iappname{latex} or \iappname{pdflatex} application (\dq{\LaTeX\ the document}). \begin{itemize} \item If there are any error messages, return to \objectref{Step}{itm:step1}. \item If there are no error messages, a \glslink{output}{PDF file}\indexPDF\ is created. \end{itemize} \item\label{itm:step3} View the \glslink{output}{PDF file} to check the result. If you need to modify your document, go back to \objectref{Step}{itm:step1}. \end{enumerate} You will therefore need: \begin{enumerate} \item A text editor (to perform \objectref{Step}{itm:step1}). For example \iappnamelink[,]{Vim}{http://www.vim.org/} \iappnamelink{Emacs}{http://www.gnu.org/software/emacs/} or \iappnamelink[.]{Gedit}{http://projects.gnome.org/gedit/} \refstepcounter{object}\label{obj:MiKTeX}% \item The \gls{tex} software\faq{(La)TeX for different machines}{TeXsystems} (to perform \objectref{Step}{itm:step2}). If you don't already have \TeX\ on your machine, you will need to install it. The most convenient way to do this is to install from the \TeX\ Collection DVD ROM, which is distributed to all \gls{tug} members, but you can also download and install free \TeX\ distributions, such as \itexdistro{TeX~Live}, \itexdistro{MiKTeX} or \itexdistro{MacTeX}, from the Internet (see \xpageref{below}{obj:install}). There is also \itexdistro{proTeXt}, an enhancement of \texdistro{MiKTeX} that aims to be an easy-to-install \TeX\ Distribution. For more information including up-to-date links, go to \url{http://www.ctan.org/starter.html}. \item A PDF viewer (to perform \objectref{Step}{itm:step3}). For example \iappnamelink[,]{Adobe Reader}{http://www.adobe.com/} \iappnamelink[,]{Sumatra}{http://blog.kowalczyk.info/software/sumatrapdf/free-pdf-reader.html} \iappnamelink{Evince}{http://projects.gnome.org/evince/} or \iappnamelink[.]{Okular}{http://okular.kde.org/} \end{enumerate} This can be rather complicated for a beginner, especially for those with no experience writing computer code. Fortunately, there are some all-in-one applications (often called a \keyword{front-end}) that provide a text editor (for \objectref{Step}{itm:step1}), buttons or menu items to run the \appname{latex} or \appname{pdflatex} \glslink{terminal}{command-line application} (for \objectref{Step}{itm:step2}) and, in some cases, a viewer to perform \objectref{Step}{itm:step3}. \sectionref[The next section]{sec:texworks} describes one such front-end called \iappnamelink[.]{TeXWorks}{http://www.tug.org/texworks/} I~have chosen to describe TeXWorks because it is a free, cross-platform application. Binaries are available for Microsoft Windows, Mac~OS~X and GNU/Linux. The screen shots of TeXWorks in this book were taken from the Linux version running under Fedora. If you run TeXWorks on other operating systems, it may have a slightly different look, but it has the same functionality. New versions of \texdistro{TeX~Live} and \texdistro{MiKTeX} include TeXWorks for MS~Windows, and new versions of \texdistro{MacTeX} include TeXWorks for Mac~OS~X users. GNU/Linux users can use their Add\slash Remove Software utility to install TeXWorks. Alternatively, you can download TeXWorks by following the links provided at \url{http://www.tug.org/texworks/}. \refstepcounter{object}\label{obj:install}% If you're confused by all the options, let's keep things as simple as possible: \begin{itemize} \item MS~Windows: You have a choice between \texdistro{MiKTeX} (or \texdistro{proTeXt}) and \texdistro{TeX~Live}. \texdistro{MiKTeX} provides a smaller and quicker installation, but the downside is that you may not have the classes or packages you want to use. \texdistro{MiKTeX} can install these whenever you try to \LaTeX\ a document that uses them, but you need an Internet connection while it does this. \texdistro{TeX~Live} installs everything, so it takes longer and needs more space, but you should have the majority of packages and classes that you need. \begin{description} \item[TeX~Live:]\mbox{} \begin{enumerate} \item Fetch and unpack \url{http://mirror.ctan.org/systems/texlive/tlnet/install-tl.zip} \item Run \iappname{install-tl} and follow the instructions. This can take an hour or more. \end{enumerate} \item[proTeXt:]\mbox{} \begin{enumerate} \item Go to \url{http://tug.org/protext/} \item Click on the \dq{download the self-extract protext.exe} link to download and run the executable. \end{enumerate} \item[MiKTeX:]\mbox{} \begin{enumerate} \item Go to \url{http://www.miktex.org/} \item In the left-hand panel, there is a link to the download page for the latest version. At time of writing, it is \texdistro{MiKTeX}~2.9. Click on that link. \item Scroll down to the section \dq{Installing a basic \texdistro{MiKTeX} system}. \item If you're happy with the selected mirror location, click on the \dq{Download} button. \item Run the executable. \end{enumerate} \end{description} \item Mac~OS~X: \begin{enumerate} \item Go to \url{http://tug.org/mactex/} \item Follow the instructions on that page. \end{enumerate} \item GNU/Linux: \begin{enumerate} \item Fetch and unpack \url{http://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz} \item Follow the instructions at \url{http://tug.org/texlive/quickinstall.html} \item Once \texdistro{TeX~Live} has finished installing, run your system's \dq{Add\slash Remove Software} tool. \item Find \dq{texworks}, select the newest version and install. \end{enumerate} \end{itemize} If you run into problems, there are mailing lists at \url{http://tug.org/mailman/listinfo/tex-live} and \url{http://docs.miktex.org/manual/lists.html} for \itexdistro{TeX~Live} and \itexdistro{MiKTeX}, and \itexdistro{MacTeX} help at \url{http://www.tug.org/mactex/help/}. There is also a list of places where you can ask for help in \appendixref{ch:help}. %%%%%%%%%%%%%%%%%%% TeXWorks %%%%%%%%%%%%%%%%%%%%% \setnode{texworks} \section{TeXWorks} \label{sec:texworks} Hopefully you've managed to successfully install \gls{tex} and TeXWorks as described \latexhtml{above}{in the \htmlref{previous section}{ch:tex2pdf}}, so let's test it out. First run TeXWorks. On Windows, you can access it via the \menu{Start} menu. On GNU/Linux, it's probably located in \menu{Applications}\menuto\menu{Office}, or you can type \iappname{texworks} in a \gls{terminal}. You should now see the TeXWorks window. The button marked with a grey triangle in a green circle is the build or typeset function. It runs the application in the drop-down list next to it. This is set to pdfLaTeX, which is what we want for now. It's a good idea to switch on the syntax highlighting, if it isn't already on. This is done via the \menu{Format}\menuto\menu{Syntax Coloring} sub-menu. Make sure the \menu{LaTeX} item is selected. Next, type in the following sample source code, as shown in \figureref{fig:texworks2} (the commands used here will be described in more detail in \chapterref{ch:simpledoc}): \begin{code} \begin{verbatim} \documentclass{scrartcl} \begin{document} This is an example document. \end{document} \end{verbatim} \end{code} \textbf{Pay close attention to the backslashes at the start of each command name.} If you find the font is a bit too small for you, you can make it larger using the \menu{Format}\menuto\menu{Font} menu item. \emph{This doesn't affect the font size in your PDF file, just the font size of your code.} This displays the \dq{Select Font} dialog box. Set the font size as appropriate. Then save the document, using the \menu{File}\menuto\menu{Save As} menu item. I~called my document \texttt{example1.tex} (remember the \texttt{.tex} extension and stick to file names that only consist of alphabetical characters, digits and hyphens\dash don't uses spaces or underscores). \begin{figure}[htbp] \figconts {pictures/texworks2} {% \caption[Source Code for an Example Document]{Source Code for an Example Document. (Syntax highlighting switched on.)}% }% {fig:texworks2} \end{figure} Now that you have saved the file, you can run pdfLaTeX. Make sure the drop-down list next to the build button has \dq{pdfLaTeX} selected and click on the build button. If all goes well, a new window should open displaying the typeset document (\figureref{fig:texworks3}). \begin{figure}[htbp] \figconts {pictures/texworks3} {% \caption{The Typeset Document} }% {fig:texworks3} \end{figure} \begin{figure}[htbp] \figconts {pictures/texworks4} {% \caption{The Source Code Has a Misspelt Command} }% {fig:texworks4} \end{figure} Now let's see what happens if there is an error in the source code. In \figureref{fig:texworks4} I~have misspelt the \glsni{documentclass} command. This time, when I~click on the build button, I~get the error message: \begin{verbatim} ! Undefined control sequence. l.1 \documentclas {scrartcl} ? \end{verbatim} (Shown in \figureref{fig:texworks5}.) \begin{figure}[htbp] \figconts {pictures/texworks5-annote} {% \caption{An Error Message is Displayed}% }% {fig:texworks5} \end{figure} Here \dq{Undefined control sequence} means an unrecognised command, and below that message, \dq{\texttt{l.1}} means the error was encountered on line~1. An input line at the bottom of the window has appeared with a cursor. \LaTeX\ is in interactive mode and is awaiting a response. There are several responses, but I'm only going to mention two of them: \begin{enumerate} \item Type \texttt{h} and press the Return/Enter key \enter. This displays a short help message and awaits a new response (see \figureref{fig:texworks6}). \item Type \texttt{x} and press Return/Enter. This aborts the \LaTeX\ run. \end{enumerate} Notice that the green circle button with the grey triangle has turned into a red stop button. This button can be used to abort the process instead of typing \texttt{x}. \begin{figure}[htbp] \figconts {pictures/texworks6} {% \caption{A Short Help Message}% }% {fig:texworks6} \end{figure} Now, there is a second tab at the bottom of the TeXWork's window (\figureref{fig:texworks7}). This lists the error message and provides a link to the line where the error occurred. Clicking on this link highlights line~1. Next I~need to fix the error by correcting the spelling of the command. Once it's fixed, I~can click on the build button. \begin{figure}[htbp] \figconts {pictures/texworks7} {% \caption{Error Tab}% }% {fig:texworks7} \end{figure} Here's another error you might encounter: I'm now going to misspell the class name. It should be \texttt{scrartcl}, but in \figureref{fig:texworks8} it has been misspelt. This time, when I click on the build button, I~get the error: \begin{verbatim} ! LaTeX Error: File `scrartc.cls' not found. \end{verbatim} I~have two choices: type in the correct name on the line below \dq{Enter file name:} or I~can abort the process using the red abort button. In either case I~need to go back and fix the error in my code. \begin{figure}[htbp] \figconts {pictures/texworks8} {% \caption{Misspelt Class File}% }% {fig:texworks8} \end{figure} %%%%%%%%%%%%% CREATING A SIMPLE DOCUMENT %%%%%%%%%%%%%%%%%% \setnode{simpledoc} \chapter{Creating a Simple Document} \label{ch:simpledoc} Having installed and tested the software, let's now look at how to actually write the \gls{source}. The very first line of any document that you create must have the \gls{command}: \begin{definition} \gls{documentclass}\oarg{\meta{option-list}}\marg{\meta{class-name}} \end{definition}% This tells \LaTeX\ what type of document you want to create (for example an article, a technical report or correspondence). The \glsni{documentclass} command takes one \gls{mandatory}, \meta{class-name}, that specifies the \gls{cls}. There are many class files available, and some publishers, institutions or journals provide their own custom classes (for example, the \icls{jmlr} class for the Journal of Machine Learning Research). Popular classes include \icls{memoir} (for books and reports) and those supplied in the \koma\ bundle (for books, reports, articles and correspondence). There's also \icls{beamer} (for presentations) as well as classes for typesetting exams, flashcards, concert programmes etc. For simplicity, this book will concentrate on three of the \koma\ classes \icls{scrartcl} (for articles), \icls{scrreprt} (for technical reports, theses etc) and \icls{scrbook} (for books). We'll start with a very simple document, so let's use the \icls{scrartcl} class file. In this case the very first line of the \gls{source} should be: \begin{codeS} \glsni{documentclass}\marg{scrartcl} \end{codeS} The \glsni{documentclass} command also takes an \gls{optional}, \meta{option-list}, which should be a comma separated list of options to be passed to the class file. This allows you to override the class file defaults. For example, the \icls{scrartcl} class file by default uses A4 paper, but if you are in the USA you will probably want to use letter paper. This can be achieved using the option \clsopt{letterpaper}. So you would need to edit the above line to: \begin{codeS} \glsni{documentclass}\oarg{letterpaper}\marg{scrartcl} \end{codeS} \refstepcounter{object}\label{obj:sizeopt}% Let's change another option. The normal font size is \clsopt{11pt} by default, but we have the option to change it, so let's use \clsopt{12pt}: \begin{codeS} \glsni{documentclass}\oarg{letterpaper,12pt}\marg{scrartcl} \end{codeS} You can also change your document so that it is in a two-column format using the \clsopt{twocolumn} option: \begin{codeS} \glsni{documentclass}\oarg{letterpaper,12pt,twocolumn}\marg{scrartcl} \end{codeS} After deciding what type of document you want, you now need to specify the contents of the document. This is done inside the \gls{env-document} \gls{environment}. The document is started with the command: \begin{codeS} \glsni{begin}\marg{document} \end{codeS} and ended with \begin{codeS} \glsni{end}\marg{document} \end{codeS} (\LaTeX\ stops reading the file when it reaches the above line, so anything occurring after it is ignored.) My \gls{source} now looks like: \begin{code} \glsni{documentclass}[12pt]\marg{scrartcl}\newline \mbox{}\newline \glsni{begin}\marg{document}\newline \mbox{}\newline \glsni{end}\marg{document} \end{code} Every document you create must have this form. You can't simply start typing the document text. You must first specify your class file\indexCLS, and then place the contents of the document inside the \glsni{env-document} environment.\screenpagebreak So far so good, but at the moment we have an empty document, so we won't get any output. Let's now put some text into our document: \begin{code} \begin{alltt} \glsni{documentclass}\oarg{12pt}\marg{scrartcl} \glsni{begin}\marg{document} This is a simple document. Here is the first paragraph. Here is the second paragraph. As you can see it's a rather short paragraph, but not as short as the previous one. \glsni{end}\marg{document} \end{alltt} \end{code} \xminisec{Top Five Mistakes Made by New Users} I first started teaching \LaTeX\ in 1998, and these are the most common errors I've seen when people start learning \LaTeX: \begin{enumerate} \item Missing out the backslash \glsni{backslashchar} at the start of one or more of the \glspl{command}. \item Using a forward slash \glsni{slashchar} instead of a backslash \glsni{backslashchar}. \item Forgetting \texttt{\glsni{end}\marg{document}}. \item Misspelling \dq{document} (in \texttt{\glsni{begin}\marg{document}} and \texttt{\glsni{end}\marg{document}}). \item Missing a closing brace \glsni{rightbracechar}. \end{enumerate} If you encounter any problems when you start out, go through that check list first. Then check \appendixref{ch:errors}. Whenever you start a new document, always type in the \glsni{documentclass}, \texttt{\glsni{begin}\marg{document}} and \texttt{\glsni{end}\marg{document}} commands first (\figureref{fig:newdoc-1}). Then move your cursor between the \glsni{begin} and \glsni{end} lines and type the document text (\figureref{fig:newdoc-2}). \begin{figure}[htbp] \figconts {pictures/newdoc-1} {% \caption[Starting a New Document (1)]{Starting a New Document: always type these three lines first.}% }% {fig:newdoc-1} \ifscreenorother {% \end{figure} \begin{figure}[htbp] }% {% \strut } \figconts {pictures/newdoc-2} {% \caption[Starting a New Document (2)]{Starting a New Document: move the cursor inside the \glsni{env-document} environment and start typing the document text.}% }% {fig:newdoc-2} \end{figure} \begin{exercise}{Simple Document}{ex:simpledoc} Try typing the code in the above example into TeXWorks or the editor of your choice (see \chapterref[the previous section]{ch:tex2pdf} if you can't remember what to do.) You can also \download{simpledoc} a copy of this file, but I~recommend that you try typing it in to give yourself some practice. Things to note while you are typing: firstly, when you press the return character at the end of a line this end-of-line character is converted into a space in the \gls{output}. So the fact that I~have some very ragged lines in my \gls{source} has no effect on the final result. (Note that some front-ends will reformat your lines as you type.) Whereas a completely blank line will be converted into a paragraph break (\gls{par} has the same effect). Secondly, multiple \Index{spaces} are converted into a single space, so the large gap between the words \dq{\texttt{can}} and \dq{\texttt{see}} is no different from having a single space. Once you have typed up your \gls{source}, save your file (called, for example, \texttt{exercise1.tex}), and run PDF\LaTeX\ as described in \sectionref{sec:texworks}. If all goes well, TeXWorks should display the resulting PDF file in a new window, usually alongside the window containing the source code. \xminisec{Notes:} \begin{enumerate} \item Each paragraph automatically starts with an indentation in the PDF. \item There is no blank line between the paragraphs in the PDF document. (See what happens if you add the \koma\ class option \scrclsopt[full]{parskip}: \begin{codeS} \glsni{documentclass}\oarg{12pt,parskip=full}\marg{scrartcl} \end{codeS} and rebuild the PDF.) \item Move the mouse over one of paragraphs in the PDF viewer and pop-up the context menu (usually a right mouse click). Select \menu{Jump to Source}. The window containing the source code should now gain the focus and the line of code matching the typeset line you clicked on in the PDF should now be highlighted. \end{enumerate} \end{exercise} %%%%%%%%%%%%%%%%%% Simple Commands %%%%%%%%%%%%%%%%%% \setnode{simplecommands} \section{Using Simple Commands} \label{sec:simple} \faq{Typesetting all those TeX-related logos}{logos}Now let's try adding a few simple \glspl{command} to our document. The command \gls{LaTeX} produces the \makeimg{ALT=LaTeX}{\LaTeX} logo and the command \gls{today} prints the current date. \LaTeX\ always ignores any spaces that follow a command name that consists of letters, as it uses the space to indicate the end of the command name. This means that if we want a space to occur immediately after the command, we need to explicitly say so using the command \gls{spacesym} (recall from \ifscreenorother{\htmlref{earlier}{obj:visiblespace}}{page~\pageref{obj:visiblespace}} \gls{visiblespace} indicates a space character). So, for example: \begin{codeS} \glsni{LaTeX}\glsni{spacesym}logo \end{codeS}% produces the output: \begin{resultS}[LaTeX logo] \LaTeX\ logo \end{resultS}% Some people when starting out can get a bit confused by this and read it as the entity \dq{\cmdname{LaTeX}\cmdname{}} whereas it is in fact two commands: \dq{\cmdname{LaTeX}} (print the \LaTeX\ logo) followed \dq{\cmdname{\ }} (print a space.) Let's also try using a command that takes an \gls{argument}. The command \begin{definition} \gls{footnote}\refstepcounter{object}\label{cmd:footnote}\marg{\meta{text}} \end{definition}% takes one argument that specifies the text that should appear in the footnote. This command must be placed where you want the footnote marker to appear. \begin{exercise}{Using Simple Commands}{ex:simple} Edit the document you created in \exerciseref{ex:simpledoc}, so that it looks like the following: (You can \download{simple} it if you like, but again it is better if you try typing it in yourself.) \begin{bcode} \glsni{documentclass}\oarg{12pt}\marg{scrartcl}\newline \mbox{}\newline \glsni{begin}\marg{document}\newline \mbox{}\newline This is a simple \glsni{LaTeX}\glsni{spacesym}document. Here is the first paragraph.\newline \mbox{}\newline Here is the second paragraph\glsni{footnote}\marg{with a footnote}. As you can see it's a rather short paragraph, but not as short as the previous one. This document was created on: \glsni{today}.\newline \glsni{end}\marg{document} \end{bcode} Now \htmlref{\LaTeX\ your document}{ch:tex2pdf} and view the result. (Remember to check \appendixref{ch:errors} if you have a problem.) You should see the \LaTeX\ logo, the footnote marker and the current date. If you scroll down to the bottom of the page, you should see the footnote. \end{exercise} %%%%%%%%%%%%%%%%%%%%%%%%%% PACKAGES %%%%%%%%%%%%%%%%%%%%%%%% \setnode{packages} \section{Packages} \label{sec:packages} Packages\indexSTY\ are files with the extension \texttt{.sty} that either define new \glspl{command} or redefine existing commands\faq{What are LaTeX classes and packages?}{clsvpkg}. They're like a type of add-on or plug-in. Most of the commonly used packages should have been installed when you installed your \gls{tex} distribution (see \chapterref{ch:tex2pdf}). \appendixref{ch:installsty} covers how to install new packages. Most packages come with documentation that can be accessed using the \iappname{texdoc} application described in \sectionref{sec:texdoc}. Packages are loaded in the \gls{preamble} (after \gls{documentclass} and before \glsni{begin}\marg{document}) using \begin{definition} \gls{usepackage}\oarg{\meta{option list}}\marg{\meta{package}} \end{definition} where \meta{package} is the name of the package and \meta{option list} is a list of comma-separated options. For example, to load the package \isty{graphicx} with the \istyopt{graphicx}{draft} option: \begin{codeS} \glsni{usepackage}\oarg{draft}\marg{graphicx} \end{codeS} Any applicable class options are also passed to packages, so in \begin{code} \gls{documentclass}\oarg{draft}\marg{scrartcl}\newline \glsni{usepackage}\marg{graphicx} \end{code} the \clsopt{draft} option is set for both the \icls{scrartcl} class and the \isty{graphicx} package. You can specify more than one package in the argument of \glsni{usepackage}, where each package name is separated by a comma. For example: \begin{codeS} \glsni{usepackage}\marg{amsmath,amsfonts} \end{codeS} The \isty{graphicx} package is covered in \chapterref{ch:graphicx} and the \isty{amsmath} package is covered in \chapterref{ch:maths}, so let's start out with a~relatively simple example. \setnode{datetime} \subsection{Changing the Format of \latexhtml{\texorpdfstring{\protect\cmdname{today}}{\protect\textbackslash today}}{\protect\cmdname{today}}} \label{sec:today} In the \htmlref{previous exercise}{ex:simple}, we used the \gls{today} command to produce the current date. By default, this command displays the date in US format. To illustrate how to use packages, this section will look at how to use the \isty{datetime} package to change the way that \gls{today} displays the date. The \isty{datetime} package has various options that can be used to change the format of \gls{today}. For example, by default the \isty{datetime} package redefines \gls{today} to display the date in the form: {\showdowtrue\longdate \renewcommand{\fmtord}[1]{\textsuperscript{#1}}\docdate}. The option \istyopt{datetime}{short} will produce an abbreviated form, (for example {\shortdate\docdate}) and the option \istyopt{datetime}{nodayofweek} won't display the day of the week (for example {\showdowfalse\docdate}). For those who don't like the raised ordinal, there is the \istyopt{datetime}{level} option. These can be passed as a comma separated list in the \gls{optional} to the \gls{usepackage} command. It is also possible to use a declaration instead. For example, to redefine \gls{today} to display the date in the form {\ddmmyyyydate\docdate}, you can either do \begin{codeS} \glsni{usepackage}\oarg{ddmmyyyy}\marg{datetime} \end{codeS}% or \begin{code} \begin{alltt} \glsni{usepackage}\marg{datetime} \gls{ddmmyyyydate} \end{alltt} \end{code} The \isty{datetime} package also defines the command \begin{definition} \gls{currenttime} \end{definition} which displays the current time, where again the format can be changed by the package options. So the option \istyopt{datetime}{12hr} will cause \glsni{currenttime} to display the date in 12 hour format (for example, \ampmtime) and the option \istyopt{datetime}{24hr} will cause \glsni{currenttime} to display the date in 24 hour format (for example, \xxivtime). \begin{exercise}{Using the datetime Package}{ex:datetime} Edit your document from \exerciseref{ex:simple} so that it uses the \isty{datetime} package. Experiment with the different package options, for example \begin{codeS} \glsni{usepackage}\oarg{short,nodayofweek,level,12hr}\marg{datetime} \end{codeS} and add the current time \begin{codeS} This document was created on: \glsni{today}\glsni{spacesym}at \glsni{currenttime}. \end{codeS} You can \downloadorview{datetime} an example. For a full list \isty{datetime} of package options, see the \sty{datetime} \htmlref{documentation}{sec:texdoc}. \latex{(Refer to \sectionref{sec:texdoc} on how to find package documentation.)} \end{exercise} %%%%%%%%%%%%%%%%%%%%%% Special Characters %%%%%%%%%%%%%%%%%%%% \setnode{symbols} \section{Special Characters and Symbols} \label{sec:chars} You can use most of the standard characters that you find on your keyboard, but the 10 symbols shown in \tableref{tab:specialchars} have a special meaning. \begin{table}[htbp] \caption{Special Characters} \label{tab:specialchars} \centering \begin{makeimage}\end{makeimage} \glsi{leftbracechar} \glsi{rightbracechar} \glsi{percentchar} \glsi{ampchar} \glsi{dollarchar} \glsi{hashchar} \glsi{underscorechar} \glsi{circumchar} \glsi{tildechar} \glsi{backslashchar} \end{table} We have already used the curly braces \gls{leftbracechar} and \gls{rightbracechar}. The percent symbol \gls{percentchar} is a comment character. Everything from the percent symbol up to the end of line is ignored by \LaTeX. This means you can have comments in your \gls{source} to remind you what a particular part of your code is doing. We have also used the backslash symbol \glsni{backslashchar} which indicates that we are using a \LaTeX\ command, as in \glstext{LaTeX} or \glstext{today}. The meaning of the other special characters will be covered later. So what do you do if you want one of these symbols to actually appear in your document? \faq{Where can I find the symbol for \ldots?}{symbols} \tableref{tab:symbols} lists commands that produce these and other symbols\faq{How to get copyright, trademark, etc}{tradesyms}. Note that some of the commands have short cuts, such as \glsni{emdash} instead of \glsni{textemdash} and \glsni{questiondown} instead of \glsni{textquestiondown}. The symbol \texttt{`} is the backtick (or grave) symbol, as opposed to the apostrophe symbol~\texttt{'}. \latexhtml{The backtick symbol usually looks like~\texttt{\`{}} on a keyboard, and on}{On} most UK keyboards it is situated to the left of the \texttt{1}~key. The opening double quote is created using two adjacent backtick symbols and the closing double quote with two adjacent apostrophe symbols. This gives 66 and 99 style quotes, which you wouldn't get using the double quote symbol on your keyboard. Note that the symbols \gls{barchar} \gls{ltchar} and \gls{gtchar} have to be created using \glsni{textbar}, \glsni{textless} and \glsni{textgreater} when in normal text mode. If you try to enter them using the corresponding keyboard characters you may get \makeimg{em dash}{\textemdash} \makeimg{upside down exclamation mark}{\textexclamdown} and \makeimg{upside down question mark}{\textquestiondown}. (They do however work if you are in \htmlref{maths mode}{ch:maths}.\footnote{There are also some text fonts that will display them correctly, but don't rely on it.}) The slash character \gls{text.slash} may be used directly, as in \dq{\texttt{and\glsni{text.slash}or}}, but no line break will be permitted at the slash, whereas \glsni{slash} (as in \dq{\texttt{and\glsni{slash}\glsni{visiblespace}or}}) will allow a line break at that point. \begin{table}[htbp] \caption{Symbols} \label{tab:symbols} \centering \begin{latexonly} \begin{tabular}{@{}ll@{\hspace{4\tabcolsep}}ll@{\hspace{4\tabcolsep}}ll@{}} \begin{inlinedef}\gls{textbackslash}\end{inlinedef} & \textbackslash& \begin{inlinedef}\gls{slash}\end{inlinedef} & \slash & \begin{inlinedef}\gls{textgreater}\end{inlinedef} & \textgreater \\ \begin{inlinedef}\gls{textasciicircum}\end{inlinedef} & \textasciicircum & \begin{inlinedef}\gls{dollar}\end{inlinedef} & \$ & \begin{inlinedef}\gls{textbar}\end{inlinedef} & \textbar \\ \begin{inlinedef}\gls{textasciitilde}\end{inlinedef} & \textasciitilde& \begin{inlinedef}\gls{leftbrace}\end{inlinedef} & \{ & \begin{inlinedef}\gls{textless}\end{inlinedef} & \textless \\ \begin{inlinedef}\gls{pounds}\end{inlinedef} & \pounds & \begin{inlinedef}\gls{rightbrace}\end{inlinedef} & \} & \begin{inlinedef}\gls{dag}\end{inlinedef} & \dag \\ \begin{inlinedef}\gls{textregistered}\end{inlinedef}& \textregistered& \begin{inlinedef}\gls{hash}\end{inlinedef} & \# & \begin{inlinedef}\gls{ddag}\end{inlinedef} & \ddag \\ \begin{inlinedef}\gls{texttrademark}\end{inlinedef} & \texttrademark & \begin{inlinedef}\gls{percent}\end{inlinedef} & \% & \begin{inlinedef}\gls{quoteright}\end{inlinedef} or \begin{inlinedef}\gls{textquoteright}\end{inlinedef} & \textquoteright\\ \begin{inlinedef}\gls{copyright}\end{inlinedef} & \copyright & \begin{inlinedef}\gls{amp}\end{inlinedef} & \& & \begin{inlinedef}\gls{quoteleft}\end{inlinedef} or \begin{inlinedef}\gls{textquoteleft}\end{inlinedef} & \textquoteleft \\ \begin{inlinedef}\gls{textbullet}\end{inlinedef} & \textbullet & \begin{inlinedef}\gls{i}\end{inlinedef} & \i & \begin{inlinedef}\gls{quotedblright}\end{inlinedef} or \begin{inlinedef}\gls{textquotedblright}\end{inlinedef} & \textquotedblright\\ \begin{inlinedef}\gls{questiondown}\end{inlinedef} or \begin{inlinedef}\gls{textquestiondown}\end{inlinedef} & ?` & \begin{inlinedef}\gls{j}\end{inlinedef} & \dotlessj & \begin{inlinedef}\gls{quotedblleft}\end{inlinedef} or \begin{inlinedef}\gls{textquotedblleft}\end{inlinedef} & \textquotedblleft\\ \begin{inlinedef}\gls{exclamdown}\end{inlinedef} or \begin{inlinedef}\gls{textexclamdown}\end{inlinedef} & !` & \begin{inlinedef}\gls{dash}\end{inlinedef} & - & \begin{inlinedef}\gls{endash}\end{inlinedef} or \begin{inlinedef}\gls{textendash}\end{inlinedef} & \textendash \\ \begin{inlinedef}\gls{emdash}\end{inlinedef} or \begin{inlinedef}\gls{textemdash}\end{inlinedef} & \textemdash & \begin{inlinedef}\gls{S}\end{inlinedef} & \S & \begin{inlinedef}\gls{textperiodcentered}\end{inlinedef} & \textperiodcentered\\ \begin{inlinedef}\gls{ldots}\end{inlinedef} & \ldots & \begin{inlinedef}\gls{P}\end{inlinedef} & \P & \begin{inlinedef}\gls{underscore}\end{inlinedef} or \begin{inlinedef}\gls{textunderscore}\end{inlinedef}& \_ \end{tabular} \end{latexonly} \begin{htmlonly} \begin{tabular}{ll|ll} \begin{inlinedef}\gls{textbackslash}\end{inlinedef} & \textbackslash& \begin{inlinedef}\gls{underscore}\end{inlinedef}\space or \begin{inlinedef}\gls{textunderscore}\end{inlinedef}& \_ \\ \begin{inlinedef}\gls{dash}\end{inlinedef} & - & \begin{inlinedef}\gls{endash}\end{inlinedef}\space or \begin{inlinedef}\gls{textendash}\end{inlinedef} & \makeimg{en dash character}{\textendash} \\ \begin{inlinedef}\gls{emdash}\end{inlinedef}\space or \begin{inlinedef}\gls{textemdash}\end{inlinedef} & \makeimg{em dash character}{\textemdash} & \begin{inlinedef}\gls{P}\end{inlinedef} & \P \\ \begin{inlinedef}\gls{textasciicircum}\end{inlinedef} & \textasciicircum & \begin{inlinedef}\gls{dollar}\end{inlinedef} & \$ \\ \begin{inlinedef}\gls{S}\end{inlinedef} & \S & \begin{inlinedef}\gls{textasciitilde}\end{inlinedef} & \textasciitilde\\ \begin{inlinedef}\gls{leftbrace}\end{inlinedef} & \{ & \begin{inlinedef}\gls{ldots}\end{inlinedef} & \ldots \\ \begin{inlinedef}\gls{pounds}\end{inlinedef} & \pounds & \begin{inlinedef}\gls{rightbrace}\end{inlinedef} & \} \\ \begin{inlinedef}\gls{dag}\end{inlinedef} & \makeimg{dagger symbol}{\dag} & \begin{inlinedef}\gls{questiondown}\end{inlinedef}\space or \begin{inlinedef}\gls{textquestiondown}\end{inlinedef} & \makeimg{upside-down question mark}{?`} \\ \begin{inlinedef}\gls{textregistered}\end{inlinedef}& \makeimg{registered symbol}{\textregistered}& \begin{inlinedef}\gls{hash}\end{inlinedef} & \# \\ \begin{inlinedef}\gls{ddag}\end{inlinedef} & \makeimg{double dagger symbol}{\ddag} & \begin{inlinedef}\gls{exclamdown}\end{inlinedef}\space or \begin{inlinedef}\gls{textexclamdown}\end{inlinedef} & \makeimg{upside-down exclamation mark}{!`} \\ \begin{inlinedef}\gls{texttrademark}\end{inlinedef} & \texttrademark & \begin{inlinedef}\gls{percent}\end{inlinedef} & \% \\ \begin{inlinedef}\gls{quoteright}\end{inlinedef}\space or \begin{inlinedef}\gls{textquoteright}\end{inlinedef} & \makeimg{closing single quote}{\textquoteright}& \begin{inlinedef}\gls{quotedblright}\end{inlinedef}\space or \begin{inlinedef}\gls{textquotedblright}\end{inlinedef} & \makeimg{closing double quote}{\textquotedblright}\\ \begin{inlinedef}\gls{copyright}\end{inlinedef} & \copyright & \begin{inlinedef}\gls{amp}\end{inlinedef} & \& \\ \begin{inlinedef}\gls{quoteleft}\end{inlinedef}\space or \begin{inlinedef}\gls{textquoteleft}\end{inlinedef} & \makeimg{opening single quote}{\textquoteleft} & \begin{inlinedef}\gls{quotedblleft}\end{inlinedef}\space or \begin{inlinedef}\gls{textquotedblleft}\end{inlinedef} & \makeimg{opening double quote}{\textquotedblleft}\\ \begin{inlinedef}\gls{textbullet}\end{inlinedef} & \makeimg{bullet point}{\textbullet} & \begin{inlinedef}\gls{i}\end{inlinedef} & \makeimg{dotless i}{\i} \\ \begin{inlinedef}\gls{j}\end{inlinedef} & \makeimg{dotless j}{\dotlessj} & \begin{inlinedef}\gls{textbar}\end{inlinedef} & \textbar\\ \begin{inlinedef}\gls{textperiodcentered}\end{inlinedef} & \middot & \begin{inlinedef}\gls{textless}\end{inlinedef} & \textless\\ \begin{inlinedef}\gls{textgreater}\end{inlinedef} & \textgreater& \begin{inlinedef}\gls{slash}\end{inlinedef} & / \\ \end{tabular} \end{htmlonly} \end{table} Ligatures and special symbols are shown in \tableref{tab:ligatures}. (Note that, as mentioned in the \htmlref{introduction}{ch:intro}, the f-ligatures are automatically converted.) When using a command in the middle of a word, take care that the command doesn't run into the rest of the word. For example, the British spelling of the word man\oe{}uvre has an \latexhtml{\oe}{oe}-ligature in the middle of it. You will get an error if you try: \begin{alltt}\wrong man\cmdname{oe}uvre \end{alltt} as \LaTeX\ will interpret it as the command \verb|\oeuvre| which doesn't exist. There are several ways to code this in \LaTeX: \begin{enumerate} \item Place a space after the command: \begin{codeS} man\glsni{oe}\glsni{visiblespace}uvre \end{codeS} \item Place an empty brace after the command: \begin{codeS} man\glsni{oe}\marg{}uvre \end{codeS} \item Group the command: \begin{codeS} man\marg{\glsni{oe}}uvre \end{codeS} (This can adversely affect the kerning so is best avoided.) \end{enumerate} \begin{table}[htbp] \caption[Ligatures and Special Symbols]{Ligatures and Special Symbols (Computer Modern Font)} \label{tab:ligatures} \centering \begin{tabular}{ll@{\hspace{3\tabcolsep}}ll@{\hspace{3\tabcolsep}}ll@{\hspace{3\tabcolsep}}ll} \gls{AE} & \makeimg{upper case AE ligature}{\fontfamily{cmr}\selectfont\AE} & \gls{ae} & \makeimg{lower case ae ligature}{\fontfamily{cmr}\selectfont\ae} & \gls{OE} & \makeimg{upper case OE ligature}{\fontfamily{cmr}\selectfont\OE} & \gls{oe} & \makeimg{lower case oe ligature}{\fontfamily{cmr}\selectfont\oe}\\ \Indextt{fi} & \makeimg{fi ligature}{\fontfamily{cmr}\selectfont fi} & \Indextt{ffi} & \makeimg{ffi ligature}{\fontfamily{cmr}\selectfont ffi} & \Indextt{fl} & \makeimg{fl ligature}{\fontfamily{cmr}\selectfont fl} & \Indextt{ffl} & \makeimg{ffl ligature}{\fontfamily{cmr}\selectfont ffl}\\ \gls{AA} & \makeimg{upper case A ring}{\fontfamily{cmr}\selectfont\AA} & \gls{aa} & \makeimg{lower case a ring}{\fontfamily{cmr}\selectfont\aa} & \gls{L} & \makeimg{upper case L with a stroke}{\fontfamily{cmr}\selectfont\L} & \gls{l} & \makeimg{lower case l with a stroke}{\fontfamily{cmr}\selectfont\l}\\ \gls{O} & \makeimg{upper case slashed O}{\fontfamily{cmr}\selectfont\O}& \gls{o} & \makeimg{lower case slashed o}{\fontfamily{cmr}\selectfont\o} & \gls{SS} & \makeimg{upper case Eszett}{\fontfamily{cmr}\selectfont\SS} & \gls{ss} & \makeimg{lower case eszett}{\fontfamily{cmr}\selectfont\ss} \end{tabular} \end{table} \refstepcounter{object}\label{obj:accents}% English speakers are by and large very lackadaisical when it comes to accents, but accents affect pronunciation, and so are just as important as the correct spelling. There is a big difference between putting your knife into someone's p\^at\'e (meat paste), and putting your knife into someone's pate (head)! Accented letters are created by specifying which accent you want, and the letter on which to put the accent. The accent commands are listed in \xtableref{tab:accents}, and each command takes one \gls{mandatory}. The command indicates what accent to use, and the argument indicates the letter on which to put the accent. You may have noticed in \tableref{tab:symbols} the commands \gls{i} and \gls{j} which produce a dotless i and j (\i\ and \dotlessj). With old versions of \LaTeX\ (or \TeX) an accent over a normal \dq{i} or \dq{j} left the original dot in, which is incorrect, so a dotless \dq{\i} or \dq{\dotlessj} were required. With modern distributions, an accented \dq{i} or \dq{j} is correctly rendered. \bookpagebreak \xminisec{Example:} \begin{code} It's na\glsni{doublequote}ive to think that eating mouldy p\glsni{circum}at\glsni{acute}e won't result in food poisoning. \end{code}% Result: \begin{resultS}[naive.html] It's na\"{\i}ve to think that eating mouldy p\^at\'e won't result in food poisoning. \end{resultS}% \begin{table}[htbp] \caption{Accent Commands} \label{tab:accents} \centering \begin{tabular}{llc@{\hspace{3\tabcolsep}}llc} \toprule & \multicolumn{2}{c@{\hspace{3\tabcolsep}}}{Example} & & \multicolumn{2}{c}{Example} \\ Definition & Input & Output & Definition & Input & Output\\\midrule \begin{inlinedef}\gls{acute}\marg{\meta{object}}\end{inlinedef} & \verb|\'{c}| & \makeimg{c with an acute accent}{\'{c}} & \begin{inlinedef}\gls{macron}\marg{\meta{object}}\end{inlinedef} & \verb|\={c}| & \makeimg{c with a macron accent}{\={c}} \\ \begin{inlinedef}\gls{grave}\marg{\meta{object}}\end{inlinedef} & \verb|\`{c}| & \makeimg{c with a grave accent}{\`{c}} & \begin{inlinedef}\gls{period}\marg{\meta{object}}\end{inlinedef} & \verb|\.{c}| & \makeimg{c with a dot over it}{\.{c}} \\ \begin{inlinedef}\gls{circum}\marg{\meta{object}}\end{inlinedef} & \verb|\^{c}| & \makeimg{c with a circumflex}{\^{c}} & \begin{inlinedef}\gls{tilde}\marg{\meta{object}}\end{inlinedef} & \verb|\~{c}| & \makeimg{c with a tilde above}{\~{c}} \\ \begin{inlinedef}\gls{doublequote}\marg{\meta{object}}\end{inlinedef} & \verb|\"{c}| & \makeimg{c with an umlaut}{\"{c}} & \begin{inlinedef}\gls{v}\marg{\meta{object}}\end{inlinedef} & \verb|\v{c}| & \makeimg{c with a caron accent}{\v{c}} \\ \begin{inlinedef}\gls{u}\marg{\meta{object}}\end{inlinedef} & \verb|\u{c}| & \makeimg{c with a breve accent over it}{\u{c}} & \begin{inlinedef}\gls{H}\marg{\meta{object}}\end{inlinedef} & \verb|\H{c}| & \makeimg{c with double acute accent}{\H{c}} \\ \begin{inlinedef}\gls{t}\marg{\meta{object}}\end{inlinedef} & \verb|\t{xy}| & \makeimg{x and y with a tie over them}{\t{xy}} & \begin{inlinedef}\gls{c}\marg{\meta{object}}\end{inlinedef} & \verb|\c{c}| & \makeimg{c with a cedilla}{\c{c}}\\ \begin{inlinedef}\gls{d}\marg{\meta{object}}\end{inlinedef} & \verb|\d{c}| & \makeimg{c with a dot under it}{\d{c}} & \begin{inlinedef}\gls{b}\marg{\meta{object}}\end{inlinedef} & \verb|\b{c}| & \makeimg{c with a bar under it}{\b{c}}\\ \begin{inlinedef}\gls{r}\marg{\meta{object}}\end{inlinedef} & \verb|\r{c}| & \makeimg{c with a ring above}{\r{c}} & & &\\ \bottomrule \end{tabular} \end{table} This book only covers a very small subset of available symbol commands. If the command you want isn't here, try Scott~Pakin's comprehensive symbol list~\cite{pakin09}. Another useful resource is \iappnamelink[.]{detexify}{http://detexify.kirelabs.org/classify.html} \setnode{inputenc} \subsection{The \sty{inputenc} Package} \label{sec:inputenc} Instead of using the accent and ligature commands described \htmlref{above}{sec:chars}, you can use the \isty{inputenc} package and enter the character directly, but you must ensure you match the encoding with that used by your text editor. For example, this book uses UTF8 encoding so I~have loaded the \sty{inputenc} package in the \glsterm{preamble} with the \istyopt{inputenc}{utf8} option: \begin{codeS} \glsni{usepackage}\oarg{utf8}\marg{inputenc} \end{codeS} Note that it's a good idea to also use the \isty{fontenc} package as well. For example, if you want to use Type~1 fonts: \begin{code} \begin{alltt} \glsni{usepackage}\oarg{T1}\marg{fontenc} \glsni{usepackage}\oarg{utf8}\marg{inputenc} \end{alltt} \end{code} Returning to an earlier example, I~can directly enter the Unicode character (U+0153) for the lower case \oe\ ligature: \bookpagebreak % actually I can't do it because latex2html won't like it, but lets % pretend I have \begin{codeS} man\oe uvre \end{codeS} Note that if you are collaborating on a document and you want to use this approach, you must ensure that all your co-authors use the same input encoding. For example, suppose you decide to use ISO~Latin~1 encoding (\istyopt{inputenc}{latin1} option): \begin{codeS} \glsni{usepackage}\oarg{latin1}\marg{inputenc} \end{codeS} but your co-author is using a UTF-8 editor and types: \begin{codeS} na\"ive \end{codeS} where \texttt{\"i} is the Unicode character U+00EF\@. UTF-8 characters use one to four 8-bit bytes whereas ISO Latin~1 uses an 8-bit single-byte character set. So the U+00EF binary sequence is interpreted by ISO Latin~1 encoding as two characters: \~A\ (0xC3) and \={ } (0xAF)\@. Therefore the resulting PDF file will end up containing the rather odd looking: \begin{flushleft}\wrong na\~A\={ }ve \end{flushleft}\html{\par}% (If you are using TeXWorks, you can set your preferred encoding using \menu{Edit}\menuto\menu{Preferences} and select the \dq{Editor} tab where there is an \dq{Encoding} setting. Make sure this setting matches the \isty{inputenc} option you use in your document.) \begin{exercise}{Using Special Characters}{ex:spchar} Start a new file in TeXworks, and see if you can write the source code to create the output below. \doifnotbook{(Ignore any \gls{hyphenation} that may appear below, \LaTeX\ does that automatically where necessary, see \sectionref{sec:hyphenation}. Likewise, ignore where the line breaks occur, except for the paragraph break.) }Choose whether you want to use the \isty{inputenc} package or if you want to use commands such as \gls{c}, but in either case you need to be careful of the \htmlref{special characters}{tab:specialchars}\doifbook{\ listed in \tableref{tab:specialchars}}. \begin{result}[spcharex.html]\setlength{\parindent}{1.5em}% Item \#1: Our travel expenditure came to \$2000.00 \& our equipment expenditure came to \pounds 100.00 plus VAT @ 17.5\%. Chlo\"e collected Zo\"e from the cr\`eche. They stopped to admire the fa\c{c}ade of a new caf\'e and then went to a matin\'ee. \end{result} You can \downloadorview{spchar} the source code if you can't work out how to do it, and remember to check \appendixref{ch:errors} if you have a problem. \end{exercise} %%%%%%%%%%%%%%%%%%%%%%%%% Lists %%%%%%%%%%%%%%%%%%%%%%%%%% \setnode{lists} \section{Lists} \label{sec:lists} Now you've had a go at using some \glspl{command}, let's use some \glspl{environment}\latex{ (recall \sectionref{sec:environment})}. A good example of environments are the list making environments. There are three basic list making environments: \glsni{env-itemize} (for unordered lists), \glsni{env-enumerate} (for ordered lists) and \glsni{env-description} (for lists where you want to specify your own label.) In each of these environments, each item in the list must be started with the command: \begin{definition} \gls{item}\oarg{\meta{marker}} \end{definition} The optional argument \meta{marker} can be used to override the default marker for that particular item. (For example, to replace the bullet point for an individual item in an \htmlref{unordered list}{sec:itemize} to make that item stand out from all the other items.) We will be looking at how to change the default marker in \sectionref{sec:renewcom}. \xminisec{Related \gls{ukfaq} topics:} \begin{itemize} \item \faqlink{Perhaps a missing \cmdname{item}?}{errmissitem} \item \faqlink{Fancy enumeration lists}{enumerate} \item \faqlink{How to adjust list spacing}{complist} \item \faqlink{Interrupting enumerated lists}{interruptlist} \item \faqlink{\dq{Too deeply nested}}{toodeep} \end{itemize} %---------------------- Itemize -------------------------- \setnode{itemize} \subsection{Unordered Lists} \label{sec:itemize} Unordered lists are created using the \gls{env-itemize} environment. \xminisec{Example:} \begin{code} \glsni{begin}\marg{itemize}\newline \glsni{item} Animal\newline \glsni{item} Vegetable\newline \glsni{item} Mineral\newline \glsni{end}\marg{itemize} \end{code} \begin{result}[itemize.html] \begin{itemize} \item Animal \item Vegetable \item Mineral \end{itemize} \end{result} \xminisec{Another Example:} Changing the default markers is covered in \sectionref{sec:renewcom}, but it's also possible to override the default marker for a particular item, as in this example (recall the double-dagger symbol command \gls{ddag} from \tableref{tab:symbols}): \begin{code} \glsni{begin}\marg{itemize}\newline \glsni{item} Animal\newline \glsni{item}\oarg{\glsni{ddag}} Vegetable\newline \glsni{item} Mineral\newline \glsni{end}\marg{itemize} \end{code}% \begin{result}[itemizedag.html] \begin{itemize} \item Animal \item[\ddag] Vegetable \item Mineral \end{itemize} \end{result} Be careful about using square brackets \gls{text.opensq}\gls{text.closesq} inside an optional argument. Grouping is required, as in: \begin{code} \glsni{begin}\marg{itemize}\newline \glsni{item} Animal\newline \glsni{item}\oarg{\marg{\gls{text.opensq}X\gls{text.closesq}}} Vegetable\newline \glsni{item} Mineral\newline \glsni{end}\marg{itemize} \end{code}% \begin{result}[itemizesqbr.html] \begin{itemize} \item Animal \item[{[X]}] Vegetable \item Mineral \end{itemize} \end{result} Similarly if the item starts with an open square bracket \glsni{opensq}, as in: \begin{code} \glsni{begin}\marg{itemize}\newline \glsni{item} Animal\newline \glsni{item} \marg{\gls{text.opensq}sic\gls{text.closesq}} Wegetable\newline \glsni{item} Mineral\newline \glsni{end}\marg{itemize} \end{code} \begin{result}[itemizetextsqbr.html] \begin{itemize} \item Animal \item {[sic]} Wegetable \item Mineral \end{itemize} \end{result} \setnode{nesteditemize} \subsubsection{Nested Lists} \label{sec:nesteditemise} It is also possible to nest \glsni{env-itemize} environments. The following example has three levels, each using its own default marker. \begin{code} \glsni{begin}\marg{itemize}\newline \glsni{item} Animal\newline \glsni{begin}\marg{itemize}\newline \glsni{item} Mammals\newline \glsni{item} Birds\newline \glsni{item} Reptiles. For example:\newline \glsni{begin}\marg{itemize}\newline \glsni{item} dinosaurs\newline \glsni{item} crocodiles\newline \glsni{end}\marg{itemize}\newline \glsni{end}\marg{itemize}\newline \glsni{item} Vegetable\newline \glsni{begin}\marg{itemize}\newline \glsni{item} Cultivated\newline \glsni{item} Wild\newline \glsni{end}\marg{itemize}\newline \glsni{item} Mineral\newline \glsni{end}\marg{itemize} \end{code} \begin{result}[nesteditemize.html] \begin{itemize} \item Animal \begin{itemize} \item Mammals \item Birds \item Reptiles. For example: \begin{itemize} \item dinosaurs \item crocodiles \end{itemize} \end{itemize} \item Vegetable \begin{itemize} \item Cultivated \item Wild \end{itemize} \item Mineral \end{itemize} \end{result} You might have noticed the code in the above example is a little difficult to read. Each new list item starts a new paragraph, so it doesn't matter if we have blank lines before each item. Also, recall from \chapterref{ch:def} that spaces at the start of each line of code are ignored, so it's possible to make the code more readable without affecting the final result: \begin{code} \begin{alltt} \glsni{begin}\marg{itemize} \glsni{item} Animal \glsni{begin}\marg{itemize} \glsni{item} Mammals \glsni{item} Birds \glsni{item} Reptiles. For example: \glsni{begin}\marg{itemize} \glsni{item} dinosaurs \glsni{item} crocodiles \glsni{end}\marg{itemize} \glsni{end}\marg{itemize} \glsni{item} Vegetable \glsni{begin}\marg{itemize} \glsni{item} Cultivated \glsni{item} Wild \glsni{end}\marg{itemize} \glsni{item} Mineral \glsni{end}\marg{itemize} \end{alltt} \end{code} It's now a little easier to see which \verb|\begin{itemize}| matches up with the corresponding \verb|\end{itemize}|. \xminisec{Example (Four Levels)} This example has four levels, which is the maximum allowed by most classes. \begin{code} \begin{alltt} \glsni{begin}\marg{itemize} \glsni{item} Animal \glsni{begin}\marg{itemize} \glsni{item} Mammal \glsni{begin}\marg{itemize} \glsni{item} Placental \glsni{item} Monotreme \glsni{begin}\marg{itemize} \glsni{item} Platypus \glsni{end}\marg{itemize} \glsni{item} Marsupial \glsni{begin}\marg{itemize} \glsni{item} Kangaroo \glsni{item} Koala \glsni{end}\marg{itemize} \glsni{end}\marg{itemize} \glsni{item} Reptile \glsni{end}\marg{itemize} \glsni{item} Vegetable \glsni{item} Mineral \glsni{end}\marg{itemize} \end{alltt} \end{code} \begin{result}[fourlevelitemize.html] \begin{itemize} \item Animal \begin{itemize} \item Mammal \begin{itemize} \item Placental \item Monotreme \begin{itemize} \item Platypus \end{itemize} \item Marsupial \begin{itemize} \item Kangaroo \item Koala \end{itemize} \end{itemize} \item Reptile \end{itemize} \item Vegetable \item Mineral \end{itemize} \end{result} If you try adding a further level, \LaTeX\ will give a \dq{Too deeply nested} error. %---------------- Enumerate ------------------------- \setnode{enumerate} \subsection{Ordered Lists} \label{sec:enumerate} Ordered lists are created using the \gls{env-enumerate} environment. It has exactly the same format as the \gls{env-itemize} environment described \htmlref{above}{sec:itemize}. We can use the same example as before, only this time use \glsni{env-enumerate} instead of \gls{env-itemize}. \begin{code} \begin{alltt} \glsni{begin}\marg{enumerate} \glsni{item} Animal \glsni{item} Vegetable \glsni{item} Mineral \glsni{end}\marg{enumerate} \end{alltt} \end{code}% The above input will produce the following output: \begin{result}[enumerate.html] \begin{enumerate} \item Animal \item Vegetable \item Mineral \end{enumerate} \end{result} As before, the marker for a particular item can be overridden: \begin{code} \glsni{begin}\marg{enumerate}\newline \strut~~\glsni{item} Animal\newline \strut~~\glsni{item}\oarg{\marg{\gls{text.opensq}X\gls{text.closesq}}} Vegetable\newline \strut~~\glsni{item} Mineral\newline \glsni{end}\marg{enumerate} \end{code}% \begin{result}[enumeratesqbr.html] \begin{enumerate} \item Animal \item[{[X]}] Vegetable \item Mineral \end{enumerate} \end{result} \xminisec{Example (Nested):} As with the \gls{env-itemize} environment, most classes allow a maximum of four nested \gls{env-enumerate} environments. \begin{code} \begin{alltt} \glsni{begin}\marg{enumerate} \glsni{item} Animal \glsni{begin}\marg{enumerate} \glsni{item} Mammal \glsni{begin}\marg{enumerate} \glsni{item} Placental \glsni{item} Monotreme \glsni{begin}\marg{enumerate} \glsni{item} Platypus \glsni{end}\marg{enumerate} \glsni{item} Marsupial \glsni{begin}\marg{enumerate} \glsni{item} Kangaroo \glsni{item} Koala \glsni{end}\marg{enumerate} \glsni{end}\marg{enumerate} \glsni{item} Reptile \glsni{end}\marg{enumerate} \glsni{item} Vegetable \glsni{item} Mineral \glsni{end}\marg{enumerate} \end{alltt} \end{code} \begin{result}[nestedenumerate.html] \begin{enumerate} \item Animal \begin{enumerate} \item Mammal \begin{enumerate} \item Placental \item Monotreme \begin{enumerate} \item Platypus \end{enumerate} \item Marsupial \begin{enumerate} \item Kangaroo \item Koala \end{enumerate} \end{enumerate} \item Reptile \end{enumerate} \item Vegetable \item Mineral \end{enumerate} \end{result} %--------------------- Description ------------------------- \setnode{description} \subsection{Description Environment} \label{sec:description} The \gls{env-description} environment has the same format as the \gls{env-itemize} environment described in \sectionref{sec:itemize}, only this time you need to specify a marker as an \gls{optional} to the \gls{item} command, since there is no default marker for this environment. The marker may be a textual label, and most classes will typeset it in bold. The \koma\ classes, such as \icls{scrartcl}, default to a bold sans-serif font, as illustrated in this next example: \begin{code} \begin{alltt} \glsni{begin}\marg{description} \glsni{item}\oarg{Animal} Living being \glsni{item}\oarg{Vegetable} Plant \glsni{item}\oarg{Mineral} Natural inorganic substance \glsni{end}\marg{description} \end{alltt} \end{code} \begin{result}[description.html] \dodescriptionexample \end{result} The \koma\ classes provide a way of changing the font style in the \glsni{env-description} label markers. (The font changing commands \glsni{normalfont} and \glsni{scshape} will be covered in \sectionref{sec:fonts}, and the \koma\ command \glsni{addtokomafont} in \sectionref{sec:section}.) \begin{code} \begin{alltt} \glsni{addtokomafont}\marg{descriptionlabel}\marg{\glsni{normalfont}\glsni{scshape}} \glsni{begin}\marg{description} \glsni{item}\oarg{Animal} Living being \glsni{item}\oarg{Vegetable} Plant \glsni{item}\oarg{Mineral} Natural inorganic substance \glsni{end}\marg{description} \end{alltt} \end{code} \begin{result}[descriptionkoma.html] % Make sure LaTeX2HTML doesn't think this should be the same % image as the previous example \dodescriptionkomaexample \end{result} It is possible to nest all the listing environments, as long as you don't exceed four \gls{env-itemize} and four \gls{env-enumerate} environments. The \gls{env-description} environment has no restriction on the number of times it can be nested. However, just because you can do something, doesn't mean you should. In general it's best to avoid an excessively complicated block of text in your document. \xminisec{Example (Assorted Nesting):} This example uses each of the listing environments described above. \bookpagebreak \begin{code} \begin{alltt} \glsni{begin}\marg{description} \glsni{item}\oarg{Animal} Living being \glsni{begin}\marg{itemize} \glsni{item} Mammals \glsni{item} Birds \glsni{item} Reptiles. For example: \glsni{begin}\marg{enumerate} \glsni{item} dinosaurs \glsni{item} crocodiles \glsni{end}\marg{enumerate} \glsni{end}\marg{itemize} \glsni{item}\oarg{Vegetable} Plant \glsni{begin}\marg{itemize} \glsni{item} Cultivated. For example: \glsni{begin}\marg{enumerate} \glsni{item} Carrots \glsni{item} Broccoli \glsni{item} Potatoes \glsni{end}\marg{enumerate} \glsni{item} Wild \glsni{end}\marg{itemize} \glsni{item}\oarg{Mineral} Natural inorganic substance \glsni{end}\marg{description} \end{alltt} \end{code} \begin{result}[nestedlists.html] \begin{description} \item[Animal] Living being \begin{itemize} \item Mammals \item Birds \item Reptiles. For example: \begin{enumerate} \item dinosaurs \item crocodiles \end{enumerate} \end{itemize} \item[Vegetable] Plant \begin{itemize} \item Cultivated. For example: \begin{enumerate} \item Carrots \item Broccoli \item Potatoes \end{enumerate} \item Wild \end{itemize} \item[Mineral] Natural inorganic substance \end{description} \end{result} \begin{exercise}{Lists}{ex:lists} Try writing the \gls{source} that will create the output shown below. \begin{result}[listex.html] \begin{description} \item[Village] A small collection of dwelling places. Examples: \begin{enumerate} \item Marlingford \item Saxlingham Nethergate \end{enumerate} \item[Town] A large collection of dwelling places. Examples: \begin{enumerate} \item Great Yarmouth \item Beccles \end{enumerate} \item[City] A large town, usually containing a cathedral. Examples: \begin{enumerate} \item Norwich \item Birmingham \item London \end{enumerate} \end{description} \end{result}\bookpagebreak You can \downloadorview{lists} the answer if you can't work out how to do it. \end{exercise} %%%%%%%%%%%%%%%%%% Font Changing Commands %%%%%%%%%%%%%%%%%%%%%% \setnode{fontcommands} \section{Fonts} \label{sec:fonts} \LaTeX\ uses Donald~Knuth's Computer Modern fonts by default\faq{Using PostScript fonts with TeX}{usepsfont}. This supplies three font families: serif, sans-serif and a typewriter (or monospaced) font (as well as the maths fonts which are discussed in \sectionref{sec:mathsfonts}). With each font family, you can change the shape and weight, as well as the size. \reportpagebreak \setnode{fontstyle} \subsection{Changing the Font Style} \label{sec:fontstyle} There are two basic ways of changing fonts: you can either change the font for a small selection of text, for example, if you want to \emph{emphasize} a word, or you may wish to change the font \dq{from this point onwards}. The \glspl{command} shown in \tableref{tab:fontsI} are of the first type (text-block commands\index{command!text-block|hyperpage}), whereas those shown in \tableref{tab:fontsII} are of the second type\dash a \gls{declaration} (or modal command\index{command!modal|hyperpage}). \xminisec{Note:} \warning Don't be tempted to use \cmdname{bf}, \cmdname{md}, \cmdname{it}, \cmdname{sl}, \cmdname{sc}, \cmdname{sf}, \cmdname{tt} or \cmdname{rm}. These commands are \textbf{obsolete}~\cite{l2tabu}.\faq{What's wrong with \cmdname{bf}, \cmdname{it} etc.?}{2letterfontcmd} If you use an italic or slanted font declaration, such as \glsni{itshape}, you will need to add an \keyword{italic correction} \gls{itcorr} at the end of the block of text, when the last letter of the sloping text leans too far over. This isn't necessary for text-block commands, such as \glsni{textit}, just for the modal commands. The effect is more noticeable when part of a word is stressed, particularly with certain fonts. \xminisec{Example:} In the code below, the first instance of \dq{repeated} doesn't have an italic correction but the second does: \begin{codeS} \marg{\glsni{itshape} repeated}ly \marg{\glsni{itshape} repeated\glsni{itcorr}}ly \end{codeS}% Using Computer Modern: \begin{resultS}[repeatedly repeatedly]\fontfamily{cmr}\selectfont {\itshape repeated}ly {\itshape repeated\/}ly \end{resultS} Using Helvetica: \begin{resultS}[repeatedly repeatedly]\fontfamily{phv}\selectfont {\itshape repeated}ly {\itshape repeated\/}ly \end{resultS} Using Antykwa Toru\'nska typeface: \begin{resultS}[repeatedly repeatedly] {\itshape repeated}ly {\itshape repeated\/}ly \end{resultS} \begin{table}[tp] \caption{Font Changing Text-Block Commands} \label{tab:fontsI} \centering \begin{tabular}{@{}lll@{}} \toprule \bfseries Command & \bfseries Example Input & \bfseries Corresponding output\\ & & (Computer Modern)\\ \midrule \begin{inlinedef}\gls{textrm}\marg{\meta{text}}\end{inlinedef} & \verb|\textrm{roman} text| & \makeimg{Roman text}{\fontfamily{cmr}\selectfont{\fontfamily{cmr}\selectfont roman} text}\\ \begin{inlinedef}\gls{textsf}\marg{\meta{text}}\end{inlinedef} & \verb|\textsf{sans serif} text| & \makeimg{sans serif text}{\fontfamily{cmr}\selectfont{\fontfamily{cmss}\selectfont sans serif} text}\\ \begin{inlinedef}\gls{texttt}\marg{\meta{text}}\end{inlinedef} & \verb|\texttt{typewriter} text| & \makeimg{typewriter text}{\fontfamily{cmr}\selectfont{\fontfamily{cmtt}\selectfont typewriter} text}\\[5pt] \begin{inlinedef}\gls{textmd}\marg{\meta{text}}\end{inlinedef} & \verb|\textmd{medium} text| & \makeimg{medium text}{\fontfamily{cmr}\selectfont\textmd{medium} text}\\ \begin{inlinedef}\gls{textbf}\marg{\meta{text}}\end{inlinedef} & \verb|\textbf{bold} text| & \makeimg{bold text}{\fontfamily{cmr}\selectfont\textbf{bold} text}\\[5pt] \begin{inlinedef}\gls{textup}\marg{\meta{text}}\end{inlinedef} & \verb|\textup{upright} text| & \makeimg{upright text}{\fontfamily{cmr}\selectfont\textup{upright} text}\\ \begin{inlinedef}\gls{textit}\marg{\meta{text}}\end{inlinedef} & \verb|\textit{italic} text| & \makeimg{italic text}{\fontfamily{cmr}\selectfont\textit{italic} text}\\ \begin{inlinedef}\gls{textsl}\marg{\meta{text}}\end{inlinedef} & \verb|\textsl{slanted} text| & \makeimg{slanted text}{\fontfamily{cmr}\selectfont\textsl{slanted} text}\\[5pt] \begin{inlinedef}\gls{textsc}\marg{\meta{text}}\end{inlinedef} & \verb|\textsc{Small Caps} text| & \makeimg{Small Caps text}{\fontfamily{cmr}\selectfont\textsc{Small Caps} text}\\ \begin{inlinedef}\gls{emph}\marg{\meta{text}}\end{inlinedef} & \verb|\emph{emphasized} text| & \makeimg{emphasized text}{\fontfamily{cmr}\selectfont\emph{emphasized} text}\\[5pt] \begin{inlinedef}\gls{textnormal}\marg{\meta{text}}\end{inlinedef} & \verb|\textnormal{default} text| & \makeimg{default text}{\fontfamily{cmr}\selectfont default text} \\\bottomrule \end{tabular} \end{table} Note that if you want to typeset an URL, rather than using \glsni{texttt} it is better to use\bookpagebreak \begin{definition} \gls{url}\marg{\meta{address}} \end{definition} which is defined in the \isty{url} package. For example: \begin{codeS}% \begin{alltt} \glsni{url}\marg{http://theoval.cmp.uea.ac.uk/\glsnl{tildechar}nlct/} \end{alltt} \end{codeS} produces: \begin{resultS}[http://theoval.cmp.uea.ac.uk/\tildesym nlct/] % simulate to prevent link, which might confuse the reader into % thinking links automatically occur. \texttt{http://theoval.cmp.uea.ac.uk/\tildesym nlct/} \end{resultS} (Note there is no need to do anything with the \gls{tildechar} (tilde) \htmlref{special character}{sec:chars} if you use it in the argument of \glsni{url}.) \begin{table}[hbtp] \caption{Font Changing Declarations} \label{tab:fontsII} \centering \begin{tabular}{@{}lll@{}} \toprule \bfseries Declaration & \bfseries Example Input & \bfseries Corresponding output\\ & & (Computer Modern)\\ \midrule \begin{inlinedef}\gls{rmfamily}\end{inlinedef} & \verb|\rmfamily roman text| & \makeimg{Roman text}{\fontfamily{cmr}\selectfont roman text}\\ \begin{inlinedef}\gls{sffamily}\end{inlinedef} & \verb|\sffamily sans serif text| & \makeimg{sans serif text}{\fontfamily{cmss}\selectfont sans serif text}\\ \begin{inlinedef}\gls{ttfamily}\end{inlinedef} & \verb|\ttfamily typewriter text| & \makeimg{typewriter text}{\fontfamily{cmtt}\selectfont typewriter text}\\[5pt] \begin{inlinedef}\gls{mdseries}\end{inlinedef} & \verb|\mdseries medium text| & \makeimg{medium text}{\fontfamily{cmr}\selectfont\mdseries medium text}\\ \begin{inlinedef}\gls{bfseries}\end{inlinedef} & \verb|\bfseries bold text| & \makeimg{bold text}{\fontfamily{cmr}\selectfont\bfseries bold text}\\[5pt] \begin{inlinedef}\gls{upshape}\end{inlinedef} & \verb|\upshape upright text| & \makeimg{upright text}{\fontfamily{cmr}\selectfont\upshape upright text}\\ \begin{inlinedef}\gls{itshape}\end{inlinedef} & \verb|\itshape italic text| & \makeimg{italic text}{\fontfamily{cmr}\selectfont\itshape italic text}\\ \begin{inlinedef}\gls{slshape}\end{inlinedef} & \verb|\slshape slanted text| & \makeimg{slanted text}{\fontfamily{cmr}\selectfont\slshape slanted text}\\ \begin{inlinedef}\gls{scshape}\end{inlinedef} & \verb|\scshape Small Caps text| & \makeimg{Small Caps text}{\fontfamily{cmr}\selectfont\scshape Small Caps text}\\[5pt] \begin{inlinedef}\gls{em}\end{inlinedef} & \verb|\em emphasized text| & \makeimg{emphasized text}{\fontfamily{cmr}\selectfont\em emphasized text}\\[5pt] \begin{inlinedef}\gls{normalfont}\end{inlinedef} & \verb|\normalfont default text| & \makeimg{default text}{\fontfamily{cmr}\selectfont default text} \\\bottomrule \end{tabular} \end{table} \refstepcounter{object}\label{obj:fontenv}\Glspl{environment} can be used instead. Each \gls{environment} has the same name as its corresponding declaration, but \emph{without} the preceding backslash. For example: \begin{codeS} \begin{alltt} \glsni{begin}\marg{sffamily}Some sans-serif text.\glsni{end}\marg{sffamily} \end{alltt} \end{codeS}% yields: \begin{resultS}[Some sans-serif text.] \begin{sffamily}Some sans-serif text.\end{sffamily} \end{resultS} You can combine a font family with a given shape and weight using a variety of methods. \xminisec{Examples:} \begin{enumerate} \item Localised declarations: \begin{codeS} \marg{\glsni{sffamily}\glsni{slshape} Some slanted sans-serif text.} \end{codeS} \item Declarations that later get explicitly reset: \begin{codeS} \glsni{sffamily}\glsni{slshape} Some slanted sans-serif text.\glsni{normalfont} \end{codeS} \bookpagebreak \item Mixing text-block and modal commands: \begin{codeS} \glsni{textsf}\marg{\glsni{slshape} Some slanted sans-serif text.} \end{codeS} \item Nested commands: \begin{codeS} \glsni{textsf}\marg{\glsni{textsl}\marg{Some slanted sans-serif text.}} \end{codeS} \item Mixing environments and declarations: \begin{code} \glsni{begin}\marg{sffamily}\glsni{slshape} Some slanted sans-serif text.\glsni{end}\marg{sffamily} \end{code} \end{enumerate} All of the above produce the same output: \begin{resultS}[Some slanted sans-serif text.] \textsf{\slshape Some slanted sans-serif text.} \end{resultS} \faq{Warning: \dq{Font shape \ldots\ not available}}{fontunavail}Note that some combinations are not available, in which case \LaTeX\ will give a warning message, and will substitute the font for what it considers to be the closest available match. \xminisec{Example:} \begin{codeS} \glsni{textsc}\marg{\glsni{bfseries} Text} \end{codeS} With the Antykwa Toru\'nska typeface, this appears as: \begin{resultS}[Text (in bold small caps)] \textsc{\bfseries Text} \end{resultS}\bookpagebreak\noindent whereas with Computer Modern, the result is: \begin{resultS}[Text (in bold)]\fontfamily{cmr}\selectfont \textsc{\bfseries Text} \end{resultS} This is because Computer Modern doesn't have a bold small-caps font, so it just uses bold. \LaTeX\ gives the following warning: \begin{verbatim} LaTeX Font Warning: Font shape `T1/cmr/b/sc' undefined (Font) using `T1/cmr/b/n' instead on input line 2792. \end{verbatim} Most sans-serif fonts don't provide a small-caps variant, so \begin{codeS} \glsni{textsf}\marg{\glsni{scshape} Text} \end{codeS} will either appear in regular sans-serif or small-caps serif, depending on the font in use. Using Libris sans-serif the result is: \begin{resultS}[Text (in sans-serif)] \textsf{\scshape Text} \end{resultS} whereas using Computer Modern Sans, the result is: \begin{resultS}[Text (in small caps)] \fontfamily{cmss} \scshape Text \end{resultS} \setnode{emph} \subsubsection{Emphasizing Words or Phrases} \label{sec:emph} The \gls{command} \gls{emph}, the \gls{declaration} \gls{em} and the \gls{environment} \gls{env-em} behave slightly differently to the corresponding \gls{textit} command, \gls{itshape} declaration and \gls{env-itshape} environment. The latter group simply use an italic font, whereas the former will toggle between sloping and upright. So if the surrounding font is upright then \gls{emph}, \gls{em} and \glsni{env-em} will use the sloping font, but if the surrounding font is italic or slanted, \gls{emph}, \gls{em} and \glsni{env-em} will use an upright font. This is particularly useful in abstracts where the \Index{abstract} font varies between \glspl{cls}. It is recommended that if your intention is to emphasize something, you should use \gls{emph} etc.\ rather than \gls{textit} etc.\screenpagebreak \xminisec{Examples:} \begin{enumerate} \item Emphasized text in upright surrounding: \begin{codeS} Some \glsni{emph}\marg{emphasized} text. \end{codeS}% yields \begin{resultS}[Some emphasized text.] Some \emph{emphasized} text. \end{resultS} \item Emphasized text in italic surrounding: \begin{codeS} \marg{\glsni{itshape} Some \glsni{emph}\marg{emphasized} text.} \end{codeS}% yields \begin{resultS}[Some emphasized text] {\itshape Some \emph{emphasized} text.} \end{resultS} \bookpagebreak \item Emphasized text in upright sans-serif surrounding: \begin{codeS} \marg{\glsni{sffamily} Some \glsni{emph}\marg{emphasized} text.} \end{codeS}% yields \begin{resultS}[Some emphasized text] {\sffamily Some \emph{emphasized} text.} \end{resultS} \end{enumerate} \setnode{fontsize} \subsection{Changing the Font Size} \label{sec:fontsize} When you start writing a document, you need to decide what the base font size should be. The \koma\ classes default to 11pt, but this can be changed using the class options \scrclsopt{8pt}, \scrclsopt{9pt}, \clsopt{10pt}, \clsopt{12pt}, \scrclsopt{14pt}, \scrclsopt{17pt} or \scrclsopt{20pt}. You can then change the font size \emph{relative to} the base size, using one of the declarations shown in \tableref{tab:fontsize}. That way, if you later decide to change the normal font size from, say, 11pt to 12pt, all you need do is change the class option (see \latexhtml{page~\pageref{obj:sizeopt}}{\htmlref{earlier}{obj:sizeopt}}) and re-run \LaTeX. Note that there are no equivalent text-block commands. \begin{table}[tbhp] \caption{Font Size Changing Declarations} \label{tab:fontsize} \centering \begin{tabular}{@{}lll@{}} \toprule \bfseries Declaration & \bfseries Example Input & \bfseries Corresponding Output\\ \midrule \begin{inlinedef}\gls{tiny}\end{inlinedef} & \verb|\tiny tiny text| & \makeimg{tiny text}{\tiny tiny text}\\ \begin{inlinedef}\gls{scriptsize}\end{inlinedef} & \verb|\scriptsize script size| & \makeimg{script size}{\scriptsize script size}\\ \begin{inlinedef}\gls{footnotesize}\end{inlinedef} & \verb|\footnotesize footnote size| & \makeimg{footnote size}{\footnotesize footnote size}\\ \begin{inlinedef}\gls{small}\end{inlinedef} & \verb|\small small text| & \makeimg{small text}{\small small text}\\ \begin{inlinedef}\gls{normalsize}\end{inlinedef} & \verb|\normalsize normal size| & \makeimg{normal size}{\normalsize normal size}\\ \begin{inlinedef}\gls{large}\end{inlinedef} & \verb|\large large text| & \makeimg{large text}{\large large text}\\ \begin{inlinedef}\gls{Large}\end{inlinedef} & \verb|\Large even larger| & \makeimg{even larger}{\Large even larger}\\ \begin{inlinedef}\gls{LARGE}\end{inlinedef} & \verb|\LARGE larger still| & \makeimg{larger still}{\LARGE larger still}\\ \begin{inlinedef}\gls{huge}\end{inlinedef} & \verb|\huge huge| & \makeimg{huge}{\huge huge}\\ \begin{inlinedef}\gls{Huge}\end{inlinedef} & \verb|\Huge extra huge| & \makeimg{extra huge}{\Huge extra huge} \\\bottomrule \end{tabular} \end{table} Again, \glspl{environment} can be used instead, where each \gls{environment} has the same name as its corresponding declaration, but \emph{without} the preceding backslash. Font environments may be nested, for example:% \indexEnv{itshape}\indexEnv{Large} \begin{code} \glsni{begin}\marg{itshape} Some italic text. \glsni{begin}\marg{Large}This text is large.\glsni{end}\marg{Large} \glsni{end}\marg{itshape} Back to normal. \end{code}% Output: \begin{resultS}[Some italic text. This text is large. Back to normal.] \begin{itshape} Some italic text. \begin{Large}This text is large.\end{Large} \end{itshape} Back to normal. \end{resultS} \setnode{documentfonts} \subsection{Changing Document Fonts} \label{sec:changingfonts} \faq{Choice of scalable outline fonts}{psfchoice}What if you don't want to use the default Computer Modern fonts? Some publishers and institutions insist on a combination of Times Roman (serif), Helvetica (sans-serif) and Courier (typewriter). To do this, you can load the following packages: \begin{description} \item[\isty{mathptmx}] (Times) Only affects \gls{rmfamily} and \gls{textrm}. \item[\isty{helvet}] (Helvetica) Only affects \gls{sffamily} and \gls{textsf}. \item[\isty{courier}] (Courier) Only affects \gls{ttfamily} and \gls{texttt}. \end{description} \xminisec{Notes:} \begin{enumerate} \item \warning Don't be tempted to use the \sty{times} package. It's obsolete~\cite{l2tabu}. Use \isty{mathptmx} instead. \item Although Times and Helvetica are commonly used together, they don't match, as illustrated below (temporarily switching from this book's fonts to Times and Helvetica): \begin{codeS} \glsni{rmfamily} xx \glsni{sffamily} xx \end{codeS} Results in: \begin{resultS}[xx xx] \fontfamily{ptm}\selectfont xx \fontfamily{phv}\selectfont xx \end{resultS} The first two x's are in Times Roman and the second two are in Helvetica, which are somewhat larger. To compensate for this you need to scale the Helvetica font using the \istyopt{helvet}{scaled} option: \begin{alltt} \glsni{usepackage}\oarg{scaled=0.9}\marg{helvet} \end{alltt} \item Loading \isty{helvet} or \isty{courier} doesn't change the default font family. Consider the following: \begin{alltt} \glsni{documentclass}\marg{scrartcl} \glsni{usepackage}\marg{helvet} \glsni{begin}\marg{document} This is a sample document. \glsni{end}\marg{document} \end{alltt} Here, the text \dq{This is a sample document} will be typeset in Computer Modern Roman. This is because \gls{rmfamily} is the default font and \isty{helvet} only affects \gls{sffamily}, which hasn't been used. (See \sectionref{sec:renewcom} to find out how to change the default font family.) \end{enumerate} \latexhtml{This book}{The PDF version of this document} has used the following packages: \begin{alltt} \glsni{usepackage}\oarg{T1}\marg{fontenc} \glsni{usepackage}\oarg{math}\marg{anttor} \glsni{usepackage}\marg{libris} \end{alltt} The \isty{fontenc} package is used to switch to Type~1 font encoding\faq{Why bother with \sty{inputenc} and \sty{fontenc}?}{why-inp-font}, the \isty{anttor} package is used to set the serif family to Antykwa Toru\'nska typeface, and the \isty{libris} package is used to set the sans-serif family to the Libris ADF typeface. \begin{exercise}{Fonts}{ex:fonts} Go back to the document you created in \exerciseref{ex:simpledoc} and change the first paragraph to a large bold font and the second paragraph to normal size italic. Emphasize the words \dq{simple} and \dq{short}. (Again, you can \downloadorview{fonts} the solution.) If you like, you can try experimenting with loading different font packages, such as \isty{mathptmx}, to change the default typeface. The \LaTeX\ Font Catalogue~\cite{fontcat} provides a useful list of fonts, although you may not have all of them installed. \end{exercise} %%%%%%%%%%%%%% Aligning Material in Rows and Columns %%%%%%%%%%%%%%%% \setnode{tabular} \section{Aligning Material in Rows and Columns} \label{sec:tabular} Text can be aligned in rows and columns using the \gls{env-tabular} environment. \begin{definition} \glsni{begin}\marg{tabular}\oarg{\meta{pos}}\marg{\meta{column specifiers}} \end{definition}% This \glsterm{environment} has a \glsterm{mandatory} \meta{column specifiers} that specifies how to align each column. Within \meta{column specifiers}, there must be a specifier for each column. The three basic are: \texttt{r} (right aligned), \texttt{l} (left aligned) and \texttt{c} (centred). (Make sure you don't confuse \texttt{l} (the letter \dq{ell}) with \texttt{1} (the digit one).) The optional argument \meta{pos} is covered \latexhtml{in \sectionref{sec:boxes}}{\htmlref{later}{sec:boxes}}. \xminisec{Example:} Three columns (\underline{l}eft, \underline{c}entred, \underline{c}entred): \begin{codeS} \glsni{begin}\marg{tabular}\marg{lcc} \end{codeS} \xminisec{Another Example:} Four columns (\underline{l}eft, \underline{c}entred, \underline{c}entred, \underline{r}ight): \begin{codeS} \glsni{begin}\marg{tabular}\marg{lccr} \end{codeS} The \texttt{r}, \texttt{l} and \texttt{c} specifiers don't allow line breaks or paragraphs within a cell. It's not a good idea to have too much text in a cell, but if it's required you can use \begin{definition} p\marg{\meta{width}} \end{definition} which indicates a paragraph cell of the given width. \xminisec{Example:} Three columns (\underline{p}aragraph of width 1in, \underline{c}entred, \underline{r}ight): \begin{codeS} \glsni{begin}\marg{tabular}\marg{p\marg{1in}cr} \end{codeS} The paragraph cell will be formatted fully justified, which is often inappropriate for a narrow block of text. The \isty{array} package provides \begin{definition} \gls{gtcol}\marg{\meta{declaration}} \end{definition} which can be used directly in front of the \texttt{l}, \texttt{c}, \texttt{r} or \texttt{p} column specifiers. This inserts \meta{declaration} in front of the entries for that column, so it can be used to insert, say, \gls{raggedright}. \xminisec{Example:} Three columns, the first \underline{l}eft justified where each entry is in bold, the second a \underline{p}aragraph column of width 1in set to ragged right and the third \underline{c}entered: \begin{codeS} \glsni{begin}\marg{tabular}\marg{\glsni{gtcol}\marg{\glsni{bfseries}}l\glsni{gtcol}\marg{\glsni{raggedright}}p\marg{1in}c} \end{codeS} The \isty{array} package also provides \begin{definition} \gls{ltcol}\marg{\meta{declaration}} \end{definition} which can be used directly after the \texttt{l}, \texttt{c}, \texttt{r} or \texttt{p} column specifiers. This inserts \meta{declaration} after the entries for that column. \xminisec{Inter-Column Gap:} The gap between columns is given by twice the value of the \gls{length} register: \begin{definition} \gls{tabcolsep} \end{definition} A gap of \glsni{tabcolsep} is also inserted before the first column and after the last column. This length can be changed using one of the commands described in \sectionref{sec:length}. For example: \begin{codeS} \gls{setlength}\marg{\glsni{tabcolsep}}\marg{4pt} \end{codeS} This will put an 8pt gap between columns and a 4pt gap before the first column and after the last column. The column specifiers can also include: \begin{definition} \gls{atchar}\marg{\meta{inter-column text}} \end{definition} This inserts \meta{inter-column text} at that place on each row of the table, replacing the default inter-column gap. \xminisec{Example:} Suppose we want a centred first column, a right justified second column and a left justified third column with a dot between the second and third columns: \begin{codeS} \begin{alltt} \glsni{begin}\marg{tabular}\marg{cr\glsni{atchar}\marg{.}l} \end{alltt} \end{codeS} Alternatively, you may want a larger gap between groups of columns, for example, two groups of three left justified columns: \begin{codeS} \begin{alltt} \glsni{begin}\marg{tabular}\marg{lll\glsni{atchar}\marg{\glsni{hspace}\marg{4\glsni{tabcolsep}}}lll} \end{alltt} \end{codeS} This uses the command: \begin{definition} \gls{hspace}\marg{\meta{length}} \end{definition} which inserts a horizontal space of a given \gls{length}. In this case, four times the value of \glsni{tabcolsep}. This makes the gap between the third and fourth columns twice as wide as the gap between the other columns. \setnode{rowscols} \subsection{Column and Row Separation} \label{sec:rowscols} Remember the \latexhtml{special characters mentioned in \sectionref{sec:chars}}{\htmlref{special characters}{sec:chars}}? The ampersand character \gls{ampchar} is used to separate column entries. Rows are separated using: \begin{definition} \gls{tab.dbbackslashchar}\oarg{\meta{vertical space}} \end{definition} where \meta{vertical space} is extra vertical spacing between rows, if required. There is also a longer equivalent: \begin{definition} \gls{tabularnewline} \end{definition} \faq{Alignment tab changed to \cmdname{cr}}{altabcr}% If you have used something like \texttt{\gls{gtcol}\marg{\gls{raggedright}}p\marg{\meta{length}}} as the specifier for your last column, you must use \glsni{tabularnewline} instead of \glsni{tab.dbbackslashchar} to indicate the row break otherwise you will get the following error: \begin{verbatim} ! Extra alignment tab has been changed to \cr. \endtemplate \end{verbatim} \screenpagebreak \xminisec{Example:} Let's have two columns, the first left justified and the second right justified: \begin{code} \glsni{begin}\marg{tabular}\marg{lr}\newline Video \glsni{ampchar} 8.99\glsni{tab.dbbackslashchar}\newline CD \glsni{ampchar} 9.11\glsni{tab.dbbackslashchar}\newline DVD \glsni{ampchar} 15.00\glsni{tab.dbbackslashchar}\newline Total \glsni{ampchar} 33.10\newline \glsni{end}\marg{tabular} \end{code} \begin{result}[tabular1.html] \begin{tabular}{lr} Video & 8.99\\ CD & 9.11\\ DVD & 15.00\\ Total & 33.10 \end{tabular} \end{result}% Recall from \chapterref{ch:def} that \LaTeX\ ignores spaces at the start of a line and treats multiple spaces as a single space, so I~could just have easily done: \begin{code} \glsni{begin}\marg{tabular}\marg{lr}\newline \strut~~Video \glsni{ampchar} 8.99\glsni{tab.dbbackslashchar}\newline \strut~~CD~~~~\glsni{ampchar} 9.11\glsni{tab.dbbackslashchar}\newline \strut~~DVD~~~\glsni{ampchar} 15.00\glsni{tab.dbbackslashchar}\newline \strut~~Total \glsni{ampchar} 33.10\newline \glsni{end}\marg{tabular} \end{code}% and still have got the same result, but now the code is easier to read. Entries form implicit \glsing{group}, so \glspl{declaration} made within a \gls{env-tabular} environment only have an effect up to the next \gls{ampchar} or \gls{tab.dbbackslashchar}. \xminisec{Example:} \begin{code} \glsni{begin}\marg{tabular}\marg{lr}\newline \strut~~Video~\glsni{ampchar} 8.99\glsni{tab.dbbackslashchar}\newline \strut~~CD~~~~\glsni{ampchar} 9.11\glsni{tab.dbbackslashchar}\newline \strut~~DVD~~~\glsni{ampchar} 15.00\glsni{tab.dbbackslashchar}\newline \strut~~\glsni{bfseries} Total \glsni{ampchar} 33.10\newline \glsni{end}\marg{tabular} \end{code}% Output:\screenpagebreak \begin{result}[Image: as the previous example except that the word Total has appeared in bold] \begin{tabular}{lr} Video & 8.99\\ CD & 9.11\\ DVD & 15.00\\ \bfseries Total & 33.10 \end{tabular} \end{result}% Let's add an extra column and a header row: \begin{code}\obeyspaces \glsni{begin}\marg{tabular}\marg{lrr}\newline \strut~~Item~~\glsni{ampchar} ex VAT \glsni{ampchar} inc VAT\glsni{tab.dbbackslashchar}\newline \strut~~Video~\glsni{ampchar}~~~8.99 \glsni{ampchar}~~10.56 \glsni{tab.dbbackslashchar}\newline \strut~~CD~~~~\glsni{ampchar}~~~9.11 \glsni{ampchar}~~10.70 \glsni{tab.dbbackslashchar}\newline \strut~~DVD~~~\glsni{ampchar}~~15.00 \glsni{ampchar}~~17.63 \glsni{tab.dbbackslashchar}\newline \strut~~\glsni{bfseries} Total \glsni{ampchar}~~33.10 \glsni{ampchar}~~39.89\newline \glsni{end}\marg{tabular} \end{code}% Output: \begin{result}[tabular2.html] \begin{tabular}{lrr} Item & ex VAT & inc VAT\\ Video & 8.99 & 10.56\\ CD & 9.11 & 10.70\\ DVD & 15.00 & 17.63\\ \bfseries Total & 33.10 & 39.89 \end{tabular} \end{result}% \xminisec{Example (Aligning on a Decimal Point):} \label{xmp:decpt}If you want to align on the decimal point, it's best to use the \isty{siunitx} package. That's beyond the scope of this book, but for simple data this can be achieved using the \gls{atchar} inter-column specifier. For example: \begin{code}\obeyspaces \glsni{begin}\marg{tabular}\marg{lr\glsni{atchar}\marg{.}l}\newline \strut~~Video \glsni{ampchar} 8 \glsni{ampchar} 99\glsni{tab.dbbackslashchar}\newline \strut~~CD~~~~\glsni{ampchar} 9 \glsni{ampchar} 11\glsni{tab.dbbackslashchar}\newline \strut~~DVD~~~\glsni{ampchar} 15 \glsni{ampchar} 00\glsni{tab.dbbackslashchar}\newline \strut~~\glsni{bfseries} Total \glsni{ampchar} 33 \glsni{ampchar} 10\newline \glsni{end}\marg{tabular} \end{code}% Output:\reportpagebreak \begin{result}[Image: as the second example but the decimal points are aligned] \begin{tabular}{lr@{.}l} Video & 8 & 99\\ CD & 9 & 11\\ DVD & 15 & 00\\ \bfseries Total & 33 & 10 \end{tabular} \end{result}% \setnode{multicolumn} \subsection{Spanning Columns} \label{sec:multicolumn} You may have noticed I~omitted the column headers in the \htmlref{above example}{xmp:decpt}. \faq{Merging cells in a column of a table}{multirow} The problem with rewriting the table using \texttt{r\glsni{atchar}\marg{.}l} to align the decimal point is that the header now needs to span the last two columns. This can be done using the command: \begin{definition} \gls{multicolumn}\marg{\meta{cols spanned}}\marg{\meta{col specifier}}\marg{\meta{text}} \end{definition}% The first \gls{mandatory} \meta{cols spanned} is the number of columns you want to span, the second argument \meta{col specifier} indicates how to align this column-spanning entry, the third argument \meta{text} indicates what should go in this entry. Note that \meta{col specifier} should only have a single column specifier, such as \texttt{\marg{c}} or \texttt{\marg{r}}. We can use \glsni{multicolumn} to modify an earlier example as follows:\screenpagebreak \begin{code} \glsni{begin}\marg{tabular}\marg{lrr}\newline \strut~~~~~~~~\glsni{ampchar} \glsni{multicolumn}\marg{2}\marg{c}\marg{Price (\glsni{pounds})}\glsni{tab.dbbackslashchar}\newline \strut~~Item~~\glsni{ampchar} ex VAT \glsni{ampchar} inc VAT\glsni{tab.dbbackslashchar}\newline \strut~~Video~\glsni{ampchar}~~~8.99 \glsni{ampchar}~~10.56 \glsni{tab.dbbackslashchar}\newline \strut~~CD~~~~\glsni{ampchar}~~~9.11 \glsni{ampchar}~~10.70 \glsni{tab.dbbackslashchar}\newline \strut~~DVD~~~\glsni{ampchar}~~15.00 \glsni{ampchar}~~17.63 \glsni{tab.dbbackslashchar}\newline \strut~~\glsni{bfseries} Total \glsni{ampchar}~~33.10 \glsni{ampchar}~~39.89\newline \glsni{end}\marg{tabular} \end{code}% Output: \begin{result}[tabular2multicol.html] \begin{tabular}{lrr} & \multicolumn{2}{c}{Price (\pounds)}\\ Item & ex VAT & inc VAT\\ Video & 8.99 & 10.56\\ CD & 9.99 & 11.74\\ DVD & 15.00 & 17.63\\ \bfseries Total & 33.98 & 39.93 \end{tabular} \end{result}% Here we are spanning two columns, so the first argument to \glsni{multicolumn} is \verb|{2}|, we want the entry centred, so the second argument is \verb|{c}| and the text to go in this entry is simply \texttt{\marg{Price (\gls{pounds})}}. \faq{How to alter the alignment of tabular cells}{tabcellalign}The \glsni{multicolumn} command can also be used to override the alignment of individual entries. Consider the following example: \begin{code} \glsni{begin}\marg{tabular}\marg{lrr}\newline \strut~~~~~~~~~~\glsni{ampchar} Year1 \glsni{ampchar} Year2 \glsni{tab.dbbackslashchar}\newline Travel~~~~\glsni{ampchar} 100,000 \glsni{ampchar} 110,000\glsni{tab.dbbackslashchar}\newline Equipment \glsni{ampchar} 50,000 \glsni{ampchar} 60,000\newline \glsni{end}\marg{tabular} \end{code} Output: \begin{result}[tabular3.html] \begin{tabular}{lrr} & Year1 & Year2 \\ Travel & 100,000 & 110,000\\ Equipment & 50,000 & 60,000 \end{tabular} \end{result}% In this example, the headers \dq{Year1} and \dq{Year2} would look better centred, but the rest of the entries in the second and third columns look best right aligned. We can use \glsni{multicolumn} to span just one column, and use the second argument of \glsni{multicolumn} to override the column specification: \begin{code} \glsni{begin}\marg{tabular}\marg{lrr}\newline \strut~~~~~~~~~~\glsni{ampchar} \glsni{multicolumn}\marg{1}\marg{c}\marg{Year1}\newline \strut~~~~~~~~~~\glsni{ampchar} \glsni{multicolumn}\marg{1}\marg{c}\marg{Year2}\glsni{tab.dbbackslashchar}\newline Travel~~~~\glsni{ampchar} 100,000 \glsni{ampchar} 110,000\glsni{tab.dbbackslashchar}\newline Equipment \glsni{ampchar} 50,000 \glsni{ampchar} 60,000\newline \glsni{end}\marg{tabular} \end{code} Output: \begin{result}[Image: as the previous example except that the words 'Year1' and 'Year2' have been centred in their columns] \begin{tabular}{lrr} & \multicolumn{1}{c}{Year1} & \multicolumn{1}{c}{Year2} \\ Travel & 100,000 & 110,000\\ Equipment & 50,000 & 60,000 \end{tabular} \end{result} \setnode{tabrules} \subsection{Rules} \label{sec:rules} In general, vertical rules are considered superfluous~\cite{oxford}. Although Turabian~\cite{turabian96} allows for the possibility of vertical rules for tabulated material containing more than two columns but still advises against having too many and deprecates the use of them at either end. Horizontal rules may be used at the top and bottom of the tabulated material, but other horizontal rules should be kept to a minimum. In general, the top and bottom rule should be thicker than the mid rules. The \isty{booktabs} package provides: \begin{definition} \gls{toprule}\oarg{\meta{wd}} \end{definition} for the top horizontal rule, \begin{definition} \gls{bottomrule}\oarg{\meta{wd}} \end{definition} for the bottom horizontal rule, and \begin{definition} \gls{midrule}\oarg{\meta{wd}} \end{definition} for horizontal rules in between rows, such as after the header row. These commands should all go at the start of the appropriate row. This means that if you want a bottom rule, you need to add \gls{tab.dbbackslashchar} followed by \glsni{bottomrule} at the end of the tabulated material. \xminisec{Example:} \begin{code} \glsni{begin}\marg{tabular}\marg{lrr}\newline \glsni{toprule}\newline \strut~~~~~~~~~~\glsni{ampchar} \glsni{multicolumn}\marg{1}\marg{c}\marg{Year1}\newline \strut~~~~~~~~~~\glsni{ampchar} \glsni{multicolumn}\marg{1}\marg{c}\marg{Year2}% \glsni{tab.dbbackslashchar}\newline \glsni{midrule}\newline Travel~~~~\glsni{ampchar} 100,000 \glsni{ampchar} 110,000\glsni{tab.dbbackslashchar}\newline Equipment \glsni{ampchar} 50,000 \glsni{ampchar} 60,000% \glsni{tab.dbbackslashchar}\newline \glsni{bottomrule}\newline \glsni{end}\marg{tabular} \end{code} results in: \begin{result}[Image: as previous example but with horizontal rules at the start and end and between the first and second rows.] \begin{tabular}{lrr} \toprule & \multicolumn{1}{c}{Year1} & \multicolumn{1}{c}{Year2} \\ \midrule Travel & 100,000 & 110,000\\ Equipment & 50,000 & 60,000 \\\bottomrule \end{tabular} \end{result} The thickness of the top and bottom rule is given by the \gls{length} register \booklinebreak\gls{heavyrulewidth}, and the thickness of the mid rule is given by the \gls{length} register \gls{lightrulewidth}. These rule thicknesses can be overridden using the optional argument \meta{wd} for \glsni{toprule}, \glsni{midrule} and \glsni{bottomrule}. \begin{exercise}{Aligning Material}{ex:tabular} Go back to the document you created in \exerciseref{ex:simple} (and later modified in \exerciseref{ex:datetime}), and add the following: \begin{result}[tabex.html] \begin{tabular}{lrr} & \multicolumn{2}{c}{\bfseries Expenditure (\pounds)}\\ & \multicolumn{1}{c}{Year1} & \multicolumn{1}{c}{Year2} \\ \bfseries Travel & 100,000 & 110,000\\ \bfseries Equipment & 50,000 & 60,000 \end{tabular} \end{result} Note that the \gls{env-tabular} environment doesn't create a caption, all it does is arrange its contents in rows and columns. You can find out how to turn your \gls{env-tabular} environment into a table in \sectionref{sec:tables}. You can \downloadorview{tabular} the solution to this exercise. (Remember to check \appendixref{ch:errors} if you encounter an error message.) \end{exercise} For more information about using the \gls{env-tabular} environment see \latexbook, \latexguide\ or \latexcomp. \emph{The \LaTeX\ Companion} also describes how to span rows using the \isty{multirow} \htmlref{package}{sec:packages}. For information on how to create coloured tables using the \isty{colortbl} \htmlref{package}{sec:packages}, see \latexgraphic. \xminisec{Related \gls{ukfaq} topics:} \begin{itemize} \item \faqlink{How to change a whole row of a table}{wholerow} \item \faqlink{Merging cells in a column of a table}{multirow} \item \faqlink{Fixed width tables}{fixwidtab} \item \faqlink{Variable-width columns in tables}{varwidcol} \item \faqlink{Spacing lines in tables}{struttab} \end{itemize} %%%%%%%%%%%%%%%% Boxes and Mini-Pages %%%%%%%%%%%%%%%%%%% \setnode{boxes} \section{Boxes and Mini-Pages} \label{sec:boxes} \gls{tex} views everything on a page as a form of box. Each box has an associated width, height and depth, and the boxes are placed together on the page with \keyword{glue}. This is reminiscent of the days of manual typesetting, where each letter or symbol was on a wooden block, and the wooden blocks were glued in place. The simplest form of box is a single letter. Some letters, such as \dq{a} only have a height and width, whereas other letters, such as \dq{y} have a height, width and depth (see \figureref{fig:letterbox}). \begin{figure}[htbp] \figconts[alt=Image of the letters y and a illustrating their height depth and width. The letter a has zero depth as it does not extend below the baseline.] {pictures/letterbox}% {% \caption{\texorpdfstring{\protect\TeX}{TeX}\protect\space Views Each Letter as a Box}% }% {fig:letterbox}% \end{figure} For example, the phrase \dq{cabbages and peas} is made up of 15 boxes: \begin{center} \makeimg{c a b b a g e s a n d p e a s}{\setlength{\fboxsep}{0.5pt}% \setlength{\fboxrule}{0.1pt}\LARGE \fbox{c}\fbox{a}\fbox{b}\fbox{b}\fbox{a}% \fbox{g}\fbox{e}\fbox{s}~\fbox{a}\fbox{n}\fbox{d}~\fbox{p}\fbox{e}% \fbox{a}\fbox{s}} \end{center} whereas the word \dq{cauliflower} consists of 10 boxes:\footnote{The fl-ligature is a single character, and so is one box not two.} \begin{center} \makeimg{c a u l i fl-ligature o u r}{\setlength{\fboxsep}{0.5pt}% \setlength{\fboxrule}{0.1pt}\LARGE \fbox{c}\fbox{a}\fbox{u}\fbox{l}\fbox{i}% \fbox{fl}\fbox{o}\fbox{w}\fbox{e}\fbox{r}} \end{center} More complicated boxes are made up of smaller boxes. We have already encountered one of these more complicated boxes: the \gls{env-tabular} environment, discussed in the \htmlref{previous section}{sec:tabular}. This type of box is called a \keyword{horizontal box}, which means that it can go in a line of text. For example: \begin{code}\obeyspaces Here is some text.\newline \glsni{begin}\marg{tabular}\marg{cc}\newline A \glsni{ampchar} B\glsni{tab.dbbackslashchar}\newline C \glsni{ampchar} D\newline \glsni{end}\marg{tabular}\newline The rest of the line. \end{code} produces: \begin{result}[Image illustrating the typeset output: the tabulated material is centred vertically within the line of text.] Here is some text. \begin{tabular}{cc} A & B\\ C & D \end{tabular} The rest of the line. \end{result} Recall from \htmlref{the previous section}{sec:tabular} that the \gls{env-tabular} environment had an optional argument \meta{pos}. This governs the vertical alignment when the \gls{env-tabular} environment occurs within a line of text. This can be one of \texttt{c} (centred\dash the default, as illustrated above), \texttt{t} (top) and \texttt{b} (bottom). For example, \begin{code}\obeyspaces Here is some text.\newline \glsni{begin}\marg{tabular}\oarg{b}\marg{cc}\newline A \glsni{ampchar} B\glsni{tab.dbbackslashchar}\newline C \glsni{ampchar} D\newline \glsni{end}\marg{tabular}\newline The rest of the line. \end{code}% produces: \begin{result}[Image illustrating the typeset output: the last row of the tabulated material rests on the baseline of the text outside it.] Here is some text. \begin{tabular}[b]{cc} A & B\\ C & D \end{tabular} The rest of the line. \end{result} Since a box can't be broken across a line of text, you can use the box making command: \begin{definition} \gls{mbox}\marg{\meta{text}} \end{definition} to prevent \meta{text} from spanning a line break. \xminisec{Example:} Compare: \begin{code} \gls{raggedright} Some text at the beginning of a paragraph. Some text in the middle of the paragraph. Some more text. \glsni{par} \end{code} \begin{result}[Image of typeset output: paragraph is left-justified] \raggedright Some text at the beginning of a paragraph. Some text in the middle of the paragraph. Some more text. \par \end{result} with: \begin{code} \gls{raggedright} Some text at the beginning of a paragraph. \glsni{mbox}\marg{Some text in the middle of the paragraph.} Some more text. \glsni{par} \end{code} \begin{result}[Image of typeset output: line break occurs at the start of the second sentence leaving a large white space at the end of the first line.] \raggedright Some text at the beginning of a paragraph. \mbox{Some text in the middle of the paragraph.} Some more text. \par \end{result} (If \gls{raggedright} had not been used, the text in the \glsni{mbox} would've spilt out over the edge of the page.) Another type of box which can again be placed in a line of text, is the \gls{env-minipage} environment. \begin{definition} \glsni{begin}\marg{minipage}\oarg{\meta{pos}}\oarg{\meta{height}}% \marg{\meta{width}} \end{definition} As the name suggests, this environment creates a \dq{mini-page} of the given width. \xminisec{Example:} \begin{code} Some text.\newline \glsni{begin}\marg{minipage}\marg{2in}\newline This is a mini-page. The text inside it is formatted as usual.\newline \mbox{}\newline Paragraph breaks can also be used, but there is no indentation by default\gls{footnote}\marg{and this is how a footnote appears}.\newline \glsni{end}\marg{minipage}\newline The rest of the line. \end{code}% which produces:\reportpagebreak \begin{result}[Image: the contents of the minipage including footnote have been typeset in a rectangular block within the outer line of text.] Some text. \begin{minipage}{2in} This is a mini-page. The text inside it is formatted as usual. Paragraph breaks can also be used, but there is no indentation by default\mpexfootnote{and this is how a footnote appears}. \end{minipage} The rest of the line. \end{result} You can optionally specify a height, and how the mini-page is aligned with the rest of the text. As with the \gls{env-tabular} environment, the alignment option \meta{pos} can be one of \texttt{t} (top), \texttt{c} (centred) or \texttt{b} (bottom). The default is \texttt{c}, which is why the above example has the mini-page centred vertically. This can be changed, for example: \begin{code} Some text.\newline \glsni{begin}\marg{minipage}\oarg{t}\marg{2in}\newline This is a mini-page. The text inside it is formatted as usual.\newline \mbox{}\newline Paragraph breaks can also be used, but there is no indentation by default\gls{footnote}\marg{and this is how a footnote appears}.\newline \glsni{end}\marg{minipage}\newline The rest of the line. \end{code} which produces \begin{result}[Image: as previous example but the first line of the minipage is aligned with the outer text.] \begin{makeimage} Some text. \begin{minipage}[t]{2in} This is a mini-page. The text inside it is formatted as usual. Paragraph breaks can also be used, but there is no indentation by default\mpexfootnote{and this is how a footnote appears}. \end{minipage} The rest of the line. \end{makeimage} \end{result} Note that the width can be specified relative to the current line width, using the \gls{length} register \gls{linewidth}. For example, \begin{alltt} \glsni{begin}\marg{minipage}\marg{0.5\glsni{linewidth}} \end{alltt} will start a mini-page that is half the width of the current line. There is also a corresponding command \begin{definition} \gls{parbox}\oarg{\meta{pos}}\oarg{\meta{height}}% \marg{\meta{width}}\marg{\meta{text}} \end{definition}% which behaves in a similar way. So the above example can be rewritten using a \glsni{parbox}: \begin{code} Some text.\newline \glsni{parbox}[t]\marg{2in}\marg{This is a parbox. The text inside it is formatted as usual.\newline \mbox{}\newline Paragraph breaks can also be used, but there is no indentation by default.}\newline The rest of the line. \end{code} which produces \begin{result}[Image: as previous example but without a footnote] Some text. \parbox[t]{2in}{This is a parbox. The text inside it is formatted as usual. Paragraph breaks can also be used, but there is no indentation by default.} The rest of the line. \end{result} You may have noticed that the \gls{footnote} command has not been used in the above example. The \glsni{parbox} command is more restricted than the \gls{env-minipage} environment, so you can't use the \gls{footnote} command in it. There are also certain environments, such as the \htmlref{list-making environments}{sec:lists}\latex{\ifscreenorother{}{\ described in \sectionref{sec:lists}}}, that can be used in a \gls{env-minipage} but not in a \glsni{parbox}. \setnode{fbox} \subsection{Framed Boxes} \label{sec:fbox} Recall the \gls{framebox} command described in \sectionref{sec:optional}: \begin{definition} \glsni{framebox}\oarg{\meta{width}}\oarg{\meta{align}}\marg{\meta{text}} \end{definition} This treats \meta{text} as a box of width \meta{width} and puts a frame around it. The second optional argument may be one of: \texttt{c} (centred contents), \texttt{l} (left-aligned contents), \texttt{r} (right-aligned contents). \xminisec{Example:} \begin{codeS} Some \glsni{framebox}\oarg{2in}\marg{framed} text. \end{codeS} \begin{resultS}[Some framed text (the word 'framed' is inside a 2 inch wide box)] Some \framebox[2in]{framed} text. \end{resultS} There is a shorter related command with no optional arguments: \begin{definition} \gls{fbox}\marg{\meta{text}} \end{definition} The \isty{fancybox} package provides some additional framing commands: \begin{definition} \gls{shadowbox}\marg{\meta{text}} \end{definition} Puts a shadow-style frame around its contents:\bookpagebreak \begin{codeS} Some \glsni{shadowbox}\marg{framed} text. \end{codeS} \begin{resultS}[Some framed text (the word 'framed' is in a box with a shadow)] Some \shadowbox{framed} text. \end{resultS} \begin{definition} \gls{doublebox}\marg{\meta{text}} \end{definition} Puts a double-lined frame around its contents: \begin{codeS} Some \glsni{doublebox}\marg{framed} text. \end{codeS} \begin{resultS}[Some framed text (the word 'framed' is in a box with a double lined frame)] Some \doublebox{framed} text. \end{resultS} \begin{definition} \gls{ovalbox}\marg{\meta{text}} \end{definition} Puts a thin-lined oval frame around its contents: \begin{codeS} Some \glsni{ovalbox}\marg{framed} text. \end{codeS} \begin{resultS}[Some framed text (the word 'framed' is in a a box with rounded corners)] Some \ovalbox{framed} text. \end{resultS} \begin{definition} \gls{Ovalbox}\marg{\meta{text}} \end{definition} Puts a thick-lined oval frame around its contents: \begin{codeS} Some \glsni{Ovalbox}\marg{framed} text. \end{codeS} \begin{resultS}[Some framed text (the word 'framed' is in a a thick bordered box with rounded corners)] Some \Ovalbox{framed} text. \end{resultS} If you want a different frame effect, you will need to use a graphical package, such as \isty{pgf}/\isty{tikz}. \xminisec{Example:} This example uses commands beyond the scope of this book, but gives you an idea of what's possible. \begin{code} \begin{verbatim} \documentclass{scrartcl} \usepackage{tikz} \usetikzlibrary{shapes} \usetikzlibrary{decorations.pathmorphing} \begin{document} Some \begin{tikzpicture}[baseline=(n.base),decoration=bumps] \node[draw,ellipse,decorate] (n) {framed}; \end{tikzpicture} text. \end{document} \end{verbatim} \end{code} \begin{resultS}[Some framed text (the word 'framed' is in a decorated with a wiggly border)] Some \begin{tikzpicture}[baseline=(n.base),decoration=bumps] \node[draw,ellipse,decorate] (n) {framed}; \end{tikzpicture} text. \end{resultS} For further details, see the \isty{pgf} \htmlref{documentation}{sec:texdoc}. \xminisec{Related \gls{ukfaq} topics:} \begin{itemize} \item \faqlink{Automatic sizing of minipage}{varwidth} \item \faqlink{Float(s) lost}{fllost} \item \faqlink{Perhaps a missing \cmdname{item}?}{errmissitem} \end{itemize} %%%%%%%%%%%%%%%%% CHAPTERS, SECTIONS ETC %%%%%%%%%%%%%%%%%%%%%%% \setnode{structure} \chapter{Structuring Your Document} \label{ch:sections} Let's go back to the document we modified in \exerciseref{ex:tabular}. In this \latexhtml{chapter}{section} we shall edit that document step by step until we have a fully-fledged document with title, abstract, table of contents, sections etc. %%%%%%%%%%%%%%%%%% Maketitle %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \setnode{title} \section{Author and Title Information} \label{sec:title} The term \keyword{title page} is used to indicate the author, title and date information that can appear either on the front cover by itself or along the top of the first page of text. In order to do this, you must first specify the information. Once this information has been specified it can then be displayed. The author, title and date are entered using the \glspl{command}: \begin{definition} \gls{author}\marg{\meta{author names}} \\%\end{definition} %\begin{definition} \gls{title}\marg{\meta{title text}} \\%\end{definition} %\begin{definition} \gls{date}\marg{\meta{document date}} \end{definition}% The \koma\ classes also define: \begin{definition} \gls{titlehead}\marg{\meta{Title heading}}\\ \gls{subject}\marg{\meta{Subject}}\\ \gls{subtitle}\marg{\meta{Subtitle}}\\ \gls{publishers}\marg{\meta{Publisher}} \end{definition} \faq{The style of document titles}{titlsty}All these title-related commands only \emph{store} information, they don't actually display anything. These commands can be put in the \gls{preamble}. With most classes, you will typically need to use at least \glsni{author} and \glsni{title}. Once you have used these commands, you can then display the information using the command:\refstepcounter{object}\label{obj:maketitle} \begin{definition} \gls{maketitle} \end{definition} This command should be placed where you want the title page to appear, which is normally at the start of the \gls{env-document} environment. Note that if you don't use the \glsni{date} command, the current date will be inserted. If you want no date to appear, you need to specify an empty argument: \begin{codeS} \glsni{date}\marg{} \end{codeS} \bookpagebreak Multiple authors should be separated by the command \gls{and}. For example: \begin{code} \begin{alltt} \glsni{author}\marg{A. Jones\glsni{tab.dbbackslashchar}University of Somewhere \glsni{and} B. Smith\glsni{tab.dbbackslashchar}University of Somewhere Else} \end{alltt} \end{code}% Within these titling fields, you can also use the command: \begin{definition} \gls{thanks}\marg{text} \end{definition}% which produces a special type of footnote. For example: \begin{codeS} \glsni{title}\marg{A Great Project\glsni{thanks}\marg{funded by XYZ}} \end{codeS}% Note that the footnote marker produced using \glsni{thanks} is considered to have zero width, so if it occurs in the middle of a line, rather than the end, you will need to insert some extra space using \gls{spacesym} (backslash space). The argument of \glsni{thanks} is a \glslink{fragile}{moving argument}\index{argument!moving|hyperpage}. \begin{exercise}{Creating Title Pages}{ex:title} Try editing the document you modified in \exerciseref{ex:tabular} to include title information. Modifications are illustrated in bold \modification{like this}: \begin{bcode} \begin{alltt} \glsni{documentclass}\oarg{12pt}\marg{scrartcl} \glsni{usepackage}\marg{datetime} \modification{\glsni{title}\marg{A Simple Document}} \modification{\glsni{author}\marg{Me}} \glsni{begin}\marg{document} \modification{\glsni{maketitle}} This is a simple \glsni{LaTeX}\glsni{spacesym}document. Here is the first paragraph. Here is the second paragraph\glsni{footnote}\marg{with a footnote}. As you can see it's a rather short paragraph, but not as short as the previous one. This document was created on: \glsni{today}\glsni{spacesym}at \glsni{currenttime}. \glsni{begin}\marg{tabular}\marg{lrr} \glsni{ampchar} \glsni{multicolumn}\marg{2}\marg{c}\marg{\glsni{bfseries} Expenditure}\glsni{tab.dbbackslashchar} \glsni{ampchar} \glsni{multicolumn}\marg{1}\marg{c}\marg{Year1} \glsni{ampchar} \glsni{multicolumn}\marg{1}\marg{c}\marg{Year2}\glsni{tab.dbbackslashchar} \glsni{bfseries} Travel \glsni{ampchar} 100,000 \glsni{ampchar} 110,000\glsni{tab.dbbackslashchar} \glsni{bfseries} Equipment \glsni{ampchar} 50,000 \glsni{ampchar} 60,000 \glsni{end}\marg{tabular} \glsni{end}\marg{document} \end{alltt} \end{bcode} You can \download{title} this document. \end{exercise} %%%%%%%%%%%%%%%%%%%%%%%%% Abstract %%%%%%%%%%%%%%%%%%%%%%%% \setnode{abstr} \section{Abstract} \label{sec:abstract} The \gls{env-abstract} \glsterm{environment} is used to create an \Index{abstract} for the document\faq{1-column abstract in 2-column document}{onecolabs}. The way in which the abstract is formatted depends on the class file\indexCLS. The \icls{scrreprt} class file will put the abstract on a page by itself, some class files will indent the abstract and some will typeset the abstract in italic. Note also that some class files (such as \icls{scrbook}) don't have an \glsni{env-abstract} environment. Abstracts traditionally go at the start of the document after the title, so the \glsni{env-abstract} environment should go after the \gls{maketitle} command. \begin{exercise}{Creating an Abstract}{ex:abstr} Try editing your document so that it has an abstract: Modifications are illustrated \modification{like this}: \begin{bcode} \begin{alltt} \glsni{documentclass}\oarg{12pt}\marg{scrartcl} \glsni{usepackage}\marg{datetime} \glsni{title}\marg{A Simple Document} \glsni{author}\marg{Me} \glsni{begin}\marg{document} \glsni{maketitle} \modification{\glsni{begin}\marg{abstract}} \modification{A brief document to illustrate how to use \glsni{LaTeX}.} \modification{\glsni{end}\marg{abstract}} This is a simple \glsni{LaTeX}\glsni{spacesym}document. Here is the first paragraph. Here is the second paragraph\glsni{footnote}\marg{with a footnote}. As you can see it's a rather short paragraph, but not as short as the previous one. This document was created on: \glsni{today}\glsni{spacesym}at \glsni{currenttime}. \glsni{begin}\marg{tabular}\marg{lrr} \glsni{ampchar} \glsni{multicolumn}\marg{2}\marg{c}\marg{\glsni{bfseries} Expenditure}\glsni{tab.dbbackslashchar} \glsni{ampchar} \glsni{multicolumn}\marg{1}\marg{c}\marg{Year1} \glsni{ampchar} \glsni{multicolumn}\marg{1}\marg{c}\marg{Year2}\glsni{tab.dbbackslashchar} \glsni{bfseries} Travel \glsni{ampchar} 100,000 \glsni{ampchar} 110,000\glsni{tab.dbbackslashchar} \glsni{bfseries} Equipment \glsni{ampchar} 50,000 \glsni{ampchar} 60,000 \glsni{end}\marg{tabular} \glsni{end}\marg{document} \end{alltt} \end{bcode} You can \download{abstr} this document. \end{exercise} %%%%%%%%%%%%%%%%% Sections, Subsections etc %%%%%%%%%%%%%%%%%%%%%%%%%%%% \setnode{sectionunits} \section{Chapters, Sections, Subsections \ldots} \label{sec:section} Chapters, sections, subsections etc can be inserted using the commands: \begin{definition} \gls{part}\oarg{\meta{short title}}\marg{\meta{title}}\\ \gls{chapter}\oarg{\meta{short title}}\marg{\meta{title}}\\ \gls{section}\oarg{\meta{short title}}\marg{\meta{title}}\\ \gls{subsection}\oarg{\meta{short title}}\marg{\meta{title}}\\ \gls{subsubsection}\oarg{\meta{short title}}\marg{\meta{title}}\\ \gls{paragraph}\oarg{\meta{short title}}\marg{\meta{title}}\\ \gls{subparagraph}\oarg{\meta{short title}}\marg{\meta{title}} \end{definition}% All these commands have a \latexhtml{moving argument (see \sectionref{sec:fragile})}{\glslink{fragile}{moving argument}\index{argument!moving|hyperpage}}, so fragile commands will need to be protected using \gls{protect}. \faq{How to create a \cmdname{subsubsub\-section}}{subsubsub}The final two commands in the above list, \glsni{paragraph} and \glsni{subparagraph}, represent subsubsubsections and subsubsubsubsections, although most \glspl{cls} typeset their arguments as unnumbered running titles. Note that the availability of these commands depends on the \gls{cls} you are using. For example, the \icls{scrartcl} class file that we have been using is designed for articles, so the \glsni{chapter} command is not defined in that class, whereas it is defined in the \icls{scrreprt} and \icls{scrbook} class files. Each of the commands above has a \gls{mandatory} \meta{title} and an \gls{optional} \meta{short title}. The mandatory argument \meta{title} is simply the title of the chapter\slash section\slash subsection etc. For example: \begin{codeS} \glsni{section}\marg{Introduction} \end{codeS}% If you are using the \icls{scrartcl} class file, the output will look like: \begin{resultS}[Image: The text '1 Introduction' is typeset in a large bold font] \textbf{\sffamily\Large 1\quad Introduction} \end{resultS}% Note that you don't specify the section number as \LaTeX\ does this automatically. This means that you can insert a new section or chapter or swap sections around or even change a section to a subsection etc, without having to worry about updating all the section numbers\faq{The style of section headings}{secthead}. \renewcommand{\fmtord}[1]{\textsuperscript{#1}}% If you are using a class file\indexCLS\ that contains chapters as well as sections, the section number will depend on the chapter. So, for example, the current section is the \ordinal{section}\ section of chapter~\arabic{chapter}, so the section number is \thesection. \faq{Why are my sections numbered 0.1 ...?}{zerochap}(Note that if you are using a class file where the section number depends on the chapter number, you must have a \gls{chapter} command before your first \gls{section} command, otherwise your section numbers will come out as 0.1, 0.2 etc.) Unnumbered chapters/sections etc are produced by placing an asterisk \texttt{*} after the command name. For example: \begin{codeS} \glsni{chapter}*\marg{Acknowledgements} \end{codeS} You can switch to appendices using the command \begin{definition} \gls{appendix} \end{definition}% then continue using \gls{chapter}, \gls{section} etc\faq{Appendixes}{appendix}. For example (using the \icls{scrreprt} class file): \begin{code} \begin{alltt} \glsni{appendix} \glsni{chapter}\marg{Derivations} Some derivations. \glsni{chapter}\marg{Tables} Some tables. \end{alltt} \end{code} \xminisec{Note:} The \koma\ classes have another type of sectioning command: \begin{definition} \gls{minisec}\marg{\meta{heading}} \end{definition}\screenpagebreak This provides an unnumbered heading not associated with any of the structuring levels. For example, the above was produce using: \begin{code} \begin{alltt} \glsni{minisec}\marg{Note:} The \koma\ classes have another type of sectioning command: \end{alltt} \end{code} The next note below was produced using: \begin{code} \begin{alltt} \glsni{minisec}\marg{Important Note:} If you want to change the font style used by headings, \glsni{emph}\marg{\glsni{bfseries} do not} use font declarations in the sectioning command arguments. \end{alltt} \end{code} \xminisec{Important Note:} If you want to change the font style used by headings, \emph{\bfseries do not} use font declarations in the sectioning command arguments. Don't do, for example: \begin{alltt}\wrong \glsni{chapter}\marg{\glsni{itshape} Introduction} \end{alltt} The \koma\ classes provide the command: \begin{definition} \gls{addtokomafont}\marg{\meta{element}}\marg{\meta{commands}} \end{definition} where \meta{element} is the name of a structuring element (no backslash) and \meta{commands} is the list of font changing declarations (see \tableref{tab:fontsII}) to apply to that element style. For example, \latexhtml{this book}{the PDF version of this document} uses the commands: \begin{code} \begin{alltt} \glsni{addtokomafont}\marg{section}\marg{\glsni{rmfamily}\glsni{bfseries}} \glsni{addtokomafont}\marg{minisec}\marg{\glsni{rmfamily}\glsni{bfseries}\glsni{scshape}} \end{alltt} \end{code} \begin{exercise}{Creating Chapters, Sections etc}{ex:section} Let's try editing our document so that it now has chapters, sections and an appendix. Since the \icls{scrartcl} class file doesn't have chapters, let's change to the \icls{scrreprt} class. Changes from our previous document are shown \modification{like this}. \begin{bcode}% \begin{alltt} \glsni{documentclass}\oarg{12pt}\marg{\modification{scrreprt}} \glsni{usepackage}\marg{datetime} \glsni{title}\marg{A Simple Document} \glsni{author}\marg{Me} \glsni{begin}\marg{document} \glsni{maketitle} \glsni{begin}\marg{abstract} A brief document to illustrate how to use \glsni{LaTeX}. \glsni{end}\marg{abstract} \modification{\glsni{chapter}\marg{Introduction}} \modification{\glsni{section}\marg{The First Section}} This is a simple \glsni{LaTeX}\glsni{spacesym}document. Here is the first paragraph. \modification{\glsni{section}\marg{The Next Section}} Here is the second paragraph\glsni{footnote}\marg{with a footnote}. As you can see it's a rather short paragraph, but not as short as the previous one. This document was created on: \glsni{today}\glsni{spacesym}at \glsni{currenttime}. \modification{\glsni{chapter}\marg{Another Chapter}} \modification{Here\textquoteright{}s another very interesting chapter.} \modification{We\textquoteright{}re going to put a picture here later.} \modification{\glsni{chapter}*\marg{Acknowledgements}} \modification{I would like to acknowledge all those} \modification{very helpful people who have assisted me in my work.} \modification{\glsni{appendix}} \modification{\glsni{chapter}\marg{Tables}} \modification{We will turn this tabular environment into a table later.} \glsni{begin}\marg{tabular}\marg{lrr} \glsni{ampchar} \glsni{multicolumn}\marg{2}\marg{c}\marg{\glsni{bfseries} Expenditure}\glsni{tab.dbbackslashchar} \glsni{ampchar} \glsni{multicolumn}\marg{1}\marg{c}\marg{Year1} \glsni{ampchar} \glsni{multicolumn}\marg{1}\marg{c}\marg{Year2}\glsni{tab.dbbackslashchar} \glsni{bfseries} Travel \glsni{ampchar} 100,000 \glsni{ampchar} 110,000\glsni{tab.dbbackslashchar} \glsni{bfseries} Equipment \glsni{ampchar} 50,000 \glsni{ampchar} 60,000 \glsni{end}\marg{tabular} \glsni{end}\marg{document} \end{alltt} \end{bcode} (You can \download{section} a copy of this file if you like, but I~recommend that you try editing the file yourself to give you practice.) \end{exercise} %%%%%%%%%%%%%%%%%%% Table of Contents %%%%%%%%%%%%%%%%%%%%%%%% \setnode{toc} \section{Creating a Table of Contents} \label{sec:toc} Once you have all your \htmlref{sectioning commands}{sec:section}, such as \gls{chapter} and \gls{section}, you can create a table of contents with the command \begin{definition} \gls{tableofcontents} \end{definition}% This command should go where you want your table of contents to appear (usually after \gls{maketitle}).\faq{The format of the Table of Contents, etc}{tocloft} The \koma\ classes provide two options that govern the format of the table of contents: \scrclsopt[graduated]{toc} and \scrclsopt[flat]{toc}. The first is the default and indents the different sectioning levels. The second doesn't use any indentation. \xminisec{Example:} \begin{codeS} \glsni{documentclass}\oarg{12pt,toc=flat}\marg{scrreprt} \end{codeS} You may recall from \htmlref{the previous section}{sec:section} that the sectioning commands all had an optional argument \meta{short title}. If your chapter or section title is particularly long\faq{My section title is too wide for the page header}{runheadtoobig}, you can use \meta{short title} to specify a shorter title that should go in the table of contents.\footnote{\label{ftn:header}and in the page header, depending on the page style.} The longer title (given by the other argument \meta{title}) will still appear in the section heading in the main part of the document. \LaTeX\ processes all source code sequentially, so when it first encounters the \glsni{tableofcontents} command, it doesn't yet know anything about the chapters, sections etc. So the first time the \htmlref{document is \LaTeX{}ed}{ch:tex2pdf} the necessary information is written to the table of contents (\texttt{.toc})\indexTOC\ file (see \sectionref{sec:auxiliary}). The subsequent pass reads the information in from the \texttt{.toc}\indexTOC\ file, and generates the table of contents. You will therefore need to \LaTeX\ your document twice to make sure that the table of contents is up-to-date\faq{Numbers too large in table of contents, etc}{tocloftwrong}. \xminisec{Adding Extra Information} The \htmlref{starred versions}{itm:starredcommand} of the sectional commands (such as \glsnl{chapter}\texttt{*}) don't get added to the table of contents. It may be that you want to add it, in which case you need to use \begin{definition} \gls{addcontentsline}\marg{\meta{toc}}\marg{\meta{section unit}}\marg{\meta{text}} \end{definition} after the heading. The first argument \meta{toc} is the file extension without the dot. As mentioned above, the table of contents file has the extension \texttt{.toc}, so the first argument should be \texttt{toc} (\htmlref{later}{ch:floats}\latex{ in \chapterref{ch:floats}}, we'll be adding a list of figures and a list of tables, and those have file extensions \texttt{.lof}\indexLOF\ and \texttt{.lot}\indexLOT, respectively). The second argument \meta{section unit} is the name of the section unit. This is just the name of the relevant sectioning command \emph{without} the backslash. The final argument \meta{text} is the entry text. For example (using \icls{scrreprt} class): \begin{code} \gls{chapter}*\marg{Acknowledgments}\newline \glsni{addcontentsline}\marg{toc}\marg{chapter}\marg{Acknowledgements} \end{code} \begin{exercise}{Creating a Table of Contents}{ex:toc} Try modifying your document so that it has a table of contents. Modifications from the previous exercise are illustrated \modification{like this}: \begin{bcode} \begin{alltt} \glsni{documentclass}\oarg{12pt}\marg{scrreprt} \glsni{usepackage}\marg{datetime} \glsni{title}\marg{A Simple Document} \glsni{author}\marg{Me} \glsni{begin}\marg{document} \glsni{maketitle} \modification{\glsni{tableofcontents}} \glsni{begin}\marg{abstract} A brief document to illustrate how to use \glsni{LaTeX}. \glsni{end}\marg{abstract} \glsni{chapter}\marg{Introduction} \glsni{section}\marg{The First Section} This is a simple \glsni{LaTeX}\glsni{spacesym}document. Here is the first paragraph. \glsni{section}\marg{The Next Section} Here is the second paragraph\glsni{footnote}\marg{with a footnote}. As you can see it's a rather short paragraph, but not as short as the previous one. This document was created on: \glsni{today}\glsni{spacesym}at \glsni{currenttime}. \glsni{chapter}\marg{Another Chapter} Here's another very interesting chapter. We're going to put a picture here later. \glsni{chapter}*\marg{Acknowledgements} I would like to acknowledge all those very helpful people who have assisted me in my work. \glsni{appendix} \glsni{chapter}\marg{Tables} We will turn this tabular environment into a table later. \glsni{begin}\marg{tabular}\marg{lrr} \glsni{ampchar} \glsni{multicolumn}\marg{2}\marg{c}\marg{\glsni{bfseries} Expenditure}\glsni{tab.dbbackslashchar} \glsni{ampchar} \glsni{multicolumn}\marg{1}\marg{c}\marg{Year1} \glsni{ampchar} \glsni{multicolumn}\marg{1}\marg{c}\marg{Year2}\glsni{tab.dbbackslashchar} \glsni{bfseries} Travel \glsni{ampchar} 100,000 \glsni{ampchar} 110,000\glsni{tab.dbbackslashchar} \glsni{bfseries} Equipment \glsni{ampchar} 50,000 \glsni{ampchar} 60,000 \glsni{end}\marg{tabular} \glsni{end}\marg{document} \end{alltt} \end{bcode} If your table of contents doesn't come out right, try \LaTeX{}ing it again. (Again, you can \download{toc} this file.) You might want to try experimenting with the \scrclsopt[flat]{toc} class options to see what difference it makes: \begin{codeS} \glsni{documentclass}\oarg{12pt,toc=flat}\marg{scrreprt} \end{codeS} \end{exercise} %%%%%%%%%%%%%%%%% Cross-Referencing %%%%%%%%%%%%%%%%%%%%%%%%%%%% \setnode{crossref} \section{Cross-Referencing} \label{sec:crossref} We have already seen that \LaTeX\ takes care of all the numbering for the chapters etc, but what happens if you want to refer to a chapter or section? There's no point leaving \LaTeX\ to automatically generate the section numbers if you have to keep track of them all, and change all your cross-references every time you add a new section. Fortunately \LaTeX\ provides a way to generate the correct number. All you have to do is label the part of the document you want to reference, and then refer to this label when you want to cross-reference it\faq{Referring to labels in other documents}{extref}. \LaTeX\ will then determine the correct number that needs to be inserted at that point. The first part, labelling the place you want to reference, is done using the command: \begin{definition} \gls{label}\marg{\meta{string}} \end{definition}\refstepcounter{object}\label{obj:label}% The \gls{argument} \meta{string} should be a unique textual label. This label can be anything you like as long as it is unique, but it's a good idea to make it something obvious so that, firstly, you can remember the label when you want to use it, and secondly, when you read through your code at some later date, it's immediately apparent to you to which part of the document you are referring. People tend to have their own conventions for labelling. I usually start the label with two or three letters that signify what type of thing I'm labelling. For example, if I'm labelling a chapter I'll start with \texttt{ch}, if I'm labelling a section I'll start with \texttt{sec}. \xminisec{Examples:} \begin{enumerate} \item Labelling a chapter: \begin{code} \begin{alltt} \glsni{chapter}\marg{Introduction} \glsni{label}\marg{ch:intro} \end{alltt} \end{code} \item Labelling a section: \begin{code} \begin{alltt} \glsni{section}\marg{Technical Details} \glsni{label}\marg{sec:details} \end{alltt} \end{code} \end{enumerate} Note that the \glsni{label} command doesn't produce any text, it simply assigns a label. You can now refer to that object using the command: \begin{definition} \gls{ref}\marg{\meta{string}} \end{definition} which will produce the relevant number. \xminisec{Example:} \begin{codeS} See Section \glsni{ref}\marg{sec:results} for an analysis of the results. \end{codeS} \refstepcounter{object}\label{cmd:tilde}% It is a typographical convention that you should never start a new line with a number. For example, if you have the text \dq{Chapter~1} the \dq{1} must be on the same line as the \dq{Chapter}. We can do this by using an \keyword{unbreakable space}, which will put a space but won't allow \LaTeX\ to break the line at that point. This is done using the tilde (\gls{tildechar}) \htmlref{special character}{sec:chars}, so the example above should actually be:\bookpagebreak \begin{codeS} See Section\glsni{tildechar}\glsni{ref}\marg{sec:results} for an analysis of the results. \end{codeS} There is a similar command to reference the page number: \begin{definition} \gls{pageref}\marg{\meta{string}} \end{definition} \xminisec{Example:} \begin{code} See Chapter\glsni{tildechar}\glsni{ref}\marg{ch:def} on page\glsni{tildechar}\glsni{pageref}\marg{ch:def} for a list of definitions. \end{code} The label \texttt{ch:def} obviously needs to be defined somewhere: \begin{code} \begin{alltt} \glsni{chapter}\marg{Definitions} \glsni{label}\marg{ch:def} \end{alltt} \end{code} In fact, I~have done this in my source code for \chapterref[the definitions section]{ch:def} of this document, so the above example would look like: \begin{resultS}[See Chapter 2 on page 8 for a list of definitions] See Chapter~\ref*{ch:def} on page~\pageref*{ch:def} for a list of definitions. \end{resultS} \faq{Referring to things by their name}{nameref}% It's not just chapters and sections that you can reference, most of the numbers that \LaTeX\ automatically generates can be cross-referenced. \xminisec{Example:} The source code for footnote~\ref{ftn:header} \latexhtml{on page~\pageref{ftn:header}}{in \sectionref{sec:toc}} is: \begin{code} \glsni{footnote}\marg{\glsni{label}\marg{ftn:header}and in the page header, depending on the page style} \end{code} \latexhtml{and it was referenced above using:}{and can be referenced using:} \begin{code} The source code for footnote\glsni{tildechar}\glsni{ref}\marg{ftn:header} on page\glsni{tildechar}\glsni{pageref}\marg{ftn:header} is: \end{code} The \isty{varioref} package provides a more convenient way of doing this using the command: \begin{definition} \gls{vref}\marg{\meta{label}} \end{definition} This is like \gls{ref} but also adds information about the location, such as \dq{on page~\meta{n}} or \dq{on the following page}, if the corresponding \gls{label} occurs on a different page, so the above example can be changed to: \begin{codeS} The source code for footnote\glsni{tildechar}\glsni{vref}\marg{ftn:header} is: \end{codeS} \begin{latexonly} \ifscreenorother {% which produces \begin{resultS} The source code for footnote~\vref{ftn:header} is: \end{resultS} }% {% \bookpagebreak\noindent which still produces \begin{resultS} The source code for footnote~\vref{ftn:header} is: \end{resultS} Compare with a reference to one of the labels in the next example: \begin{codeS} See step\glsni{tildechar}\cmdname{vref}\marg{itm:edit}. \end{codeS} which produces: \begin{resultS} See step~\vref{itm:edit}. \end{resultS} }% \end{latexonly} \begin{htmlonly} which produces \begin{resultS}[The source code for footnote 5.1 on page 110 is:] The source code for footnote~\vref{ftn:header} is: \end{resultS} \end{htmlonly} \xminisec{Caveat:} You can run into trouble if the \glsni{vref} command occurs on a page break. When it tries to insert the location information, such as \dq{on the next page}, the information is no longer correct. This can cause an \dq{Infinite loop} error. When this happens, either edit your paragraph so the reference no longer falls on the page break or use \gls{ref} instead of \glsni{vref} for that instance. \xminisec{Another Example:} The \gls{env-enumerate} environment \latex{\ifscreenorother{}{described in \sectionref{sec:enumerate} }}% automatically numbers the items within an ordered list, so it's possible to label list items. Recall the numbered list of instructions at the start of \chapterref{ch:tex2pdf}. Here's the code: \begin{code}[0.9\linewidth] \begin{alltt} \glsni{begin}\marg{enumerate} \glsni{item}\glsni{label}\marg{itm:edit} Write or edit the source code. \glsni{item} Pass the source code to the \glsni{texttt}\marg{latex} or \glsni{texttt}\marg{pdflatex} application (``\glsni{LaTeX}\glsni{spacesym}the document''). \glsni{begin}\marg{itemize} \glsni{item} If there are any error messages, return to Step\glsni{tildechar}\glsni{ref}\marg{itm:edit}. \glsni{item} If there are no error messages, a PDF file is created, go to Step\glsni{tildechar}\glsni{ref}\marg{itm:view}. \glsni{end}\marg{itemize} \glsni{item}\glsni{label}\marg{itm:view} View the PDF file to check the result. \glsni{end}\marg{enumerate} \end{alltt} \end{code} Output: \begin{result}[enumerateref.html] \begin{enumerate} \item\label{itm:edit} Write or edit the source code. \item Pass the source code to the \texttt{latex} or \texttt{pdflatex} application (\dq{\LaTeX\ the document}). \begin{itemize} \item If there are any error messages, return to Step~\ref*{itm:edit}. \item If there are no error messages, a PDF file is created, go to Step~\ref*{itm:view}. \end{itemize} \item\label{itm:view} View the PDF file to check the result. \end{enumerate} \end{result} The \gls{ref} and \gls{pageref} commands may come before or after the corresponding \gls{label} command. As with the table of contents, \LaTeX\ first writes out all the cross-referencing information to another file (the \iauxfile, see \sectionref{sec:auxiliary}) and then reads it in the next time, so you will need to \LaTeX\ your document twice to get everything up-to-date. If the references aren't up-to-date, you will see the following message at the end of the \LaTeX\ run: \begin{verbatim} LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right. \end{verbatim} The following warning \begin{verbatim} LaTeX Warning: There were undefined references. \end{verbatim} means that \LaTeX\ found a reference to a label that does not appear in the auxiliary file\indexAUX. This could mean that it's a new label, and the warning will go away the next time you \LaTeX\ your document, or it could mean that either you've forgotten to define your label with the \gls{label} command, or you've simply misspelt the label. The undefined references will show up as two question marks \doublequestionmark\ in the \gls{output}. \faq{\dq{Rerun} messages won't go away}{rerun}Very occasionally, if you have cross-references and a table of contents, you might have to \LaTeX\ your document three times to get everything up to date. Just check to see if the \texttt{Label(s) may have changed} warning appears. If you find it inconvenient having to remember to click the typeset button twice, you can use \iappname{latexmk}. This will run \LaTeX\ the required number of times to ensure the document is up-to-date. To do this in TeXWorks, change the drop-down menu to \dq{LaTeXmk}, as illustrated in \figureref{fig:latexmk}. Note that \appname{latexmk} is a \gls{perl} script, so you need to make sure you have \iappname{perl} installed (see \sectionref{sec:perl}). \begin{figure}[htbp] \figconts {pictures/texworks-latexmk} {% \caption{Selecting LaTeXmk in TeXWorks} }% {fig:latexmk} \end{figure} If \appname{latexmk} isn't listed in the drop-down menu, you can add it via \menu{Edit}\menuto\menu{Preferences}. This opens the dialog box shown in \figureref{fig:texworks-pref}. You can add a new tool as follows: \begin{enumerate} \item To the right of the box labelled \dq{Processing Tools} there is a button marked with a plus (+) sign. Click on it to open the tool configuration dialog, shown in \figureref{fig:texworks-toolconfig}. \item Fill in the name \dq{LaTeXmk} in the box labelled \dq{Name} and either type in the location of \appname{latexmk} in the box labelled \dq{Program} or use the \dq{Browse} button to locate it on your filing system. (See \figureref{fig:texworks-toolconfig2}.) This will vary depending on your operating system and \gls{tex}-distribution, but it will probably be in a subdirectory (folder) called \texttt{bin} somewhere in the \gls*{tex}-distribution tree. \item There are lots of options that can be passed to \appname{latexmk}, but if you want to produce PDF output you need to add \texttt{-pdf} as an argument. This is done by clicking on the button marked with a plus to the right of the \dq{Arguments} box and type \texttt{-pdf}, as shown in \figureref{fig:texworks-toolconfig3}. \item Another argument needs to be added that specifies the basename of the \LaTeX\ file. This is done by again clicking on the plus button and typing \verb|$basename|, as shown in \figureref{fig:texworks-toolconfig4} . \item Click on \dq{OK} to close the Tool Configuration dialog. \item If you want to set \appname{latexmk} to be your default processing tool, you can select it from the drop-down list labelled \dq{Default}. \item Click \dq{OK} when you're done. \end{enumerate} \begin{figure}[htbp] \figconts {pictures/texworks-preferences} {% \caption{TeXWorks Preferences} } {fig:texworks-pref} \end{figure} \begin{figure}[htbp] \figconts {pictures/texworks-toolconfig1} {% \caption{Tool Configuration Dialog} } {fig:texworks-toolconfig} \end{figure} \begin{figure}[htbp] \figconts {pictures/texworks-toolconfig2} {% \caption{Tool Configuration Dialog: set the name and program location} } {fig:texworks-toolconfig2} \end{figure} \begin{figure}[htbp] \figconts {pictures/texworks-toolconfig3} {% \caption{Tool Configuration Dialog: adding \protect\texttt{-pdf} argument} } {fig:texworks-toolconfig3} \end{figure} \begin{figure}[htbp] \figconts {pictures/texworks-toolconfig4} {% \caption{Tool Configuration Dialog: adding \protect\texttt{\$basename} argument} } {fig:texworks-toolconfig4} \end{figure} \begin{exercise}{Cross-Referencing}{ex:crossref} Try modifying your code so that it has cross-references. Again, changes made from the previous exercise are illustrated \modification{like this}: \begin{bcode} \begin{alltt} \glsni{documentclass}\oarg{12pt}\marg{scrreprt} \glsni{usepackage}\marg{datetime} \glsni{title}\marg{A Simple Document} \glsni{author}\marg{Me} \glsni{begin}\marg{document} \glsni{maketitle} \glsni{tableofcontents} \glsni{begin}\marg{abstract} A brief document to illustrate how to use \glsni{LaTeX}. \glsni{end}\marg{abstract} \glsni{chapter}\marg{Introduction} \modification{\glsni{label}\marg{ch:intro}} \glsni{section}\marg{The First Section} This is a simple \glsni{LaTeX}\glsni{spacesym}document. Here is the first paragraph. \modification{The next chapter is Chapter\glsni{tildechar}\glsni{ref}\marg{ch:another}} \modification{and is on page\glsni{tildechar}\glsni{pageref}\marg{ch:another}.} \modification{The next section is Section\glsni{tildechar}\glsni{ref}\marg{sec:next}.} \glsni{section}\marg{The Next Section} \modification{\glsni{label}\marg{sec:next}} Here is the second paragraph\glsni{footnote}\marg{with a footnote}. As you can see it's a rather short paragraph, but not as short as the previous one. This document was created on: \glsni{today}\glsni{spacesym}at \glsni{currenttime}. \glsni{chapter}\marg{Another Chapter} \modification{\glsni{label}\marg{ch:another}} Here's another very interesting chapter. We're going to put a picture here later. \modification{See Chapter\glsni{tildechar}\glsni{ref}\marg{ch:intro} for an } \modification{introduction.} \glsni{chapter}*\marg{Acknowledgements} I would like to acknowledge all those very helpful people who have assisted me in my work. \glsni{appendix} \glsni{chapter}\marg{Tables} We will turn this tabular environment into a table later. \glsni{begin}\marg{tabular}\marg{lrr} \glsni{ampchar} \glsni{multicolumn}\marg{2}\marg{c}\marg{\glsni{bfseries} Expenditure}\glsni{tab.dbbackslashchar} \glsni{ampchar} \glsni{multicolumn}\marg{1}\marg{c}\marg{Year1} \glsni{ampchar} \glsni{multicolumn}\marg{1}\marg{c}\marg{Year2}\glsni{tab.dbbackslashchar} \glsni{bfseries} Travel \glsni{ampchar} 100,000 \glsni{ampchar} 110,000\glsni{tab.dbbackslashchar} \glsni{bfseries} Equipment \glsni{ampchar} 50,000 \glsni{ampchar} 60,000 \glsni{end}\marg{tabular} \glsni{end}\marg{document} \end{alltt} \end{bcode} (You can \download{crossref} a copy of this file.) \end{exercise} %%%%%%%%%%%%%%%%%%%% Bibliography %%%%%%%%%%%%%%%%%%%%%%%%% \setnode{biblio} \section{Creating a Bibliography} \label{sec:bib} If you have a large number of citations in your document, it's best to use an external bibliographic application\faq{Creating a BibTeX bibliography file}{buildbib}, such as \iappname{bibtex} or \iappname{biber}. However, that is beyond the scope of this book (see, instead, \latexguide, \latexcomp\ or \latexthesis). Therefore this section just gives a brief explanation of the \gls{env-thebibliography} environment, which is usually automatically generated using \appname{bibtex} or \appname{biber}. \begin{definition} \glsni{begin}\marg{thebibliography}\marg{\meta{widest tag}} \end{definition} This environment is very similar to the list making environments described in \sectionref{sec:lists}, but instead of \gls{item} use \begin{definition} \gls{bibitem}\oarg{\meta{tag}}\marg{\meta{key}} \end{definition}% where \meta{key} is a unique keyword that identifies this item. Your keyword can be anything you like, but as with \glsni{label} I~recommend that you use a short memorable keyword. I~tend to use the first author's surname followed by the year of publication. The bibliography heading depends on the class file you are using. Most of the article-style classes, such as \icls{scrreprt}, use \glsi{refname} (which produces \dq{\refname}) in an unnumbered section, whereas the report and book-styles, such as \icls{scrreprt} and \icls{scrbook}, use \glsi{bibname} (which produces \dq{\bibname}) in an unnumbered chapter. See \tableref{tab:textlab} for the list of the common textual label commands. Most class files don't automatically add the bibliography to the table of contents. The \koma\ classes provide the \scrclsopt{bibliography} option. This can be \scrclsopt[totoc]{bibliography} (an unnumbered unit added to the table of contents), for example, \begin{codeS} \glsni{documentclass}\oarg{bibliography=totoc}\marg{scrreprt} \end{codeS} or \scrclsopt[totocnumbered]{bibliography} (a numbered unit added to the table of contents), for example, \begin{codeS} \glsni{documentclass}\oarg{bibliography=totocnumbered}\marg{scrreprt} \end{codeS} If you're not using one of the \koma\ classes, consult the \htmlref{documentation}{sec:texdoc} for your class to see if there is an equivalent option. Failing that, you can use \gls{addcontentsline} (described in \sectionref{sec:toc}). For example (using a class that defines chapters): \begin{code} \glsni{addcontentsline}\marg{toc}\marg{chapter}\marg{\glsni{bibname}}\\ \glsni{begin}\marg{bibliography}\marg{1} \end{code} \xminisec{Example:} (This example uses the command \gls{LaTeXe} which produces the \LaTeXe\ logo. This indicates the current version of \LaTeX\ rather than the old 2.09 version.)\footnote{If a friend or colleague gives you a file containing \cmdname{documentstyle} instead of \cmdname{documentclass} they are nearly 20~years out of date.} The class style in use is \cls{scrbook}, so the title is given by \glsni{bibname} (\dq{Bibliography}). \begin{code} \glsni{begin}\marg{thebibliography}\marg{3}\newline \glsni{bibitem}\marg{lamport94} \glsni{quotedblleft}\glsni{LaTeX}: a document preparation system\glsni{quotedblright}, Leslie Lamport, 2nd edition (updated for \glsni{LaTeXe}), Addison-Wesley (1994).\newline \mbox{}\newline \glsni{bibitem}\marg{kopka95} \glsni{quotedblleft}A Guide to \glsni{LaTeX}: document preparation for beginners and advanced users\glsni{quotedblright}, Helmut Kopka and Patrick W. Daly, Addison-Wesley (1995).\newline \mbox{}\newline \glsni{bibitem}\marg{goossens94} \glsni{quotedblleft}The \glsni{LaTeX}\glsni{spacesym}Companion\glsni{quotedblright}, Michel Goossens, Frank Mittelbach and Alexander Samarin, Addison-Wesley, (1994).\newline \mbox{}\newline \glsni{end}\marg{thebibliography} \end{code} \begin{result}[references.html] \dobibexamplenumbered \end{result} You can cite an item in your bibliography with the command \begin{definition} \gls{cite}\oarg{\meta{text}}\marg{\meta{key list}} \end{definition}% \bookpagebreak \xminisec{Example:} \begin{code} \begin{alltt} For more information about writing bibliographies see Goossens \glsni{emph}\marg{et al.}\glsni{tildechar}\glsni{cite}\marg{goossens94}. \end{alltt} \end{code}% Output: \begin{resultS}[cite.html] For more information about writing bibliographies see Goossens \emph{et al.}~[3]. \end{resultS} If you want to cite multiple works, use a comma-separated list: \begin{code} \begin{alltt} For more information about writing bibliographies see\glsni{tildechar}\glsni{cite}\marg{kopka95,goossens94}. \end{alltt} \end{code}% Output: \begin{resultS}[mcite.html] For more information about writing bibliographies see~[2,3]. \end{resultS} The \gls{optional} \meta{text} to the \glsni{cite} command can be used to add text to the citation. \xminisec{Example:} \begin{code} \begin{alltt} For more information about writing bibliographies see Goossens \glsni{emph}\marg{et al.}\glsni{tildechar}\glsni{cite}\oarg{Chapter~13}\marg{goossens94}. \end{alltt} \end{code}% Output: \begin{result}[chcite.html] For more information about writing bibliographies see Goossens \emph{et al.}~[3, Chapter~13]. \end{result} The \gls{env-thebibliography} environment has a \gls{mandatory}: \begin{definition} \glsni{begin}\marg{thebibliography}\marg{\meta{widest tag}} \end{definition}% The argument \meta{widest tag} is the widest tag in the list of entries. This helps \LaTeX\ to align the references correctly. In the example above, the tags appeared as: [1], [2] and [3], and [3] is the widest so that was used as the argument. These tags can be changed from the default numbers to something else using the optional argument to the \gls{bibitem} command. \xminisec{Example (Textual Tags):} This example uses the \gls{optional} of \gls{bibitem} to use textual rather than numerical tags. The widest tag is [Goossens 1994] so that is chosen to be the argument of the \gls{env-thebibliography} environment: \begin{code} \glsni{begin}\marg{thebibliography}\marg{Goossens 1994}\newline \mbox{}\newline \glsni{bibitem}[Lamport 1994]\marg{lamport94} \glsni{quotedblleft}\glsni{LaTeX}\cmdname{ } : a document preparation system\glsni{quotedblright}, Leslie Lamport, 2nd edition (updated for \glsni{LaTeXe}), Addison-Wesley (1994).\newline \mbox{}\newline \glsni{bibitem}[Kopka 1995]\marg{kopka95} \glsni{quotedblleft}A Guide to \glsni{LaTeX}: document preparation for beginners and advanced users\glsni{quotedblright}, Helmut Kopka and Patrick W. Daly, Addison-Wesley (1995).\newline \mbox{}\newline \glsni{bibitem}[Goossens 1994]\marg{goossens94} \glsni{quotedblleft}The \glsni{LaTeX}\glsni{spacesym}Companion\glsni{quotedblright}, Michel Goossens, Frank Mittelbach and Alexander Samarin, Addison-Wesley, (1994).\newline \mbox{}\newline \glsni{end}\marg{thebibliography} \end{code} \begin{result}[references2.html] \dobibexamplelabelled \end{result} \begin{exercise}{Creating a Bibliography}{ex:biblio} Try adding the following chapter to your document: \begin{code} \glsni{chapter}\marg{Recommended Reading} For a basic introduction to \glsni{LaTeX}\glsni{spacesym}see Lamport\glsni{tildechar}\glsni{cite}\marg{lamport94}. For more detailed information about \glsni{LaTeX}\glsni{spacesym}and associated applications, consult Kopka and Daly\glsni{tildechar}\glsni{cite}\marg{kopka95} or Goossens \glsni{emph}\marg{et al}\glsni{tildechar}\glsni{cite}\marg{goossens94}. \end{code}% and also add the bibliography shown above to the end of your document. You can \downloadorview{biblio} the solution, but have a go by yourself first. Remember that, as before, you will need to \LaTeX\ the document twice to get the references up-to-date, unless you're using \iappname{latexmk} (as described in \sectionref{sec:crossref}) in which case it will be done automatically. \end{exercise} %%%%%%%%%%%%%%%%%%%%%%%%% Page Styles %%%%%%%%%%%%%%%%%%%%%%%%%% \setnode{pagestyle} \section{Page Styles and Page Numbering} \label{sec:pagestyle} You may have noticed that the documents you have created have all had their page numbers automatically inserted at the foot of most of the pages\faq{Page numbering \dq{\meta{n} of \meta{m}}}{nofm}. If you have created the document that has gradually been modified over the previous few sections, you may have noticed that the title page has no header or footer, the table of contents starts on page~1, the abstract page has no page number, and the pages after the abstract start on page~1 and continue incrementally onwards from that point. All the page numbers are Arabic numerals. This can be changed using the command: \begin{definition} \gls{pagenumbering}\marg{\meta{style}} \end{definition}% where \meta{style} can be one of: \begin{fwlist}{\pagenumberingfmt{arabic}} \fwitem{\ipagenumbering{arabic}} Arabic numerals (1, 2, 3, \ldots) \fwitem{\ipagenumbering{roman}} Lower case Roman numerals (i, ii, iii, \ldots) \fwitem{\ipagenumbering{Roman}} Upper case Roman numerals (I, II, III, \ldots) \fwitem{\ipagenumbering{alph}} Lower case alphabetical characters (a, b, c, \ldots) \fwitem{\ipagenumbering{Alph}} Upper case alphabetical characters (A, B, C, \ldots) \end{fwlist} Traditionally, the front matter (table of contents, list of figures etc) should have lower case Roman numeral page numbering, while the main matter should be in Arabic numerals\faq{Page numbering by chapter}{pagebychap}. \xminisec{Example:} \begin{code} \begin{alltt} \glsni{author}\marg{Me} \glsni{title}\marg{A Simple Document} \glsni{maketitle} \glsni{pagenumbering}\marg{roman} \glsni{tableofcontents} \glsni{begin}\marg{abstract} This is the abstract. \glsni{end}\marg{abstract} \glsni{pagenumbering}\marg{arabic} \glsni{chapter}\marg{Introduction} \end{alltt} \end{code} The \icls{scrbook} class provides: \begin{definition} \gls{frontmatter} \end{definition} which switches to lower case Roman numeral page numbering, and \begin{definition} \gls{mainmatter} \end{definition} which switches to Arabic numeral page numbering. These two declarations also change the way the sectioning units, such as \gls{chapter} and \gls{section}, appear. The former, \glsni{frontmatter}, suppresses the numbering (regardless of whether or not you've used the \htmlref{starred version}{itm:starredcommand} of the sectioning commands). The latter, \glsni{mainmatter}, switches the numbering back on (unless otherwise suppressed by using the starred sectioning commands). In addition, \icls{scrbook} provides \begin{definition} \gls{backmatter} \end{definition} which doesn't affect the page numbering but, like \glsni{frontmatter}, suppresses the sectional unit numbering. \xminisec{Note:} The \gls{env-abstract} environment isn't defined by the \icls{scrbook} class, as a book summary is usually incorporated into an introductory section. \xminisec{Example:} \begin{code} \begin{alltt} \glsni{documentclass}\oarg{12pt}\marg{scrbook} \glsni{title}\marg{A Simple Document} \glsni{author}\marg{Me} \glsni{begin}\marg{document} \glsni{maketitle} \glsni{frontmatter} \glsni{tableofcontents} \glsni{chapter}\marg{Summary} A brief document to illustrate how to use \glsni{LaTeX}. \glsni{mainmatter} \glsni{chapter}\marg{Introduction} \glsni{label}\marg{ch:intro} \glsni{end}\marg{document} \end{alltt} \end{code} The headers and footers can be changed using the command \begin{definition} \gls{pagestyle}\marg{\meta{style}} \end{definition}% Individual pages can be changed using \begin{definition} \gls{thispagestyle}\marg{\meta{style}} \end{definition}% Standard styles are: \begin{fwlist}{myheadings} \fwitem{\ipagestyle{empty}} No header or footer. \fwitem{\ipagestyle{plain}} Header empty, page number in footer. \fwitem{\ipagestyle{headings}} Header contains page number and various information, footer empty. \fwitem{\ipagestyle{myheadings}} Header specified by user, footer empty. \end{fwlist} If the \ipagestyle{myheadings} style is used, the header information can be specified using: \begin{definition} \gls{markboth}\marg{\meta{left head}}\marg{\meta{right head}} \end{definition}% if the \clsopt{twoside} option has been passed to the \gls{cls} (default for \icls{scrbook}), or \begin{definition} \gls{markright}\marg{\meta{right head}} \end{definition}% if the \clsopt{oneside} option has been passed to the \gls{cls} (default for \icls{scrartcl} and \icls{scrreprt}). The \icls{scrreprt} class file uses the \pagestylefmt{empty} style for the \Index{title} and \Index{abstract} pages and \pagestylefmt{plain} for the first page of each new chapter. By default the remaining pages are also \pagestylefmt{plain}, but these can be changed using the \glsni{pagestyle} command. The \icls{scrbook} class defaults to the \pagestylefmt{headings} style instead of \pagestylefmt{plain}. \faq{Alternative head- and footlines in LaTeX}{fancyhdr}% The \koma\ bundle provides a way to define new page styles, but that's beyond the scope of this introductory tutorial. See the \koma\ documentation for further details if you are interested. \casemedia {% A4 This book mostly uses the \pagestylefmt{headings} page style and the \icls{scrbook} class with the \clsopt{oneside} option, so there is no difference between odd and even page headers, whereas the paperback version uses the \clsopt{twoside} option, so the odd pages display the chapter number and title and the even pages display the current section header and title. The on-screen PDF version of this book uses a page style I~defined myself that incorporates a navigation bar in the footer. }% {% screen This screen version of the book uses a page style I~defined myself that incorporates a navigation bar in the footer. The \htmladdnormallink{A4 version}{\baseurl/latex/novices/novices-a4.pdf} mostly uses the \pagestylefmt{headings} page style. If you look at it, you will see that the chapter number and title appear on the top left and the page number appears in the top right of most pages. The \clsopt{oneside} option was used, so there is no difference between the formatting of odd and even numbered pages. Whereas the paperback version uses the \clsopt{twoside} option so the odd and even page headers are different. } {% book This book mostly\footnote{I made some modifications to the page style for the footers in the summary and index.}\ uses the \pagestylefmt{headings} page style and the \icls{scrbook} class with the \clsopt{twoside} option, so the odd and even page headers are different, whereas the A4 PDF version (available from \url{\baseurl/}) uses the \clsopt{oneside} option, so the odd and even page headers are the same. The on-screen PDF version of this book uses a page style I~defined myself that incorporates a navigation bar in the footer. } {% html The \htmladdnormallink{A4 version}{\baseurl/latex/novices/novices-a4.pdf} of this book mostly uses the \pagestylefmt{headings} page style. If you look at it, you will see that the chapter number and title appear on the top left and the page number appears in the top right of most pages. The \clsopt{oneside} option was used, so there is no difference between the formatting of odd and even numbered pages. Whereas the paperback version uses the \clsopt{twoside} option, so the odd pages display the chapter number and title and the even pages display the current section header and title. The \htmladdnormallink{on-screen PDF version}{\baseurl/latex/novices/novices-screen.pdf} of this book uses a page style I~defined myself that incorporates a navigation bar in the footer. } \begin{exercise}{Page Styles and Page Numbering}{ex:pagestyle} Try modifying your code so that it uses the \icls{scrbook} class, \gls{frontmatter} and \gls{mainmatter}. Replace the \gls{env-abstract} environment with an unnumbered chapter, as shown below. Again, changes made from the previous document are illustrated \modification{like this}:\screenpagebreak \begin{bcode} \begin{alltt} \glsni{documentclass}\oarg{12pt}\marg{\modification{scrbook}} \glsni{usepackage}\marg{datetime} \modification{\glsni{pagestyle}\marg{headings}} \glsni{title}\marg{A Simple Document} \glsni{author}\marg{Me} \glsni{begin}\marg{document} \glsni{maketitle} \modification{\glsni{frontmatter}} \glsni{tableofcontents} \modification{\glsni{chapter}\marg{Summary}} A brief document to illustrate how to use \glsni{LaTeX}. \modification{\glsni{mainmatter}} \glsni{chapter}\marg{Introduction} \glsni{label}\marg{ch:intro} \glsni{section}\marg{The First Section} This is a simple \glsni{LaTeX}\glsni{spacesym}document. Here is the first paragraph. The next chapter is Chapter\glsni{tildechar}\glsni{ref}\marg{ch:another} and is on page\glsni{tildechar}\glsni{pageref}\marg{ch:another}. The next section is Section\glsni{tildechar}\glsni{ref}\marg{sec:next}. \glsni{percentchar} Rest of document unchanged but \glsni{percentchar} omitted for brevity. \glsni{end}\marg{document} \end{alltt} \end{bcode} (You can \downloadorview{pagestyle} the edited document.) \end{exercise} %%%%%%%%%%%%%%%%%%%%%%% babel %%%%%%%%%%%%%%%%%%%%%%%%% \setnode{babel} \section{Multi-Lingual Support: using the \texorpdfstring{\sty{babel}}{babel} package} \label{sec:babel} You may have noticed that the \gls{tableofcontents} and \gls{chapter} commands have produced English words like \dq{Contents} and \dq{Chapter}\faq{How to change LaTeX's \dq{fixed names}}{fixnam}. If you are writing in another language, this is not appropriate. In this case, you can use the \isty{babel} package, and specify which language you will be using, either as an option to the \isty{babel} package, or as an option to the class file\faq{Using a new language with Babel}{newlang}. If you are writing in more than one language, list all the languages that you will be using where the last named language is the default language\faq{Parallel setting of text}{parallel}. For example: \begin{alltt} \glsni{usepackage}\oarg{english,french}\marg{babel} \end{alltt} or \begin{alltt} \glsni{documentclass}\oarg{english,french}\marg{scrreprt} \glsni{usepackage}\marg{babel} \end{alltt} You can then switch between the named languages either using the \gls{declaration}: \begin{definition} \gls{selectlanguage}\marg{\meta{language}} \end{definition}% or the \gls{env-otherlanguage} \glsterm{environment}: \begin{definition} \glsni{begin}\marg{otherlanguage}\marg{\meta{language}} \end{definition}% These will affect all translations, including the date format and predefined names like \dq{Chapter}. This also changes the \gls{hyphenation} patterns.\latex{ (See \sectionref{sec:hyphenation}.)} If you only want to set a short section of text in a different language, without affecting the date format or predefined names, then you can either use the command: \begin{definition} \gls{foreignlanguage}\marg{\meta{language}}\marg{\meta{text}} \end{definition}% or the starred version of the \glsni{env-otherlanguage} environment: \begin{definition} \glsni{begin}\marg{otherlanguage*}\marg{\meta{language}} \end{definition}% You can test to see if a given language is currently selected using: \begin{definition} \gls{iflanguage}\marg{\meta{language}}\marg{\meta{true text}}% \marg{\meta{false text}} \end{definition}% \xminisec{Example:} \begin{code} \begin{alltt} \glsni{documentclass}\oarg{UKenglish,USenglish,french}\marg{scrartcl} \glsni{percentchar} french is the last named option, so that's the current language \glsni{usepackage}\oarg{T1}\marg{fontenc} \glsni{usepackage}\oarg{utf8}\marg{inputenc} \glsni{usepackage}\marg{babel} \glsni{begin}\marg{document} Ce texte est en fran\glsni{c}\marg{c}ais. La date aujourd'hui est: \glsni{today}. \glsni{selectlanguage}\marg{USenglish} This text is in US English. Today's date is: \glsni{today}. \glsni{selectlanguage}\marg{UKenglish} This text is in UK English. Today's date is: \glsni{today}. \glsni{end}\marg{document} \end{alltt} \end{code} Result: \begin{result}[babel.html] Ce texte est en fran\c{c}ais. La date aujourd'hui est~: {\datefrench\docdate}. This text is in US English. Today's date is: {\usdate\docdate}. This text is in UK English. Today's date is: {\ukenglishdate\docdate}. \end{result} \xminisec{Note:} \warning If you are using the \istyopt{babel}{french} option, the colon character (\Indextt{:}) is made active (that is, it's turned into a special character) so if you are writing in French it's best not to use a colon in labels (so where I've used, say, \texttt{ch:def} you may need to change the colon to something else). %%%%%%%%%%%%%%%%%%%%%%%% graphicx %%%%%%%%%%%%%%%%%%% \setnode{graphicx} \chapter{The \texorpdfstring{\sty{graphicx}}{graphicx} Package} \label{ch:graphicx} It is possible to generate images using \LaTeX\ commands\faq{Drawing with TeX}{drawing} (See the \isty{pgf}\slash\isty{tikz} package or \latexgraphic) however most people find it easier to create a picture in some other application, and include that file into their \LaTeX\ document. PDF\LaTeX\ can insert PDF, PNG and JPG image files into your document. If your image file is in a different format, you may be able to find an application to convert it. \faq{Spawning programs from (La)TeX: \cmdname{write}18}{spawnprog}Modern \gls{tex}-distributions can automatically convert EPS\indexEPS\ files to PDF during the \LaTeX\ run using the \gls{perl} script \iappname{epstopdf}. If your \gls{tex}-distribution doesn't support this, you can convert your EPS file using \appname{epstopdf} explicitly. For example, if you have an EPS image called, say, \texttt{sample-image.eps}, you can convert it to a PDF image called \texttt{sample-image.pdf}, by using the following command in a \glslink{terminal}{terminal or command prompt}: \begin{verbatim} epstopdf sample-image.eps \end{verbatim} or (full path name may be required) \begin{verbatim} perl epstopdf sample-image.eps \end{verbatim} To insert an image file into your document, you first need to specify that you want to use the \isty{graphicx} package. So the following must go in the \gls{preamble}: \begin{codeS} \glsni{usepackage}\marg{graphicx} \end{codeS} The image can then be included in your document using the command \begin{definition} \gls{includegraphics}\oarg{\meta{key-val options}}\marg{\meta{filename}} \end{definition} where \meta{filename} is the name of your image file \emph{without the file extension}\faq{\dq{Modern} graphics file names}{grffilenames}, and \meta{key-val options} is a comma-separated list of options that can be used to change the way the image is displayed. Note that if you have an image where the file name contain spaces or multiple dots, you need to use the \isty{grffile} package: \begin{codeS} \glsni{usepackage}\marg{graphicx,grffile} \end{codeS} \xminisec{Example:} Suppose you had a file called \texttt{shapes.pdf}, then to include it in your document you would do: \begin{codeS} \glsni{includegraphics}\marg{shapes} \end{codeS}% which would produce: \begin{resultS*} \incGraphics[alt=Image of some shapes]{pictures/shapes} \end{resultS*} You can specify a full or relative pathname, but you must use a forward slash \gls{dir.slash} as the directory divider, even if you are using Windows. For example: \begin{codeS} \glsni{includegraphics}\marg{pictures\glsni{dir.slash}shapes} \end{codeS} means the file \texttt{pictures/shapes.pdf} on Unix-type systems, and it means the file \texttt{pictures\backslashsym shapes.pdf} on Windows.\footnote{Or \texttt{shapes.png} or \texttt{shapes.jpg} or \texttt{shapes.eps}. The example assumes a PDF image file.} This is mainly because the backslash character is a \LaTeX\ special character indicating a command, but it also helps portability between platforms. You can specify the order of the file types to look for with the command \begin{definition} \gls{DeclareGraphicsExtensions}\marg{\meta{ext-list}} \end{definition}% where \meta{ext-list} is a comma-separated list of extensions. For example, you might want to search first for PDF files, then for PNG files, then for JPG files and finally for EPS files: \begin{codeS} \glsni{DeclareGraphicsExtensions}\marg{.pdf,.png,.jpg,.eps} \end{codeS}% The default for \iPDFLaTeX\ is: \begin{flushleft}\ttfamily .png\comma .pdf\comma .jpg\comma .mps\comma .jpeg\comma .jbig2\comma .jb2\comma .PNG\comma .PDF\comma .JPG\comma .JPEG\comma .JBIG2\comma .JB2\comma .eps \end{flushleft} The \gls{optional} \meta{key-val options} should be a comma-separated list of \meta{key}\texttt{=}\meta{value} pairs. Common options are: \begin{fwlist}{\ikeyvalopt{includegraphics}{trim}=\meta{l} \meta{b} \meta{r} \meta{t}} \fwitem{\ikeyvalopt{includegraphics}{angle}=\meta{\mathorit{x}}} rotate the image by \degrees{x} anticlockwise. \fwitem{\ikeyvalopt{includegraphics}{width}=\meta{length}} scale the image so that the width is \meta{length}. (Remember to specify the \htmlref{units}{tab:units}.) \fwitem{\ikeyvalopt{includegraphics}{height}=\meta{length}} scale the image so that the height is \meta{length}. (Remember to specify the \htmlref{units}{tab:units}.) \fwitem{\ikeyvalopt{includegraphics}{scale}=\meta{value}} Scale the image by \meta{value} \fwitem{\ikeyvalopt{includegraphics}{trim}=\meta{l} \meta{b} \meta{r} \meta{t}} Specifies the amount to remove from each side. For example \begin{codeS} \glsni{includegraphics}\oarg{trim=1 2 3 4}\marg{shapes} \end{codeS} crops the image by 1bp from the left, 2bp from the bottom, 3bp from the right and 4bp from the top. (Recall the \iunit{bp}{big point} unit from \tableref{tab:units}.)\reportpagebreak \fwitem{\ikeyvalopt{includegraphics}{draft}} Don't actually print the image, just draw a box of the same size and print the filename inside it. \end{fwlist} \xminisec{Example:} This example first rotates the image by \degrees{45} anticlockwise, then scales it so that the width is 1~inch. \begin{codeS} \glsni{includegraphics}\oarg{angle=45,width=1in}\marg{shapes} \end{codeS} \begin{resultS}[Image of shapes rotated then scaled] \includegraphics[angle=45,width=1in]{pictures/shapes} \end{resultS} Note that this isn't the same as scaling and then rotating: \begin{codeS} \glsni{includegraphics}\oarg{width=1in,angle=45}\marg{shapes} \end{codeS} \begin{resultS}[Image of shapes scaled then rotated] \includegraphics[width=1in,angle=45]{pictures/shapes} \end{resultS} You can also scale an image relative to the text area using the \gls{length} registers \gls{textwidth} and \gls{textheight}. For example, to scale a portrait image so that its height is three-quarters of the text area height, you can do: \begin{codeS} \glsni{includegraphics}\oarg{height=0.75\glsni{textheight}}\marg{shapes} \end{codeS} or to scale a landscape image so that its width is half the text area width, you can do: \begin{codeS} \glsni{includegraphics}\oarg{height=0.5\glsni{textwidth}}\marg{shapes} \end{codeS} \xminisec{Note:} The \gls{includegraphics} command is another form of box (see \sectionref{sec:boxes}), and can be used in the middle of a line of text, just like the \gls{env-tabular} environment. See \sectionref{sec:figures} to find out how to put the image in a figure with a caption. \xminisec{Example:} \refstepcounter{object}\label{example:inlinegraphic}% Recall the \iunit{ex}{relative unit} unit of measure from \tableref{tab:units}. This can be used to scale an image relative to the font size: \begin{code} An image can be inserted into a line of text like this: \glsni{includegraphics}\oarg{height=2ex}\marg{shapes} \end{code} \begin{resultS}[Image of typeset output: the included image has been scaled so that it fits into the line of text] An image can be inserted into a line of text like this: \includegraphics[height=2ex]{pictures/shapes} \end{resultS} \setnode{graphictrans} \section{Graphical Transformations} \label{sec:graphtrans} The \isty{graphicx} package also provides commands to rotate, resize, reflect and scale text. They are as follows: \begin{definition} \gls{rotatebox}\oarg{\meta{option list}}\marg{\meta{angle}}\marg{\meta{text}} \end{definition} Rotates \meta{text} by \meta{angle} (degrees anti-clockwise by default). The optional argument \meta{option list} is a comma-separated list of any of the following options: \begin{itemize} \item \ikeyvalopt{rotatebox}{units}=\meta{number} The number of units in one full anti-clockwise rotation. So \texttt{units=-360} means that \meta{angle} specifies degrees clockwise whereas \texttt{units=6.283185} means that \meta{angle} is in radians. \item \ikeyvalopt{rotatebox}{origin}=\meta{label} The point of rotation. The value \meta{label} may contain one from either or both of the two lists: \texttt{lrc} (left, right, centre) and \texttt{tbB} (top, bottom, baseline). Alternatively the origin may be specified using the following two keys: \item \ikeyvalopt{rotatebox}{x}=\meta{dimen} \item \ikeyvalopt{rotatebox}{y}=\meta{dimen} \end{itemize} \xminisec{Example:} \begin{code} \begin{alltt} base line \glsni{rotatebox}\marg{45}\marg{Some text} \glsni{rotatebox}\oarg{units=-360}\marg{45}\marg{Some text} \glsni{rotatebox}\oarg{units=-360,origin=rB}\marg{45}\marg{Some text} \glsni{rotatebox}\oarg{x=3em,y=3em}\marg{45}\marg{Some text} base line \end{alltt} \end{code}\screenpagebreak \begin{result}[Image of typeset output: each occurrence of 'Some text' has been rotated] base line \rotatebox{45}{Some text} \rotatebox[units=-360]{45}{Some text} \rotatebox[units=-360,origin=rB]{45}{Some text} \rotatebox[x=3em,y=3em]{45}{Some text} base line \end{result} \begin{definition} \gls{scalebox}\marg{\meta{h scale}}\oarg{\meta{v scale}}\marg{\meta{text}} \end{definition} Scales \meta{text} by \meta{h scale} in both directions if \meta{v scale} omitted, otherwise scales \meta{text} by \meta{h scale} horizontally and \meta{y scale} vertically. \xminisec{Example:} \begin{codeS} \glsni{scalebox}\marg{0.8}\marg{Some text} \end{codeS} \begin{resultS}[Some text (scaled by a factor of 0.8)] \scalebox{0.8}{Some text} \end{resultS} Compare with: \begin{codeS} \glsni{scalebox}\marg{0.8}\oarg{1.2}\marg{Some text} \end{codeS} \begin{resultS}[Some text (aspect ratio changed)] \scalebox{0.8}[1.2]{Some text} \end{resultS} \begin{definition} \gls{reflectbox}\marg{\meta{text}} \end{definition} Reflects \meta{text} (equivalent to \glsni{scalebox}\marg{-1}\oarg{1}\marg{\meta{text}}). \xminisec{Example:} \begin{codeS} \glsni{reflectbox}\marg{Some text} \end{codeS} \begin{resultS}[Some text (mirror image)] \reflectbox{Some text} \end{resultS} \begin{definition} \gls{resizebox}\marg{\meta{h length}}\marg{\meta{v length}}\marg{\meta{text}} \end{definition} Scales \meta{text} so that it is \meta{h length} wide and \meta{v length} high. To preserve the aspect ratio, use \gls{resizebox.exclamchar} instead of one of the dimensions. \xminisec{Example:} \begin{code} \begin{alltt} \glsni{resizebox}\marg{12mm}\marg{1cm}\marg{Some text} \glsni{resizebox}\marg{\glsni{resizebox.exclamchar}}\marg{1cm}\marg{Some text} \end{alltt} \end{code}% \begin{resultS}[Image of typeset output: two instances of 'Some text' scaled with and without changing the aspect ratio.] \dohtmlcolorbox{% \resizebox{12mm}{1cm}{Some text} \resizebox{!}{1cm}{Some text} } \end{resultS} \setnode{graphicxoptions} \section{Package Options} The \isty{graphicx} package can have the following options passed to it: \begin{fwlist}{\optfmt{hiderotate}} \fwitem{\mdseries \istyopt{graphicx}{draft}} Don't actually display the images, just print the filename in a box of the correct size. This is useful if you want to print out a draft copy of a document to check the text rather than the images. \fwitem{\mdseries \istyopt{graphicx}{final}} Opposite of \istyopt{graphicx}{draft} (default). \fwitem{\mdseries \istyopt{graphicx}{hiderotate}} Don't show rotated text. \fwitem{\mdseries \istyopt{graphicx}{hidescale}} Don't show scaled text. \end{fwlist} Remember that relevant options passed to the class file\indexCLS\ also affect packages. \xminisec{Example (Draft Mode):} Draft mode helps to speed up compilation of a large document when you are editing the text. In the preamble: \begin{codeS} \glsni{usepackage}\oarg{draft}\marg{graphicx} \end{codeS} or \begin{code} \begin{alltt} \glsni{documentclass}\oarg{draft}\marg{scrbook} \glsni{usepackage}\marg{graphicx} \end{alltt} \end{code} Later in the document: \begin{codeS} \glsni{includegraphics}\oarg{width=1in,angle=45}\marg{pictures/shapes} \end{codeS} \begin{resultS}[Only bounding box and file name drawn] \incGraphics{pictures/draftimage} \end{resultS} \begin{exercise}{Using the \sty{graphicx} Package}{ex:graphicx} Download the image file \htmladdnormallink{\texttt{shapes.pdf}}{\exerciseurl/shapes.pdf}% \latex{ from \url{\exerciseurl/}} (or create your own image), and include it into your document. (You can \downloadorview{graphicx} an example solution.) \end{exercise} \bookpagebreak\screenpagebreak For more information on the \isty{graphicx} package see \latexgraphic\ or the \isty{graphicx} documentation. \xminisec{Related \gls{ukfaq} topics:} \begin{itemize} \item \faqlink{How to import graphics into (La)TeX documents}{impgraph} \item \faqlink{Imported graphics in PDFLaTeX}{pdftexgraphics} \item \faqlink{Imported graphics in dvips}{dvipsgraphics} \item \faqlink{Imported graphics in dvipdfm}{dvipdfmgraphics} \item \faqlink{Importing graphics from \dq{somewhere else}}{graphicspath} \item \faqlink{Portable imported graphics}{graph-pspdf} \item \faqlink{Repeated graphics in a document}{repeatgrf} \item \faqlink{Limit the width of imported graphics}{grmaxwidth} \item \faqlink{Top-aligning imported graphics}{topgraph} \item \faqlink{Labelling graphics}{labelfig} \item \faqlink{Graphics division by zero}{divzero} \end{itemize} %%%%%%%%%%%%%%%%%%%%%%%%%%% FLOATS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \setnode{floats} \chapter{Floats} \label{ch:floats} Figures and tables are referred to as \dq{floats} because they are \emph{floated} to the nearest location. This prevents ugly large spaces appearing on the page if there isn't enough room for the figure or table before the page break. Floats have a caption and associated number\faq{The style of captions}{captsty}. It is customary for captions to appear at the bottom of figures but at the top of tables~\cite{turabian96,oxford}. For both figures and tables, the caption is generated using the command: \begin{definition} \gls{caption}\oarg{\meta{short caption}}\marg{\meta{text}} \end{definition}% Note that the \cmdname{caption} command has a moving argument\index{argument!moving|hyperpage}, so \glspl{fragile}\faq{Footnotes in captions}{ftncapt} will need to be protected using \gls{protect}. The \glsterm{optional} \meta{short caption} is used to provide an alternative shorter caption for the list of figures or list of tables, akin to the optional argument to the \htmlref{sectioning commands}{sec:section}\latex{\ifscreenorother{}{\ described in \sectionref{sec:section}}}. \xminisec{Note:} Although the \glsni{caption} command can have an optional short title, in general, captions should be brief. They should not contain lots of description or background detail~\cite{turabian96}. That type of information should be placed in the main text not the caption. \xminisec{Positioning:} \refstepcounter{object}\label{obj:positioning}% \faq{Wide figures in two-column documents}{widefigs}Both the \glsni{env-figure} and \glsni{env-table} environments have an optional argument \meta{placement specifiers}, which indicates permissible locations for the float. This may be a combination of \texttt{h} (\dq{here}), \texttt{t} (top), \texttt{b} (bottom) and \texttt{p} (page of floats.) Note that this only gives a general guideline as to where the float will end up. The final location is governed by other factors, such as space left on the page and the proportion of text to floats on the page. If you omit one or more of the placement specifiers, then you are prohibiting the float from being placed in that location. A common mistake is to do \begin{alltt} \wrong\glsni{begin}\marg{figure}\oarg{h} \end{alltt} which says \dq{I~want the figure here and it can't go anywhere else!} If the figure \emph{can't} be placed exactly here (for example, there may not be enough room on the page), then you have given it no alternative location, which can result in this and all subsequent figures being dumped at the end of the chapter or document, or can result in a fatal error when running \LaTeX\faq{\dq{Too many unprocessed floats}}{tmupfl}. You may be able to manage with only one of the other options, for example, \begin{alltt} \glsni{begin}\marg{figure}\oarg{t} \end{alltt} (In fact, modern \TeX\ distributions now replace \oarg{h} with \oarg{t} if the float can't be placed.) However, if you have a large number of floats it is advisable to provide as many options as possible: \begin{alltt} \glsni{begin}\marg{figure}\oarg{htbp} \end{alltt} Similarly for tables. If you are absolutely adamant that an image must go \dq{right here}, then it's not a float, and you shouldn't be using the \glsni{env-figure} environment. It's just a horizontal box, like the example \xpageref{earlier}{example:inlinegraphic}. Similarly for tabulated material. It's worth bearing in mind what the Oxford Style Manual~\cite{oxford} has to say: \begin{quote} \dq{Text must not be read into it so as to give [the figure] an explicit and fixed introduction, for example \sq{in the following figure}: the final placement is determined by page breaks, which cannot be anticipated before setting, and this makes rewording the text necessary if the illustration does not fit the make-up of the page.} \end{quote} Turabian~\cite{turabian96} gives the same advice (and reiterates it for figures): \begin{quote} \dq{All text references to a table should be by a number, not by an introductory phrase such as \sq{in the following table}.} \end{quote} \setnode{figures} \section{Figures} \label{sec:figures} Figures are created using the \gls{env-figure} environment. \begin{definition} \glsni{begin}\marg{figure}\oarg{\meta{placement specifiers}} \end{definition}% This environment may contain one or more captions (specified, as described \htmlref{above}{ch:floats}, with the \glsni{caption} command) but page breaks are not allowed in the contents of a \glsni{env-figure} environment. The optional argument \meta{placement specifiers} is as described \htmlref{above}{obj:positioning}. Recall from \chapterref{ch:graphicx} that we can include an image in our document with the command \gls{includegraphics} defined in the \isty{graphicx} package. We can put our \htmladdnormallink{\texttt{shapes.pdf}}{\exerciseurl/shapes.pdf} image into a figure as follows: \begin{code} \glsni{begin}\marg{figure}\oarg{htbp}\newline \strut~~\glsni{includegraphics}\marg{shapes}\newline \strut~~\glsni{caption}\marg{Some Shapes}\newline \glsni{end}\marg{figure} \end{code}% So far so good, but our picture needs to be centred. This can be done using the \gls{centering} declaration mentioned in \sectionref{sec:declaration}: \begin{code} \glsni{begin}\marg{figure}\oarg{htbp}\newline \strut~~\glsni{centering}\newline \strut~~\glsni{includegraphics}\marg{shapes}\newline \strut~~\glsni{caption}\marg{Some Shapes}\newline \glsni{end}\marg{figure} \end{code} The \gls{caption} command generates a number, just like \gls{section}, so we can \htmlref{cross-reference}{sec:crossref} it with \gls{ref} and \gls{label}. First, let's label the figure: \begin{code} \glsni{begin}\marg{figure}\oarg{htbp}\newline \strut~~\glsni{centering}\newline \strut~~\glsni{includegraphics}\marg{shapes}\newline \strut~~\glsni{caption}\marg{Some Shapes}\newline \strut~~\glsni{label}\marg{fig:shapes}\newline \glsni{end}\marg{figure} \end{code}% Now we can reference it: \begin{codeS} Figure\glsni{tildechar}\glsni{ref}\marg{fig:shapes} shows some shapes. \end{codeS}% (As \htmlref{before}{cmd:tilde} we use \gls{tildechar} to make an unbreakable space.) This produces the following output in the text: \begin{resultS}[Figure 7.1 shows some shapes.] Figure~\ref*{fig:shapes} shows some shapes. \end{resultS}% and produces \figureref{fig:shapes}. \begin{figure}[hbtp] \figconts {pictures/shapes} {% \caption{Some Shapes}% }% {fig:shapes} \end{figure} \xminisec{Important Note:} If you want to change the caption font, \textbf{\em don't} do, e.g.: \begin{alltt} \wrong\glsni{caption}\marg{\gls{bfseries} Some Shapes} \end{alltt} Recall \gls{addtokomafont} from \sectionref{sec:section}. This can also be used to change the fonts used by the caption.\bookpagebreak \begin{alltt} \correct\glsni{addtokomafont}\marg{caption}\marg{\glsni{bfseries}} \end{alltt} Similarly for the caption label. For example: \begin{codeS} \glsni{addtokomafont}\marg{captionlabel}\marg{\glsni{scshape}} \end{codeS} \xminisec{List of Figures} Just as we were able to generate a \htmlref{table of contents}{sec:toc} using \gls{tableofcontents}, we can also generate a list of figures using the command \begin{definition} \gls{listoffigures} \end{definition} This creates a file with the extension \texttt{.lof}\indexLOF\ (see \sectionref{sec:auxiliary}). As with \reportlinebreak\glsni{tableofcontents} you will need to \LaTeX\ your document twice to get the list of figures up-to-date, unless you're using \iappname{latexmk} (as described in \sectionref{sec:crossref}) in which case it will be done automatically. \begin{exercise}{Creating Figures}{ex:figures} If you did \exerciseref{ex:graphicx}, you should have a document with an image in it. You now need to put this image into a \gls{env-figure} environment. Remember to centre the image, and give the figure a caption. Next, try labelling the figure and referencing it in the text. You could also put in a list of figures after the table of contents. You can \downloadorview{figures} an example. \end{exercise} \setnode{sidebysidefigs} \subsection{Side-By-Side Figures} \label{sec:sidebysidefigs} Recall at the start of \sectionref{sec:figures}, I mentioned that the \gls{env-figure} environment may contain one or more captions. In most cases, you'll just have a single caption per \glsni{env-figure} environment, but sometimes you may want to have two figures side-by-side, in which case you'll need two captions within the same \gls{env-figure} environment in order to keep the figures together. To do this, we can use the \gls{env-minipage} environment, which was covered in \sectionref{sec:boxes}. Recall that the \gls*{env-minipage} environment creates a \Index{horizontal box}, which means that two mini-pages can be placed side-by-side on the same line. All you need to do now, is place one image and caption in one mini-page, and the other image and caption in the neighbouring mini-page. (Do you remember what effect is obtained by placing a \htmlref{percent symbol}{obj:suppresseol} at the end of a line?)\doifbook{\footnote{See page~\pageref{obj:suppresseol}.}}\bookpagebreak \begin{code} \glsni{begin}\marg{figure}\oarg{htbp}\newline \strut~\glsni{begin}\marg{minipage}\marg{0.5\glsni{linewidth}}\newline \strut~~\glsni{centering}\newline \strut~~\glsni{includegraphics}\marg{circle}\newline \strut~~\glsni{caption}\marg{A Circle}\newline \strut~~\glsni{label}\marg{fig:circle}\newline \strut~\glsni{end}\marg{minipage}\glsni{percentchar}\newline \strut~\glsni{begin}\marg{minipage}\marg{0.5\glsni{linewidth}}\newline \strut~~\glsni{centering}\newline \strut~~\glsni{includegraphics}\marg{rectangle}\newline \strut~~\glsni{caption}\marg{A Rectangle}\newline \strut~~\glsni{label}\marg{fig:rectangle}\newline \strut~\glsni{end}\marg{minipage}\newline \glsni{end}\marg{figure} \end{code}% \latex{The above code produces Figures~\ref{fig:circle-sbs} and~\vref{fig:rectangle-sbs}. }Note that each mini-page uses \gls{centering} to centre its contents, and the label is also placed in the same mini-page, after the \gls{caption} command. If the \gls{label} was not in the same \htmlref{scope}{sec:group} as the \gls{caption}, the cross-reference would be incorrect. A common mistake when trying to create side-by-side figures is to do: \begin{alltt} \glsni{begin}\marg{figure}[htbp] \glsni{begin}\marg{minipage}\marg{0.5\glsni{linewidth}} \glsni{centering} \glsni{includegraphics}\marg{circle} \glsni{caption}\marg{A Circle} \glsni{label}\marg{fig:circle} \glsni{end}\marg{minipage} \wrong \glsni{begin}\marg{minipage}\marg{0.5\glsni{linewidth}} \glsni{centering} \glsni{includegraphics}\marg{rectangle} \glsni{caption}\marg{A Rectangle} \glsni{label}\marg{fig:rectangle} \glsni{end}\marg{minipage} \glsni{end}\marg{figure} \end{alltt} This produces one figure on top of the other, instead of side-by-side\html{, as illustrated in \figureref{fig:circle-sbs} and \figureref{fig:rectangle-sbs}}. This is because the blank line indicates a paragraph break, so each minipage is in a separate paragraph, so it's not possible for them to be on the same line. If you want a bit of spacing in your code to make it more readable, use \gls{percentchar} to comment out the paragraph break. For example: \begin{alltt} \glsni{end}\marg{minipage}% \correct\glsni{percentchar} \glsni{begin}\marg{minipage}\marg{0.5\glsni{linewidth}} \end{alltt} \begin{figure}[htbp] \begin{makeimage}\end{makeimage} \begin{minipage}{0.5\linewidth} \figuretop{fig:circle-sbs} \centering \incGraphics[alt=Image of a circle]{pictures/circle} \caption{A Circle} \label{fig:circle-sbs} \end{minipage}% \begin{minipage}{0.5\linewidth} \figuretop{fig:rectangle-sbs} \centering \incGraphics[alt=Image of a rectangle]{pictures/rectangle} \caption{A Rectangle} \label{fig:rectangle-sbs} \end{minipage} \end{figure} %%%%%%%%%%%%%%%%%%%%%% Tables %%%%%%%%%%%%%%%%%%%%%%%%% \setnode{tables} \section{Tables} \label{sec:tables} Tables are produced in much the same way as figures, except that the \gls{env-table} environment is used instead. \begin{definition} \glsni{begin}\marg{table}\oarg{\meta{placement specifiers}} \end{definition} Where the optional argument \meta{placement specifiers} is as described \xpageref{earlier}{obj:positioning}. As mentioned at the \htmlref{start of this chapter}{ch:floats}, tables typically have the caption at the top of the table~\cite{turabian96}. With the \koma\ classes, such as \icls{scrartcl}, \icls{scrreprt} and \icls{scrbook}, use the class option \scrclsopt[tableabove]{captions} to ensure that the vertical spacing appears correctly between the caption and the table content and put \gls{caption} at the start of the \envname{table} environment. \faq{Tables longer than a single page}{longtab}Page breaks are not permitted in the \glsni{env-table} environment. (The \isty{longtable} package can be used for that instead. See the \sty{longtable} \htmlref{documentation}{sec:texdoc} for further details.) \xminisec{Example:} In the \glsterm{preamble}: \begin{codeS} \glsni{documentclass}\oarg{captions=tableabove}\marg{scrbook} \end{codeS} Later in the document: \begin{code} \begin{alltt} \glsni{begin}\marg{table}\oarg{htbp} \glsni{caption}\marg{A Sample Table} \glsni{label}\marg{tab:sample} \glsni{centering} \glsni{begin}\marg{tabular}\marg{lr} Item \glsni{ampchar} Cost\glsni{tab.dbbackslashchar} Video \glsni{ampchar} 8.99\glsni{tab.dbbackslashchar} CD \glsni{ampchar} 9.99\glsni{tab.dbbackslashchar} DVD \glsni{ampchar} 15.00 \glsni{end}\marg{tabular} \glsni{end}\marg{table} \end{alltt} \end{code}% This produces \tableref{tab:sample}. \begin{table}[htbp] \caption{A Sample Table} \label{tab:sample} \centering \begin{makeimage} \begin{tabular}{lr} Item & Cost\\ Video & 8.99\\ CD & 9.99\\ DVD & 15.00 \end{tabular} \end{makeimage} \end{table} Again, the \gls{centering} declaration is used to centre the \gls{env-tabular} environment. As with figures, you can create a list of tables using the command \begin{definition} \gls{listoftables} \end{definition} This creates a file with the extension \texttt{.lot}\indexLOT\ (see \sectionref{sec:auxiliary}). As with the table of contents and list of figures, you will need to \LaTeX\ your document twice to get the list of tables up-to-date, unless you're using \iappname{latexmk} (as described in \sectionref{sec:crossref}) in which case it will be done automatically. \begin{exercise}{Creating Tables}{ex:tables} If you did \exerciseref{ex:tabular}, you should have a \gls{env-tabular} environment in your document. Try turning this into a table, and add \tableref{tab:sample}. You could also try adding a list of tables. As before, you can \downloadorview{tables} the solution. \end{exercise} \setnode{sidebysidetab} \subsection{Side-by-Side Tables} \label{sec:sidebysidetab} You can create side-by-side tables using an analogous method to the side-by-side figures approach described \htmlref{above}{sec:sidebysidefigs}. \xminisec{Example:} This example is similar to the one in \sectionref{sec:sidebysidefigs}. Again, take care to ensure that there is no paragraph break between the two \gls{env-minipage} environments. \begin{code} \begin{alltt} \glsni{begin}\marg{table} \glsni{begin}\marg{minipage}\marg{0.5\glsni{linewidth}} \glsni{caption}\marg{Prices for 2011} \glsni{label}\marg{tab:prices2011} \glsni{centering} \glsni{begin}\marg{tabular}\marg{lr} Item \glsni{ampchar} Price (\pounds)\glsni{tab.dbbackslashchar} Widgets \glsni{ampchar} 10.99\glsni{tab.dbbackslashchar} Whatsits \glsni{ampchar} 5.99 \glsni{end}\marg{tabular} \glsni{end}\marg{minipage}\glsni{percentchar} \glsni{percentchar} \glsni{begin}\marg{minipage}\marg{0.5\glsni{linewidth}} \glsni{caption}\marg{Prices for 2012} \glsni{label}\marg{tab:prices2012} \glsni{centering} \glsni{begin}\marg{tabular}\marg{lr} Item \glsni{ampchar} Price (\glsni{pounds})\glsni{tab.dbbackslashchar} Widgets \glsni{ampchar} 11.99\glsni{tab.dbbackslashchar} Whatsits \glsni{ampchar} 6.99 \glsni{end}\marg{tabular} \glsni{end}\marg{minipage}\glsni{percentchar} \glsni{end}\marg{table} \end{alltt} \end{code} This produces Tables~\ref{tab:prices2011} and~\vref{tab:prices2012}. \begin{table}[htbp] \begin{minipage}{0.5\linewidth} \caption{Prices for 2011} \label{tab:prices2011} \centering \begin{makeimage} \begin{tabular}{lr} Item & Price (\pounds)\\ Widgets & 10.99\\ Whatsits & 5.99 \end{tabular} \end{makeimage} \end{minipage}% % \begin{minipage}{0.5\linewidth} \caption{Prices for 2012} \label{tab:prices2012} \centering \begin{makeimage} \begin{tabular}{lr} Item & Price (\pounds)\\ Widgets & 11.99\\ Whatsits & 6.99 \end{tabular} \end{makeimage} \end{minipage}% \end{table} \setnode{sidewaysfloats} \section{Sideways Floats} \label{sec:sidewaysfloats} The \isty{rotating} package provides the \gls{env-sidewaysfigure} environment: \begin{definition} \glsni{begin}\marg{sidewaysfigure} \end{definition} and the \gls{env-sidewaystable} environment: \begin{definition} \glsni{begin}\marg{sidewaystable} \end{definition} which are like \gls{env-figure} and \gls{env-table}, respectively, but rotate the entire float (including caption) sideways. This sideways float is always placed on a page of its own. If you have used the \clsopt{twoside} class option (or you are using a class like \icls{scrbook}, which defaults to that option) then the sideways floats will be rotated clockwise or anti-clockwise, depending on whether they fall on an even (verso) or odd (recto) numbered page. (Requires a second \LaTeX\ run to get it correct.) \xminisec{Example:} \begin{code} \begin{alltt} \glsni{begin}\marg{sidewaysfigure} \glsni{centering} \glsni{includegraphics}\oarg{width=0.75\glsni{textheight}}\marg{shapes} \glsni{caption}\marg{A Sideways Figure} \glsni{label}\marg{fig:sideways} \glsni{end}\marg{sidewaysfigure} \end{alltt} \end{code} The above code produces \figureref{fig:sideways}. \dosidewaysfigure {fig:sideways} {\includegraphics[width=0.75\textheight]{pictures/shapes}} {A Sideways Figure} \begin{htmlonly} \begin{figure} \figuretop{fig:sideways} \centering \makeimg{A sideways figure}{% \colorbox{white}{% \rotatebox[br]{90}{% \begin{tabular}{c} \includegraphics{pictures/shapes}\\ {\usekomafont{captionlabel}Figure~\ref*{fig:sideways}}\captionformat A Sideways Figure \end{tabular} }% }% } \caption{A Sideways Figure} \label{fig:sideways} \end{figure} \end{htmlonly} \setnode{subfloats} \section{Sub-Floats} \label{sec:subfloats} Some floats have sub-floats within them. For example, a figure may contain several sub-figures, each of which requires a caption. The simplest way to do this is to use the \isty{subcaption} package that provides the \gls{env-subfigure} and \gls{env-subtable} environments: \begin{definition} \glsni{begin}\marg{subfigure}\oarg{\meta{pos}}\marg{\meta{width}} \end{definition} \begin{definition} \glsni{begin}\marg{subtable}\oarg{\meta{pos}}\marg{\meta{width}} \end{definition} Within these environments, you can use \gls{caption} to create a sub-caption. (In addition to the main \gls{caption} for the containing \gls{env-figure} or \gls{env-table} environment.) \xminisec{Note:} The \isty{subcaption} package requires the \isty{caption} package, but doesn't automatically load it, so you'll need to load both:\reportpagebreak \begin{codeS} \glsni{usepackage}\marg{caption,subcaption} \end{codeS} \xminisec{Example:} This is very similar to the side-by-side figures example from \sectionref{sec:sidebysidefigs}. \begin{code}[0.9\linewidth] \glsni{begin}\marg{figure}\oarg{htbp}\newline \strut~\glsni{begin}\marg{subfigure}\oarg{b}\marg{0.5\glsni{linewidth}}\newline \strut~~\glsni{centering}\newline \strut~~\glsni{includegraphics}\marg{rectangle}\newline \strut~~\glsni{caption}\marg{Rectangle}\glsni{label}\marg{fig:rectangle}\newline \strut~\glsni{end}\marg{subfigure}\glsni{percentchar}\newline \glsni{percentchar}\newline \strut~\glsni{begin}\marg{subfigure}\oarg{b}\marg{0.5\glsni{linewidth}}\newline \strut~~\glsni{centering}\newline \strut~~\glsni{includegraphics}\marg{circle}\newline \strut~~\glsni{caption}\marg{Circle}\glsni{label}\marg{fig:circle}\newline \strut~\glsni{end}\marg{subfigure}\glsni{percentchar}\newline \glsni{caption}\marg{Two Shapes}\newline \glsni{label}\marg{fig:shape}\newline \glsni{end}\marg{figure} \end{code} This produces \figureref{fig:shapes2}. Elsewhere in the document, the figure and its components can be referenced: \begin{code} Figure\gls{tildechar}\gls{ref}\marg{fig:shapes2} shows some shapes. Figure\gls{tildechar}\gls{ref}\marg{fig:rectangle} shows a rectangle and Figure\gls{tildechar}\gls{ref}\marg{fig:circle} shows a circle. \end{code} which produces the following text: \begin{result}[Figure 7.5 shows some shapes. Figure 7.5a shows a rectangle and Figure 7.5b shows a circle.] Figure~\ref*{fig:shapes2} shows some shapes. Figure~\ref*{fig:rectangle} shows a rectangle and Figure~\ref*{fig:circle} shows a circle.\relax \end{result} You can also reference just the sub-float using \begin{definition} \gls{subref}\marg{\meta{label}} \end{definition} which is analogous to \gls{ref}, but only displays the sub-float number without the number associated with its containing float. \xminisec{Example:} \begin{code} Figure\glsni{tildechar}\cmdname{ref}\marg{fig:shapes2} shows: (\glsni{subref}\marg{fig:rectangle}) a rectangle and (\glsni{subref}\marg{fig:circle}) a circle. \end{code} produces \begin{resultS}[Figure 7.5 shows: (a) a rectangle and (b) a circle.] Figure~\ref*{fig:shapes2} shows: (\subref*{fig:rectangle}) a rectangle and (\subref*{fig:circle}) a circle. \end{resultS} \begin{figure}[htbp] \begin{makeimage}\end{makeimage} \figuretop{fig:shapes2} \centering \begin{latexonly} \begin{subfigure}[b]{0.5\linewidth} \centering \includegraphics{pictures/rectangle} \caption{Rectangle}\label{fig:rectangle} \end{subfigure}% \begin{subfigure}[b]{0.5\linewidth} \centering \includegraphics{pictures/circle} \caption{Circle}\label{fig:circle} \end{subfigure}% \end{latexonly} \begin{htmlonly} \begin{tabular}{cc} \htmladdimg{exercises/rectangle.png} \hspace{0.8in}& \htmladdimg{exercises/circle.png}\\ (a) Rectangle & (b) Circle \end{tabular} \end{htmlonly} \caption{Two Shapes} \label{fig:shapes2} \end{figure} \xminisec{Note:} The subfigure labels (a, b, etc) should typically be in italic~\cite{turabian96}. This can be achieved with the \isty{caption} package using: \begin{definition} \gls{DeclareCaptionLabelFormat}\marg{\meta{format-name}}\marg{\meta{code}} \end{definition} where \meta{format-name} is the name for this new format and \meta{code} is the code used to format the label where \texttt{\glsni{hashchar}2} gets replaced by the reference number. Once you have defined a new format, you can then use \begin{definition} \gls{captionsetup}\oarg{\meta{type}}\marg{\meta{options}} \end{definition} to switch to that new format. For subfloats, \meta{type} needs to be set to \texttt{sub}. The second argument \meta{options} is a \meta{key}=\meta{value} comma-separated list. The key that sets the format is \ikeyvalopt{captionsetup}{labelformat}. (For further details about both \glsni{DeclareCaptionLabelFormat} and \glsni{captionsetup}, see the \isty{caption} package \htmlref{documentation}{sec:texdoc}.) For example, to create a format called \texttt{em-noparens} that displays the number in an emphasized font without parentheses: \begin{codeS} \glsni{DeclareCaptionLabelFormat}\marg{em-noparens}\marg{\glsni{emph}\marg{\glsni{hashchar}2}} \end{codeS} Now switch to that new format: \begin{codeS} \glsni{captionsetup}\oarg{sub}\marg{labelformat=em-noparens} \end{codeS} Note that this only changes the caption label format. It doesn't affect the font used by \gls{ref} or \glsni{subref}. For \gls{ref}, you can use the \isty{fncylab} package, which provides the command: \begin{definition} \gls{labelformat}\marg{\meta{ctr}}\marg{\meta{defn}} \end{definition} Within \meta{defn}, use \glsni{hashchar}1 to represent the subfigure value and use \glsi{thefigure} for the encapsulating figure number. For example: \begin{codeS} \glsni{labelformat}\marg{subfigure}\marg{\glsni{thefigure}\glsni{emph}\marg{\glsni{hashchar}1}} \end{codeS} Now \begin{codeS} \glsni{ref}\marg{fig:circle} \end{codeS} will produce \begin{resultS}[7.5a (the letter a is emphasized)] \ref*{fig:shapes2}\emph{a} \end{resultS} Unfortunately, this doesn't work for \glsni{subref}. Instead you will have to do, for example, the following in the text: \begin{codeS} \glsni{emph}\marg{\glsni{subref}\marg{fig:circle}} \end{codeS} If you want to add parentheses, the above can be modified to: \begin{code} \glsni{DeclareCaptionLabelFormat}\marg{em-parens}\marg{(\glsni{emph}\marg{\glsni{hashchar}2})}\newline \glsni{captionsetup}\oarg{sub}\marg{labelformat=em-parens}\newline \glsni{labelformat}\marg{subfigure}\marg{\glsni{thefigure}(\glsni{emph}\marg{\glsni{hashchar}1})} \end{code} For \glsni{subref}, you will have to do, for example, the following in the text: \begin{codeS} (\glsni{emph}\marg{\glsni{subref}\marg{fig:circle}}) \end{codeS} \begin{exercise}{Creating Sub-Figures}{ex:subfloats} Download the image files \htmladdnormallink{\texttt{rectangle.pdf}}{\exerciseurl/rectangle.pdf} and \htmladdnormallink{\texttt{circle.pdf}}{\exerciseurl/circle.pdf} \latex{from \url{\exerciseurl/}} (or create your own images) and add \figureref{fig:shapes2} to your document. You can \downloadorview{subfloats} the solution. \end{exercise} %%%%%%%%%%%%%%%%%%% DEFINING COMMANDS %%%%%%%%%%%%%%%%%%% \setnode{newcom} \chapter{Defining Commands} \label{ch:newcom} It's possible to define your own \glspl{command} or redefine existing ones. Be very careful about redefining existing commands; don't redefine a command simply because you want to use the name, only redefine it if you are making a modification. For example, if you want to change the format of the current date, you would redefine \gls{today}, but if you want to define a command to display a specific date, you should define a new command with a different name. There are several reasons why you might want to define a new command: \begin{enumerate} \item Reduce typing: Suppose you have a series of commands or text that you find yourself frequently using, then you could define a command to do all these other commands for you. \xminisec{Example:} Suppose you want a lot of large bold slanted sans-serif portions of text within your document. Every time you type those portions of text, you will have to do something like: \begin{codeS} \glsni{textsf}\marg{\glsni{large}\glsni{bfseries}\glsni{slshape} Some text} \end{codeS}% It would be much easier if you could use just one command to do all that, called, say, \cmdname{largeboldsfsl}: \begin{codeS} \begin{verbatim} \largeboldsfsl{Some text} \end{verbatim} \end{codeS}% or you could call it, say, \cmdname{lbsfsl} which is shorter, but slightly less memorable: \begin{codeS} \begin{verbatim} \lbsfsl{Some text} \end{verbatim} \end{codeS} \item Ensure consistency: You may find that you want to format an object a certain way. \xminisec{Example:} Recall near the end of \sectionref{sec:subfloats}, I~suggested the following to reference a subfigure (when using \gls{subref} instead of \gls{ref}): \begin{codeS} (\glsni{emph}\marg{\glsni{subref}\marg{fig:circle}}) \end{codeS} For consistency, you might want to define a command, say, \begin{alltt} \cmdname{formattedsubref}\marg{\meta{label}} \end{alltt} that was the same as (\glsni{emph}\marg{\glsni{subref}\marg{\meta{label}}}). \xminisec{Another Example} \refstepcounter{object}\label{example:keywords}% Suppose your document has a lot of keywords in it, and you want to format these keywords in a different font, say sans-serif, so that they stand out. You could just do: \begin{codeS} A \glsni{textsf}\marg{command} usually begins with a backslash. \end{codeS}% however, it is better to define a new command called, say, \cmdname{keyword} that will typeset its argument in a sans-serif font. That way it becomes a lot easier to change the format at some later date. For example, you may decide to splash out and have your keywords typed in a particular colour. In which case, all you need to do is simply change the definition of the command \cmdname{keyword}, otherwise you'll have to go through your entire document looking for keywords and changing each one which could be very time consuming if you have a large document. You might also decide at some later date to make an index for your document. Indexing all the keywords then becomes much simpler, as again all you'll need to do is modify the \cmdname{keyword} command. \end{enumerate} New commands are defined using the command: \begin{definition} \gls{newcommand}\marg{\meta{cmd}}\oarg{\meta{n-args}}\oarg{\meta{default}}\marg{\meta{text}} \end{definition}% The first \gls{mandatory} \meta{cmd} is the name of your new command, which must start with a backslash. The \gls{optional} \meta{n-args} specifies how many arguments your new command must take. The next optional argument \meta{default} will be discussed later. The final mandatory argument \meta{text} specifies what \LaTeX\ should do every time it encounters this command. \xminisec{Example (No Parameters):} Let's begin with a trivial example. Suppose I~wanted to write a document about a particular course, say \dq{Programming \textemdash\ Languages and Software Construction}, and I~had to keep writing the course title, then I~might decide to define a command that prints the course title rather than having to laboriously type it out every time. Let's call our new command \cmdname{coursetitle}. We want the following code: \begin{codeS} The course \glsni{emph}\marg{\cmdname{coursetitle}} is an undergraduate course. \end{codeS}% to produce the following output: \begin{result}[coursetitle.html] The course \emph{Programming \textemdash\ Languages and Software Construction} is an undergraduate course. \end{result}% Clearly this command doesn't need any arguments, so we don't need to worry about the optional argument \meta{n-args} to \gls{newcommand}, and the only thing our new command needs to do is print: \begin{alltt} Programming \glsni{emdash} Languages and Software Construction \end{alltt} so we would define our new command as follows: \begin{code} \glsni{newcommand}\marg{\cmdname{coursetitle}}\marg{Programming \glsni{emdash} Languages and Software Construction} \end{code}% Commands must always be defined before they are used. The best place to define commands is in the \gls{preamble}: \begin{code} \begin{alltt} \glsni{documentclass}\marg{scrartcl} \glsni{newcommand}\marg{\cmdname{coursetitle}}\marg{Programming \glsni{emdash} Languages and Software Construction} \glsni{begin}\marg{document} \glsni{section}\marg{\cmdname{coursetitle}} The course \glsni{emph}\marg{\cmdname{coursetitle}} is an undergraduate course. \glsni{end}\marg{document} \end{alltt} \end{code} \xminisec{Example (One Mandatory Argument):} \refstepcounter{object}\label{sec:newcomarg}% Now let's try defining a command that takes an \gls{argument} (or parameter). Let's go back to our \htmlref{\cmdname{keyword} example}{example:keywords}\latex{ \vpageref{example:keywords}}. This command needs to take one argument that is the keyword. Let's suppose we want keywords to come out in \htmlref{sans-serif}{sec:fontstyle}, then we could do: \begin{codeS} \glsni{newcommand}\marg{\cmdname{keyword}}\oarg{1}\marg{\glsni{textsf}\marg{\glsni{hashchar}1}} \end{codeS}% In this case we have used the optional argument \meta{n-args} to \gls{newcommand}. We want our command \cmdname{keyword} to have one argument, so we have \texttt{[1]}. In \texttt{\glsni{textsf}\marg{\glsni{hashchar}1}} the \gls{hashchar}\texttt{1} represents the first argument. (If we had more than one argument, \glsni{hashchar}\texttt{2} would represent the second argument, \glsni{hashchar}\texttt{3} would represent the third argument etc.\ up to a maximum of~9\faq{How to break the 9-argument limit}{moren9}.) So \begin{verbatim} \keyword{commands} \end{verbatim} will be equivalent to \begin{alltt} \glsni{textsf}\marg{commands} \end{alltt} and \begin{verbatim} \keyword{environment} \end{verbatim} will be equivalent to \begin{alltt} \glsni{textsf}\marg{environment} \end{alltt} and so on. Again, it's best to put the command definition in the preamble to ensure the command won't be used before it's defined. \begin{code} \begin{alltt} \glsni{documentclass}\marg{scrartcl} \glsni{newcommand}\marg{\cmdname{keyword}}\oarg{1}\marg{\glsni{textsf}\marg{\glsni{hashchar}1}} \glsni{begin}\marg{document} A \cmdname{keyword}\marg{command} usually begins with a backslash. \glsni{end}\marg{document} \end{alltt} \end{code} Now if we want to change the way the keywords are formatted, we can simply change the definition of \cmdname{keyword}. Let's modify our code so that the keyword is now in a slanted sans-serif font: \begin{code} \begin{alltt} \glsni{documentclass}\marg{scrartcl} \glsni{newcommand}\marg{\cmdname{keyword}}\oarg{1}\marg{\glsni{textsf}\marg{\glsni{slshape} \glsni{hashchar}1}} \glsni{begin}\marg{document} A \cmdname{keyword}\marg{command} usually begins with a backslash. \glsni{end}\marg{document} \end{alltt} \end{code}% Let's go one stage further. The \isty{color} \htmlref{package}{sec:packages} provides the \gls{declaration}: \begin{definition} \gls{color}\marg{\meta{col-name}} \end{definition} which switches the foreground colour to \meta{col-name}. It also provides the text-block command: \begin{definition} \gls{textcolor}\marg{\meta{col-name}}\marg{\meta{text}} \end{definition} which sets \meta{text} in the colour given by \meta{col-name}. So let's use the \isty{color} package to make our keywords blue:\screenpagebreak \begin{code} \begin{alltt} \glsni{documentclass}\marg{scrartcl} \glsni{usepackage}\marg{color} \glsni{newcommand}\marg{\cmdname{keyword}}\oarg{1}\marg{\glsni{textsf}\marg{\glsni{slshape}\glsni{color}\marg{blue}\glsni{hashchar}1}} \glsni{begin}\marg{document} A \cmdname{keyword}\marg{command} usually begins with a backslash. \glsni{end}\marg{document} \end{alltt} \end{code} Or we could index the keywords. To do this we need the \isty{makeidx} \htmlref{package}{sec:packages} and the commands \gls{makeindex}, \begin{inlinedef}\gls{index}\marg{\meta{text}}\end{inlinedef} and \gls{printindex}: \begin{code} \begin{alltt} \glsni{documentclass}\marg{scrartcl} \glsni{usepackage}\marg{makeidx} \glsni{makeindex} \glsni{newcommand}\marg{\cmdname{keyword}}\oarg{1}\marg{\glsni{textsf}\marg{\glsni{slshape} \glsni{hashchar}1}\glsni{index}\marg{\glsni{hashchar}1}} \glsni{begin}\marg{document} A \cmdname{keyword}\marg{command} usually begins with a backslash. \glsni{printindex} \glsni{end}\marg{document} \end{alltt} \end{code} For further information about how to create an index, see \latexguide\ or \latexcomp. Alternatively, if you want a brief overview, try \latexthesis. Since it is unlikely that the keyword will contain a paragraph break, we should indicate that this is a \gls{short} using the \htmlref{starred form}{itm:starredcommand}: \begin{codeS} \glsni{newcommand}*\marg{\cmdname{keyword}}\oarg{1}\marg{\glsni{textsf}\marg{\glsni{slshape} \glsni{hashchar}1}\glsni{index}\marg{\glsni{hashchar}1}} \end{codeS} Now if you forget to add the closing brace, for example, \verb|\keyword{command|, then \gls{tex}['s] error checking mechanism will pick up the error sooner. This will give an error message that looks like: \begin{verbatim} ! Paragraph ended before \keyword was complete. \par l.604 \end{verbatim} This at least gives you the line number (604 in this example) of the end of the paragraph where the error has occurred. If you don't used the starred form of \gls{newcommand}, then you will get the somewhat less than helpful error: \begin{verbatim} ! File ended while scanning use of \keyword. \end{verbatim} If you have a very large document, it may take a while to track down where exactly you have missed a brace. \begin{exercise}{Defining a New Command}{ex:newcom} Try typing up the following code: \begin{bcode} \begin{alltt} \glsni{documentclass}\marg{scrartcl} \glsni{newcommand}*\marg{\cmdname{keyword}}\oarg{1}\marg{\glsni{textsf}\marg{\glsni{hashchar}1}} \glsni{begin}\marg{document} A \cmdname{keyword}\marg{command} usually begins with a backslash. Segments of code may be \cmdname{keyword}\marg{grouped}. Some \cmdname{keyword}\marg{commands} take one or more \cmdname{keyword}\marg{arguments}. \glsni{end}\marg{document} \end{alltt} \end{bcode} Then modify your code so that the keywords are in a slanted sans-serif font or modify your code so that the keywords come out in blue (using the \isty{color} package as in the example earlier). Again you can \downloadorview{newcom} the result. \xminisec{For the more adventurous:} If you want to create an index as in the previous example, you will need to use the application \iappname{makeindex}. If you used \iappname{latexmk} back in \sectionref{sec:crossref}, you can just carry on using that as before. If not you need to do the following in TeXworks: \begin{enumerate} \item Create the PDF as described in \sectionref{sec:texworks}. \item Select \menu{MakeIndex} from the drop-down list next to the build (typeset) button (see \figureref{fig:texworks9}). \item Click on the build button. If all goes well, you won't see anything different. If you see something like the following: \begin{alltt} Couldn't find input index file exercise\theexercise\space nor exercise\theexercise.idx. \end{alltt} then you probably forgot to add the command \gls{makeindex} to the preamble. Add it in and go back to Step~1. \item Select \menu{pdfLaTeX} from the drop-down list and build the PDF file again. Move to the last page of the PDF, and you should see the index. \end{enumerate} \begin{figure}[htbp] \figconts {pictures/texworks9} {% \caption{Selecting MakeIndex in TeXWorks} }% {fig:texworks9} \end{figure} \end{exercise} %%%%%%%%%%%%% Defining Commands with an Optional Argument %%%%%%%%%%%%% \setnode{newcomopt} \section{Defining Commands with an Optional Argument} \label{sec:newcomopt} As mentioned earlier, the \gls{newcommand} command has a second optional argument \meta{default}. This allows you to define a command with an optional argument\faq{More than one optional argument}{twooptarg}. For example, suppose we want a command called, say, \cmdname{price}. Suppose we want the following code: \begin{codeS} \begin{verbatim} \price{100} \end{verbatim} \end{codeS}% to produce the following output: \begin{resultS}[price.html] \pounds100 excl VAT @ 17.5\%\relax \end{resultS}% and let's suppose we want an optional argument so that we can change the VAT. That is, we would want the following code: \begin{codeS} \begin{verbatim} \price[20]{30} \end{verbatim} \end{codeS}% to produce the following output: \begin{resultS}[price2.html] \pounds30 excl VAT @ 20\% \end{resultS}% Therefore we want to define a command such that if the optional argument is absent we will have \texttt{17.5}, and if it is present the optional argument will be substituted instead. This command can be defined as follows: \begin{codeS} \gls{newcommand}\marg{\cmdname{price}}\oarg{2}\oarg{17.5}\marg{\glsni{pounds} \gls{hashchar}2 excl VAT @ \glsni{hashchar}1\glsni{percent}} \end{codeS}% Here, \texttt{\glsni{hashchar}1} represents the optional argument (by default \texttt{17.5}) and \texttt{\glsni{hashchar}2} represents the mandatory argument (the second argument if the optional argument is present, or the only argument if the optional argument is absent.) As before, since the argument is unlikely to contain a paragraph break, we should indicate that it is a \gls{short} using the \htmlref{starred form}{itm:starredcommand}: \begin{codeS} \gls{newcommand}*\marg{\cmdname{price}}\oarg{2}\oarg{17.5}\marg{\glsni{pounds} \glsni{hashchar}2 excl VAT @ \glsni{hashchar}1\gls{percent}} \end{codeS}% \begin{exercise}{Defining Commands with an Optional Argument}{ex:newcomopt} In this exercise, you will need to define a slightly modified version of the above example. Try defining a command called, say, \cmdname{cost}. It should take one optional argument and one mandatory argument. Without the optional argument, it behaves in the same way as the \cmdname{price} example above, so that, say, \begin{codeS} \begin{verbatim} \cost{50} \end{verbatim} \end{codeS}% will produce \begin{resultS}[price3.html] \pounds50 excl VAT @ 17.5\%\null \end{resultS}% but with the optional argument, you can change the \verb|excl VAT @ 17.5\%| bit. So that, say, \begin{codeS} \begin{verbatim} \cost[inc VAT]{50} \end{verbatim} \end{codeS}% will produce \begin{resultS}[price4.html] \pounds50 inc VAT\mbox{}% LaTeX2HTML is getting confused! \end{resultS} You can \downloadorview{newcomopt} the solution. \xminisec{For the more adventurous:} If you did \exerciseref{ex:newcom} and you modified \cmdname{keyword} so that it indexed the keyword, you may have noticed that \begin{codeS} \verb|\keyword{command}| \end{codeS} and \begin{codeS} \verb|\keyword{commands}| \end{codeS} produced separate entries in the index. It would be better to have an optional argument to override the indexing mechanism. For example, \begin{codeS} \verb|\keyword{command}| \end{codeS} should print and index the word \dq{command}, whereas \begin{codeS} \verb|\keyword[command]{commands}| \end{codeS} should print \dq{commands} and index \dq{command}. In other words, we need an optional argument that defaults to the mandatory argument if it is not present. This is how to achieve that type of effect:\footnote{Recall from \chapterref{ch:def} the percent symbol discards the space resulting from the end of line character.} \begin{code} \glsni{newcommand}*\marg{\cmdname{keyword}}\oarg{2}\oarg{\cmdname{keywordentry}}\marg{\glsni{percentchar}\newline \strut~~\icmdname{def}\cmdname{keywordentry}\marg{\glsni{hashchar}2}\glsni{percentchar}\newline \strut~~\glsni{textsf}\marg{\glsni{hashchar}2}\glsni{percentchar}\newline \strut~~\gls{index}\marg{\glsni{hashchar}1}\glsni{percentchar}\newline } \end{code} In this example, the default value for the optional argument is set to the command \cmdname{keywordentry}. At the start of \cmdname{keyword} this is defined to be the mandatory argument (as specified by \verb|#2|) using \gls{tex}['s] \cmdname{def} command:\footnote{\cmdname{def} is too complicated for an introductory \LaTeX\ guide but, if you're interested, read \emph{The \TeX{}book}~\cite{texbook}.} \begin{alltt} \cmdname{def}\cmdname{keywordentry}\marg{\glsni{hashchar}2} \end{alltt} Then typeset the keyword (given in the mandatory argument \texttt{\glsni{hashchar}2}) in a sans-serif font: \begin{alltt} \glsni{textsf}\marg{\glsni{hashchar}2} \end{alltt} Now index the term using the optional argument (\texttt{\glsni{hashchar}1}): \begin{alltt} \glsni{index}\marg{\glsni{hashchar}1} \end{alltt} If an optional argument is specified, \texttt{\glsni{hashchar}1} will be the given argument, but if the optional argument is missing, \texttt{\glsni{hashchar}1} will be \cmdname{keywordentry}, which has earlier been set to the mandatory argument \texttt{\glsni{hashchar}2}. \end{exercise} %%%%%%%%%%%%%%%%%%%%%%%%% Redefining Commands %%%%%%%%%%%%%%%%%%%%% \setnode{renewcom} \section{Redefining Commands} \label{sec:renewcom} Commands can be redefined using the command: \begin{definition} \gls{renewcommand}\marg{\meta{cmd}}\oarg{\meta{n-args}}\oarg{\meta{default}}\marg{\meta{text}} \end{definition}\reportpagebreak\noindent This has exactly the same format as \gls{newcommand} but is used for redefining existing commands. Again there is a \htmlref{starred version}{itm:starredcommand} to indicate that the command is a \gls{short}. \xminisec{Caveat:} \warning Never redefine a command whose existing function is unknown to you or just because you want to use a particular command name, regardless of its previous function. By way of illustration: as a production editor, I~have to combine articles by different authors into a single book. Each author supplies the \LaTeX\ code for their own article. Every so often, I~get code that redefines a command for the convenience of the author. Later on another author tries to use the same command, on the assumption that the command behaves according to its original definition. This tends to involve the accent commands as they are short and that saves the author typing. It usually goes along these lines: author~A redefines \gls{c} (the cedilla accent command) to display a maths bold \dq{\boldc} to indicate a vector. Later, author~B, uses the cedilla accent, say, in the name Fran\c{c}ois: \begin{alltt} Fran\gls{c}\marg{c}ois \end{alltt} Author~A's hack turns this into Fran\boldc cois. \xminisec{Example (Redefining List Labels):} Recall the \gls{env-itemize} environment discussed in \sectionref{sec:itemize}. You may have up to four nested \gls{env-itemize} environments, the labels for the outer environment are specified by the command \gls{labelitemi}, the labels for the second level are specified by \gls{labelitemii}, the third by \gls{labelitemiii} and the fourth by \gls{labelitemiv}. By default, \glsni{labelitemi} is a bullet point (\makeimg{bullet symbol}{\labelitemi}), \glsni{labelitemii} is an en dash (\makeimg{en dash}{\labelitemii}), \glsni{labelitemiii} is an asterisk (\makeimg{asterisk}{\labelitemiii}) and \glsni{labelitemiv} is a centred dot (\makeimg{centered dot}{\labelitemiv}). These can be changed by redefining \glsni{labelitemi} etc. Recall from \tableref{tab:symbols} that the command \gls{dag} produces a dagger symbol, we can use this symbol instead of a bullet point: \begin{code} \glsni{renewcommand}*\marg{\glsni{labelitemi}}\marg{\gls{dag}}\newline \glsni{begin}\marg{itemize}\newline \mbox{}\newline \gls{item} Animal\newline \mbox{}\newline \glsni{item} Mineral\newline \mbox{}\newline \glsni{item} Vegetable\newline \mbox{}\newline \glsni{end}\marg{itemize} \end{code}% Output: \begin{result}[List uses dagger symbol instead of a bullet point for the marker] \renewcommand*{\labelitemi}{\dag} \begin{itemize} \item Animal \item Mineral \item Vegetable \end{itemize} \end{result} Here's another example, it uses the \Index{PostScript} font ZapfDingbats via the \isty{pifont} package: \begin{code} \glsni{renewcommand}*\marg{\glsni{labelitemi}}\marg{\gls{ding}\marg{43}}\newline \glsni{begin}\marg{itemize}\newline \mbox{}\newline \glsni{item} Animal\newline \mbox{}\newline \glsni{item} Mineral\newline \mbox{}\newline \glsni{item} Vegetable\newline \mbox{}\newline \glsni{end}\marg{itemize} \end{code}\bookpagebreak\noindent Output: \begin{result}[List uses a pointing finger instead of a bullet point for the marker] \renewcommand*{\labelitemi}{\ding{43}} \begin{itemize} \item Animal \item Mineral \item Vegetable \end{itemize} \end{result}% In the above example, it would actually be easier to use the \gls{env-dinglist} environment defined in the \isty{pifont} package: \begin{code} \begin{alltt} \glsni{begin}\marg{dinglist}\marg{43} \glsni{item} Animal \glsni{item} Mineral \glsni{item} Vegetable\screenpagebreak \glsni{end}\marg{dinglist} \end{alltt} \end{code} \xminisec{Example (Redefining the Default Font):} Recall from \sectionref{sec:changingfonts} that the default font family is usually the serif (Roman) family. So what happens if you need to write your entire document in, say, Helvetica? The default font family name is stored in: \begin{definition} \gls{familydefault} \end{definition} This command is usually defined to be just \gls{rmdefault}, which in turn stores the name of the default serif font (initially \texttt{cmr}, Computer Modern Roman). If you want the default font to be sans-serif, all you need do is add the following line to the \glsterm{preamble}: \begin{codeS} \glsni{renewcommand}\marg{\glsni{familydefault}}\marg{\gls{sfdefault}} \end{codeS} \glsni{sfdefault} stores the name of the default sans-serif font (initially \texttt{cmss}, Computer Modern Sans-Serif) and the \isty{helvet} package redefines \glsni{sfdefault} to \texttt{phv}, which is the identifier for the Helvetica font. So the following document will be in Helvetica: \begin{alltt} \glsni{documentclass}\marg{scrartcl} \glsni{usepackage}\marg{helvet} \glsni{renewcommand}\marg{\glsni{familydefault}}\marg{\glsni{sfdefault}} \glsni{begin}\marg{document} This is a sample document. \glsni{end}\marg{document} \end{alltt} Similarly, if you want the default font to be monospaced (typewriter) then you'd need to do: \begin{codeS} \glsni{renewcommand}\marg{\glsni{familydefault}}\marg{\gls{ttdefault}} \end{codeS} Incidentally, you may have noticed in \sectionref{sec:changingfonts} that although I~said I'd used the \isty{anttor} and \isty{libris} packages to set the serif and sans-serif families for \latexhtml{this book}{the PDF version of this book}, I didn't mention anything about the typewriter (monospaced) font. I~used the TXTT font, but that doesn't have a corresponding package. You just redefine \glsni{ttdefault} to \texttt{txtt}: \begin{codeS} \glsni{renewcommand}*\marg{\glsni{ttdefault}}\marg{txtt} \end{codeS} \xminisec{Example (Redefining Fixed Names):} You may have noticed that \LaTeX\ automatically generates pieces of text such as \dq{Chapter}, \dq{Figure}, \dq{Bibliography}. These are generated by the commands shown in \tableref{tab:textlab}. \begin{table}[hbtp] \caption[Predefined Names]{Predefined Names (\supdag Book and report style classes (such as \icls{scrreprt} and \icls{scrbook}), \supddag article-style classes (such as \icls{scrartcl}), remainder book, report and article-style classes)} \label{tab:textlab} \centering \begin{tabular}{ll} \toprule \bfseries Command & \bfseries Default Text\\ \midrule \gls{contentsname} & \contentsname\\ \gls{listfigurename} & \listfigurename\\ \gls{listtablename} & \listtablename\\ \gls{bibname}\supdag & \bibname\\ \gls{refname}\supddag & \refname\\ \gls{indexname} & \indexname\\ \gls{figurename} & \figurename\\ \gls{tablename} & \tablename\\ \gls{partname} & \partname\\ \gls{chaptername}\supdag & \chaptername\\ \gls{appendixname} & \appendixname\\ \gls{abstractname} & \abstractname \\\bottomrule \end{tabular} \end{table} You can change the defaults using \gls{renewcommand}. For example, suppose you want the table of contents to be labelled \dq{Table of Contents}, instead of the default \dq{Contents}, you would need to do: \begin{codeS} \glsni{renewcommand}*\marg{\glsni{contentsname}}\marg{Table of Contents} \end{codeS} \faq{Changing the words babel uses}{latexwords}In fact, the \isty{babel} package (see \sectionref{sec:babel}) uses this method to redefine the commands in \tableref{tab:textlab} whenever you switch language using \reportlinebreak\screenlinebreak \gls{selectlanguage} or within the contents of the \gls{env-otherlanguage} environment. This unfortunately has the side-effect that means if you try to redefine these commands, \sty{babel} will automatically overwrite your definition whenever there's a language change, which includes at the beginning of the \gls{env-document} environment. Instead you need to use \sty{babel}'s \glsni{addto} mechanism. \begin{definition} \gls{addto}\marg{\meta{command}}\marg{\meta{code}} \end{definition} This patches the definition of a command (specified in the first \gls{argument}) adding \meta{code} to the end of the command definition. Whenever \sty{babel} switches the current language, it uses the command \cmdname{captions}\meta{language}, which performs all the redefinitions of commands like those listed in \tableref{tab:textlab}. For example, if you are using \sty{babel} with the \istyopt{babel}{english} option and you want to change \glsni{contentsname} so that it does \dq{Table of Contents} instead of \dq{Contents}, you need to do: \begin{code} \begin{alltt} \glsni{addto}\marg{\cmdname{captionsenglish}}\marg{\glsni{percentchar} \glsni{renewcommand}\marg{\glsni{contentsname}}\marg{Table of Contents}\glsni{percentchar} } \end{alltt} \end{code} \xminisec{Notes:} \warning Take care if you want to patch an existing command. For example, suppose you want to append something to the action of a command. You might be tempted to do \begin{alltt} \wrong\glsni{renewcommand}*\marg{\cmdname{foo}}\marg{\cmdname{foo} Something else} \end{alltt} This will cause an infinite loop where \cmdname{foo} recursively calls itself. Instead you should use one of the commands provided by the \isty{etoolbox} package (such as \gls{appto}, which has the same syntax as \sty{babel}'s \glsni{addto} described above). For further details, read the \sty{etoolbox} \htmlref{documentation}{sec:texdoc}. \begin{exercise}{Renewing Commands}{ex:renewcom} If you did Exercises~\ref{ex:figures} and \ref{ex:tables}, go back to that document and changed the figures and tables so that they are labelled \dq{Fig} and \dq{Tab} instead of \dq{Figure} and \dq{Table}. Hint: you need to redefine \glsni{tablename} and \glsni{figurename}. You can \downloadorview{renewcom} the solution. \end{exercise} %%%%%%%%%%%%%%%%%%%%%%%% MATHEMATICS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \setnode{mathematics} \chapter{Mathematics} \label{ch:maths} As mentioned in the \htmlref{introduction}{ch:intro}, \LaTeX\ is particularly good at typesetting mathematics. In order to use any of the maths commands we need to be in one of the mathematics \glspl{environment}. There are two basic types of mathematics: \keyword{in-line maths} and \keyword{displayed maths}. In-line maths is mathematics that occurs within a line of text, for example: \begin{resultS}[inlinemaths.html] The variable $x$ is transformed by the function $f(x)$. \end{resultS}% Displayed maths is mathematics that occurs on a line of its own. For example: \begin{result}[displaymath.html] A polynomial is a function of the form \[ f(x) = \sum_{i=0}^na_ix^i \] \end{result} The maths environments switch to \LaTeX's \dq{math mode}, which uses specialist maths fonts and spacing rather than just using an italic font. If you want to typeset any mathematics, I~strongly advise using the \istystart{amsmath} package: \begin{alltt} \glsni{usepackage}\marg{amsmath} \end{alltt} This patches some existing \LaTeX\ commands and environments and also provides many useful additions. This chapter is just an introduction to typesetting mathematics in \LaTeX. If you want a comprehensive guide, I~recommend you read \emph{Math Mode} by Herbert~Vo\ss~\cite{voss}, which can be access via \appname{texdoc} (see \sectionref{sec:texdoc}): \begin{verbatim} texdoc mathmode \end{verbatim} %%%%%%%%%%%%%%%% In-Line Mathematics %%%%%%%%%%%%%%%%%%% \setnode{inlinemaths} \section{In-Line Mathematics} \label{sec:inline} In-line mathematics is created using the \gls{env-math} environment. (Note U.S. spelling --- \dq{math} not \dq{maths}). \xminisec{Example:} \begin{code} The variable \glsni{begin}\marg{math}x\glsni{end}\marg{math} is transformed by the function \glsni{begin}\marg{math}f(x)\glsni{end}\marg{math}. \end{code} It's somewhat cumbersome having to type \glsni{begin}\marg{math} and \glsni{end}\marg{math} and it also makes the \gls{source} a little difficult to read so there are shorthand notations that can be used instead: \gls{beginmath} is equivalent to \glsni{begin}\marg{math} and \gls{endmath} is equivalent to \glsni{end}\marg{math}. So the example above can be rewritten: \begin{codeS} The variable \glsni{beginmath}x\glsni{endmath} is transformed by the function \glsni{beginmath}f(x)\glsni{endmath}. \end{codeS}% There is an even shorter notation: The \htmlref{special character}{sec:chars} \gls{dollarchar} is equivalent to both \glsni{begin}\marg{math} and \glsni{end}\marg{math}: \begin{codeS} The variable \glsni{dollarchar}x\glsni{dollarchar} is transformed by the function \glsni{dollarchar}f(x)\glsni{dollarchar}. \end{codeS}% This is considerably easier to type and to read, but you need to make sure that all your \glsni{dollarchar} symbols have matching pairs. The above code will look like: \begin{resultS}[inlinemaths2.html] The variable $x$ is transformed by the function $f(x)$. \end{resultS}% The other advantage in using \glsni{dollarchar} over \glsni{beginmath} and \glsni{endmath} is that \glsni{dollarchar} is a \gls{robust}, whereas \glsni{beginmath} and \glsni{endmath} are \glspl{fragile} and will need to be protected if they occur in a \glslink{fragile}{moving argument}.\casemedia{}{}{ (See \sectionref{sec:fragile}.)}{} Note: you should always make sure you are in maths mode to typeset any variables (such as $x$, $y$, $z$), as this will ensure that the correct maths fonts are used, as well as the appropriate spacing. Similarly, don't use \glsni{dollarchar} as a short cut for an italic font. \begin{codeS}[\linewidth] Notice the \glsni{dollarchar}difference\glsni{dollarchar} between \glsni{dollarchar}(x', y', z')\glsni{dollarchar} and \glsni{textit}\marg{(x', y', z')}. \end{codeS}% \begin{resultS}[Image of result: the brackets are upright in the maths font but slanted in the italic font. The apostrophe becomes a prime in the maths font. The spacing is also different.] Notice the $difference$ between $(x', y', z')$ and \textit{(x', y', z')}. \end{resultS} %%%%%%%%%%%%%%%% Displayed Mathematics %%%%%%%%%%%%%%%%%%%%%% \setnode{displayedmaths} \section{Displayed Mathematics} \label{sec:displayed} One-line unnumbered displayed mathematics can be created using: \begin{definition} \gls{begindispmath}\meta{maths}\gls{enddispmath} \end{definition} where \meta{maths} is the mathematics to be displayed. \xminisec{Example:} \begin{code} \begin{alltt} A linear function is a function of the form \glsni{begindispmath} y = mx + c \glsni{enddispmath} \end{alltt} \end{code}% Output: \begin{result}[displaymath2.html] A linear function is a function of the form \[ y = mx + c \] \end{result}% \warning Don't use the \envname{displaymath} environment or \verb|$$|\ldots\verb|$$|~\cite{l2tabu}. Use \glsni{begindispmath} and \glsni{enddispmath} with the \isty{amsmath} package. The \glsni{env-equation}\refstepcounter{object}\label{env:equation} environment provides something similar to \glsni{begindispmath} \glsni{enddispmath}, except that the equation is numbered. Modifying the above example: \begin{code} \begin{alltt} A linear function is a function of the form \glsni{begin}\marg{equation} y = mx + c \glsni{end}\marg{equation} \end{alltt} \end{code}% results in the following output: \begin{result}[As before but the equation now has a number in brackets on the right.] A linear function is a function of the form \begin{equation} y = mx + c \end{equation} \end{result} Normal text can be inserted into the equation using \begin{definition} \gls{text}\marg{\meta{text}} \end{definition} which is provided by the \isty{amsmath} package. \xminisec{Example:} \begin{codeS} \glsni{begindispmath} x = 2 \glsni{text}\marg{ and } y = -1 \glsni{enddispmath} \end{codeS}% results in the following output: \begin{result}[x equals 2 and y equals minus 1 (the word 'and' is in normal text font)] \[ x = 2 \text{ and } y = -1 \] \end{result} \faq{Re-using an equation}{reuseq}% Recall from \sectionref{sec:crossref} that we can \htmlref{cross-reference}{sec:crossref} most things that \LaTeX\ automatically numbers using \gls{ref} and \gls{label}. Equations can be cross-referenced in the same way:\reportpagebreak \begin{code} \begin{alltt} Equation\glsni{tildechar}\glsni{ref}\marg{eqn:linear} is a linear function. \glsni{begin}\marg{equation} \glsni{label}\marg{eqn:linear} f(x) = mx + c \glsni{end}\marg{equation}\screenpagebreak \end{alltt} \end{code} \begin{result}[eqref.html] Equation~\ref*{eqn:linear} is a linear function. \begin{equation} \label{eqn:linear} f(x) = mx + c \end{equation} \end{result} Equation numbers are usually given in parentheses, which can be done using: \begin{codeS} Equation\glsni{tildechar}(\glsni{ref}\marg{eqn:linear}) \end{codeS} The \isty{amsmath} package provides a convenient short cut: \begin{definition} \gls{eqref}\marg{\meta{label}} \end{definition} So the above can be written as: \begin{codeS} Equation\glsni{tildechar}\glsni{eqref}\marg{eqn:linear} \end{codeS} \begin{resultS}[Equation (9.2)] % fake it to suppress hyperlink Equation~(\ref*{eqn:linear}) \end{resultS} \xminisec{Note:} Both the \gls{env-equation} environment and \gls{begindispmath}\ldots\gls{enddispmath} are only designed for one line of maths. Therefore you must not have any line breaks or paragraph breaks within them. The following will cause an error: \begin{alltt} \glsni{begin}\marg{equation} \wrong f(x) = mx + c \wrong \glsni{end}\marg{equation} \end{alltt} Either remove the blank lines or comment them out: \begin{alltt} \glsni{begin}\marg{equation} \glsni{percentchar}\correct f(x) = mx + c \glsni{percentchar}\correct \glsni{end}\marg{equation} \end{alltt} \setnode{align} \section{Multiple Lines of Displayed Maths} \label{sec:align} The \isty{amsmath} package provides the \gls{env-align} and \gls{env-align*} environments for aligned equations. The starred version doesn't number the equations. These environments provide pairs of left- and right-aligned columns. As with the \gls{env-tabular} environment, use \gls{ampchar} to separate columns and \gls{tab.dbbackslashchar} to separate rows. Unlike the \gls{env-tabular} environment, there is no argument as the column specifiers are predefined. Another difference is that no page breaks can occur in the \gls{env-tabular} environment, but it's possible to allow a page break in \glsni{env-align} or \glsni{env-align*} using \begin{definition} \gls{displaybreak}\oarg{\meta{n}} \end{definition} immediately before the \gls{tab.dbbackslashchar} where it is to take effect. The optional argument is a number from~0 to~4 indicating the desirability to break the page (from~0 the least to~4 the most). If you want to mix numbered and unnumbered rows, you can use \begin{definition} \gls{notag} \end{definition} to suppress the numbering for a particular row in the \glsni{env-align} environment. This command must go before \gls{tab.dbbackslashchar} at the end of the row. The default equation numbering can be overridden for a particular row using: \begin{definition} \gls{tag}\marg{\meta{tag}} \end{definition} where \meta{tag} is the replacement for the equation number. \screenpagebreak\warning Don't use the \envname{eqnarray} or \envname{eqnarray*} environments. They're obsolete~\cite{l2tabu}. \xminisec{Example (Unnumbered):} \begin{code} \glsni{begin}\marg{align*}\newline y \glsni{ampchar}= 2x + 2\glsni{tab.dbbackslashchar}\newline \strut~~\glsni{ampchar}= 2(x+1)\newline \glsni{end}\marg{align*} \end{code} \begin{result}[align.html] \begin{align*} y &= 2x + 2\\ &= 2(x+1) \end{align*} \end{result} Note that the equals sign is placed at the start of the second column, \emph{after} the ampersand \gls{ampchar}. This ensures the correct amount of spacing on either side. If the first line of the above equation was changed to:\bookpagebreak \begin{alltt} \wrong y =\gls{ampchar} 2x + 2\gls{tab.dbbackslashchar} \end{alltt} there wouldn't be enough space on the right of the equal sign: \begin{htmlresult}{y equals 2x + 2} \begin{makeimage} \begin{align*} y =& 2x + 2 \end{align*} \end{makeimage} \end{htmlresult} \xminisec{Example (One Row Numbered):} \begin{code} \glsni{begin}\marg{align}\newline y \glsni{ampchar}= 2x + 2\glsni{notag}\glsni{tab.dbbackslashchar}\newline \strut~~\glsni{ampchar}= 2(x+1)\newline \glsni{end}\marg{align} \end{code} \begin{result}[Image of result: as the earlier example but the second equation has been numbered] \begin{align} y &= 2x + 2\notag\\ &= 2(x+1) \end{align} \end{result}\screenpagebreak \xminisec{Example (Four Columns):} \begin{code} \glsni{begin}\marg{align*}\newline y \glsni{ampchar}= 2x + 2 \glsni{ampchar} z \glsni{ampchar}= 6x + 3\glsni{tab.dbbackslashchar}\newline \strut~~\glsni{ampchar}= 2(x+1) \glsni{ampchar}~~~\glsni{ampchar}= 3(2x+1)\newline \glsni{end}\marg{align*} \end{code} \begin{result}[4colalign.html] \begin{align*} y &= 2x + 2 & z &= 6x + 3\\ &= 2(x+1) & &= 3(2x+1) \end{align*} \end{result} As with \gls{env-equation}, you can cross-reference individual rows of an \glsni{env-align} environment, but you must remember to put \gls{label} \emph{before} the end of row \gls{tab.dbbackslashchar} separator. You can reference a row in the \glsni{env-align*} environment if you have assigned it a tag with \gls{tag}, but don't try labelling a row in the \glsni{env-align} environment where the numbering has been suppressed with \gls{notag}. \xminisec{Example (Cross-Referenced):} This example has two numbered equations in an \gls{env-align} environment, both of which are labelled and referenced: \begin{code} The function \glsni{dollarchar}f(x)\glsni{dollarchar} is given in Equation\glsni{tildechar}\glsni{eqref}\marg{eq:fx}, and its derivative \glsni{dollarchar}f'(x)\glsni{dollarchar} is given in Equation\glsni{tildechar}\glsni{eqref}\marg{eq:dfx}. \newline \glsni{begin}\marg{align}\newline f(x) \glsni{ampchar}= 2x + 1 \glsni{label}\marg{eq:fx}\glsni{tab.dbbackslashchar}\newline f'(x) \glsni{ampchar}= 2 \glsni{label}\marg{eq:dfx}\newline \glsni{end}\marg{align} \end{code} \begin{result}[alignref.html] The function $f(x)$ is given in Equation~(\ref*{eq:fx}), and its derivative $f'(x)$ is given in Equation~(\ref*{eq:dfx}). \begin{align} f(x) &= 2x + 1\label{eq:fx}\\ f'(x) &= 2 \label{eq:dfx} \end{align} \end{result} Recall the command \gls{text}\marg{\meta{text}} from the \htmlref{previous section}{sec:displayed}. This can be used within cells of the \glsni{env-align} and \glsni{env-align*} environments, but the \isty{amsmath} package also provides \begin{definition} \gls{intertext}\marg{\meta{text}} \end{definition} which can be used for a line of interjection between the rows. This command may only go right after \gls{tab.dbbackslashchar}. \xminisec{Example} \begin{code} \glsni{begin}\marg{align*}\newline y \glsni{ampchar}= 2x + 2\glsni{tab.dbbackslashchar}\newline \glsni{intertext}\marg{Using the distributive law:}\newline \glsni{ampchar}= 2(x+1)\newline \glsni{end}\marg{align*} \end{code} \begin{result}[intertext.html] \begin{align*} y &= 2x + 2\\ \intertext{Using the distributive law:} &= 2(x+1) \end{align*} \end{result}\bookpagebreak There are other environments for multiple-line displayed maths, but they are beyond the scope of this book. See the \isty{amsmath} documentation for further details. %%%%%%%%%%%%%%%% Mathematical Commands %%%%%%%%%%%%%%%%%%%% \setnode{mathscom} \section{Mathematical Commands} \label{sec:mathscom} Most of the \glspl{command} described in this section may only be used in one of the mathematics environments. If you try to use a mathematics command outside a maths environment you will get a \dq{\texttt{Missing \$ inserted}} error message. %------------------ Maths Fonts ------------------ \setnode{mathsfonts} \subsection{Maths Fonts} \label{sec:mathsfonts} Just as we are able to \htmlref{change text fonts}{sec:fonts} using the commands \gls{textrm}, \gls{textbf} etc, we can also use commands to change the maths font. Basic maths font changing commands are shown in \tableref{tab:mathsfonts}. \begin{table}[tbhp] \caption{Maths Font Changing Commands} \label{tab:mathsfonts} \centering \begin{tabular}{lll} \toprule \bfseries Command & \bfseries Example Input & \bfseries Corresponding Output\\ & & (Computer Modern)\\ \midrule \begin{inlinedef}\gls{mathrm}\marg{\meta{maths}}\end{inlinedef} & \verb|$\mathrm{xyz}$| & $\cmmathrm{xyz}$\\ \begin{inlinedef}\gls{mathsf}\marg{\meta{maths}}\end{inlinedef} & \verb|$\mathsf{xyz}$| & $\cmmathsf{xyz}$\\ \begin{inlinedef}\gls{mathtt}\marg{\meta{maths}}\end{inlinedef} & \verb|$\mathtt{xyz}$| & $\cmmathtt{xyz}$\\ \begin{inlinedef}\gls{mathit}\marg{\meta{maths}}\end{inlinedef} & \verb|$\mathit{xyz}$| & $\cmmathit{xyz}$\\ \begin{inlinedef}\gls{mathbf}\marg{\meta{maths}}\end{inlinedef} & \verb|$\mathbf{xyz}$| & $\cmmathbf{xyz}$\\ \begin{inlinedef}\gls{mathcal}\marg{\meta{maths}}\end{inlinedef} & \verb|$\mathcal{XYZ}$| & $\cmmathcal{XYZ}$ \\\bottomrule \end{tabular} \end{table} The calligraphic fonts via \glsni{mathcal} are only available for upper-case characters\faq{Better script fonts for maths}{scriptfonts}. \tableref{tab:amsmathfont} lists additional font commands supplied with the \isty{amsmath} and \isty{amsfonts} \htmlref{packages}{sec:packages}. \begin{table}[hbtp] \caption[The amsfonts and amsmath Font Commands]{The \isty{amsfonts}\supddag\ and \isty{amsmath}\supdag\ Font Commands} \label{tab:amsmathfont} \centering \begin{tabular}{lll} \toprule \bfseries Command & \bfseries Example Input & \bfseries Example Output\\ \midrule \begin{inlinedef}\supddag\gls{mathbb}\marg{\meta{maths}}\end{inlinedef} & \verb|$\mathbb{A+B=C}$| & $\mathbb{A+B=C}$\\ \begin{inlinedef}\supddag\gls{mathfrak}\marg{\meta{maths}}\end{inlinedef} & \verb|$\mathfrak{A+B=C}$| & $\mathfrak{A+B=C}$\\ \begin{inlinedef}\supdag\gls{boldsymbol}\marg{\meta{maths}}\end{inlinedef} & \verb|$\boldsymbol{A+B=C}$| & $\boldsymbol{A+B=C}$\\ \begin{inlinedef}\supdag\gls{pmb}\marg{\meta{symbol}}\end{inlinedef} & \verb|$\pmb{+-=}$| & $\pmb{+-=}$ \\\bottomrule \end{tabular} \end{table} %----------------- Greek Letters ----------------------- \setnode{greek} \subsection{Greek Letters} \label{sec:greek} Greek letters that differ from the corresponding Roman letters are obtained by placing a backslash in front of the name.\footnote{So, for example, there is no omicron since it looks the same as a Roman o.} Lower case and upper case Greek letters are shown in \tableref{tab:greek} and \tableref{tab:Greek}, respectively. There are also some variants of certain symbols, such as \glsni{vartheta} as opposed to \glsni{theta}. \begin{table}[htbp] \caption{Lower Case Greek Letters} \label{tab:greek} \centering \begin{tabular}{llllll} \gls{alpha} & $\alpha$ & \gls{beta} & $\beta$ & \gls{gamma} & $\gamma$ \\ \gls{delta} & $\delta$ & \gls{epsilon} & $\epsilon$ & \gls{varepsilon} & $\varepsilon$\\ \gls{zeta} & $\zeta$ & \gls{eta} & $\eta$ & \gls{theta} & $\theta$ \\ \gls{vartheta} & $\vartheta$ & \gls{iota} & $\iota$ & \gls{kappa} & $\kappa$ \\ \gls{lambda} & $\lambda$ & \gls{mu} & $\mu$ & \gls{nu} & $\nu$ \\ \gls{xi} & $\xi$ & \gls{pi} & $\pi$ & \gls{varpi} & $\varpi$\\ \gls{rho} & $\rho$ & \gls{varrho} & $\varrho$ & \gls{sigma} & $\sigma$ \\ \gls{varsigma} & $\varsigma$ & \gls{tau} & $\tau$ & \gls{upsilon} & $\upsilon$ \\ \gls{phi} & $\phi$ & \gls{varphi} & $\varphi$ & \gls{chi} & $\chi$ \\ \gls{psi} & $\psi$ & \gls{omega} & $\omega$ \end{tabular} \end{table} \begin{table}[htbp] \caption{Upper Case Greek Letters} \label{tab:Greek} \centering \begin{tabular}{llllll} \gls{Gamma} & $\Gamma$ & \gls{Delta} & $\Delta$ & \gls{Theta} & $\Theta$ \\ \gls{Lambda} & $\Lambda$ & \gls{Xi} & $\Xi$ & \gls{Pi} & $\Pi$ \\ \gls{Sigma} & $\Sigma$ & \gls{Upsilon} & $\Upsilon$ & \gls{Phi} & $\Phi$ \\ \gls{Psi} & $\Psi$ & \gls{Omega} & $\Omega$ \end{tabular} \end{table} \xminisec{Example:} The following code \begin{codeS} \glsni{begindispmath} x' = x + \glsni{Delta} x \glsni{enddispmath} \end{codeS} produces: \begin{resultS}[x prime equals x plus capital Delta x] \[ x' = x + \Delta x \] \end{resultS} %------------- Subscripts and Superscripts ------------ \setnode{subsupscripts} \subsection{Subscripts and Superscripts} \label{sec:scripts} Subscripts are obtained either by the command \begin{definition} \gls{sb}\marg{\meta{maths}} \end{definition}% or by the \htmlref{special character}{sec:chars}: \begin{definition} \gls{underscorechar}\marg{\meta{maths}} \end{definition}% Superscripts are obtained either by the command \begin{definition} \gls{sp}\marg{\meta{maths}} \end{definition}% or by the special character: \begin{definition} \gls{circumchar}\marg{\meta{maths}} \end{definition}% \xminisec{Examples:} \begin{enumerate} \item This example uses \glsni{sb} and \glsni{sp}: \begin{codeS} \glsni{begindispmath}y = x\glsni{sb}\marg{1}\glsni{sp}\marg{2} + x\glsni{sb}\marg{2}\glsni{sp}\marg{2}\glsni{enddispmath} \end{codeS}% \item This example uses \glsni{underscorechar} and \glsni{circumchar} \begin{codeS} \glsni{begindispmath}y = x\glsni{underscorechar}\marg{1}\glsni{circumchar}\marg{2} + x\glsni{underscorechar}\marg{2}\glsni{circumchar}\marg{2}\glsni{enddispmath} \end{codeS}% \item Recall from \latexhtml{page~\pageref{itm:argnogrp}}{\htmlref{earlier}{itm:argnogrp}} that \glspl{mandatory} only consisting of one character don't need to be grouped, so the above code can also be written as: \begin{codeS} \glsni{begindispmath}y = x\glsni{underscorechar}1\glsni{circumchar}2 + x\glsni{underscorechar}2\glsni{circumchar}2\glsni{enddispmath} \end{codeS}% This is simpler than the first two examples. However it's a good idea to be in the habit of always using braces in case you forgot them when they're needed. \end{enumerate} All three of the above examples produce the same output: \begin{resultS}[subsup.html] \[y = x_1^2 + x_2^2\] \end{resultS}% Notice how the subscript gets tucked under the slope of the $Y$ in: \begin{codeS} \glsni{begindispmath} Y\glsni{underscorechar}\marg{1}\glsni{circumchar}\marg{2} \glsni{enddispmath} \end{codeS} \begin{resultS}[ysubsup1.html] \[ Y_{1}^{2} \] \end{resultS} Compare with \begin{codeS} \glsni{begindispmath} Y\marg{}\glsni{underscorechar}\marg{1}\glsni{circumchar}\marg{2} \glsni{enddispmath} \end{codeS} \begin{resultS}[ysubsup2.html] \[ Y{}_{1}^{2} \] \end{resultS} \xminisec{Example (Nested)} Subscripts and superscripts can also be nested (note that it is now necessary to group the argument to the superscript command): \begin{codeS} \glsni{begindispmath} f(x) = e\glsni{circumchar}\marg{x\glsni{underscorechar}1} \glsni{enddispmath} \end{codeS}% which produces \begin{resultS}[nestedsup.html] \[ f(x) = e^{x_1} \] \end{resultS} This example isn't quite right as e isn't actually a variable and shouldn't be typeset in italic. The correct way to do this is:\bookpagebreak \begin{codeS} \glsni{begindispmath} f(x) = \gls{mathrm}\marg{e}\glsni{circumchar}\marg{x\glsni{underscorechar}1} \glsni{enddispmath} \end{codeS}% which results in: \begin{resultS}[Image: as above but the letter e is upright] \[ f(x) = \mathrm{e}^{x_1} \] \end{resultS} \refstepcounter{object}\label{obj:e}If you are going to use e a lot, it will be simpler to \htmlref{define a new command}{ch:newcom} to do this. The definition should go in the \glsterm{preamble}: \begin{codeS} \gls{newcommand}\marg{\cmdname{e}}\marg{\glsni{mathrm}\marg{e}} \end{codeS}% Then in the document: \begin{codeS} \glsni{begindispmath} f(x\glsni{underscorechar}1, x\glsni{underscorechar}2) = \cmdname{e}\glsni{circumchar}\marg{x\glsni{underscorechar}1\glsni{circumchar}2} + \cmdname{e}\glsni{circumchar}\marg{x\glsni{underscorechar}2\glsni{circumchar}2} \glsni{enddispmath} \end{codeS}% \begin{resultS}[nestedsup2.html] \[ f(x_1, x_2) = \e^{x_1^2} + \e^{x_2^2} \] \end{resultS} Take care when nesting subscripts or superscripts. The following \begin{alltt}\wrong x\glsni{underscorechar}1\glsni{underscorechar}2 \end{alltt} will give a \texttt{!\ Double subscript} error. %-------------- Functional Names -------------- \setnode{functionnames} \subsection{Functional Names} \label{sec:funcnames} Functions such as log and tan can't simply be typed in as \texttt{log} or \texttt{tan} otherwise they will come out looking like the variables \mathorit{l} times \mathorit{o} times \mathorit{g} (\makeimg{l o g}{$ l o g$}) or \mathorit{t} times \mathorit{a} times \mathorit{n} (\makeimg{t a n}{$ t a n$}). Instead you should use one of the commands listed in \tableref{tab:fnnames}. The functions denoted with \supdag\ can have limits by using the subscript command \gls{underscorechar} or the superscript command \gls{circumchar}\faq{Sub- and superscript positioning for operators}{limits}. In addition, the modulo commands listed in \tableref{tab:mod} are also available. \begin{table}[bhtp] \caption[Function Names]{Function Names (\supdag indicates command may have limits, \supddag defined by \protect\isty{amsmath}).} \label{tab:fnnames} \centering \begin{tabular}{llllll} \gls{arccos} & $\arccos$ & \gls{arcsin} & $\arcsin$ & \gls{arctan} & $\arctan$ \\ \gls{arg} & $\arg$ & \gls{cos} & $\cos$ & \gls{cosh} & $\cosh$ \\ \gls{cot} & $\cot$ & \gls{coth} & $\coth$ & \gls{csc} & $\csc$ \\ \gls{deg} & $\deg$ & \gls{det}\supdag & $\det$ & \gls{dim} & $\dim$ \\ \gls{exp} & $\exp$ & \gls{gcd}\supdag & $\gcd$ & \gls{hom} & $\hom$ \\ \gls{inf}\supdag & $\inf$ & \gls{injlim}\supdagddag & $\injlim$ & \gls{ker} & $\ker$ \\ \gls{lg} & $\lg$ & \gls{lim}\supdag & $\lim$ & \gls{liminf}\supdag & $\liminf$ \\ \gls{limsup}\supdag & $\limsup$ & \gls{ln} & $\ln$ & \gls{log} & $\log$ \\ \gls{max}\supdag & $\max$ & \gls{min}\supdag & $\min$ & \gls{Pr}\supdag & $\Pr$ \\ \gls{projlim}\supdagddag & $\projlim$ & \gls{sec} & $\sec$ & \gls{sin} & $\sin$ \\ \gls{sinh} & $\sinh$ & \gls{sup}\supdag & $\sup$ & \gls{tan} & $\tan$ \\ \gls{tanh} & $\tanh$ & \gls{varinjlim}\supdagddag & $\varinjlim$ & \gls{varliminf}\supdagddag & $\varliminf$ \\ \gls{varlimsup}\supdagddag & $\varlimsup$ & \gls{varprojlim}\supdagddag & $\varprojlim$ & \end{tabular} \end{table} \begin{table}[htbp] \caption[Modulo Commands]{Modulo Commands (\supddag defined by \protect\isty{amsmath} package)} \label{tab:mod} \centering \begin{tabular}{lll} \toprule \bfseries Command & \bfseries Example Input & \bfseries Example Output\\ \midrule \gls{bmod} & \verb|$m \bmod n$| & $m \bmod n$\\ \gls{pmod}\marg{\meta{maths}} & \verb|$m \pmod{n}$| &$m \pmod{n}$\\ \gls{mod}\marg{\meta{maths}}\supddag & \verb|$m \mod{n}$| &$m \mod{n}$\\ \gls{pod}\marg{\meta{maths}}\supddag & \verb|$m \pod{n}$| &$m \pod{n}$ \\\bottomrule \end{tabular} \end{table} \xminisec{Example (Trigonometric Functions):} This example uses the cos and sin functions and also the \htmlref{Greek letter}{sec:greek} theta. \begin{codeS} \glsni{begindispmath} z = r(\glsni{cos}\glsni{theta} + i\glsni{sin}\glsni{theta}) \glsni{enddispmath} \end{codeS}% \begin{resultS}[Image: z equals r (cos theta plus i sign theta)] \[ z = r(\cos\theta + i\sin\theta) \] \end{resultS} \xminisec{Example (Limit):} The command \gls{infty} is the infinity symbol \makeimg{image of infinity symbol}{$\infty$}, and the command \gls{to} displays an arrow pointing to the right. Note the use of \gls{underscorechar} since the limit is a subscript. \begin{codeS} \glsni{begindispmath} \glsni{lim}\glsni{underscorechar}\marg{x\glsni{to}\glsni{infty}} f(x) \glsni{enddispmath} \end{codeS}% \begin{resultS}[Image: limit as x tends to infinity of f of x] \[ \lim_{x\to\infty} f(x) \] \end{resultS}% The operators with limits behave differently depending on whether they are in \htmlref{displayed}{sec:displayed} or \htmlref{in-line}{sec:inline} maths. Notice the difference when the same code appears in-line: \begin{codeS} In a line of text \glsni{dollarchar}\glsni{lim}\glsni{underscorechar}\marg{x\glsni{to}\glsni{infty}} f(x)\glsni{dollarchar} \end{codeS}% which now displays as: \begin{resultS}[Image: the limit appears to the side of lim instead of below it.] In a line of text $\lim_{x\to\infty} f(x)$ \end{resultS} \xminisec{Example (With Subscript):} This is another example of a functional name using a subscript: \begin{codeS} \glsni{begindispmath} \glsni{min}\glsni{underscorechar}x f(x) \glsni{enddispmath} \end{codeS}% \begin{resultS}[Image: the x appears below the word min.] \[ \min_x f(x) \] \end{resultS}% Again, notice the difference when it is used in-line: \begin{codeS} In a line of text \glsni{dollarchar}\glsni{min}\glsni{underscorechar}x f(x)\glsni{dollarchar} \end{codeS}% \begin{resultS}[Image: the x appears to the side of the word min.] In a line of text $\min_x f(x)$ \end{resultS} \bookpagebreak \setnode{declaremathop} \subsubsection{Defining New Functional Operators} \label{sec:declaremathop} It may be that you want a function that isn't specified in \tableref{tab:fnnames}. In this case, the \isty{amsmath} provides the \textbf{\em \gls{preamble} only} command \begin{definition} \gls{DeclareMathOperator}\marg{\meta{cmd}}\marg{\meta{operator name}} \end{definition} or its \htmlref{starred variant}{itm:starredcommand} \begin{definition} \glsni{DeclareMathOperator}*\marg{\meta{cmd}}\marg{\meta{operator name}} \end{definition} \faq{Defining a new log-like function in LaTeX}{newfunction}% Both versions define a command called \meta{cmd}, which must start with a backslash, that typesets \meta{operator name} as a function name. The starred version is for function names that can take limits (like \gls{lim} and \gls{min} described above). \xminisec{Example (Operator Without Limits):} Suppose I want a function called card, which represents the cardinality of a set $\mathcal{S}$. First I~need to define the new operator command (which I'm going to call \cmdname{card}) \emph{in the \gls{preamble}}: \begin{codeS} \glsni{DeclareMathOperator}\marg{\cmdname{card}}\marg{card} \end{codeS} This operator doesn't take any limits, so I~have used the unstarred version. Later in the document, I~can use this new operator command: \begin{codeS} \glsni{begindispmath} n = \cmdname{card}(\glsni{mathcal}\marg{S}) \glsni{enddispmath} \end{codeS}% \begin{resultS}[Image: n equals card (S)] \[ n = \card(\mathcal{S}) \] \end{resultS}% In this example \gls{mathcal} is used as sets are typically represented in a calligraphic font. \xminisec{Example (Operator With Limits):} Suppose I~now want a function called mode, which represents the mode of a set of numbers. First, I~define the operator command in the preamble: \begin{codeS} \glsni{DeclareMathOperator}*\marg{\cmdname{mode}}\marg{mode} \end{codeS} This operator needs to be able to have a subscript, so I~have used the starred version. Later in the document, I~can use this new operator command: \begin{codeS} \glsni{begindispmath} x\glsni{underscorechar}m = \cmdname{mode}\glsni{underscorechar}\marg{x \glsni{in} \glsni{mathcal}\marg{S}}(x) \glsni{enddispmath} \end{codeS} \begin{resultS}[Image: x subscript m equals mode of x in S of x] \[ x_m = \mode_{x \in \mathcal{S}}(x) \] \end{resultS} %----------- Fractions ------------ \bookpagebreak \setnode{fractions} \subsection{Fractions} \label{sec:fractions} Fractions are created using the command \begin{definition} \gls{frac}\marg{\meta{numerator}}\marg{\meta{denominator}} \end{definition} The \isty{amsmath} package also provides the command \begin{definition} \gls{cfrac}\oarg{\meta{pos}}\marg{\meta{numerator}}\marg{\meta{denominator}} \end{definition} which is designed for continued fractions. The optional argument \texttt{pos} can be used for left (\texttt{l}) or right (\texttt{r}) placement of any of the numerators. (The default is centred.) \xminisec{Example:} A simple fraction: \begin{codeS} \glsni{begindispmath} \glsni{frac}\marg{1}\marg{1+x} \glsni{enddispmath} \end{codeS} Produces: \begin{resultS}[Image of fraction with 1 as the numerator and 1+x as the denominator.] \[ \frac{1}{1+x} \] \end{resultS} Compare with: \begin{codeS} In-line: \glsni{dollarchar} \glsni{frac}\marg{1}\marg{1+x} \glsni{dollarchar} \end{codeS} which produces: \begin{resultS}[Image: as before but fraction is smaller.] In-line: $\frac{1}{1+x}$ \end{resultS} \xminisec{Example (Nested):} \begin{codeS} \glsni{begindispmath} \glsni{frac}\marg{1+\glsni{frac}\marg{1}\marg{x}}\marg{1+x+x\glsni{circumchar}2} \glsni{enddispmath} \end{codeS}% \begin{resultS}[Image of fraction with (1+1/x) as the numerator and (1 + x + x squared as the denominator.] \[ \frac{1+\frac{1}{x}}{1+x+x^2} \] \end{resultS} \xminisec{Example (Continued Fraction);} A continued fraction (example taken from \isty{amsmath} documentation and uses \glsni{sqrt}, described in \sectionref{sec:roots}, and \glsni{dotsb}, described in \sectionref{sec:mathssym}): \begin{code} \begin{alltt} \glsni{begindispmath} \glsni{cfrac}\marg{1}\marg{\glsni{sqrt}\marg{2}+ \glsni{cfrac}\marg{1}\marg{\glsni{sqrt}\marg{2}+ \glsni{cfrac}\marg{1}\marg{\glsni{sqrt}\marg{2}+\glsni{dotsb} }}} \glsni{enddispmath} \end{alltt} \end{code}\screenpagebreak \begin{result}[Image of a continued fraction (the denominator has a fraction with a fraction in its denominator etc).] \[ \cfrac{1}{\sqrt{2}+ \cfrac{1}{\sqrt{2}+ \cfrac{1}{\sqrt{2}+\dotsb }}} \] \end{result} \xminisec{Example (A Derivative):} \begin{codeS} \glsni{begindispmath} f'(x) = \glsni{frac}\marg{df}\marg{dx} \glsni{enddispmath} \end{codeS}% \begin{resultS}[Image: f'(x) = d f by d x] \[ f'(x) = \frac{df}{dx} \] \end{resultS}% As with \dq{e}, the differential operator \dq{d} should be in an upright font as it is not a variable: \begin{code} \begin{alltt} \glsni{begindispmath} f'(x) = \glsni{frac}\marg{\glsni{mathrm}\marg{d}f}\marg{\glsni{mathrm}\marg{d}x} \glsni{enddispmath} \end{alltt} \end{code}% \begin{resultS}[Image: as above but the letter d is upright] \[ f'(x) = \frac{\mathrm{d}f}{\mathrm{d}x} \] \end{resultS} The above example is rather cumbersome, particularly if you have a lot of derivatives, so it might be easier to \htmlref{define a new command}{ch:newcom}\latex{ (see \chapterref{ch:newcom})}. In the \glsterm{preamble} define: \begin{codeS} \gls{newcommand}\marg{\cmdname{deriv}}\oarg{2}\marg{\glsni{frac}\marg{\glsni{mathrm}\marg{d}\glsni{hashchar}1}\marg{\glsni{mathrm}\marg{d}\glsni{hashchar}2}} \end{codeS}% Then in the document: \begin{codeS} \glsni{begindispmath} f'(x) = \cmdname{deriv}\marg{f}\marg{x} \glsni{enddispmath} \end{codeS}% \begin{resultS}[Image: same as before] \newcommand{\deriv}[2]{\frac{\mathrm{d}#1}{\mathrm{d}#2}} \[ f'(x) = \deriv{f}{x} \] \end{resultS} \xminisec{Example (Partial Derivative):} \label{itm:pderiv}% Partial derivatives can be obtained similarly using the command \gls{partial} to display the partial derivative symbol. As in the previous example, first define a new command to format a partial derivative in the \glsterm{preamble}: \begin{codeS} \gls{newcommand}\marg{\cmdname{pderiv}}\oarg{2}\marg{\glsni{frac}\marg{\glsni{partial} \glsni{hashchar}1}{\glsni{partial} \glsni{hashchar}2}} \end{codeS}% Then in the document: \begin{codeS} \glsni{begindispmath} f\glsni{underscorechar}x = \cmdname{pderiv}\marg{f}\marg{x} \glsni{enddispmath} \end{codeS}% \begin{resultS}[Image: f subscript x = partial d f by partial d x] \[ f_x = \pderiv{f}{x} \] \end{resultS} \xminisec{Example (Double Partial Derivative):} \begin{code} \begin{alltt} \glsni{begindispmath} f\glsni{underscorechar}\marg{xy} = \glsni{frac}\marg{\glsni{partial}\glsni{circumchar}2 f}\marg{\glsni{partial} x \glsni{partial} y} \glsni{enddispmath} \end{alltt} \end{code}% \begin{resultS}[Image: f subscript xy = partial d 2 f by partial d x partial d y.] \[ f_{xy} = \frac{\partial^2 f}{\partial x \partial y} \] \end{resultS} \xminisec{Example (First principles):} \begin{code} \glsni{begindispmath}\newline \mbox{}\qquad f'(x) = \gls{lim}\gls{underscorechar}\marg{\gls{Delta} x \gls{to} 0}\newline \mbox{}\qquad \glsni{frac}\marg{f(x + \gls{Delta} x)-f(x)}\marg{\gls{Delta} x}\newline \glsni{enddispmath} \end{code} \begin{resultS} \[ f'(x) = \lim_{\Delta x\to0} \frac{f(x+\Delta x) - f(x)}{\Delta x} \] \end{resultS} %------------ Roots -------------- \setnode{roots} \subsection{Roots} \label{sec:roots} Roots are obtained using the command \begin{definition} \gls{sqrt}\oarg{\meta{order}}\marg{\meta{maths}} \end{definition}% without the optional argument \meta{order} it will produce a simple square root. Cubic roots etc can be obtained using the optional argument. \xminisec{Examples:} \begin{enumerate} \item A square root: \begin{codeS} \glsni{begindispmath} \glsni{sqrt}\marg{a+b} \glsni{enddispmath} \end{codeS}% \begin{resultS}[Image: square root of (a + b)] \[ \sqrt{a+b} \] \end{resultS} \item A cubic root: \begin{codeS} \glsni{begindispmath} \glsni{sqrt}\oarg{3}\marg{a+b} \glsni{enddispmath} \end{codeS}% \begin{resultS}[Image: cubic root of (a + b)] \[ \sqrt[3]{a+b} \] \end{resultS} \item An \ensuremath{n}th root: \begin{codeS} \glsni{begindispmath} \glsni{sqrt}\oarg{n}\marg{a+b} \glsni{enddispmath} \end{codeS}% \begin{resultS}[Image: the nth root of (a + b)] \[ \sqrt[n]{a+b} \] \end{resultS} \end{enumerate} %-------- Mathematical Symbols ------------- \setnode{mathssym} \subsection{Mathematical Symbols} \label{sec:mathssym} Relational symbols\faq{Where can I find the symbol for \ldots}{symbols} are shown in \tableref{tab:relsym}. If you want a negation that is not shown, you can obtain it by preceding the symbol with the command \gls{not}. For example: \glsni{not}\glsni{subset} produces the symbol \makeimg{image of subset symbol with slash through it}{$\not\subset$}. \begin{table}[hbtp] \caption{Relational Symbols} \label{tab:relsym} \centering \begin{tabular}{llllll} \gls{approx} & $\approx$ & \gls{asymp} & $\asymp$ & \gls{bowtie} & $\bowtie$ \\ \gls{cong} & $\cong$ & \gls{dashv} & $\dashv$ & \gls{doteq} & $\doteq$ \\ \gls{equiv} & $\equiv$ & \gls{frown} & $\frown$ & \gls{ge} or \gls{geq} & $\geq$ \\ \gls{gg} & $\gg$ & \gls{in} & $\in$ & \gls{le} or \gls{leq} & $\leq$ \\ \gls{ll} & $\ll$ & \gls{mid} or \verb"|" & $\mid$ & \gls{models} & $\models$ \\ \gls{neq} & $\neq$ & \gls{ni} & $\ni$ & \gls{notin} & $\notin$ \\ \gls{parallel} & $\parallel$ & \gls{prec}& $\prec$ & \gls{preceq}& $\preceq$ \\ \gls{perp} & $\perp$ & \gls{propto} & $\propto$ & \gls{sim} & $\sim$ \\ \gls{simeq} & $\simeq$ & \gls{smile} & $\smile$ & \gls{sqsubseteq} & $\sqsubseteq$ \\ \gls{sqsupseteq} & $\sqsupseteq$ & \gls{subset} & $\subset$ & \gls{subseteq} & $\subseteq$ \\ \gls{succ} & $\succ$ & \gls{succeq} & $\succeq$ & \gls{supset} & $\supset$ \\ \gls{supseteq} & $\supseteq$ & \gls{vdash} & $\vdash$ & \end{tabular} \end{table} Binary operator symbols are shown in \tableref{tab:binop}, and arrow symbols are shown in \xtableref{tab:arrows}. There are also over and under arrows (\xtableref{tab:overunderarrows}) that have an argument. The over arrows put an extendible arrow over their argument, and the under arrows put an extendible arrow under their argument. In addition, the \isty{amsmath} package provides extensible arrows that take a superscript and, optionally, a subscript: \begin{definition} \gls{xleftarrow}\oarg{\meta{subscript}}\marg{\meta{superscript}} \end{definition} \begin{definition} \gls{xrightarrow}\oarg{\meta{subscript}}\marg{\meta{superscript}} \end{definition} \xminisec{Example:} \begin{code} \glsni{begindispmath}\newline \mbox{}\qquad A \glsni{xleftarrow}\marg{n+m-p} B \glsni{xrightarrow}\oarg{X}\marg{n+p} C\newline \glsni{enddispmath} \end{code} \begin{result}[Image of result: the arrow subscripts and superscript are centred over the arrow.] \[ A \xleftarrow{n+m-p} B \xrightarrow[X]{n+p} C \] \end{result} \begin{table}[tbhp] \caption{Binary Operator Symbols} \label{tab:binop} \centering \begin{tabular}{llllll} \gls{amalg} & $\amalg$ & \gls{ast} & $\ast$ & \gls{bullet} & $\bullet$ \\ \gls{bigcirc} & $\bigcirc$ & \gls{bigtriangledown} & $\bigtriangledown$ & \gls{bigtriangleup} & $\bigtriangleup$ \\ \gls{cap} & $\cap$ & \gls{cdot} & $\cdot$ & \gls{circ} & $\circ$ \\ \gls{cup} & $\cup$ & \gls{dagger} & $\dagger$ & \gls{ddagger} & $\ddagger$ \\ \gls{diamond} & $\diamond$ & \gls{div} & $\div$ & \gls{mp} & $\mp$ \\ \gls{odot} & $\odot$ & \gls{ominus} & $\ominus$ & \gls{oplus} & $\oplus$ \\ \gls{oslash} & $\oslash$ & \gls{otimes} & $\otimes$ & \gls{pm} & $\pm$ \\ \gls{setminus} & $\setminus$ & \gls{sqcap} & $\sqcap$ & \gls{sqcup} & $\sqcup$ \\ \gls{star} & $\star$ & \gls{times} & $\times$ & \gls{triangleleft} & $\triangleleft$ \\ \gls{triangleright} & $\triangleright$ & \gls{uplus} & $\uplus$ & \gls{vee} & $\vee$ \\ \gls{wedge} & $\wedge$ & \gls{wr} & $\wr$ \end{tabular} \end{table} \begin{table}[tbhp] \caption{Arrow Symbols} \label{tab:arrows} \centering \begin{tabular}{llll} \gls{downarrow} & $\downarrow$ & \gls{Downarrow} & $\Downarrow$ \\ \gls{hookleftarrow} & $\hookleftarrow$ & \gls{hookrightarrow} & $\hookrightarrow$ \\ \gls{leftarrow} or \gls{gets} & $\leftarrow$ & \gls{Leftarrow} & $\Leftarrow$ \\ \gls{leftharpoondown} & $\leftharpoondown$ & \gls{leftharpoonup} & $\leftharpoonup$ \\ \gls{leftrightarrow} & $\leftrightarrow$ & \gls{Leftrightarrow} & $\Leftrightarrow$ \\ \gls{longleftarrow} & $\longleftarrow$ & \gls{Longleftarrow} & $\Longleftarrow$ \\ \gls{longleftrightarrow} & $\longleftrightarrow$ & \gls{Longleftrightarrow} & $\Longleftrightarrow$ \\ \gls{longmapsto} & $\longmapsto$ & \gls{longrightarrow} & $\longrightarrow$ \\ \gls{Longrightarrow} & $\Longrightarrow$ & \gls{mapsto} & $\mapsto$ \\ \gls{nearrow} & $\nearrow$ & \gls{nwarrow} & $\nwarrow$ \\ \gls{rightarrow} or \gls{to} & $\to$ & \gls{Rightarrow} & $\Rightarrow$ \\ \gls{rightharpoondown} & $\rightharpoondown$ & \gls{rightharpoonup} & $\rightharpoonup$ \\ \gls{rightleftharpoons} & $\rightleftharpoons$ & \gls{searrow} & $\searrow$ \\ \gls{swarrow} & $\swarrow$ & \gls{uparrow} & $\uparrow$ \\ \gls{Uparrow} & $\Uparrow$ & \gls{updownarrow} & $\updownarrow$ \\ \gls{Updownarrow} & $\Updownarrow$ & \end{tabular} \end{table} \begin{table}[htbp] \caption[Over and Under Arrows]{Over and Under Arrows (\supdag defined by \protect\isty{amsmath})} \label{tab:overunderarrows} \centering \begin{tabular}{@{}lll@{}} \toprule \bfseries Definition & \multicolumn{2}{c}{\bfseries Example}\\ \midrule \begin{inlinedef}\gls{overleftarrow}\marg{\meta{maths}}\end{inlinedef} & \verb|\overleftarrow{ABC}| & $\overleftarrow{ABC}$\\ \begin{inlinedef}\gls{overrightarrow}\marg{\meta{maths}}\end{inlinedef} & \verb|\overrightarrow{ABC}| & $\overrightarrow{ABC}$\\ \begin{inlinedef}\gls{overleftrightarrow}\marg{\meta{maths}}\end{inlinedef}\supdag & \verb|\overleftrightarrow{ABC}| & $\overleftrightarrow{ABC}$\\ \begin{inlinedef}\gls{underleftarrow}\marg{\meta{maths}}\end{inlinedef}\supdag & \verb|\underleftarrow{ABC}| & $\underleftarrow{ABC}$\\ \begin{inlinedef}\gls{underrightarrow}\marg{\meta{maths}}\end{inlinedef}\supdag & \verb|\underrightarrow{ABC}| & $\underrightarrow{ABC}$\\ \begin{inlinedef}\gls{underleftrightarrow}\marg{\meta{maths}}\end{inlinedef}\supdag & \verb|\underleftrightarrow{ABC}| & $\underleftrightarrow{ABC}$ \\\bottomrule \end{tabular} \end{table} \bookpagebreak \begin{table}[htbp] \caption{Symbols with Limits} \label{tab:symlim} \centering \begin{tabular}{llllll} \gls{sum} & $\sum$ & \gls{int} & $\int$ & \gls{oint} & $\oint$ \\[5pt] \gls{prod} & $\prod$ & \gls{coprod} & $\coprod$ & \gls{bigcap} & $\bigcap$ \\[5pt] \gls{bigcup} & $\bigcup$ & \gls{bigsqcup} & $\bigsqcup$ & \gls{bigvee} & $\bigvee$ \\[5pt] \gls{bigwedge} & $\bigwedge$ & \gls{bigodot} & $\bigodot$ & \gls{bigotimes} & $\bigotimes$ \\[5pt] \gls{bigoplus} & $\bigoplus$ & \gls{biguplus} & $\biguplus$ \end{tabular} \end{table} Symbols that can have limits are shown in \tableref{tab:symlim}. The size of these symbols depends on whether they are in displayed maths or in-line maths. \xminisec{Example (Displayed Summation and Product):} The limits of summations and products are placed above and below the symbol in displayed maths: \begin{code} \begin{alltt} \glsni{begindispmath} f(x) = \glsni{sum}\glsni{underscorechar}\marg{i=1}\glsni{circumchar}\marg{n} x\glsni{underscorechar}i + \glsni{prod}\glsni{underscorechar}\marg{i=1}\glsni{circumchar}\marg{n} x\glsni{underscorechar}i \glsni{enddispmath} \end{alltt} \end{code} \begin{resultS}[Image: f(x) = sum from i equals 1 to n x subscript i + product from i equals 1 to n x subscript i.] \[ f(x) = \sum_{i=1}^{n} x_i + \prod_{i=1}^{n} x_i \] \end{resultS} \xminisec{Example (In-line Summation and Product):} The limits of summations and products are placed to the right of the symbol in in-line maths: \begin{code} \begin{alltt} In a line of text: \glsni{begin}\marg{math} f(x) = \glsni{sum}\glsni{underscorechar}\marg{i=1}\glsni{circumchar}\marg{n} x\glsni{underscorechar}i + \glsni{prod}\glsni{underscorechar}\marg{i=1}\glsni{circumchar}\marg{n} x\glsni{underscorechar}i \glsni{end}\marg{math} \end{alltt} \end{code} \begin{resultS}[Image: as before but summation and product symbols are smaller and limits are to the side instead of above and below] In a line of text: \begin{math} f(x) = \sum_{i=1}^{n} x_i + \prod_{i=1}^{n} x_i \end{math} \end{resultS} \xminisec{Multiline Sub- or Superscripts} The \isty{amsmath} package provides the command: \begin{definition} \gls{substack}\marg{\meta{maths}} \end{definition} which can be used for multiline sub- or superscripts. Within the argument \meta{maths} use \gls{tab.dbbackslashchar} to separate rows. For example: \begin{code} \glsni{begindispmath}\newline \strut~\glsni{sum}\glsni{underscorechar}\marg{\newline \strut~~\glsni{substack}\newline \strut~~\marg{\newline \strut~~~~i \glsni{in} \glsni{mathcal}\marg{I}\glsni{tab.dbbackslashchar}\newline \strut~~~~i \glsni{neq} 0\newline \strut~~}\newline \strut~}\newline \strut~x\glsni{underscorechar}i\newline \glsni{enddispmath} \end{code} \begin{result}[substack.html] \[ \sum_{ \substack { i \in \mathcal{I}\\ i \neq 0 } } x_i \] \end{result} \setnode{ellipses} \subsection{Ellipses} \label{sec:ellipses} Ellipsis (omission mark)\index{ellipses (omission marks)|hyperpage} commands are shown in \tableref{tab:ellipsis}. The \isty{amsmath} package also provides: \glsni{dotsc} for dots with commas, \glsni{dotsb} for dots with binary operators/relations, \glsni{dotsm} for multiplication dots, \glsni{dotsi} for dots with integrals and \glsni{dotso} for other dots, which can be used as replacements for \glsni{ldots} and \glsni{cdots}. \begin{table}[hbtp] \caption[Ellipses]{Ellipses (\supdag\ provided by \sty{amsmath} package)} \label{tab:ellipsis} \centering \begin{tabular}{ll@{\hspace{4\tabcolsep}}ll@{\hspace{4\tabcolsep}}llllll} \gls{vdots} & $\vdots$ & \gls{cdots} & $\cdots$ & \gls{dotsb}\supdag & $\dotsb$ & \gls{dotsi}\supdag & $\dotsi$ & \gls{dotsm}\supdag & $\dotsm$\\ \gls{ddots} & $\ddots$ & \gls{ldots} & $\ldots$ & \gls{dotsc}\supdag & $\dotsc$ & \gls{dotso}\supdag & $\dotso$ \end{tabular} \end{table} \xminisec{Example (Low Ellipsis):} This example uses the command \refstepcounter{object}\label{cmd:forall}\gls{forall} to produce the \dq{for all} symbol $\forall$, and it also uses \glsni{spacesym} (backslash space) to make a space before the for all symbol. The \isty{amsmath} \dq{dots with commas} ellipsis \glsni{dotsc} is used rather than the standard \glsni{ldots}: \begin{code} \begin{alltt} \glsni{begindispmath} a\glsni{underscorechar}ix\glsni{underscorechar}i = b\glsni{underscorechar}i\glsni{spacesym}\glsni{forall} i = 1,\glsni{dotsc}, n \glsni{enddispmath} \end{alltt} \end{code}% \begin{resultS}[forall.html] \[ a_ix_i = b_i\ \forall i = 1,\dotsc, n \] \end{resultS} \xminisec{Example (Centred ellipsis):} This example uses the \isty{amsmath} \dq{dots with binary operators\slash relations} \glsni{dotsb} instead of the standard \glsni{cdots}: \begin{code} \begin{alltt} \glsni{begindispmath} y = a\glsni{underscorechar}1 + a\glsni{underscorechar}2 + \glsni{dotsb} + a\glsni{underscorechar}n \glsni{enddispmath} \end{alltt} \end{code}% \begin{resultS}[cdots.html] \[ y = a_1 + a_2 + \dotsb + a_n \] \end{resultS} \begin{exercise}{Maths: Fractions and Symbols}{ex:mathssym} This exercise uses a fraction, a square root, subscripts, superscripts and symbols. Try to reproduce the following output: \begin{result}[maths1ex.html] The quadratic equation \[ \sum_{i=0}^{2} a_i x^i = 0 \] has solutions given by \[ x = \frac{-a_1 \pm \sqrt{a_1^2 - 4 a_2 a_0}}{2a_2} \] \end{result}% Again you can \downloadorview{mathssym} the solution. \end{exercise} %---------- Delimiters ------------ \setnode{delimiters} \subsection{Delimiters} \label{sec:delimiters} Placing brackets around a tall object in maths mode, such as fractions, does not look right if you use normal sized brackets. For example: \begin{code} \glsni{begindispmath}\newline \strut~~(\glsni{frac}\marg{1}\marg{1+x})\newline \glsni{enddispmath} \end{code}% results in: \begin{resultS}[Image: normal sized brackets around fraction.] \[ (\frac{1}{1+x}) \] \end{resultS}\bookpagebreak\noindent Instead, you can automatically resize the delimiters using the commands: \begin{definition} \gls{left}\meta{delimiter} \end{definition}% and \begin{definition} \gls{right}\meta{delimiter} \end{definition}% Rewriting the above example: \begin{code} \begin{alltt} \glsni{begindispmath} \glsni{left}( \glsni{frac}\marg{1}\marg{1+x} \glsni{right}) \glsni{enddispmath} \end{alltt} \end{code}% produces: \begin{resultS}[Image: brackets now the same size as the fraction.] \[ \left( \frac{1}{1+x} \right) \] \end{resultS}% Note that you must always have matching \cmdname{left} and \cmdname{right} commands, although the delimiters used may be different. \refstepcounter{object}\label{obj:invisdelim}If you want one of the delimiters to be invisible, use a \gls{delimiter.periodchar}\ (full stop) as the delimiter. Available delimiters are shown in \tableref{tab:delimiters}. (Note for a vertical bar delimiter it's best to use \isty{amsmath}'s \glsni{lvert} command instead of \gls{delim.barchar} and \glsni{lVert} instead of \gls{csbar}.) Sometimes using \glsni{left} and \glsni{right} doesn't produce the optimal sized delimiters. In which case you can use additional commands provided by the \isty{amsmath} package shown in \tableref{tab:big}. \begin{table}[hbtp] \caption[Delimiters]{Delimiters (\supdag defined by \protect\isty{amsmath})} \label{tab:delimiters} \centering \begin{tabular}{llllllll} \begin{inlinedef}\gls{openparen}\end{inlinedef} & \makeimg{open round bracket}{$($} & \begin{inlinedef}\gls{closeparen}\end{inlinedef} & \makeimg{close round bracket}{$)$} & \begin{inlinedef}\gls{delimiter.opensq}\end{inlinedef} & \makeimg{open square bracket}{$[$} & \begin{inlinedef}\gls{delimiter.closesq}\end{inlinedef} & \makeimg{close square bracket}{$]$} \\ \begin{inlinedef}\gls{leftbrace}\end{inlinedef} & \makeimg{open curly brace}{$\{$} & \begin{inlinedef}\gls{rightbrace}\end{inlinedef} & \makeimg{close curly brace}{$\}$} & \begin{inlinedef}\gls{lvert}\supdag\end{inlinedef} & \makeimg{left vertical bar}{$\lvert$} & \begin{inlinedef}\gls{rvert}\supdag\end{inlinedef} & \makeimg{right vertical bar}{$\rvert$} \\ \begin{inlinedef}\gls{lVert}\supdag\end{inlinedef} & \makeimg{left double vertical bar}{$\lVert$} & \begin{inlinedef}\gls{rVert}\supdag\end{inlinedef} & \makeimg{right double vertical bar}{$\rVert$} & \begin{inlinedef}\gls{langle}\end{inlinedef} & \makeimg{left angle bracket}{$\langle$} & \begin{inlinedef}\gls{rangle}\end{inlinedef} & \makeimg{right angle bracket}{$\rangle$} \\ \begin{inlinedef}\gls{lfloor}\end{inlinedef} & \makeimg{left floor}{$\lfloor$} & \begin{inlinedef}\gls{rfloor}\end{inlinedef} & \makeimg{right floor}{$\rfloor$} & \begin{inlinedef}\gls{lceil}\end{inlinedef} & \makeimg{left ceiling}{$\lceil$} & \begin{inlinedef}\gls{rceil}\end{inlinedef} & \makeimg{right ceiling}{$\rceil$}\\ \begin{inlinedef}\gls{uparrow}\end{inlinedef} & \makeimg{up arrow}{$\uparrow$} & \begin{inlinedef}\gls{downarrow}\end{inlinedef} & \makeimg{down arrow}{$\downarrow$} & \begin{inlinedef}\gls{Uparrow}\end{inlinedef} & \makeimg{double lined up arrow}{$\Uparrow$} & \begin{inlinedef}\gls{Downarrow}\end{inlinedef} & \makeimg{double lined down arrow}{$\Downarrow$}\\ \begin{inlinedef}\gls{updownarrow}\end{inlinedef} & \makeimg{up down arrow}{$\updownarrow$} & \begin{inlinedef}\gls{Updownarrow}\end{inlinedef} & \makeimg{double lined up down arrow}{$\Updownarrow$} & \begin{inlinedef}\gls{delim.slash}\end{inlinedef} & \makeimg{forward slash}{$/$} & \begin{inlinedef}\gls{backslash}\end{inlinedef} & \makeimg{backslash}{$\backslash$} \end{tabular} \end{table} \begin{table} \caption[Delimiter Sizing]{Additional Commands Provided by \protect\isty{amsmath} for Delimiter Sizing} \label{tab:big} \centering \renewcommand*{\arraystretch}{2.2} \begin{tabular}{@{}ll@{\hspace{4\tabcolsep}}ll@{}} \toprule \multicolumn{2}{c@{\hspace{4\tabcolsep}}}{\bfseries Definitions} & \multicolumn{2}{c}{\bfseries Example}\\ \midrule \multicolumn{2}{c@{\hspace{4\tabcolsep}}}{\em Default Size} & \verb|$( X )$| & $(X)$\\ \begin{inlinedef}\gls{bigl}\meta{delim}\end{inlinedef} & \begin{inlinedef}\gls{bigr}\meta{delim}\end{inlinedef} & \verb|$\bigl( X \bigr)$| & \makeimg{(X)}{$\bigl(X\bigr)$} \\ \begin{inlinedef}\gls{Bigl}\meta{delim}\end{inlinedef} & \begin{inlinedef}\gls{Bigr}\meta{delim}\end{inlinedef} & \verb|$\Bigl( X \Bigr)$| & \makeimg{(X)}{$\Bigl(X\Bigr)$} \\ \begin{inlinedef}\gls{biggl}\meta{delim}\end{inlinedef} & \begin{inlinedef}\gls{biggr}\meta{delim}\end{inlinedef} & \verb|$\bigl( X \biggr)$| & \makeimg{(X)}{$\biggl(X\biggr)$} \\ \begin{inlinedef}\gls{Biggl}\meta{delim}\end{inlinedef} & \begin{inlinedef}\gls{Biggr}\meta{delim}\end{inlinedef} & \verb|$\Biggl( X \Biggr)$| & \makeimg{(X)}{$\Biggl(X\Biggr)$} \\ \bottomrule \end{tabular} \renewcommand*{\arraystretch}{1}% Keep LaTeX2HTML happy \end{table} \xminisec{Example (Vertical Bar Delimiters):} \begin{code} \glsni{begindispmath}\newline \glsni{left}\glsni{lvert}\newline \glsni{frac}\marg{1}\marg{1+x}\newline \glsni{right}\glsni{rvert}\newline \glsni{enddispmath} \end{code}% \begin{resultS}[Image: vertical bars same height as fraction.] \[ \left\lvert\frac{1}{1+x}\right\rvert \] \end{resultS} \xminisec{Example (Delimiter with Subscript):} Delimiters can take limits: \begin{code} \glsni{begindispmath}\newline \glsni{left}\glsni{lvert}\newline \glsni{frac}\marg{1}\marg{1+x}\newline \glsni{right}\glsni{rvert}\glsni{underscorechar}\marg{x=0}\newline \glsni{enddispmath} \end{code}\reportpagebreak \begin{resultS}[Image: as before but the right vertical bar has a subscript.] \[ \left\lvert\frac{1}{1+x}\right\rvert_{x=0} \] \end{resultS} \xminisec{Example (Mismatch):} The left and right delimiters don't have to match: \begin{code} \begin{alltt} \glsni{begindispmath} \glsni{left}\glsni{delimiter.opensq}\glsni{frac}\marg{1}\marg{1+x}\glsni{right}\glsni{rangle} \glsni{enddispmath} \end{alltt} \end{code}% \begin{resultS}[Image: large open square bracket followed by fraction followed by large right angle bracket.] \[ \left[\frac{1}{1+x}\right\rangle \] \end{resultS} \xminisec{Example (An invisible delimiter):} Every \gls{right} must have a matching \gls{left} (and vice versa), so use a \gls{delimiter.periodchar}\ (full stop) for an invisible delimiter. \begin{code} \begin{alltt} \glsni{begindispmath} \glsni{left}\glsni{delimiter.periodchar} \glsni{frac}\marg{\glsni{partial} f}\marg{\glsni{partial} x} \glsni{right}\glsni{rvert}\glsni{underscorechar}\marg{x=0} \glsni{enddispmath} \end{alltt} \end{code} \begin{resultS}[Image: partial fraction followed by large vertical line with a subscript.] \[ \left. \frac{\partial f}{\partial x} \right\rvert_{x=0} \] \end{resultS} \refstepcounter{object}\label{introeq} We have now covered enough to reproduce the equation shown in \chapterref{ch:intro}: \begin{code} \begin{alltt} \glsni{newcommand}*\marg{\cmdname{pderiv}}\oarg{2}\marg{\glsni{frac}\marg{\glsni{partial} \glsni{hashchar}1}\marg{\glsni{partial} \glsni{hashchar}2}} \glsni{newcommand}*\marg{\cmdname{e}}\marg{\glsni{mathrm}\marg{e}} \glsni{begindispmath} \cmdname{pderiv}\marg{\glsni{circumchar}2\glsni{mathcal}\marg{L}}\marg{\marg{z\glsni{underscorechar}i\glsni{circumchar}\glsni{rho}}\glsni{circumchar}2} = -\cmdname{pderiv}\marg{\glsni{rho}\glsni{underscorechar}i}\marg{z\glsni{underscorechar}i\glsni{circumchar}\glsni{rho}} \glsni{left}( \cmdname{pderiv}\marg{v\glsni{underscorechar}i}\marg{\glsni{rho}\glsni{underscorechar}i} \glsni{frac}\marg{\cmdname{e}\glsni{circumchar}\marg{v\glsni{underscorechar}i}}\marg{1-\cmdname{e}\glsni{circumchar}\marg{v\glsni{underscorechar}i}} + v\glsni{underscorechar}i \glsni{frac}\marg{\cmdname{e}\glsni{circumchar}\marg{v\glsni{underscorechar}i}\cmdname{pderiv}\marg{v\glsni{underscorechar}i}\marg{\glsni{rho}\glsni{underscorechar}i}(1-\cmdname{e}\glsni{circumchar}\marg{v\glsni{underscorechar}i}) +\cmdname{e}\glsni{circumchar}\marg{2v\glsni{underscorechar}i}\cmdname{pderiv}\marg{v\glsni{underscorechar}i}\marg{\glsni{rho}\glsni{underscorechar}i}}\marg{(1-\cmdname{e}\glsni{circumchar}\marg{v\glsni{underscorechar}i})\glsni{circumchar}2} \glsni{right}) \glsni{enddispmath} \end{alltt} \end{code}% \begin{result}[Image showing a second order partial derivative.] \[ \pderiv{^2\mathcal{L}}{{z_i^\rho}^2} = -\pderiv{\rho_i}{z_i^\rho} \left( \pderiv{v_i}{\rho_i} \frac{\e^{v_i}}{1-\e^{v_i}} + v_i \frac{\e^{v_i}\pderiv{v_i}{\rho_i}(1-\e^{v_i})+\e^{2v_i}\pderiv{v_i}{\rho_i}}{(1-\e^{v_i})^2} \right) \] \end{result} \xminisec{Note:} The above code looks a bit complicated, and there are so many braces that it can be easy to lose track, so here are some ways of making it a little easier to type: \begin{enumerate} \item Whenever you start a new environment type in the \gls{begin} and \gls{end} bits first, and then insert whatever goes inside the environment. This ensures that you always have a matching \gls{begin} and \gls{end}. The same goes for \glsni{begindispmath} and \glsni{enddispmath}. \item Whenever you type any braces, always type the opening and closing braces first, and then insert whatever goes in between. This will ensure that your braces always match up. \end{enumerate} So keeping these notes in mind, let's try typing in the code in a methodical manner:\screenpagebreak \begin{enumerate} \item Start and end the displayed maths mode: \begin{code} \glsni{begindispmath}\newline \glsni{enddispmath} \end{code} \item We now need a partial derivative. (The command \cmdname{pderiv} is defined as described \htmlref{earlier}{itm:pderiv}\latex{\ifscreenorother{}{\ on page~\pageref{itm:pderiv}}}. Make sure you remember to define it, preferably in the \gls{preamble}.) \begin{code} {\color{midgray} \glsnl{begindispmath}}\newline \cmdname{pderiv}\marg{}\marg{}\newline {\color{midgray} \glsnl{enddispmath}} \end{code} \item Let's do the first argument. This partial derivative is actually a double derivative, which means we need a squared bit on the top along with a calligraphic L: \begin{code} \begin{alltt} {\color{midgray}\glsnl{begindispmath} \cmdname{pderiv}\marg*{\textcolor{black}{\glsni{circumchar}2 \glsni{mathcal}\marg{L}}}\marg*{} \glsnl{enddispmath}} \end{alltt} \end{code} \item The second argument is the $z_i^\rho$ squared bit. This is a nested superscript \verb|{z_i^\rho}^2|: \begin{code} \begin{alltt} \color{midgray}\glsnl{begindispmath} \cmdname{pderiv}\marg*{\textasciicircum2 \cmdname{mathcal}\marg{L}}\marg*{\textcolor{black}{\marg{z\glsni{underscorechar}i\glsni{circumchar}\glsni{rho}}\glsni{circumchar}2}} \glsnl{enddispmath} \end{alltt} \end{code} \item We can do the next partial derivative in the same way. This one is slightly easier to do: \begin{code} {\color{midgray}\glsnl{begindispmath}\newline \cmdname{pderiv}\marg*{\glsnl{circumchar}2 \glsnl{mathcal}{L}}\marg*{\marg*{z\glsnl{underscorechar}i\glsnl{circumchar}\glsnl{rho}}\glsnl{circumchar}2}} =\newline -\cmdname{pderiv}\marg{\glsni{rho}\glsni{underscorechar}i}\marg{z\glsni{underscorechar}i\glsni{circumchar}\glsni{rho}}\newline {\color{midgray}\glsnl{enddispmath}} \end{code} \item Delimiters also need to occur in pairs, like curly braces and \glsni{begin} and \glsni{end}, so let's do them next: \begin{code} {\color{midgray}\verb|\[|\\ \verb|\pderiv{^2 \mathcal{L}}{{z_i^\rho}^2} =|\\ \verb|-\pderiv{\rho_i}{z_i^\rho}|}\\ \strut~~\glsni{left}(\\ \strut~~\glsni{right})\\ {\color{midgray}\verb|\]|} \end{code}\screenpagebreak \item Now we need to do the bits inside the brackets. First of all we have yet another partial derivative: \begin{code} {\color{midgray}\verb|\[|\\ \verb|\pderiv{^2 \mathcal{L}}{{z_i^\rho}^2} =|\\ \verb|-\pderiv{\rho_i}{z_i^\rho}|\\ \strut~~\glsnl{left}\glsnl{openparen}}\\ \strut~~~~\cmdname{pderiv}\marg{v\glsni{underscorechar}i}\marg{\glsni{rho}\glsni{underscorechar}i}\\ {\color{midgray}~~\glsnl{right}\glsnl{closeparen}\\ \verb|\]|} \end{code} \item Now we have a fraction following the partial derivative from the previous step. (Make sure you use braces for the exponential bit: \verb|\e^{v_i}| ($\e^{v_i}$) is not the same as \verb|\e^v_i| ($\e^v_i$). The command \cmdname{e} is defined as described \htmlref{earlier}{sec:scripts}\latex{ in \sectionref{sec:scripts}}. Make sure you define it, preferably in the \gls{preamble}.) \begin{code} {\color{midgray}\verb|\[|\\ \verb|\pderiv{^2 \mathcal{L}}{{z_i^\rho}^2} =|\\ \verb|-\pderiv{\rho_i}{z_i^\rho}|\\ \strut~~\glsnl{left}\glsnl{openparen}\\ \strut~~~~\cmdname{pderiv}\marg*{v\glsnl{underscorechar}i}\marg*{\glsnl{rho}\glsnl{underscorechar}i}} \glsni{frac}\marg{\cmdname{e}\glsni{circumchar}\marg{v\glsni{underscorechar}i}}\marg{1-\cmdname{e}\glsni{circumchar}\marg{v\glsni{underscorechar}i}}\\ {\color{midgray}~~\glsnl{right}\glsnl{closeparen}\\ \verb|\]|} \end{code} \item This is followed by $v_i$ times another fraction: \begin{code}\par\noindent {\color{midgray}\verb|\[|\\ \verb|\pderiv{^2 \mathcal{L}}{{z_i^\rho}^2} =|\\ \verb|-\pderiv{\rho_i}{z_i^\rho}|\\ \strut~~\glsnl{left}\glsnl{openparen}\\ \strut~~~~\cmdname{pderiv}\marg*{v\glsnl{underscorechar}i}\marg*{\glsnl{rho}\glsnl{underscorechar}i} \glsnl{frac}\marg*{\cmdname{e}\glsnl{circumchar}\marg*{v\glsnl{underscorechar}i}}\marg*{1-\cmdname{e}\glsnl{circumchar}\marg*{v\glsnl{underscorechar}i}}}\\ \strut~~~~+ v\glsni{underscorechar}i \glsni{frac}\marg{}\marg{}\\ {\color{midgray}~~\glsnl{right}\glsnl{closeparen}\\ \color{midgray}\verb|\]|} \end{code} \item The bottom part of the fraction (the denominator) is easier than the top, so let's do that first: \begin{code} \color{midgray}\glsnl{begindispmath}\newline \cmdname{pderiv}\marg*{\textasciicircum2 \cmdname{mathcal}\marg*{L}}\marg*{\marg*{z\_i\textasciicircum\cmdname{rho}}\textasciicircum2} =\newline -\cmdname{pderiv}\marg*{\cmdname{rho}\_i}\marg*{z\_i\textasciicircum\cmdname{rho}}\newline \strut~~\cmdname{left}(\newline \strut~~~~\cmdname{pderiv}\marg*{v\_i}\marg*{\cmdname{rho}\_i} \cmdname{frac}\marg*{\cmdname{e}\textasciicircum\marg*{v\_i}}\marg*{1-\cmdname{e}\textasciicircum\marg*{v\_i}}\newline \strut~~~~+ v\_i \cmdname{frac}\marg*{}\marg*{\textcolor{black}{(1-\cmdname{e}\glsni{circumchar}\marg{v\glsni{underscorechar}i})\glsni{circumchar}2}}\newline \strut~~\cmdname{right})\newline \glsnl{enddispmath} \color{black} \end{code} % Something weird is causing a shift in the % frame here. % Compensating by ending and restarting enumerate % environment \breakenumi \item Now for the top part of the fraction (the numerator). To refresh your memory, it should look like: \[ \e^{v_i}\pderiv{v_i}{\rho_i}(1-\e^{v_i}) + \e^{2v_i}\pderiv{v_i}{\rho_i} \] That's a bit complicated, so let's break it down: \begin{enumerate} \item The first term is: \begin{alltt} \cmdname{e}\glsni{circumchar}\marg{v\glsni{underscorechar}i} \end{alltt} \item The next term is another partial derivative: \begin{alltt} \cmdname{pderiv}\marg{v\glsni{underscorechar}i}\marg{\glsni{rho}\glsni{underscorechar}i} \end{alltt} \item Then we have: \begin{alltt} (1-\cmdname{e}\glsni{circumchar}\marg{v\glsni{underscorechar}i}) \end{alltt} \item Next we have to add on: \begin{alltt} +\cmdname{e}\glsni{circumchar}\marg{2v\glsni{underscorechar}i} \end{alltt} \item And finally we have: \begin{alltt} \cmdname{pderiv}\marg{v\glsni{underscorechar}i}\marg{\glsni{rho}\glsni{underscorechar}i} \end{alltt} \end{enumerate} So the numerator is: \begin{code} \begin{verbatim} \e^{v_i}\pderiv{v_i}{\rho_i}(1-\e^{v_i}) + \e^{2v_i}\pderiv{v_i}{\rho_i} \end{verbatim} \end{code} Inserting this into our code:\reportpagebreak \begin{code} \begin{alltt} \color{midgray}\glsnl{begindispmath} \cmdname{pderiv}\marg*{\textasciicircum2\cmdname{mathcal}\marg*{L}}\marg*{\marg*{z\_i\textasciicircum\cmdname{rho}}\textasciicircum2} = -\cmdname{pderiv}\marg*{\cmdname{rho}\_i}\marg*{z\_i\textasciicircum\cmdname{rho}} \cmdname{left}( \cmdname{pderiv}\marg*{v\_i}\marg*{\cmdname{rho}\_i} \cmdname{frac}\marg*{\cmdname{e}\textasciicircum\marg*{v\_i}}\marg*{1-\cmdname{e}\textasciicircum\marg*{v\_i}} \color{midgray}+ v\_i \cmdname{frac}\marg*{\textcolor{black}{\cmdname{e}\textasciicircum\marg{v\_i}\cmdname{pderiv}\marg{v\_i}\marg{\cmdname{rho}\_i}(1-\cmdname{e}\textasciicircum\marg{v\_i}) +\cmdname{e}\textasciicircum\marg{2v\_i}\cmdname{pderiv}\marg{v\_i}\marg{\cmdname{rho}\_i}}}\marg*{(1-\cmdname{e}\textasciicircum\marg*{v\_i})\textasciicircum2} \cmdname{right}) \glsnl{enddispmath} \end{alltt} \color{black} \end{code} \end{enumerate} %----------- Arrays ------------- \setnode{arrays} \subsection{Arrays} \label{sec:arrays} Mathematical structures such as matrices and vectors require elements to be arranged in rows and columns. Just as we can align material in rows and columns in text mode using the \gls{env-tabular} environment (\sectionref{sec:tabular}), we can do the same in maths mode using the \gls{env-array} environment. The \glsni{env-array} environment has the same format as the \gls{env-tabular} environment, however it must be in maths mode. The column half-gaps are given by the \gls{length} register \gls{arraycolsep} (analogous to \gls{tabcolsep}). \xminisec{Example:} \begin{code} \glsni{begindispmath}\newline \glsni{begin}\marg{array}\marg{rrr}\newline 0 \gls{ampchar} 1 \gls{ampchar} 19\gls{tab.dbbackslashchar}\newline -6 \gls{ampchar} 10 \gls{ampchar} 200\newline \glsni{end}\marg{array}\newline \glsni{enddispmath} \end{code} \begin{result}[Image shows 3 columns and 2 rows.] \[ \begin{array}{rrr} 0 & 1 & 19\\ -6 & 10 & 200 \end{array} \] \end{result} \xminisec{Example (Adding Delimiters):} \begin{code} \begin{alltt} \glsni{begindispmath} \glsni{left}\glsni{openparen} \glsni{begin}\marg{array}\marg{rrr} 0 \glsni{ampchar} 1 \glsni{ampchar} 19\glsni{tab.dbbackslashchar} -6 \glsni{ampchar} 10 \glsni{ampchar} 200 \glsni{end}\marg{array} \glsni{right}\glsni{closeparen} \glsni{enddispmath} \end{alltt} \end{code}% \begin{resultS}[Image: as before but has large round brackets on either side.] \[ \left( \begin{array}{rrr} 0 & 1 & 19\\ -6 & 10 & 200 \end{array} \right) \] \end{resultS} \xminisec{Adding a Vertical Rule:} A vertical rule can be added using \gls{array.barchar} in the column specifier. For example: \begin{code} \begin{alltt} \glsni{begindispmath} \glsni{left}\glsni{openparen} \glsni{begin}\marg{array}\marg{rr\glsni{array.barchar}r} 0 \glsni{ampchar} 1 \glsni{ampchar} 19\glsni{tab.dbbackslashchar} -6 \glsni{ampchar} 10 \glsni{ampchar} 200 \glsni{end}\marg{array} \glsni{right}\glsni{closeparen} \glsni{enddispmath} \end{alltt} \end{code}% \begin{resultS}[Image: 3 columns and 2 rows with a vertical line between the second and third column.] \[ \left( \begin{array}{rr|r} 0 & 1 & 19\\ -6 & 10 & 200 \end{array} \right) \] \end{resultS} \xminisec{Example (Cases):} This example uses an \htmlref{invisible delimiter}{obj:invisdelim}: \begin{code} \begin{alltt} \glsni{begindispmath} f(x) = \glsni{left}\glsni{leftbrace} \glsni{begin}\marg{array}\marg{rl} -1 \glsni{ampchar} x \glsni{ltchar} 0\glsni{tab.dbbackslashchar} 0 \glsni{ampchar} x = 0\glsni{tab.dbbackslashchar} +1 \glsni{ampchar} x \glsni{gtchar} 0 \glsni{end}\marg{array} \glsni{right}\glsni{delimiter.periodchar} \glsni{enddispmath} \end{alltt} \end{code}% \begin{resultS}[Image: array has large open brace on the left and nothing on the right of it.] \[ f(x) = \left\{ \begin{array}{rl} -1 & x < 0\\ 0 & x = 0\\ +1 & x > 0 \end{array} \right. \] \end{resultS} This can be rewritten more compactly using the \isty{amsmath} \gls{env-cases} environment: \begin{code} \gls{begindispmath}\newline f(x) = \newline \strut~\glsni{begin}\marg{cases}\newline \strut~~-1 \glsni{ampchar} x < 0\glsni{tab.dbbackslashchar}\newline \strut~~0 \glsni{ampchar} x = 0\glsni{tab.dbbackslashchar}\newline \strut~~+1 \glsni{ampchar} x > 0\newline \strut~\glsni{end}\marg{cases}\newline \gls{enddispmath} \end{code} \begin{resultS}[Image: as previous example but first column is left aligned.] \[ f(x) = \begin{cases} -1 & x < 0\\ 0 & x = 0\\ +1 & x > 0 \end{cases} \] \end{resultS} The \isty{amsmath} package provides some convenient environments to typeset matrices: \gls{env-pmatrix}, \gls{env-bmatrix}, \gls{env-Bmatrix}, \gls{env-vmatrix} and \gls{env-Vmatrix}. These are similar to the \gls{env-array} environment except there is no argument, and they add (respectively) $\bigl(~\bigr)$, $\bigl[~\bigr]$, $\bigl\{~\bigr\}$, $\bigl\lvert~\bigr\rvert$ and $\bigl\lVert~\bigr\rVert$ delimiters. There is also the \gls{env-matrix} environment that doesn't have any delimiters. \xminisec{Example:} \begin{code} \begin{alltt} \glsni{begin}\marg{equation} \glsni{begin}\marg{pmatrix} a \glsni{ampchar} b\glsni{tab.dbbackslashchar} c \glsni{ampchar} d \glsni{end}\marg{pmatrix} \glsni{end}\marg{equation} \end{alltt} \end{code} \begin{result}[Image: 2 by 2 matrix with round delimiters and an equation number.] \begin{equation} \begin{pmatrix} a & b\\ c & d \end{pmatrix} \end{equation} \end{result} The \isty{amsmath} package also provides the environment \gls{env-smallmatrix} designed for in-line use. You need to add any delimiters explicitly. \xminisec{Example:} \begin{code} \begin{alltt} Here is a small matrix \glsni{begin}\marg{math} \glsni{left}\glsni{openparen} \glsni{begin}\marg{smallmatrix} a \glsni{ampchar} b\glsni{tab.dbbackslashchar} c \glsni{ampchar} d \glsni{end}\marg{smallmatrix} \glsni{right}\glsni{closeparen} \glsni{end}\marg{math} in a line of text. \end{alltt} \end{code} \begin{resultS}[Image: matrix is small enough to fit into the line of text.] Here is a small matrix \begin{math} \left( \begin{smallmatrix} a & b\\ c & d \end{smallmatrix} \right) \end{math} in a line of text. \end{resultS} %----------- Vectors ------------ \setnode{vectors} \subsection{Vectors} \label{sec:vec} A variable representing a vector can be typeset using the command: \begin{definition} \gls{vec}\marg{\meta{variable}} \end{definition}\screenpagebreak \xminisec{Example:} \begin{codeS} \glsni{begindispmath} \glsni{vec}\marg{x} \glsni{enddispmath} \end{codeS} \begin{resultS}[Image: x with a small right arrow above it.] \[ \vec{x} \] \end{resultS} Vectors are often typeset in bold. This can be done by \htmlref{redefining}{sec:renewcom} the \glsni{vec} command\doifbook{ (see \sectionref{sec:renewcom})}. You could use \gls{mathbf}, for example: \begin{code} \begin{alltt} \gls{renewcommand}\marg{\glsni{vec}}\oarg{1}\marg{\glsni{mathbf}\marg{\glsni{hashchar}1}} \glsni{begindispmath} \glsni{vec}\marg{x}\glsni{cdot}\glsni{vec}\marg{\glsni{xi}} = z \glsni{enddispmath} \end{alltt} \end{code}\bookpagebreak\noindent \begin{resultS}[Image: upright bold x centred dot xi equals z] \[ \mathbf{x}\cdot\mathbf{\xi} = z \] \end{resultS} \refstepcounter{object}\label{cmd:vec}However, as you may have noticed, the Greek letter $\xi$ has not come out in bold. Here's an alternative (using \gls{boldsymbol} defined in the \isty{amsfonts} \htmlref{package}{sec:packages}): \begin{code} \gls{renewcommand}\marg{\glsni{vec}}\oarg{1}\marg{\glsni{boldsymbol}\marg{\glsni{hashchar}1}}\newline \glsni{begindispmath}\newline \strut~~\glsni{vec}\marg{x}\glsni{cdot}\glsni{vec}\marg{\glsni{xi}} = z\newline \glsni{enddispmath} \end{code}% \begin{resultS}[As before but x and xi in italic bold] \[ \boldsymbol{x}\cdot\boldsymbol{\xi} = z \] \end{resultS} Located (or position) vectors, on the other hand, are usually typeset with a right arrow, but the default definition of \glsni{vec} produces an arrow that is too small: \begin{codeS} \glsni{begindispmath} \glsni{vec}\marg{OP} \glsni{enddispmath} \end{codeS} \begin{resultS}[Image: the letters O P with a small right arrow above them.] \[ \vec{OP} \] \end{resultS} Instead, use \gls{overrightarrow} (\tableref{tab:overunderarrows}): \begin{codeS} \glsni{begindispmath} \glsni{overrightarrow}\marg{OP} \glsni{enddispmath} \end{codeS} \begin{resultS}[Image: as above but with a longer arrow that spans both letters.] \[ \overrightarrow{OP} \] \end{resultS} You might prefer to define separate commands for a located vector and a vector variable. \xminisec{Example:} In the \glsterm{preamble}, define \cmdname{lvec} for a located vector and \cmdname{bvec} for a vector variable: \begin{code} \begin{alltt} \gls{newcommand}*\marg{\cmdname{lvec}}\oarg{1}\marg{\glsni{overrightarrow}\marg{\glsni{hashchar}1}} \glsni{newcommand}*\marg{\cmdname{bvec}}\oarg{1}\marg{\glsni{boldsymbol}\marg{\glsni{hashchar}1}} \end{alltt} \end{code} Later in the document: \begin{code} Let \glsni{dollarchar}\cmdname{bvec}\marg{u}=(x, y)\glsni{dollarchar} represent \glsni{dollarchar}\cmdname{lvec}\marg{OP}\glsni{dollarchar}, then\newline \glsni{begindispmath}\newline \strut~~\glsni{lVert} \cmdname{bvec}\marg{u} \glsni{rVert} = \glsni{sqrt}\marg{x\glsni{circumchar}2 + y\glsni{circumchar}2}\newline \glsni{enddispmath} \end{code} \begin{result}[Image: the vector u appeas in italic bold and the letters O P are as above.] \newcommand*{\lvec}[1]{\overrightarrow{#1}}% \newcommand*{\bvec}[1]{\boldsymbol{#1}}% Let $\bvec{u}=(x, y)$ represent $\lvec{OP}$, then \[ \lVert \bvec{u} \rVert = \sqrt{x^2 + y^2} \] \end{result} \bookpagebreak \begin{exercise}{Maths: Vectors and Arrays}{ex:vectors} Try to produce the following: \renewcommand{\vec}[1]{\boldsymbol{#1}} \begin{result}[maths2ex.html] \[ \boldsymbol{A}\vec{x} = \begin{pmatrix} 0 & 1\\ 2 & 3 \end{pmatrix} \begin{pmatrix} 1\\ 2 \end{pmatrix} = \begin{pmatrix} 2\\ 8 \end{pmatrix} = \vec{y} \] \end{result}% As before, you can \downloadorview{vectors} the solution. \end{exercise} %--------------- Mathematical Spacing ------------------- \setnode{mathssp} \subsection{Mathematical Spacing} \label{sec:mathsspacing} \LaTeX\ deals with mathematical spacing fairly well, but sometimes you may find you want to adjust the spacing yourself. Available spacing commands are listed in \tableref{tab:spacing}. \begin{table}[hbtp] \caption[Mathematical Spacing Commands]{Mathematical Spacing Commands (\supdag provided by \protect\istyend{amsmath})} \label{tab:spacing} \centering \begin{tabular}{lll} \toprule \bfseries Command & \bfseries Example Input & \bfseries Example Output\\ \midrule & \verb|$AB$| & $AB$ \\ \gls{thinspace} or \gls{comma} & \verb|$A\,B$| & $A\,B$\\ \gls{medspace}\supdag\ or \gls{colon} & \verb|$A\:B$| & $A\:B$\\ \gls{thickspace}\supdag\ or \gls{semicolon} & \verb|$A\;B$| & $A\;B$\\ \gls{quad} & \verb|$A\quad B$| & $A\quad B$\\ \gls{qquad} & \verb|$A\qquad B$| & $A\qquad B$\\ \gls{negthinspace} or \gls{exclam} & \verb|$A\!B$| & $A\!B$ \\ \gls{negmedspace}\supdag & \verb|$A\negmedspace B$| & $A\negmedspace B$ \\ \gls{negthickspace}\supdag & \verb|$A\negthickspace B$| & $A\negthickspace B$ \\ \bottomrule \end{tabular} \end{table} \begin{exercise}{More Mathematics}{ex:moremaths} This exercise uses the spacing command \glsni{qquad}. In addition, it has a \htmlref{function name}{sec:declaremathop}, diag, and it uses the \gls{forall} and \htmlref{ellipses}{sec:ellipses} symbols. It also \htmlref{redefines the \cmdname{vec} command}{cmd:vec}\indexCom{vec}, as was done in the previous section, uses the \gls{env-bmatrix} environment (see \sectionref{sec:arrays}), and has \htmlref{subscripts and superscripts}{sec:scripts}. Try to reproduce the following output: \begin{result}[maths3ex.html] \renewcommand{\vec}[1]{\boldsymbol{#1}} The set of linear equations: \[ a_ix_i = b_i \qquad \forall i=1, \ldots, n \] can be written as a matrix equation: \[ \diag(\vec{a})\vec{x} = \vec{b} \] where $\vec{x} = (x_1, \ldots, x_n)^T$, $\vec{b} = (b_1, \ldots, b_n)^T$ and \[ \diag(\vec{a}) = \begin{bmatrix} a_1 & 0 & \cdots & 0\\ 0 & a_2 & \ddots & \vdots\\ \vdots & \ddots & \ddots & 0\\ 0 & \cdots & 0 & a_n \end{bmatrix} \] \end{result} Again, you can \downloadorview{moremaths} the solution. \end{exercise} %%%%%%%%%%%%%%%%%% DEFINING ENVIRONMENTS %%%%%%%%%%%%%%%% \setnode{newenv} \chapter{Defining Environments} \label{ch:newenv} Just as you can \htmlref{define new commands}{ch:newcom}, you can also define new \glspl{environment}. The command \begin{definition} \gls{newenvironment}\marg{\meta{env-name}}\oarg{\meta{n-args}}\oarg{\meta{default}}\marg{\meta{begin-code}}\marg{\meta{end-code}} \end{definition}% is used to define a new environment. As with new commands, you can use the optional argument \meta{n-args} to define an environment with arguments, and \meta{default} to define an environment with an optional argument. The first argument \meta{env-name} is the name of your new environment. Remember that the environment name must not have a backslash. The mandatory arguments \meta{begin-code} and \meta{end-code} indicate what \LaTeX\ \reportlinebreak should do at the beginning and end of the environment. Note that although \meta{begin-code} can reference the arguments using \gls{hashchar}\texttt{1} etc, the \meta{end-code} part can't. \xminisec{Example (An Exercise Environment):} Let's first consider an example of an environment without any arguments. Let's make an environment called, say, \envname{exercise} that prints \textbf{Exercise} in bold and typesets the contents of the environment in italic, with a gap between the title and the contents. In other words, we want the following code: \begin{code} \glsni{begin}\marg{exercise}\newline This is a sample.\newline \glsni{end}\marg{exercise} \end{code} to produce the following output: \begin{result}[newenv1.html] \par\noindent \textbf{Exercise} \begin{itshape} \par \vspace{\baselineskip}% \noindent This is a sample. \end{itshape} \end{result} (In the \htmlref{next chapter}{ch:counters} we will add numbering.) Let's first consider what we want this environment to do: we can get the word \dq{Exercise} in bold using \gls{textbf}, and the italic font can be obtained by using the \gls{env-itshape} environment (recall \sectionref{sec:fonts}). So, at the start of our new environment we need \begin{codeS} \glsni{textbf}\marg{Exercise}\glsni{begin}\marg{itshape} \end{codeS} and at the end of our new environment we need to end the \glsni{env-itshape} environment: \begin{codeS} \glsni{end}\marg{itshape} \end{codeS} Putting the above together into the new environment definition: \begin{code}\obeyspaces \glsni{newenvironment}\marg{exercise}\glsni{percentchar} environment name\newline \marg{\glsni{percentchar} begin code\newline \strut~~\glsni{textbf}\marg{Exercise}\glsni{begin}\marg{itshape}\glsni{percentchar}\newline }\glsni{percentchar}\newline \marg{\glsni{end}\marg{itshape}}\glsni{percentchar} end code \end{code} Let's try it out: \begin{code} \begin{verbatim} \begin{exercise} This is a sample. \end{exercise} \end{verbatim} \end{code}% \begin{resultS}[newenv2.html] \textbf{Exercise} \begin{itshape} This is a sample. \end{itshape} \end{resultS} Not quite right. Let's put a paragraph break after \textbf{Exercise}, and put one before it as well. The command \gls{par} can be used to make a paragraph break and the extra bit of vertical spacing can be produced using \glsni{vspace}. The \gls{length} \gls{baselineskip} is the interline spacing. Modifications are shown in bold \modification{like this}. \begin{code}\obeyspaces \glsnl{newenvironment}\marg*{exercise}\glsnl{percentchar} environment name\newline \marg*{\glsnl{percentchar} begin code\newline \strut~~\modification{\glsni{par}\glsni{vspace}\marg{\glsni{baselineskip}}\glsni{percentchar}}\newline \strut~~\glsnl{textbf}\marg*{Exercise}\glsnl{begin}\marg*{itshape}\glsnl{percentchar}\newline \strut~~\modification{\glsni{par}\glsni{vspace}\marg{\glsni{baselineskip}}\glsni{percentchar}}\newline }\glsnl{percentchar}\newline \marg*{\glsnl{end}\marg*{itshape}}\glsnl{percentchar} end code \end{code}% Let's have a look at the output now: \begin{result} \dohtmlcolorbox{% \par\vspace{\baselineskip}% \textbf{Exercise}\begin{itshape}% \par\vspace{\baselineskip} This is a sample. \end{itshape} } \end{result} \faq{There's a space added after my environment}{spaftend}% The indent at the start of each line is caused by the normal paragraph indentation. This can be suppressed using \gls{noindent}. It's also a good idea to suppress any spaces immediately following \verb|\begin{exercise}| and \verb|\end{exercise}|, which can be done using \gls{ignorespaces} and \reportlinebreak\screenlinebreak\gls{ignorespacesafterend}. Modifications are again shown in bold \modification{like this}. \begin{code}\obeyspaces \glsnl{newenvironment}\marg*{exercise}\glsnl{percentchar} environment name\newline \marg*{\glsnl{percentchar} begin code\newline \strut~~\glsnl{par}\glsnl{vspace}\marg*{\glsnl{baselineskip}}\modification{\glsni{noindent}}\newline \strut~~\glsnl{textbf}\marg*{Exercise}\glsnl{begin}\marg*{itshape}\glsnl{percentchar}\newline \strut~~\glsnl{par}\glsnl{vspace}\marg*{\glsnl{baselineskip}}\modification{\glsni{noindent}\glsni{ignorespaces}}\newline }\glsnl{percentchar}\newline \marg*{\glsnl{percentchar} end code\newline \strut~~\glsnl{end}\marg{itshape}\modification{\glsni{ignorespacesafterend}}\newline } \end{code}% The \envname{exercise} environment now appears as: \begin{result} \par\vspace{\baselineskip}\noindent \textbf{Exercise}\begin{itshape}% \par\vspace{\baselineskip}\noindent This is a sample. \end{itshape} \end{result} Now let's modify our code so that the environment takes an argument. The argument should indicate the exercise topic. For example, the following code: \begin{code} \begin{verbatim} \begin{exercise}{An Example} This is a sample. \end{exercise} \end{verbatim} \end{code}% should produce the following result: \begin{result}[newenv3.html] \par\vspace{\baselineskip}\noindent\textbf{Exercise (An Example)} \begin{itshape}\par\vspace{\baselineskip}\noindent This is a sample. \end{itshape} \end{result}% As with \gls{newcommand}, \gls{hashchar}\texttt{1} is used to indicate the first argument. We can now modify the code as follows: \begin{code}\obeyspaces \glsnl{newenvironment}\marg*{exercise}\modification{\oarg{1}}\glsnl{percentchar} environment name\newline \marg*{\glsnl{percentchar} begin code\newline \strut~~\glsnl{par}\glsnl{vspace}\marg*{\glsnl{baselineskip}}\glsnl{noindent}\newline \strut~~\glsnl{textbf}\marg*{Exercise\modification{ (\glsni{hashchar}1)}}\glsnl{begin}\marg*{itshape}\glsnl{percentchar}\newline \strut~~\glsnl{par}\glsnl{vspace}\marg*{\glsnl{baselineskip}}\glsnl{noindent}\glsnl{ignorespaces}\newline }\glsnl{percentchar}\newline \marg*{\glsnl{percentchar} end code\newline \strut~~\glsnl{end}\marg*{itshape}\glsnl{ignorespacesafterend}\newline } \end{code} \setnode{renewenv} \section{Redefining Environments} \label{sec:renewenv} It is also possible to redefine an environment using: \begin{definition}[\linewidth] \gls{renewenvironment}\marg{\meta{env-name}}\oarg{\meta{n-args}}\oarg{\meta{default}}\marg{\meta{begin-code}}\marg{\meta{end-code}} \end{definition}% As with \gls{renewcommand}, only redefine an existing environment if you want a modified version of that environment rather than because you like the environment name. \begin{exercise}{Defining a New Environment}{ex:newenv} If you did any of the exercises from \exerciseref{ex:section} to \exerciseref{ex:tables}, go back to the document you created and define the \envname{exercise} environment as in the example above. Then try creating some exercises using this environment. You could, maybe, put an exercise in the first chapter, and then another one in the second chapter. Again you can \downloadorview{newenv} an example. \end{exercise} %%%%%%%%%%%%%%%%% Counters %%%%%%%%%%%%%%%%%%%%%%%%% \setnode{counters} \chapter{Counters} \label{ch:counters} As we have seen, \LaTeX\ automatically generates numbers for chapters, sections, equations etc. These numbers are stored in \keyword{counters}. The names of these counters are usually the same as the name of the object with which it is associated but without any backslash. For example, the \gls{chapter} command has an associated counter called \icounter{chapter}, the \gls{footnote} command has an associated counter called \icounter{footnote}, the \gls{env-equation} environment has an associated counter called \icounter{equation}, the \gls{env-figure} environment has an associated counter called \icounter{figure} and the \gls{env-table} environment has an associated counter called \icounter{table}. There is also a counter called \icounter{page} that keeps track of the current page number. The value of a counter can be displayed using the command \begin{definition} \icmdname{the}\meta{counter} \end{definition}% where \meta{counter} is the name of the associated counter. Note that \meta{counter} does not go in curly braces and adjoins \cmdname{the} (for example, \gls{thepage}\faq{Page number is wrong at start of page}{wrongpn}, \reportlinebreak\gls{thesection} or \gls{thechapter}). In fact, we have already encountered \reportlinebreak\screenlinebreak\gls{thefigure} in \sectionref{sec:subfloats}. \xminisec{Example:} \begin{code} \begin{alltt} This page is Page\glsni{tildechar}\glsni{thepage}. The current chapter is Chapter\glsni{tildechar}\glsni{thechapter}. \end{alltt} \end{code}\label{example:thepage}% \begin{resultS}[This page is Page 226. The current chapter is Chapter 11.] % LaTeX2HTML doesn't store the page number in the image file % so use \pageref to fake \thepage instead This page is Page~\pageref*{example:thepage}. The current chapter is Chapter~\thechapter. \end{resultS}% New counters can be created using the command: \begin{definition} \gls{newcounter}\marg{\meta{counter-name}}\oarg{\meta{outer-counter}} \end{definition}% The \gls{mandatory} \meta{counter-name} is the name of your new counter (no backslash in the name). For example, let's define a counter called \texttt{exercise} to keep track of each exercise. (Recall the exercise example from \chapterref{ch:newenv}.) \begin{codeS} \glsni{newcounter}\marg{exercise} \end{codeS}% We can now display the value of the counter using the command \cmdname{theexercise}. At the moment the counter has the value zero, the value can be changed using one of the following commands: \begin{fwlist}{\cmdname{addtocounter}\marg{\meta{counter}}\marg{\meta{num}}} \fwitem{\gls{stepcounter}\marg{\meta{counter}}} Increments \meta{counter} by 1 \fwitem{\gls{refstepcounter}\marg{\meta{counter}}} As above, but allows you to cross-\reportlinebreak reference the counter using \gls{label} and \gls{ref} \fwitem{\gls{setcounter}\marg{\meta{counter}}\marg{\meta{num}}} Sets the counter to \meta{num} \fwitem{\gls{addtocounter}\marg{\meta{counter}}\marg{\meta{num}}} Adds \meta{num} to \meta{counter} \end{fwlist} A couple of the commands above take a number \meta{num} as one of the arguments. If you want to use another counter for this argument, you need to use \begin{definition} \gls{value}\marg{\meta{counter}} \end{definition}% For example, if you want to set our new \texttt{exercise} counter to the same value as the \texttt{page} counter, you would do \begin{codeS} \glsni{setcounter}\marg{exercise}\marg{\glsni{value}\marg{page}} \end{codeS}% Let's go back to the \envname{exercise} environment you created in \exerciseref{ex:newenv}. The exercises really ought to have an associated number, and this number should be incremented each time we use the exercise environment. So let's modify our code to do this. Modifications are illustrated in bold \modification{like this}: \begin{code}\obeyspaces \modification{\cmdname{newcounter}\marg{exercise}}\newline \strut\newline \glsni{newenvironment}\marg{exercise}\oarg{1}\glsni{percentchar} environment name\newline \marg{\glsni{percentchar} begin code\newline \strut~~\glsni{par}\glsni{vspace}\marg{\glsni{baselineskip}}\glsni{noindent}\newline \strut~~\modification{\glsni{refstepcounter}\marg{exercise}}\glsni{percentchar}\newline \strut~~\glsni{textbf}\marg{Exercise \modification{\cmdname{theexercise}\glsni{spacesym}}(\glsni{hashchar}1)}\glsni{percentchar}\newline \strut~~\glsni{begin}\marg{itshape}\glsni{percentchar}\newline \strut~~\glsni{par}\glsni{vspace}\marg{\glsni{baselineskip}}\glsni{percentchar}\newline \strut~~\glsni{noindent}\glsni{ignorespaces}\newline }\glsni{percentchar}\newline \marg{\glsni{percentchar} end code\newline \strut~~\glsni{end}\marg{itshape}\glsni{percentchar}\newline \strut~~\modification{\glsni{par}\glsni{vspace}\marg{\glsni{baselineskip}}\glsni{percentchar}}\newline \strut~~\modification{\glsni{noindent}}\glsni{ignorespacesafterend}\newline } \end{code}% Note that the counter needs to be incremented before it is used. I've also added an extra \gls{vspace} at the end of the environment and a paragraph break. Since we've used \glsni{refstepcounter} instead of \glsni{stepcounter} we can cross-reference our \envname{exercise} environment:\reportpagebreak \begin{code} \begin{alltt} Exercise\glsni{tildechar}\glsni{ref}\marg{ex:simple} is a simple exercise. \glsni{begin}\marg{exercise}\marg{Simple Exercise} \glsni{label}\marg{ex:simple}\glsni{percentchar} This is a simple exercise. \glsni{end}\marg{exercise} \end{alltt} \end{code}% This produces the following output: \begin{result}[newcounter.html] Exercise~1 is a simple exercise. \par\vspace{\baselineskip}\noindent\textbf{Exercise 1 (Simple Exercise)}% \begin{itshape}\par\vspace{\baselineskip}\noindent This is a simple exercise. \end{itshape} \end{result} The counter representation can be changed by redefining \cmdname{theexercise}\faq{Redefining counters' \cmdname{the}-commands}{the-commands} using the \gls{renewcommand} command described in \sectionref{sec:renewcom}. The following commands can be used to display the counter: \begin{fwlist}{\cmdname{fnsymbol}\marg{\meta{counter}}} \fwitem{\gls{arabic}\marg{\meta{counter}}} Arabic numeral (1, 2, 3, \ldots) \fwitem{\gls{Roman}\marg{\meta{counter}}} Upper case Roman numeral (I, II, III, \ldots) \fwitem{\gls{roman}\marg{\meta{counter}}} Lower case Roman numeral (i, ii, iii, \ldots) \fwitem{\gls{alph}\marg{\meta{counter}}} Lower case letter (a, b, c, \ldots, z) \fwitem{\gls{Alph}\marg{\meta{counter}}} Upper case letter (A, B, C, \ldots, Z) \fwitem{\gls{fnsymbol}\marg{\meta{counter}}} A footnote symbol (\makeimg{asterisk dagger double dagger section mark paragraph mark double bar double asterisk two single daggers two double daggers}{\footnotesymbols}) \end{fwlist} \xminisec{Example:} To make the chapter numbers appear as upper case Roman numerals you would do: \begin{codeS} \gls{renewcommand}\marg{\gls{thechapter}}\marg{\glsni{Roman}\marg{chapter}} \end{codeS} You may have noticed that \gls{newcounter} has an optional argument \meta{outer-counter}. This is for use if you require the new counter to be reset every time \meta{outer-counter} is incremented\faq{Master and slave counters}{addtoreset}. For example, the section numbers in the \icls{scrbook} class are dependent on the chapter numbers. Each time a new chapter is started, the section numbers are reset. Suppose we want our \texttt{exercise} counter to be dependent on the \icounter{chapter} counter, we would do \begin{codeS} \gls{newcounter}\marg{exercise}\oarg{chapter} \end{codeS} Note that if you make a counter dependent on another counter like this, the default action of \cmdname{the}\meta{counter} remains the same, so \cmdname{theexercise} won't print the chapter number. To make the chapter number appear as well, we need to redefine \cmdname{theexercise} (recall \sectionref{sec:renewcom}): \begin{codeS} \gls{renewcommand}\marg{\cmdname{theexercise}}\marg{\glsni{thechapter}.\glsni{arabic}\marg{exercise}} \end{codeS}% Notice the use of \gls{thechapter} instead of, say, \verb|\arabic{chapter}|. This way we don't need to keep track of the \icounter{chapter} counter format. \xminisec{Example (Footnote Markers):} The \icounter{footnote} counter is reset at the start of each chapter but by default the chapter number isn't displayed in \gls{thefootnote}. In \latexhtml{this book}{the PDF version of this document} \glsni{thefootnote} was redefined so that it displays the chapter number: \begin{codeS} \gls{renewcommand}\marg{\glsni{thefootnote}}\marg{\glsni{thechapter}.\glsni{arabic}\marg{footnote}} \end{codeS} \begin{exercise}{Using Counters}{ex:counters} Modify the document from \exerciseref{ex:newenv} so that the \envname{exercise} environment has a counter. Make the counter dependent on the chapter. You can \downloadorview{counters} an example. \end{exercise} %%%%%%%%%%%%%%%%%%%%%% APPENDICES %%%%%%%%%%%%%%%%%% \appendix %%%%%%%%%%%%%%%%%%% Installing Packages %%%%%%%%%%%%%% \setnode{installsty} \chapter{Downloading and Installing Packages} \label{ch:installsty} New \LaTeX\ packages are being created all the time\faq{Installing things on a (La)TeX system}{instpackages}, so you may find that there are some packages that you don't have on your installation. In this case, if you don't have the package you want, you can download it\faq{Installation using MiKTeX package manager}{inst-miktex*} from \gls{ctan}. Before discussing installing new packages, it is a good idea for you to understand the \gls{tds}\faq{What is the TDS?}{tds}. All the files that make up the \TeX\ distribution are stored in a standard hierarchical structure. The root directory of the main distribution is usually called \texttt{texmf} or \texttt{texmf-dist}. Its location depends on your system. For example, if you are using \itexdistro{TeX~Live}~2012 on UNIX/Linux, it will probably be located in \texttt{/usr\slash local\slash texlive\slash 2012\slash texmf-dist} or if you are using \itexdistro{MiKTeX} it may be located in \verb|c:\texmf| or \texttt{c:\backslashsym Program Files\backslashsym texmf}. Whichever system you are using, I~shall refer to this directory as \meta{TEXMF}. So, if you are using \texdistro{TeX~Live}~2012, \meta{TEXMF}\texttt{\slash doc} refers to the directory \texttt{/usr\slash local\slash texlive\slash 2012\slash texmf-dist\slash doc}, or if you are using \texdistro{MiKTeX}, \meta{TEXMF}\verb|\doc| refers to the folder \verb|c:\texmf\doc| or \texttt{c:\backslashsym Program Files\backslashsym texmf\backslashsym doc}. In general, you should not make any modifications to the \meta{TEXMF} directory tree as it will get overridden whenever you update your \TeX\ distribution. You should also have a local texmf tree. Again, the location of the local texmf tree depends on your system. If you are using \texdistro{TeX~Live}, it may be \texttt{/usr\slash local\slash texlive\slash texmf-local}. If you are using \texdistro{MiKTeX}, it may be \texttt{c:\backslashsym localtexmf} or \texttt{c:\backslashsym Program Files\backslashsym localtexmf}. Whichever system you are using, I~shall refer to this directory as \meta{TEXMF-LOCAL}. There is also the \meta{TEXMF-HOME} directory. On UNIX-like systems this is usually \verb|~/texmf|. On Windows it's usually in your user folder. This is the one where you typically install any new classes or packages. These directories must all have the same structure. The principle sub-directories relating to \LaTeX\ are illustrated in \figureref{fig:tds}. It may be that your \meta{TEXMF-HOME} directory doesn't exist or doesn't contain some of these sub-directories, if so, you will need to create them. You can use the \iappname{kpsewhich} application to find out the locations of \meta{TEXMF-LOCAL} and \meta{TEXMF-HOME}. Since \appname{kpsewhich} is a command-line application, you will need a \htmlref{command prompt or terminal}{sec:terminal} open\latex{ (see \sectionref{sec:terminal})}. At the command prompt, type \begin{verbatim} kpsewhich -var-value=TEXMFHOME \end{verbatim} to display the location of \meta{TEXMF-HOME} or \begin{verbatim} kpsewhich -var-value=TEXMFLOCAL \end{verbatim} to display the location of \meta{TEXMF-LOCAL}. (Remember to press the enter \enter\ key at the end of the line.) \refstepcounter{object}\label{obj:docdir}% The documentation for \LaTeX\ classes and packages can be found in the \texttt{doc\slash latex} sub-directories: \meta{TEXMF}\texttt{\slash doc\slash latex}, \meta{TEXMF-LOCAL}\texttt{\slash doc\slash latex} and \meta{TEXMF-HOME}\texttt{\slash doc\slash latex}. \begin{figure}[htbp] \figconts {pictures/tds} {% \caption{The \protect\TeX\protect\space Directory Structure (TDS) Showing the Main \protect\LaTeX-Related Sub-Directories.}% }% {fig:tds} \end{figure} Some packages are supplied in this format.\footnote{Complete list at \url{http://mirror.ctan.org/install/macros/latex/contrib/}.} For example, the package \sty{sample-package} may be distributed in a compressed file \texttt{sample-package.tds.zip}, which contains the files \begin{verbatim} doc/latex/sample-package/sample-package.pdf tex/latex/sample-package/sample-package.sty tex/latex/sample-package/sample-foo.sty tex/latex/sample-package/sample-bar.sty \end{verbatim} In this case all you need to do is decompress the contents of the archive into the \meta{TEXMF-LOCAL} or \meta{TEXMF-HOME} directory. \refstepcounter{object}\label{obj:runtexhash}% On older \TeX-distributions, you would then need to \htmlref{refresh the \TeX\ database}{sec:refresh}\latex{ (described in \sectionref{sec:refresh}\ifscreenorother{}{\ on page~\pageref{sec:refresh}})}. With new distributions, you don't need to do this if you are installing a new package into your \meta{TEXMF-HOME} directory. \xminisec{Example (Unix-Like):} To install \texttt{sample-package.tds.zip} (assuming you're in the same directory as that file): \begin{verbatim} unzip -d ~/texmf sample-package.tds.zip \end{verbatim} \setnode{dtxins} \section{DTX and INS Files} \label{sec:dtx} \faq{Documented LaTeX sources (.dtx files)}{dtx}Not all packages are provided in the \gls{tds} format. Instead (or additionally) many are supplied with the code and documentation all bundled together in one file. This file usually has the extension \texttt{.dtx}, and it usually comes with an installation script that has the extension \texttt{.ins}. Once you have downloaded the \texttt{.dtx} and \texttt{.ins} files, you will then have to extract the code before you can use it. Let's go back to the previous example. The package \sty{sample-package} is now distributed in a DTX file, so the \texttt{sample-package.zip} archive contains the files \begin{verbatim} sample-package.dtx sample-package.ins \end{verbatim} (with hopefully a \texttt{README} or \texttt{INSTALL} file). Note that this archive, unlike the TDS one, doesn't contain any \texttt{.sty} files. The documentation source and the package code (\texttt{sample-package.sty}, \texttt{sample-foo.sty} and \texttt{sample-bar.sty}) are all contained in the file \texttt{sample-package.dtx}. This is how to extract them: \begin{enumerate} \item Extract the contents of \texttt{sample-package.zip} to a temporary directory. \item\label{itm:ins} Run \LaTeX\ on the file \texttt{sample-package.ins}. If you are using a \latexhtml{terminal}{\htmlref{terminal}{sec:terminal}}, you can type the following at the command prompt: \begin{verbatim} latex sample-package.ins \end{verbatim} If you are using a front-end, such as TeXWorks, open the \texttt{.ins} file (for example \texttt{sample-package.ins}), and click on the build/typeset button. This will create the files containing the package code. In this example it will create the main package file \texttt{sample-package.sty} and supplementary packages \texttt{sample-foo.sty} and \texttt{sample-bar.sty}. \item Make a sub-directory of \meta{TEXMF-LOCAL}\texttt{/tex/latex}% \footnote{or \meta{TEXMF-LOCAL}\texttt{\backslashsym tex\backslashsym latex} on Windows} in which to place these files. In this example, the package is called \dq{sample-package}, so make a sub-directory called \texttt{sample-package}. \item Move the files created in \objectref{Step}{itm:ins} into the new sub-directory you created in the previous step. \item\label{itm:dtx} Run \iPDFLaTeX\ on the file \texttt{sample-package.dtx}. (The same as in \objectref{Step}{itm:ins}, but use the file \texttt{sample-package.dtx} instead of \texttt{sample-package.ins}.) This will create a file called \texttt{sample-package.pdf}. You may need to repeat this step to ensure that the cross references are up-to-date. Check the \texttt{README} file or \texttt{INSTALL} file to see if there is anything else you need to do. (If you have downloaded the package from CTAN, it's possible that the documentation has already been supplied, as package authors are encouraged to supply a PDF version of the documentation for on-line viewing. If so, you can omit this step.) \item Make a sub-directory of \meta{TEXMF-LOCAL}\texttt{/doc/latex}% \footnote{or \meta{TEXMF-LOCAL}\texttt{\backslashsym doc\backslashsym latex} on Windows} in which to place the documentation. In this example, the package is called \dq{sample-package}, so make a sub-directory called \texttt{sample-package}. \item Move the files created in \objectref{Step}{itm:dtx} into the new sub-directory you created in the previous step. \end{enumerate} As mentioned \htmlref{above}{obj:runtexhash}, on older \TeX-distributions, you would then need to \htmlref{refresh the \TeX\ database}{sec:refresh}, but this isn't required for \meta{TEXMF-HOME} installs on new distributions. \setnode{texhash} \section{Refreshing the \texorpdfstring{\protect\TeX}{TeX}\protect\space Database} \label{sec:refresh} On older \gls{tex} distributions you had to refresh the \TeX\ database whenever you installed new classes or packages. With newer installations you don't need to do this if you install them in your \meta{TEXMF-HOME} directory, except under certain circumstances (for example, you're using using a networked drive). If it turns out that \TeX\ can't find a new class or package you have installed in \meta{TEXMF-HOME} you will need to update the database using the \iappname{texhash} (or \iappname{mktexlsr}) application. This is a command-line application, so you need a \htmlref{terminal or command prompt}{sec:terminal}\latex{ (see \sectionref{sec:terminal})}. For example, on UNIX/Linux, to update \meta{TEXMF-HOME} (the directory \verb|~/texmf|) you need to type the following at the command prompt: \begin{verbatim} texhash ~/texmf \end{verbatim} If you are using a modern \TeX\ distribution, such as \itexdistro{MiKTeX}, \itexdistro{TeX~Live} or \itexdistro{MacTeX} there should be a package manager that has a package installation and refresh facility. For example, \texdistro{TeX~Live} comes with the TeX~Live Manager (\iappname{tlmgr} or \iappname{mactlmgr}) and recent versions of \texdistro{MiKTeX} have an application called \appname{MiKTeX Update Wizard} which can automatically download and install known packages. If you experience any problems, contact your system administrator for help or try one of the resources listed in \appendixref{ch:help}. \xminisec{Related \gls{ukfaq} topics:} \begin{itemize} \item \faqlink{Installing things on a (La)TeX system}{instpackages} \item \faqlink{Installing files \dq{where (La)TeX can find them}}{wherefiles} \item \faqlink{Installation using MiKTeX package manager}{inst-miktex*} \item \faqlink{\dq{Temporary} installation of (La)TeX files}{tempinst} \item \faqlink{\dq{Private} installations of files}{privinst} \end{itemize} %%%%%%%%%%%%%%%%%%%%%% ERRORS %%%%%%%%%%%%%%%%%%%%%%%%%%% \setnode{commonerrors} \chapter{Common Errors} \label{ch:errors} \begin{itemize} \item If you're running \LaTeX\ from a \gls{terminal} and the only message that gets displayed is: \begin{verbatim} latex: Command not found. \end{verbatim} or \begin{verbatim} Bad command or file name \end{verbatim} then you have either mistyped the command name, or you don't have \LaTeX\ installed on your computer, or your path hasn't been set up correctly. First check that you have typed the command correctly, then check to see if you have \TeX\ installed. Failing that, contact your system administrator for help or try one of the resources listed in \appendixref{ch:help}. \item If you're running \LaTeX\ from a \gls{terminal} and you get the message (or something similar): \begin{verbatim} This is TeX, Version 3.14159 (Web2C 7.3.1) ! I can't find file `sample'. <*> sample Please type another input file name: \end{verbatim} then you have either misspelt the filename or you are in the wrong directory. If you have misspelt the filename, simply type in the correct name at the prompt. If you are in the wrong directory or you want to quit, type \texttt{X} followed by the return character \enter. To check you are in the right directory, on a Unix-like system you can type: \begin{verbatim} ls \end{verbatim} This will list the contents of the directory. If you are certain that you have spelt the filename correctly and that you are in the right directory, there may be something wrong with your path, in which case contact your system administrator. \item Error messages will usually look something like: \begin{verbatim} ! Undefined control sequence. l.1 \docmentclass [12pt]{scrartcl} ? \end{verbatim} The first line is the error message. In this example I~have misspelt the command \cmdname{documentclass}. The next line begins with \texttt{l.}\ followed by a number. This is the line number in the source code where the error occurred. In this case the error occurred on line~1. Following the line number is the input line \LaTeX\ has processed so far, and staggered on the next line is the remainder of the input line. Here's another example. Suppose line~8 of my \gls{source} looks like: \begin{verbatim} The date today is: \toady, which is nice to know. \end{verbatim} The error in this case is the misspelling of the command \cmdname{today}. The error message will appear as follows: \begin{latexonly} \noindent \begin{tabular}{l@{}l} \multicolumn{2}{l}{% \texttt{!\ Undefined control sequence.}\rlap{\color{blue}% \tikz[baseline=-1ex]{\draw[latex-] (0em,0ex) -- (4em,2ex); \pgftext[left,center,at={\pgfpoint{4em}{2ex}}]{Error Message} }}}\\ \texttt{l.}\smash{\llap{\color{blue}% \tikz[baseline]{\draw[latex-] (0em,0ex) -- (-3em,-4ex); \pgftext[right,top,at={\pgfpoint{-3em}{-3ex}}]{\shortstack{Line\\Number}}}}}% \texttt{8 The date today is }% \smash{\llap{\color{blue}% \tikz[baseline]{\draw[latex-] (0em,0ex) -- (-3em,-3ex); \pgftext[right,top,at={\pgfpoint{-3em}{-3ex}}]{Error}}}}% \cmdname{toady}% \smash{\rlap{\color{blue}% \tikz[baseline]{\draw[latex-] (0em,0ex) -- (0em,-6ex); \pgftext[left,top,at={\pgfpoint{0em}{-6.5ex}}]{This is how far \LaTeX\ has got}}}}\\ &\texttt{, which is nice to know.}\smash{\rlap{\color{blue}% \tikz[baseline]{\draw[latex-] (0em,0.5ex) -- (3em,0.5ex); \pgftext[left,center,at={\pgfpoint{3em}{0.5ex}}]{\shortstack{Rest of\\the line}}}}}\\ \texttt{?}\color{blue}% \tikz[baseline]{\draw[latex-] (0em,0ex) -- (2em,-4ex); \pgftext[left,top,at={\pgfpoint{2em}{-4ex}}]{\LaTeX\ prompt}} \end{tabular} \vspace{\baselineskip} \end{latexonly} \html{\htmladdimg[alt="annotated error message"]{pictures/errormessage.png}} At the \LaTeX\ prompt, you can either type \texttt{h} for a help message, or type \texttt{x} to exit \LaTeX\ and go back to your source code and fix the problem. \end{itemize} There follows below a list of common error messages. If your problem isn't listed there, try the \gls{ukfaq}. %%%%%%%%%%%%%%%%%%%% * (No message) %%%%%%%%%%%%%%%%%%%%%%%%%%% \setnode{asteriskprompt} \section{* (No message, just an asterisk prompt!)} You've gone into \gls{tex}! This is probably because you've forgotten the \texttt{\gls{end}\marg{document}}. The asterisk is the \TeX\ prompt. At this point the best thing to do is to abort the \TeX\ run. %%%%%%%%%%%%% Argument of \cline has an extra } %%%%%%%%%%%%%%%% \setnode{clineextrabrace} \section{Argument of \textbackslash cline has an extra \}} If this error occurred on the first line in your \gls{env-tabular} \glsterm{environment}, you may have forgotten the \glsterm{argument} to the \gls*{env-tabular} environment. %%%%%%%%%%%%% Argument of \multicolumn has an extra } %%%%%%%%%%%%%%%% \setnode{multicolumnextrabrace} \section{Argument of \textbackslash multicolumn has an extra \}} If this error occurred on the first line in your \gls{env-tabular} \glsterm{environment}, you may have forgotten the \glsterm{argument} to the \gls*{env-tabular} environment. %%%%%%%%%%%%%%%% \begin{...} ended by \end{...} %%%%%%%%%%%%%%%%%%%% \setnode{mismatchedend} \section{\textbackslash begin\{\texorpdfstring{\ldots}{...}\} ended by \textbackslash end\{\texorpdfstring{\ldots}{...}\}} The beginning of your environment doesn't have a matching end. \begin{itemize} \item Check to make sure you have spelt the name of the environment correctly. You will get this error message if you do, say, \begin{alltt}\wrong \glsni{end}\marg{docment} \end{alltt} instead of \begin{alltt}\correct \glsni{end}\marg{document} \end{alltt} \item Check that for every \gls{begin} you have a corresponding \gls{end} with the same name. \end{itemize} %%%%%%%%%%%%%%%%%%% Bad math environment delimiter %%%%%%%%%%%%%%%% \setnode{badmathdelim} \section{Bad math environment delimiter} Only a certain type of character may be used as a \htmlref{delimiter}{sec:delimiters} (for example, \gls{openparen} \gls{closeparen} \gls{delimiter.opensq} \gls{delimiter.closesq}), check which one you have specified. This error may also occur if you have forgotten a \gls{right} or not used it in the same \glslink{group}{scope}. (Remember to use a \gls{delimiter.periodchar} if you want an invisible delimiter) or you may have forgotten to end your array environment with \verb|\end{array}|. %%%%%%%%%%%%%%%%%%%% Can only be used in preamble %%%%%%%%%%%%%%%%%% \setnode{onlypreamble} \section{Can only be used in preamble.} Some commands, such as \gls{usepackage} may only appear in the \gls{preamble}. Check to see where you have put it. For example, this error will be caused by doing: \begin{alltt} \glsni{documentclass}\marg{scrartcl} \glsni{begin}\marg{document}\wrong \glsni{usepackage}\marg{graphicx} \end{alltt} instead of \begin{alltt} \glsni{documentclass}\marg{scrartcl} \glsni{usepackage}\marg{graphicx}\correct \glsni{begin}\marg{document} \end{alltt} %%%%%%%%%%%%%%%%%% Command ... already defined %%%%%%%%%%%%%%%%%%%%% \setnode{alreadydef} \section{Command \texorpdfstring{\protect\ldots}{...}\protect\space already defined} You have tried to define a \gls{command} which already exists. Try giving it a different name. Remember never to redefine a command if you don't know what the command originally does. Alternatively, you have tried to define an \gls{environment} which already exists. Give the new environment a different name. Again, never redefine an environment where you don't know what the original environment does. %%%%%%%%%%%%% Display math should end with $$ %%%%%%%%%%%%%%%%%%%%% \setnode{missingenddispmath} \section{Display math should end with \$\$} You may have a dollar sign (\gls{dollarchar}) in a displayed maths environment, such as the \gls{env-equation} environment. Remember that \verb|$| is short hand for \verb|\begin{math}| or \verb|\end{math}|, so you can't end one of the other environments with a \verb|$|. (This error message is in fact a bit confusing, as it seems to be suggesting that you end a displayed maths environment with \verb|$$| which you also shouldn't do\faq{Why use \glsnl{begindispmath}\ldots\glsnl{enddispmath} in place of \$\$\ldots\$\$}{dolldoll}.) %%%%%%%%%%%%%% Environment ... undefined %%%%%%%%%%%%%%%%%%%%%%%%% \setnode{envundefined} \section{Environment \texorpdfstring{\protect\ldots}{...}\protect\space undefined} \LaTeX\ doesn't recognise the environment you have specified. \begin{itemize} \item Check you have spelt the environment name correctly. You will get this error if you do, say, \begin{alltt}\wrong \glsni{begin}\marg{docment} \end{alltt} instead of \begin{alltt}\correct \glsni{begin}\marg{document} \end{alltt} \item If it's your own environment, check you have defined the environment before using it. \item If the environment is defined in a package, check you have included the package using the \htmlref{\cmdname{usepackage}}{sec:packages} command. \end{itemize} %%%%%%%%%% Extra alignment tab has been changed to \cr %%%%%%%%%%%% \setnode{tab2cr} \section{Extra alignment tab has been changed to \textbackslash cr} You have too many ampersands (\gls{ampchar}) in one row. The most probable cause is that you have forgotten the end of row command \gls{tab.dbbackslashchar} on the previous row. Remember also that if you have a \gls{multicolumn} command to span more than one column, you should have fewer \glsni{ampchar}s in that row. This error can also occur from a confusion over the two meanings of \gls{dbbackslashchar}: a line break within a paragraph cell and a row break. In which case, you need to use \gls{tabularnewline} instead of \gls{tab.dbbackslashchar}. %%%%%%%%%%%%%%%%%%%%%%%%% Extra \right %%%%%%%%%%%%%%%%%%%%%%%%%% \setnode{extraright} \section{Extra \textbackslash right} There are a number of possible causes. The most probable is that you have a \gls{right} that doesn't have a matching \gls{left}. (Remember left comes before right.) Another possible cause is that you have missed out \verb|\end{array}|. (Remember that \glspl{environment} provide implicit \glsing{group}, and \glsni{left} and its matching \glsni{right} must appear within the same group level.) %%%%%%%%%%%%%% File ended while scanning use of ... %%%%%%%%%%%%% \setnode{fileendedwhilescanning} \section{File ended while scanning use of \texorpdfstring{\ldots}{...}} The most usual cause of this error is a missing closing brace. You will get this error if you do, say, \begin{alltt}\wrong \glsni{end}\glsni{leftbracechar}document \end{alltt} instead of \begin{alltt}\correct \glsni{end}\marg{document} \end{alltt} %%%%%%%%%%%%%%%%%%%%%% File not found %%%%%%%%%%%%%%%%%%%%%%%%%% \setnode{filenotfound} \section{File not found} \LaTeX\ can't find the file you have specified. You will be given the opportunity to type in the correct filename at the prompt. If you want to quit, simply type \texttt{X} followed by the return character \enter. \begin{itemize} \item Make sure that you have spelt the filename correctly. This error will be caused by, say, \begin{alltt}\wrong \gls{documentclass}\marg{scrarticle} \end{alltt} instead of \begin{alltt}\correct \gls{documentclass}\marg{scrartcl} \end{alltt} If this is the case, simply type in the correct name at the prompt (followed by the return character \enter) then go back and fix the spelling in the \gls{source}. \item Make sure that the file is in the same directory as your document or in the \LaTeX\ path. If the file is in another directory (not in the \LaTeX\ path), you will need to specify the pathname, but remember that when using \LaTeX\ under Windows, you need to use a forward slash (\glsi{dir.slash}) as the directory divider, as a backslash would be interpreted as a command. For example, if you have a file called \texttt{shapes.pdf} in the subdirectory \texttt{pictures} then you would get a \dq{file not found} error message if you did \begin{alltt}\wrong \gls{includegraphics}\marg{shapes} \end{alltt} instead of \begin{alltt}\correct \gls{includegraphics}\marg{pictures/shapes} \end{alltt} \item If the file is a \htmlref{package}{sec:packages} or \htmlref{class file}{sec:cls}, it's possible that you don't have that file installed on your computer. If this is the case you will need to download and install it as described in \appendixref{ch:installsty}. Remember that you need to refresh the database after installing a new package or class file. \end{itemize} %%%%%%%%%%%%%%%%%%%% Illegal character in array arg %%%%%%%%%%%%%%%%%% \setnode{illegalarraychar} \section{Illegal character in array arg} You have used a character in the \gls{argument} of a \gls{env-tabular} or \gls{env-array} environment that is not allowed. The standard available characters are: \texttt{r} (right justified), \texttt{l} (left justified), \texttt{c} (centred) and \texttt{p}, as well as \gls{atchar}\marg{\meta{inter-col text}}. Remember that if you want to use the \gls{gtcol}\marg{\meta{decl}} or \gls{ltcol}\marg{\meta{decl}} specifiers, you must include the \isty{array} package. This error will also occur if you have forgotten the argument to the \gls*{env-tabular} or \gls*{env-array} environment. %%%%%%%%%%%%%%%%%%% Illegal parameter number in definition %%%%%%%%%% \setnode{illegalparamnum} \section{Illegal parameter number in definition} You have referred to a \htmlref{parameter (argument) number}{sec:newcomarg} that is greater than the number of parameters you have specified. For example, suppose you defined the command to have only one parameter, then you can't use \gls{hashchar}\texttt{2} which refers to the second, non-existent, parameter. Remember that you need to specify how many parameters you want in the \gls{optional} to \glsni{newcommand}, otherwise it will be assumed that the command has no arguments. %%%%%%%%%%%%%%%%%%%%% Illegal unit of measure %%%%%%%%%%%%%%%%%%%%%%% \setnode{illegalunit} \section{Illegal unit of measure (pt inserted)} You have either not specified a unit when giving a \gls{length} (even zero lengths must have a unit) or you have specified an invalid unit or you have misspelt the unit. Available units are listed in \tableref{tab:units}. %%%%%%%%%%%%%%%%% Lonely \item %%%%%%%%%%%%%%%%%%%%%%%%% \setnode{lonelyitem} \section{Lonely \textbackslash item} The command \gls{item} may only appear in one of the list making environments (such as \gls{env-itemize}). Make sure you haven't forgotten your environment. %%%%%%%%%%%%%%% Misplaced alignment tab character & %%%%%%%%%%%%%%%%% \setnode{misplacedtab} \section{Misplaced alignment tab character \&} You have used the special character \gls{ampchar} where you shouldn't have. Recall from \sectionref{sec:chars} that if you want an \& sign to appear you need to do \gls{amp} not just \glsni{ampchar}. You would have got this error message if you had done, say, \begin{alltt}\wrong \glsni{ampchar} our equipment \end{alltt} instead of \begin{alltt}\correct \glsni{amp} our equipment \end{alltt} %%%%%%%%%%%%%%%%%%%%% Missing } inserted %%%%%%%%%%%%%%%%%%%%%%%%%%% \setnode{missingendbrace} \section{Missing \} inserted} You have missed a closing curly brace, or you may have missed out an argument. \xminisec{Example:} If the following line occurs in a tabular environment: \begin{alltt}\wrong \gls{ampchar} \gls{multicolumn}\marg{2}\marg{c}\gls{tab.dbbackslashchar} \end{alltt} this will produce the error. (The third argument to \gls{multicolumn} has been omitted.) %%%%%%%%%%%%%%%%%%%%% Missing $ inserted %%%%%%%%%%%%%%%%%%%%%%%%%%% \setnode{missingdollar} \section{Missing \$ inserted} This message can be caused by a number of errors: \begin{itemize} \item You might have missed the beginning of one of the mathematics \glspl{environment} (that is, you've used a \gls{command} that must only appear in maths mode). \item You may have typed \gls{dollarchar} instead of \gls{dollar} (you actually want a dollar symbol to appear). Recall from \sectionref{sec:chars} that if you want a \$ sign to appear you need to do \glsni{dollar} not just \glsni{dollarchar}. You would have got this error message if you had done, say, \begin{alltt}\wrong expenditure came to \glsni{dollarchar}2000.00 \end{alltt} instead of \begin{alltt}\correct expenditure came to \glsni{dollar}2000.00 \end{alltt} \item You may have missed the end of a mathematics environment, or you may have a paragraph break within an in-line or displayed maths environment, where it is not permitted. Make sure you don't have any blank lines within the environment. If you want a blank line in your code to make it easier to edit, try having a percent sign at the start of an empty line to ensure that the line is ignored by \LaTeX. For example: \begin{alltt} \glsni{begin}\marg{equation} \glsni{percentchar} E = mc\glsni{circumchar}2 \glsni{percentchar} \glsni{end}\marg{equation} \end{alltt} \end{itemize} %%%%%%%%%%%%%%% Missing \begin{document} %%%%%%%%%%%%%%%%% \setnode{missingbegindoc} \section{Missing \textbackslash begin\{document\}} You have put some text outside of the document \glsterm{environment}. Check the following: \begin{itemize} \item You have remembered \verb|\begin{document}| This error would be caused by, say, \begin{alltt} \glsni{documentclass}\marg{scrartcl} \wrong This is a simple document \end{alltt} instead of \begin{alltt} \glsni{documentclass}\marg{scrartcl} \glsni{begin}\marg{document}\correct This is a simple document. \end{alltt} \item You haven't placed any text before \verb|\begin{document}|. For example: \begin{alltt} \glsni{documentclass}\marg{scrartcl} This is a simple document\wrong \glsni{begin}\marg{document} \end{alltt} instead of \begin{alltt} \glsni{documentclass}\marg{scrartcl} \glsni{begin}\marg{document}\correct This is a simple document \end{alltt} \item You haven't missed out the backslash at the start of either \gls{documentclass} or \glsni{begin}\marg{document} This error would be caused by, say, \begin{alltt}\wrong documentclass\marg{scrartcl} \end{alltt} instead of \begin{alltt}\correct \glsni{documentclass}\marg{scrartcl} \end{alltt} \end{itemize} %%%%%%%%%%%%%%%%%%% Missing delimiter %%%%%%%%%%%%%%%%%%%%%%% \setnode{missingdelim} \section{Missing delimiter} You have forgotten to specify the type of delimiter you want (for example, \gls{openparen} \gls{closeparen} \gls{delimiter.opensq} \gls{delimiter.closesq} \gls{leftbrace} \gls{rightbrace}). (Remember to use a \gls{delimiter.periodchar} if you want an invisible delimiter, and remember that if you want a curly brace, you must have a backslash followed by the curly brace.) \xminisec{Example:} This error will occur if you do, say, \begin{alltt}\wrong f(x) = \glsni{left}\glsni{leftbracechar} \glsni{begin}\marg{array}\marg{ll} 0 \glsni{ampchar} x \cmdname{leq} 0\gls{tab.dbbackslashchar} 1 \glsni{ampchar} x > 1 \glsni{end}\marg{array} \glsni{right}. \end{alltt} instead of \begin{alltt}\correct f(x) = \glsni{left}\glsni{leftbrace} \glsni{begin}\marg{array}\marg{ll} 0 \glsni{ampchar} x \cmdname{leq} 0\gls{tab.dbbackslashchar} 1 \glsni{ampchar} x > 1 \glsni{end}\marg{array} \glsni{right}. \end{alltt} %%%%%%%%%%%%%%%% Missing \endcsname inserted %%%%%%%%%%%%%%%% \setnode{missingendcsname} \section{Missing \textbackslash endcsname inserted} This is a \gls{tex} error rather than a \LaTeX\ error which makes it harder to determine the cause, however it can be caused by placing a backslash in front of the name of an \gls{environment}. (Remember that \gls{environment} names do not contain a backslash.) This error will be caused by, say, \begin{alltt}\wrong \glsni{begin}\marg{\glsni{sffamily}} \end{alltt} instead of \begin{alltt}\correct \glsni{begin}\marg{sffamily} \end{alltt} %%%%%%%%%%%%%% Missing \endgroup inserted %%%%%%%%%%%%%%%%%% \setnode{missingendgroup} \section{Missing \textbackslash endgroup inserted} A number of things could have caused this. You may have missed out the end of an \gls{environment}, or you may have an environment inside of another environment it's not allowed to be in. For example, this error can be caused by placing an \envname{eqnarray} environment inside a \envname{displaymath} environment, which is not allowed. (But, of course, you haven't used either of those obsolete environments~\cite{l2tabu}, have you?) %%%%%%%%%%%%%%% Missing number %%%%%%%%%%%%%%%%%% \setnode{missingnum} \section{Missing number, treated as zero} \LaTeX\ is expecting a number. If your command takes more than one \gls{argument}, check to make sure the arguments are in the correct order. For example, if you are using a \gls{env-minipage} environment, you might have omitted the \gls{mandatory} which specifies the width of the minipage, or you may have the \glspl{optional} the wrong way round. The placement specifier should come first, followed by the height. If you are using \gls{addtocounter} or \gls{setcounter} remember that the second argument must be a number, so if you want the value of a counter as the argument you must use \gls{value}. This error can be caused by, say, \begin{alltt}\wrong \glsni{setcounter}\marg{exercise}\marg{chapter} \end{alltt} instead of \begin{alltt}\correct \glsni{setcounter}\marg{exercise}\marg{\glsni{value}\marg{chapter}} \end{alltt} %%%%%%%%%%%%%% Paragraph ended %%%%%%%%%% \setnode{parended} \section{Paragraph ended before \textbackslash begin was complete} You've probably missed a closing brace at the end of the argument to \gls{begin}. This error will be caused by, say, \begin{alltt}\wrong \glsni{begin}\glsni{leftbracechar}document \end{alltt} instead of \begin{alltt}\correct \glsni{begin}\marg{document} \end{alltt} %%%%%%%%%%%%%%%%%%% Runaway argument %%%%%%%%%%%%%%%%%%%%%%%%%%%% \setnode{runawayarg} \section{Runaway argument} There are a number of possible causes of this error: \begin{itemize} \item Paragraph breaks are not permitted in the \glspl{argument} of \glspl{short}. If there is a corresponding \gls{environment} then you should use that instead. For example, this error message will be generated by doing, say, \begin{alltt} \glsni{textbf}\glsni{leftbracechar}This is a simple document. Here is the first paragraph. \wrong Here is the second paragraph.\glsni{rightbracechar} \end{alltt} instead of\bookpagebreak \begin{alltt} \glsni{begin}\marg{bfseries} This is a simple document. Here is the first paragraph. \correct Here is the second paragraph. \glsni{end}\marg{bfseries} \end{alltt} \item The closing brace of a \gls{mandatory} is missing: This error will be caused by, say, \begin{alltt}\wrong \glsni{title}\glsni{leftbracechar}A Simple Document \end{alltt} instead of \begin{alltt}\correct \glsni{title}\marg{A Simple Document} \end{alltt} \item This error can also be caused by omitting the \gls{mandatory} of an \gls{environment}. For example, this error will occur if you do, say, \begin{alltt}\wrong \glsni{begin}\marg{thebibliography} \glsni{bibitem}\marg{kopka95} A Guide to \glsni{LaTeXe} \end{alltt} instead of \begin{alltt}\correct \glsni{begin}\marg{thebibliography}\marg{1} \glsni{bibitem}\marg{kopka95} A Guide to \glsni{LaTeXe} \end{alltt} \end{itemize} %%%%%%%%%%%%%%% Something's wrong--perhaps a missing \item %%%%%%%%%%%%%%%% \setnode{missingitem} \section{Something's wrong--perhaps a missing \textbackslash item} You may have missed an \gls{item} command. The first object in a list environment must either be an \gls{item} command, or another list environment. This error will be caused by, say, \begin{alltt}\wrong \glsni{begin}\marg{itemize} Animal \glsni{item} Vegetable \glsni{item} Mineral \glsni{end}\marg{itemize} \end{alltt} instead of \begin{alltt}\correct \glsni{begin}\marg{itemize} \glsni{item} Animal \glsni{item} Vegetable \glsni{item} Mineral \glsni{end}\marg{itemize} \end{alltt} \bookpagebreak This error can also be caused by a missing \gls{bibitem} in the \htmlref{bibliography}{sec:bib}. For example, the error will occur if you do, say, \begin{alltt}\wrong \glsni{begin}\marg{thebibliography}\marg{1} A Guide to \glsni{LaTeXe} \end{alltt} instead of \begin{alltt}\correct \glsni{begin}\marg{thebibliography}\marg{1} \glsni{bibitem}\marg{kopka95} A Guide to \glsni{LaTeXe} \end{alltt} See also \gls{ukfaq} entry: \faqlink{Perhaps a missing \cmdname{item}?}{errmissitem}. %%%%%%%%%%%%%%%%% There's no line here to end %%%%%%%%%%%%%%%%%%%%% \setnode{nolinetoend} \section{There's no line here to end} You have placed a line breaking command (such as \gls{newline.dbbackslashchar}, \gls{newline} or \gls{linebreak}) where it doesn't make sense to have one. %%%%%%%%%%%%%%%%% Undefined control sequence %%%%%%%%%%%%%%%%%%%%%% \setnode{csundefined} \section{Undefined control sequence} \LaTeX\ doesn't understand the \gls{command} you have used. \begin{itemize} \item Check to see if you have misspelt the command name (remember that all \LaTeX\ command names are case-sensitive.) You will get this error if you do, say, \begin{alltt}\wrong This is a simple \cmdname{Latex}\glsni{spacesym}document \end{alltt} instead of \begin{alltt}\correct This is a simple \gls{LaTeX}\glsni{spacesym}document \end{alltt} \item Check that you have remembered the space when typing \gls{spacesym} (backslash space). For example, this error will occur if you do, say, \begin{alltt}\wrong This is a \cmdname{LaTeX}\cmdname{sample} document. \end{alltt} instead of \begin{alltt}\correct This is a \glsni{LaTeX}\glsni{spacesym}sample document \end{alltt} \item If you are using a command that is defined in a \htmlref{package}{sec:packages} make sure you have included the package using \gls{usepackage}. \item Check that your command name hasn't run into the next piece of text. For example, you can do \begin{alltt} man\glsni{oe}\marg{}uvre \end{alltt} or \begin{alltt} man\glsni{oe} uvre \end{alltt} or (not recommended) \begin{alltt} man\marg{\glsni{oe}}uvre \end{alltt} but not \begin{alltt}\wrong man\cmdname{oeuvre} \end{alltt} \item Check if you have used a backslash instead of a forward slash as a directory divider. (Remember that when using \LaTeX\ under Windows, you need to use a forward slash (\glsi{dir.slash}) as the directory divider, as a backslash would be interpreted as a command.) For example, suppose you have a file called \texttt{shapes.pdf} in a subdirectory called \texttt{pictures}, then you would get an error if you did \begin{alltt}\wrong \glsni{includegraphics}\marg{pictures\cmdname{shapes}} \end{alltt} instead of \begin{alltt}\correct \glsni{includegraphics}\marg{pictures/shapes} \end{alltt} \end{itemize} %%%%%%%%%% You can't use `macro parameter character #' in horizontal mode %%%%%%%%%%%%%%% \setnode{hashinhmode} \section{You can't use `macro parameter character \#' in horizontal mode} You have used the special character \gls{hashchar} where you shouldn't have. Recall from \sectionref{sec:chars} that if you want a \# sign to appear you need to do \gls{hash} not just \glsni{hashchar}. This error message will be caused by doing, say, \begin{alltt}\wrong Item \glsni{hashchar}1 \end{alltt} instead of \begin{alltt}\correct Item \glsni{hash}1 \end{alltt} \setnode{help} \chapter{Need More Help?} \label{ch:help} First, try to find your query in the \gls{ukfaq}. \Gls{tug} also has a list of useful resources at \url{http://tug.org/interest.html}. If you're still stuck, you can post your question on a (La)TeX forum, newsgroup or mailing list, such as those listed below. If you do post a question, remember you're asking people who only have an altruistic interest in helping. No one is paying them to help you. Most of the class files and packages were written for free by people who had a need to solve a particular problem and decided to make their work publicly available. So no matter how frustrated you're feeling, stick to being polite. If you can't work out how to use a particular class or package, don't start by heaping offensive, unconstructive criticism on it as there's a chance the author will read the message. There's no sense in alienating the person most qualified to answer your question. In your message, stick to the following guidelines: \begin{enumerate} \item Cut to the chase. In other words, be concise about the nature of the problem. Don't write lots of long-winded paragraphs. \item Provide a minimal example\footnote{see \url{http://www.dickimaw-books.com/latex/minexample/}} that illustrates the problem. \end{enumerate} \xminisec{Example:} \begin{verbatim} I'm trying to use the \foo command in the "bar" package, but I'm getting the following error message: ! Undefined control sequence. l.4 \foo Here's a minimal example: \documentclass{scrartcl} \usepackage{bar} \begin{document} \foo{Blah} \end{document} I'm using bar version 1.0 (2012/06/30). \end{verbatim} \xminisec{Another example:} \begin{verbatim} I'm using the \foo command in the "bar" package. According to the documentation, this command should display its argument in a bold font, but it's coming out in italic instead. Anyone know why? Here's a minimal example: \documentclass{scrartcl} \usepackage{bar} \begin{document} \foo{Blah} \end{document} I'm using bar version 1.1 (2012/07/30). \end{verbatim} There's no guarantee that you will get an answer, but if you follow the above guidelines, you will increase your chances. \xminisec{Resources} \begin{itemize} \item The \LaTeX\ Community (\url{http://www.latex-community.org/}). \item \TeX/\LaTeX\ on StackExchange (\url{http://tex.stackexchange.com/}). \item \htmladdnormallink{\texttt{comp.text.tex} newsgroup}{http://groups.google.com/group/comp.text.tex} (use a newsreader rather than the Google interface if you want to avoid the spam). \item \htmladdnormallink{\texttt{texhax} archives}{http://tug.org/pipermail/texhax/}\doifbook{~\cite{texhax}}. \end{itemize} I~strongly recommend that you also have a look at the On-Line Catalogue~\cite{texcat}. It's also a good idea to look at the documentation that was installed with your \TeX/\LaTeX\ distribution (see \sectionref{sec:texdoc}). If you are using \itexdistro{MiKTeX} you can access the on-line help via the Start Menu: \startmenu{MiKTeX \menuto\ Help} (Please don't send your problems to me, unless you want to hire a consultant. I~read both the \LaTeX\ Community Forum and \texttt{comp.text.tex} and answer relevant questions if I~have time, but it clogs up my inbox if people keep sending attachments that are in the order of several megabytes in size.) Besides, you'll reach a wide group of experts if you post to a newsgroup, forum or mailing list, rather than a single busy individual. %%%%%%%%%%%%%%%%%%%%%%%%%% Supplemental Material %%%%%%%%%%%%%%%%%%% \ifpdf\else\input{supplemental}\fi \backmatter %%%%%%%%%%%%%%%%%%%%%%%%%%% Bibliography %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \clearpage\phantomsection \setnode{bibliography} \bibliographystyle{plain} \bibliography{novices} %%%%%%%%%%%%%%%%%%%%%%%%%%%% GLOSSARIES %%%%%%%%%%%%%%%%%%%%%%%%%%%% \setnode{acronyms} \printglossary[type=acronym,nonumberlist,style=acronyms] \setnode{summary} \setdoublecolumnglo \printglossary[style=summary] \setnode{bookindex} \printindex %%%%%%%%%%%%%%%%%%%%%%%%% LICENCE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \setnode{licence} \chapter{GNU Free Documentation License} \input{../fdl} %%%%%%%%%%%%%%%%%%%%%%%%%% HISTORY %%%%%%%%%%%%%%%%%%%%%%%%%%%% \setnode{history} \chapter{History}\markright{History} \historyitem{25th Sept 2012 (Version 1.4)} \begin{itemize} \item Paperback edition~1 produced. \item Added TeXWorks section. \item Moved \dq{Text editor and Terminal approach}, \dq{TeXnicCenter} and \dq{WinEdt} sections to new supplementary material. \item Added hardcopy-related code. \item Change to \koma\ classes (both for examples and for pdf versions of this document). \item Changed from using \sty{subfloat} to \sty{subcaption} package. \item Added section on inter-sentence spacing. \item Moved \dq{Errors} and \dq{Where to get Help?} to appendices. \item Moved section \dq{Downloading and Installing Packages} to new appendix chapter. \item Moved introduction to packages to \dq{Creating a Simple Document}. \item Moved datetime section to \dq{Creating a Simple Document} chapter. (Removed reference to ukdate package.) \item Moved babel section to \dq{Structuring Your Document} chapter. \item Moved graphicx section to its own chapter. \item Added section on align. \item Added \cmdname{cfrac}, \cmdname{substack} and \sty{amsmath} ellipses to maths chapter. \item Added extensible arrows and \cmdname{bigl} etc to maths chapter. \item Added booktabs. \item Moved lengths chapter to section in definitions. \item Added summary chapter with commands hyperlinked to their definitions in the summary. \item Changed definitions chapter to use a glossary structure. \item Moved bibliography into bib file. \item Added \sty{varioref}. \item Removed dependency on \sty{html} package (for pdf versions) to avoid conflict between \sty{html} and \sty{varioref} (\sty{html} package functions not defined by \sty{hyperref} now emulated; \sty{comment} package loaded to provide \envname{htmlonly} environment). \item Removed image of equation written in Word (Microsoft have improved their equation rendering) and added link to Murray Sargent~III blog~\cite{sargentiii}. \item Added section on what a terminal/command prompt is. \item Added section on auxiliary files. \item Added section on Perl. \item Added information about latexmk \item Mentioned grffile package. \item Mentioned on-the-fly EPS conversion. \item Mentioned \sty{etoolbox}'s \cmdname{appto} and \sty{babel}'s \cmdname{addto}. \item Changed to UTF-8 and mostly changed to using code points instead of named entities in HTML files. \item Moved the document's home page from \url{http://theoval.cmp.uea.ac.uk/~nlct/latex/novices/} to \url{http://www.dickimaw-books.com/latex/novices/}. \end{itemize} \historyitem{15th Jan 2008 (Version 1.3)} The main reason behind this change was to increase accessibility and conform to W3C guidelines. If you are experiencing problems relating to accessibility, please let me know (clearly stating the problem). \begin{itemize} \item Corrected error in the university's post code on the title page \item Added alternative text tags to more of the images, and made some of the images hyperlinks to a more detailed description of the image. \item Added information on how to break ligatures. \item Moved information on TeX to the introduction, and removed section on TeX that was in the "Some Definitions" chapter. \item Document nodes now have permanent names instead of the generic node\meta{n}.html which \LaTeX2HTML generates by default. \item Went back to using straight double quotes in the HTML document as the fancy typographic double quotes are nonstandard. \end{itemize} \historyitem{8th May 2007 (Version 1.2)} \begin{itemize} \item Links to \gls{ukfaq} added. \item Overview made into a separate section, and tidied up a bit. \item Added some extra definitions: moving arguments and fragile commands, robust commands, short and long commands. \item Changed \dq{Text editor and Terminal approach} to deal with Unix-type systems rather than MS-DOS. \item Moved section on \envname{tabular} environment. \item Added section on boxes and mini-pages. \item Segmented section on font changing commands. \item Segmented section describing \sty{graphicx}. \item Added section on the \sty{babel} package. \item Updated and segmented section on downloading and installing new packages. \item Added section on side-by-side figures. \item Updated section on sub-figures to use the new \sty{subfloat} package instead of the obsolete \sty{subfigure} package. \item Added \dq{Need More Help?} chapter. \end{itemize} \backcoverheading (See \url{http://www.gnu.org/licenses/fdl-howto-opt.html#SEC2}.) \backcovertext \end{document}