# ttoirrah's IT Notes

### Site Tools

cross_platform:encoding:text-code:latex

Get it onto MSWin:

• At first, I installed proTeXt, a MiKTeX-based distribution for Windows which comes with TeXstudio. It's a good starting bundle, but I now go directly to MikTeX.
• LaTeX has a huge number of optional packages. I'm quite happy with MikTeX's download-and-install-as-needed package management.

pdfpages:

How to add todo notes?: Seamus Bradley has a simple suggestion that I implemented. So in my preamble, I have:

\usepackage{xcolor}
\newcommand\jhtodo[1]{\textcolor{red}{#1}} % for notes, as per Seamus Bradley's suggestion
%\renewcommand\jhtodo[1]{} % for turning off notes 

And the notes themselves are \jhtodo{scattered around like this}. They're easy to find in a text editor, and they're red in the pdf, and not rendered when I turn them off. Neat!

these characters can be used in your documents all the same by adding a prefix backslash: \# \\% \^{} \& \_ \{ \} \~{} \textbackslash{} The commands \~ and \^ produce respectively a tilde and a hat which is placed over the next letter. For example \~n gives ñ. That's why you need braces to specify there is no letter as argument. Never, ever use directories (folders) or file names that contain spaces. Although your operating system probably supports them, some don't, and they will only cause grief and tears with TeX. Make filenames as short or as long as you wish, but strictly avoid spaces. Stick to lower-case letters without accents (a-z), the digits 0-9, the hyphen (–), and only one full point or period (.) to separate the file extension (somewhat similar to the conventions for a good Web URL): it will let you refer to TeX files over the Web more easily and make your files more portable. Some operating systems do not distinguish between upper-case and lower-case letters, others do. Therefore it's best not to mix them. Ancillary files None of these files contains unrecoverable information. It means you can delete them safely, compiling will regenerate them automatically. #### Engines An engine is an executable that can turn your source code into a printable output format. The engine by itself only handles the syntax, it also needs to load fonts and macros to fully understand the source code and generate output properly. The engine will determine what kind of source code it can read, and what format it can output (usually DVI or PDF). #### Errors and Warnings To easily find the location of overfull hbox in your document, you can make latex add a black bar where a line is too wide: \overfullrule=2cm Underfull hbox … This is a warning that LaTeX cannot stretch the line wide enough to fit, without making the spacing bigger than its currently permitted maximum. The badness (0-10,000) indicates how severe this is if you get the name right, but the package is not installed on your machine, you will need to download and install it before continuing. If you don't want to affect the global installation of the machine, you can simply download from Internet the necessary .sty file and put it in the same folder of the document you are compiling. #### Guides #### Internationalization The babel package by Johannes Braams and Javier Bezos will take care of everything (with XeTeX and LuaTeX you should consider polyglossia). You can load it in your preamble, providing as an argument name of the language you want to use (usually its English name, but not always): \usepackage[language]{babel} You should place it soon after the \documentclass command, so that all the other packages you load afterwards will know the language you are using. Babel will automatically activate the appropriate hyphenation rules for the language you choose. You can also add short pieces of text in another language using the command \foreignlanguage{languageB}{Text in another language} #### LaTeX intended to provide a high-level language that accesses the power of TeX. LaTeX essentially comprises a collection of TeX macros and a program to process LaTeX documents. Because the TeX formatting commands are very low-level, it is usually much simpler for end-users to use LaTeX. The current version is LaTeX2e (stylised as LATEX2ε). #### LaTeX/Installing Extra Packages Add-on features for LaTeX are known as packages. Dozens of these are pre-installed with LaTeX and can be used in your documents immediately. They should all be stored in subdirectories of texmf/tex/latex named after each package. The directory name “texmf” stands for “TEX and METAFONT”. A package is a file or collection of files containing extra LaTeX commands and programming which add new styling features or modify those already existing. There are two main file types: class files with .cls extension, and style files with .sty extension. There may be ancillary files as well. When you try to typeset a document which requires a package which is not installed on your system, LaTeX will warn you with an error message that it is missing. You can download updates to packages you already have (both the ones that were installed along with your version of LaTeX as well as ones you added). There is no limit to the number of packages you can have installed on your computer (apart from disk space!), but there is a configurable limit to the number that can be used inside any one LaTeX document at the same time, although it depends on how big each package is. In practice there is no problem in having even a couple of dozen packages active. For a TDS(TeX Directory Structure)-conformant system, your “local installation directory tree” is a folder and its subfolders. The outermost folder should probably be called texmf-local/ or texmf/. Its location depends on your system: Unix-type systems: Usually ~/texmf/. Where to put files from packages Type Directory (under texmf/ or texmf-local/) Description .cls tex/latex/base Document class file #### Modular Documents Another important difference is that using \include will force a page break (which makes it ideal for a book's chapters), whereas the \input command does not (which in turn makes it ideal for, say, a long article with discrete sections, which of course are not normally set on a new page). If you need to insert an existing, possibly multi-page, PDF file into your LaTeX document, whether or not the included PDF was compiled with LaTeX or another tool, consider using the pdfpages package. A suggestion: do not give your files names like “chapter_01.tex” or “figure_03.png”, i.e. try to avoid using numbers in file-names: if the numbering LaTeX gives them automatically, is different from the one you gave (and this will likely happen) you will get really confused. When naming a file, stop for a second, think about a short name that can fully explain what is inside the file without being ambiguous, it will let you save a lot of time as soon as the document gets larger. #### Paragraph Formatting in the Wikibook By default, the first paragraph after a heading follows the standard Anglo-American publishers' practice of no indentation. The size of subsequent paragraph indents is determined by a parameter called \parindent. The default length that this constant holds is set by the document class that you use. It is possible to override it by using the \setlength command. This will set paragraph indents to 1cm: \setlength{\parindent}{1cm} % Default is 15pt. - so \setlength{\parindent}{0pt} clears the indents globally. To create a non-indented paragraph, you can use \noindent \hangindent=7mm This paragraph has an extra indentation at the left. Oh yes it does, oh yes it does, you will see, I tell you it does! #### Text Formatting Some very long words, numbers or URLs may not be hyphenated properly and move far beyond the side margin. One solution for this problem is to use sloppypar environment, which tells LaTeX to adjust word spacing less strictly. As a result, some spaces between words may be a bit too large, but long words will be placed properly. \textsuperscript{}, Dashes and hyphens, ellipsis (\ldots). ### Colors xcolor “Driver-independent color extensions for LATEX and pdfLATEX”, whatever that means. When to use the xcolor package instead of the color package? #### The Wikibook {\color{declared-color} some text} The difference between \textcolor and \color is the same as that between \texttt and \ttfamily, you can use the one you prefer. The \color environment allows the text to run over multiple lines and other text environments whereas the text in \textcolor must all be one paragraph and not contain other environments. The 68 standard colors known to dvips Invoke the package with the usenames and dvipsnames option. If you are using tikz or pstricks package you must declare the xcolor package before that, otherwise it will not work. \usepackage[dvipsnames]{xcolor} \definecolor{orange}{HTML}{FF7F00} ### Fonts pifont “Access to PostScript standard Symbol and Dingbats fonts”  \usepackage{pifont}  Then I can insert a little star with \ding{80}. Roman font is stored as \rmdefault, which are Serif Fonts in The LaTeX Font Catalogue. Shapes are italic, bold, etc. A discussion on whether to use LaTeX2e commands (like \textbf{}, or the older shorter ones (like \bf). #### The Wikibook \usepackage[normalem]{ulem} \emph{…} = {\em …} = emphasis Typically italics. Using emph{} inside of italic text removes the italics on the emphasized text. \textit{…} {\itshape …} italic shape \textbf{…} {\bfseries …} bold You may have noticed the absence of underline. This is because underlining is not recommended for typographic reasons (it weighs the text down). You should use emph instead. However underlining text provides a useful extra form of emphasis during the editing process, for example to draw attention to changes. Although underlining is available via the \underline{…} command, text underlined in this way will not break properly. This functionality has to be added with the ulem (underline emphasis) package. Stick \usepackage{ulem} in your preamble. By default, this overrides the \emph command with the underline rather than the italic style. It is unlikely that you wish this to be the desired effect, so it is better to stop ulem taking over \emph and simply call the underline command as and when it is needed. * To restore the usual \emph formatting, add \normalem straight after the document environment begins. Alternatively, use \usepackage[normalem]{ulem}. • To underline, use \uline{…} along with \usepackage[normalem]{ulem}.. • To add a wavy underline, use \uwave{…} along with \usepackage[normalem]{ulem}.. • For a strike-out (strikethrough), use \sout{…} along with \usepackage[normalem]{ulem}.. • For a slash through each individual character \xout{…} along with \usepackage[normalem]{ulem}. Sizing text: \tiny, \scriptsize, \footnotesize, \small, \normalsize, \large, \Large, \LARGE, \huge, \Huge ### LaTeX3 #### expl3 programming environment ### Lengths \usepackage{printlen} \uselengthunit{cm}\printlength{\textheight} #### the Wikibook In TeX, a length is a floating point number followed by a unit, optionally followed by a stretching value; 3.5pt plus 1pt minus 2pt > a floating point factor followed by a macro that expands to a length. 1.7\textwidth  Definition Value in points (pt) Value in micrometers (µm) pt 1/72.27 inch ~ 0.0138 inch. 1 351.46 mm millimeter 2.84 = 7227/2540 1000 cm centimeter 28.4 = 7227/254 10000 in inch 72.27 25400 ex roughly the height of an 'x' em roughly the width of an 'M' (uppercase) The point is the default unit and 1pt is the default length. \setlength{\parskip}{10pt plus 5pt minus 3pt} means that tex will try to use a length of 10pt; if it is underfull, it will raise the length up to a maximum of 15pt; if it is overfull, it will lower the length up to a minimum of 7pt. To print a length, you can use the \the command: \the\textwidth ### Mathematics • Maths support is excellent, and playfully easy. #### AMS-LaTeX \usepackage{amsmath} The package has a suite of facilities to format multi-line equations. #### LaTeX/Advanced Mathematics makes heavy use of the AMS-LaTeX packages supplied by the American Mathematical Society. The equation environment automatically numbers your equation The align and align* environments, available through the amsmath package, are used for arranging equations of multiple lines. As with matrices and tables, specifies a line break, and & is used to indicate the point at which the lines should be aligned. Note that the align environment must not be nested inside an equation (or similar) environment. Instead, align is a replacement for such environments; the contents inside an align are automatically placed in math mode. align* suppresses numbering. #### LaTeX/Mathematics displayed formulas are separate from the main text. • Inline (within text) formulas: …\$
• Displayed equations $…$
Powers and indices are equivalent to superscripts and subscripts in normal text mode. The caret (^; also known as the circumflex accent) character is used to raise something, and the underscore (_) is for lowering.

Binary Operations

### Opinions

Andrew Roberts on the Benefits of LaTeX typesetting

The Beauty of LATEX - a brief explanation of how LaTeX beats WYSIWYG word processors.

The Problems of LaTeX - a rant, provoking a huge discussion.

#### mine

I looked into LaTeX when I was looking for a better way to handle a somewhat convoluted story that I was writing. When I wrote the first half of the story, back in 2008, I had two big monitor screens, and MSWord, with it's ability to fold up by chapters. Writing the second half of the story, last summer, I had only an underpowered netbook running LibreOffice, with it's almost useless master document functionality, and displaying on a 1024×600 screen. Not only was this slow, and cramped, but leaving notes around my story was fiddly, and searching it was laborious. Reading around the web, I quickly discovered that I wasn't alone in my frustrations, and that there were other viable options, like LaTeX.

Between then and now, I've taught myself, from scratch, gVim to quite an advanced (eg writing simple plugins) level, begun using GitHub, and just only now begun figuring out LaTeX. It doesn't feel as hard as gVim did, and it helps that I've done some programming recently (Python and Perl), because LaTeX is essentially a programming environment for typescripting documents.

### stringstrings

to the StackExchange question Change the color of capital letters

I played around with this, hoping to use it for the letters HJThjt. I couldn't figure out why it wouldn't accept lowercase redefinitions until I focussed instead on just the letters MT, then adding o showed why, as he says, it's dangerous: \catcodeo=\active breaks all further use of o within the file…

### TeXstudio

- which really works very well with MiKTeX. F1 = Build & View.

The default compiler is set thusly: Configure > Build > Default Compiler > PdfLaTeX. I changed that to XeLaTeX for easy drop in of curly-quoted text from LibreOffice.

#### in combination with gVim

TeXstudio quickly picks up the changes that I make on a tex file that I have simultaneously opened in gVim, where I prefer to work. When I want to compile and check, I Alt+tab over to TeXstudio, and hit F1. I can scan the pdf output within TeXstudio, or, less often, fire up the generated pdf in Adobe Reader.

Occasional glitch after saving a tex file from gVim:

The file <filepath> has been deleted on disk.

- which requires that I click on Ignore, then Cancel (or press Esc), then Quit TeXstudio and reload it on the file, which is of course annoying when I'm intentionally editing the tex file externally from gVim. This problem, and the fix, is discussed here. It is:

Options > Configure > Show Advanced > Adv Editor > Special options > Silently reload files on external changes

## Commands

Redefining:

#### Macros

In this chapter, we will try to give some hints on how to teach LaTeX new tricks and how to make it produce output that looks different from what is provided by default.
Name your new command \wbalTwo and not \wbal2 as digits cannot be used to name macros — invalid characters will error out at compile-time.
In certain cases you might also want to use the \providecommand command. It works like \newcommand, but if the command is already defined, LaTeX will silently ignore the new command.
The xkeyval packages will let you define key/value options for commands.

### center

\begin{center}
stuff...
\end{center}

#### & centering

\newcommand\centred[1]{\begin{center}#1\end{center}} % for centering small items

Then \centred{\ding{80}} puts in a centred star.

## Special Characters

### XeLaTeX

• In Windows 10, an empty document class file (caused by a dead symbolic link) triggered a less than informative “xelatex.exe has stopped working” pop-up.

Fonts:

• Arial doesn't support Sanskrit or Tamil
• DejaVuSerif supports “♯” & “♭”, but not Sanskrit or Tamil
• Open Sans doesn't support “♯” & “♭”

#### fontspec

• \usepackage{fontspec} followed by: \setmainfont{Arial} - allows Arabic words in the serif font.
• Tamil: \newfontfamily\lathatam[Color=gray]{Latha} in the preamble, then Tamil: {\lathatam அசாரி} in the text.

Font selection for XeLaTeX and LuaLaTeX. Easy to define a \newfontfamily command to use as needed, eg:

\newfontfamily\arabicsec{Arial}

- creates command \arabicsec (which I use in memoir class for a book that needs Arabic text in some headings).

#### Polyglossia

provides a complete Babel replacement for users of LuaLaTeX and XeLaTeX; it relies on the fontspec package
\usepackage{polyglossia}
\setdefaultlanguage[variant=uk]{english} % before setting fonts
\setmainfont{Open Sans} % fontspec loaded by polyglossia

# Document Structure

blindtext:

allow you to control the numbering mechanism of everything (sections, lists, captions, etc.)
\newcounter{slc}
\setcounter{slc}{5}
\arabic{slc}

- the last line prints the value of slc in your document.

\centred{\rule{9cm}{0.4pt}}
My footskip is \the\footskip

#### Boxes

LaTeX builds up its pages by pushing around boxes. At first, each letter is a little box, which is then glued to other letters to form words. These are again glued to other words, but with special glue, which is elastic so that a series of words can be squeezed or stretched as to exactly fill a line on the page.
Admittedly, this is a very simplistic description of what really happens, but the point is that TeX operates with glue and boxes. Letters are not the only things that can be boxes. One can put virtually everything into a box, including other boxes. Each box will then be handled by LaTeX as if it were a single letter.
TeX characters are stored in boxes like every printed element. Boxes have three dimensional properties:

* The height is the length between the baseline and the top of the box.

• The depth is the length between the baseline and the bottom of the box.
• The width is the width of the box.
LaTeX enables typesetting of hyperlinks, useful when the resulting format is PDF, and the hyperlinks can be followed. It does so using the package hyperref.
\href{mailto:my_address@wikibooks.org}{my\_address@wikibooks.org}

#### Labels and Cross-referencing

If you reference a marker that does not exist, the compilation of the document will be successful but LaTeX will return a warning: LaTeX Warning: There were undefined references. and it will replace “\ref{unknown-marker}” with “??” (so it will be easy to find in the document).
See figure~\ref{fig:test} on page~\pageref{fig:test}.
You could place the label anywhere in the section; however, in order to avoid confusion, it is better to place it immediately after the beginning of the section.

#### The Wikibook

\documentclass[11pt,twoside,a4paper]{article}

\setcounter{secnumdepth}{0} - turns off section numbering.

\setcounter{section}{4} The next section after this command will now be numbered 5.

### Importing Graphics

• \graphicspath caveat: an apostrophe in the directory name made the jpges unfindable on my Win7 netbook.
• graphicx: Enhanced support for graphics - grfguide.pdf
• Jonno_FTW's answer got me started with a document.
there is the svg package which provides an \includesvg command to convert and include svg-graphics directly in your LaTeX document using Inkscape.

#### Intro Guides

Excellent explanations in The Wikibook

After you have loaded the graphicx package in your preamble, you can include images with \includegraphics

### List Structures

\begin{enumerate}[\color{gray}{Point }1:]
\item The main practice, which is training in bodhicitta.
\item[] Absolute Bodhicitta
\end{enumerate}

- the second list item has no label, and doesn't increment the count.

#### the Wikibook

http://en.wikibooks.org/wiki/LaTeX/List_Structures \begin{description}

Alternatively, use the memoir class and with \tightlists.
The thing people want to change most often with Enumerated lists are the counters. A quick solution to this problem is provided by the enumerate package of David Carlisle, or the more sophisticated package enumitem by Javier Bezos.

### Page Layout

• Footnotes don't land in the footer, but are fitted at the base of the text they're called from.
• \pagestyle{empty} to clear header and footer, thus turning off page numbering, from current page onwards.
The package shows a (simple, uncluttered) diagram of the page layout; similar (but more complex-looking) diagrams may be obtained from the layouts and geometry packages. \usepackage{showframe}

#### fancyhdr

\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\footrulewidth}{0} % clear the footer overline
\cfoot{Page \thepage\ } % writing page numbers in a centred footer as "Page n"

#### geometry

From the manual:

• footskip foot modifies \footskip, distance separation between baseline of last line of text and baseline of footer. footskip=<length> or foot=<length>.
• footnotesep changes the dimension \skip\footins, separation between the bottom of text body and the top of footnote text.
• showframe shows visible frames for the text area and page, and the lines for the head and foot on the first page.
% Minimum top margin to see tiny top-right page numbers on Epson Stylus DX7400
\usepackage[left=14mm,top=14mm,bottom=30mm,foot=16mm,right=14mm]{geometry} 

#### verse package

\flagverse{<flag>} inserts <flag> at the left (of a line)

Verses are frequently numbered (so, as an additional note to the first part of Gonzalo Medina's answer) you can find buried in the manual verses.pdf this explanation:
Within the verse environment, the macro \\ must be used at the end of each line of a verse, except for the last line in each stanza. If the lines in a poem are to be numbered then \\! must be used at the end of the last line in each stanza (the \\ macro increments the line numbers).

To grey out numbering: \renewcommand*{\thepoemline}{\textcolor{gray}{\arabic{poemline}}}

#### the Wikibook

\usepackage[a4paper,landscape]{geometry}''.
\documentclass[a4paper,landscape]{article}
The second method is for when you are writing a document in portrait, but you have some contents, like a large diagram or table that would be displayed better on a landscape page. However, you still want the consistency of your headers and footers appearing the same place as the other pages.
The lscape package is for this very purpose. It supplies a landscape environment, and anything inside is basically rotated. No actual page dimensions are changed. This approach is more applicable to books or reports than to typical academic publications. Using pdflscape instead of lscape when generating a PDF document will make the page appear right side up when viewed: the single page that is in landscape format will be rotated, while the rest will be left in portrait orientation.

### Tables

The tabular environment can also be used to place a vertical line left of some text.

#### the Wikibook

it is possible to center a column on the decimal separator using the dcolumn package, which provides a new column specifier for floating point data.
\newcolumntype{d}[1]{D{.}{\cdot}{#1} }
%the argument for d specifies the maximum number of decimal places
Rows spanning multiple columns: The command for this looks like this:
\multicolumn{'num_cols'}{'alignment'}{'contents'}

## \documentclass{...}

• Letters - as in good old snail mail.

### leaflet

#### Usage

Section headings: leaflet-manual.pdf informs that we can renewcommand sectfont, so I figured out:

\renewcommand*{\sectfont}{\huge\bfseries\textcolor{Gray}}

- which works, but makes subsections the same size…

Top of p9 of leaflet.pdf: “The dimensions of a single small page”:

\paperwidth=0.333333334\paperwidth
\setmargins{11mm}{11mm}{8mm}{8mm}

### The Memoir Class

\setsecheadstyle{\color{gray}\Large\bfseries}
• \begin{OnehalfSpace} … \end{OnehalfSpace} works on lines (not paragraphs!
• Memoir is what I'm using for a children's story I'm developing. It allows Parts, Chapters, Sections and so on, with various ready-made styling options. I was compiling my pdf in both A4 & A5, so I wanted a simple way to regularly switch between the two, and @Jubobs gave me a quick solution, based on querying an option that was passed to the memoir class - neat!
• Page styles: Gonzalo Medina's reply to Peteris Krumins' question includes a sample tex document that illustrates.
• \the\parindent reports 17.0pt
• \the\parskip reports “0.0pt plus 1.0pt”
• \setbeforesecskip{-7ex plus -1ex minus -.2ex} doubles the standard spacing before a section

Sectioning: fontspec allowed me to create a new command \arabicsec that just sets the font to Arial, so that I can now:

\setsecheadstyle{\arabicsec\centering\Large} % create a header that can cope with Arabic

#### coded-in equivalent packages

memman.pdf states:

The memoir class includes code either equivalent to, or extensions of, the following packages; that is, the set of commands and environments is at least the same as those in the packages: abstract, appendix, array, booktabs, ccaption, chngcntr, chngpage, dcolumn, delarray, enumerate, epigraph, framed, ifmtarg, ifpdf, index, makeidx, moreverb, needspace, newfile, nextpage, parskip, patchcmd, setspace, shortvrb, showidx, tabularx, titleref, titling, tocbibind, tocloft, verbatim, verse. The class automatically ignores any \usepackage or \RequirePackage related to these. However, if you want to specifically use one of these packages rather than the integrated version then you can do so. For arguments sake, assuming you really want to use the titling package you can do this:
\documentclass[...]{memoir}
\DisemulatePackage{titling}
\usepackage{titling}

setspace equivalents: \begin{OnehalfSpace}, \end{OnehalfSpace}; there's also DoubleSpace.

The verse environment is built in, but without the useful \poemlines` functionality.

#### Peter Wilson's manual

http://texdoc.net/texmf-dist/doc/latex/memoir/memman.pdf is huge! From the Preface:

The memoir class is an attempt to integrate some of the more design-related packages with the LaTeX book class. I chose the book class as the report class is virtually identical to book, except that book does not have an abstract environment while report does; however it is easy to fake an abstract if it is needed. With a little bit of tweaking, book class documents can be made to look just like article class documents, and the memoir class is designed with tweaking very much in mind.
The default type size is 10pt.