paulgorman.org/technical

Typesetting with LaTeX

(20??, updated 2018)

UPDATE: pdflatex has some limitation, including problems with Unicode input. lualatex is the future. LuaTeX supports Unicode input, uses system font (e.g., TTF or OTF), and offers scripting in Lua. Although LuaTeX works with the familiar LaTeX macro language, it also supports the new ConTeXt macro language.

TeX is a typesetting system. Text files with the file extension ‘.tex’, written in a special markup language, can be processed to produce nicely formatted PDF’s. TeX is the typesetting system, LaTeX is a higher-level set of macros that comprise a lot of what we’ll want to use when manually formatting a document.

Compile the source file ‘mydoc.tex’ like: $ latex mydoc. That generates a bunch of files, including a DVI. For PDF output, run: $ pdflatex mydoc.

Various options exist to output HTML from LaTeX, including tth and latex2html.

Here’s a sample document:

% This a single line comment
\documentclass[12pt,twocolumn,twoside]{book}
% Documentclass could be article, report, or letter.
% An article is similar to a book, but doesn't have
% chapters and is single-sided by default. 

\pagestyle{headings}
\linespread{1.3} % Leading multiplier
\setcounter{secnumdepth}{-1} % Don't number sections

\usepackage{xcolor,graphicx}
\usepackage[bookmarks,colorlinks,linkcolor=blue,pdftex]{hyperref}

% If you need any boxed text:
\usepackage{framed}

\usepackage[bottom]{footmisc} % Keeps footnotes at bottom
\setlength{\footnotesep}{0.4cm} % Space between footnotes
\setlength{\skip\footins}{0.8cm} % Space above footnotes
\interfootnotelinepenalty=10000 % Keep footnotes on same page

% Don't add huge vertical whitespaces:
\raggedbottom

\begin{document}

\title{\bf My Book}
\author{Paul Gorman}
\date{\today}

\frontmatter
\maketitle
\tableofcontents

\mainmatter

\part{Part The First}

\chapter{My First Chapter}

\begin{center}\includegraphics{img/my_image.png}\end{center}

This is the first paragraph of my first chapter. I want to make 
sure that \verb#this bit is printer verbatim# and not 
interpreted by LaTeX. Any character can serve as the delimiter 
except for a space. Larger blocks of verbatim text would be 
specified like:

\begin{verbatim}
Some text here.
\end{verbatm}

\noindent This second paragraph will not be indented. If I'm 
talking about \TeX\ or \LaTeX, those escapes will pretty 
print them. Special characters like dollar signs, ampersands, 
and percentage sighs should be escaped: \$, \%, \&, \#, \{, 
etc. You can force a line break with \newline, and this will 
be on a new line. To force a page break use \newpage. It's 
easy to add footnotes like so.\footnote{My footnote text 
here.}

\marginpar{You can also have margin notes like this.}

\begin{framed}
This is boxed text. Framed also can be 'shaded', 'snugshade', 
or 'leftbar'.
\end{framed}

\section{This is a section of a chapter}

Text can be \underline{underlined} or emph{emphasized}. The 
font characteristics can also be changed to \textit{make it 
italic}, \texttt{make it typewriter/monospaced}, 
\textsf{make it sans-serif}, \textbf{or bold faced}.

This text {\tiny can} {\small be} {\normalsize a} 
{\large variety} {\Large of} {\LARGE different} {\huge sizes}.

\subsection{A subsection of the section}

Note that there can also be subsubsections, paragraphs, and 
subparagraphs.

\begin{quote}
This is a short block quote. There is also a "quotation" 
block, which differs from "quote" in that it indents 
paragraphs. There's also a "verse" one for poetry, which 
preserves line breaks and so forth.
\end{quote}

With the hyperref package in use, you can include clickable 
hyperlinks like \href{http://google.com}{Google}.

\include{include/chapter-x} % Note that the '.tex' is implied.

\part{Part The Second}

To include images/graphics, choose either to include only 
Postscript images (.ps, .eps) or only non-Postscript images 
(.pdf, .png, .jpg, .gif). If you're final output will be a 
PDF (made with pdflatex), you should use non-Postscript images.

Be sure to include '\usepackage{graphicx}' after the documentclass
declaration.

\includegraphics{mypic.pdf}
% Don't include actual image, draft outline box only:
\includegraphics[draft]{anotherpic.png}

\include{include/chapter-y} 

\include{include/chapter-z} 

\end{document}

Here’s a similar document in the ConTeXt macro language.

\starttext

This is the first paragraph.

\starttyping
This  is
verbatim  \ConTeXt.
\stoptyping

\completecontent

\chapter{One}

The first chapter

\chapter{Two}

The second chapter.

\startitemize[n]
\item  First  item.
\item  Second  item.
\stopitemize

\input include/chapter-y

\stoptext