Notes on ltxprimer
Source: theltxprimer from Indian TeX group
The basics
Period:
latex assumes each period not following an upper case letter ends a sentence. In traditional typesetting, an extra little space is appended. Sometimes we don’t want this, so:
In order to produce
Carrots are good for your eyes, since they contain Vitamin A. Have you ever seen a rabbit wearing glasses?, the correct input should be Carrots are good for your eyes, since they contain Vitamin A\@. Have you ever seen a rabbit wearing glasses?.
To produce
The numbers 1, 2, 3, etc. are called natural numbers. According to Kronecker, they were made by God; all else being the work of Man., the correct input should be The numbers 1, 2, 3, etc.\ are called natural numbers. According to Kronecker, they were made by God;all else being the works of Man..
Quotes:
To produce “”, input `` and '', or use \lq and \rq instead.
Hyphenation:
- Hyphen (
-): separating compound names. e.g., Munthe-Kaas; - Compound nouns are not hyphenated, but compound adjectives are; e.g., Lie group as opposed to Lie-group method. Compound adjectives that use adverbs are not hyphenated; e.g., “diagonally implicit method” is correct;
--(em-dash): used between two people, e.g., Runge–Kutta;---(en-dash): connects things that are related to each other by distance, as in theMay–September issue of a magazine.
Accents:
Él está aquı́, input \’{E}l est\’{a} aqu\’{\i}.
Some special symbols:
| Symbol | Input |
|---|---|
| ~ | \textasciitilde |
| \ | \textbackslash |
| _ | \ _ |
Fonts
Style (roman, sans serif, etc.), series (medium, boldface, etc.), shape (upright, italic, etc.)
Declaration (\upshape) and command (\textup{}). The declaration can be used as enviroment names.
Optional arguments are inclosed in [], and mandatory arguments are inclosed in ().
Document
Page format
- onecolumn/twocolumn
- oneside/twoside (affects position of page number)
- openany(chapters begin on “any” new page)/openright(chapters begin only on new right , that is, odd numbered, page)
- notitlepage/titlepage (whether to separate title page)
Page style
-
\pagestyle{...},\thispagestyle{...} -
plain/empty/headings/myheadings
-
\pagenumbering{...} -
arabic/roman/Roman/alph/Alph
-
\setcounter{page}{ number }
Forming a document
\andhelps you to put authors parallel- A proper hierarchy:\chapter\section\subsection\subsubsection\paragraph\subparagraph
\subsubsectionis not numbered- A detailed structure, see P24 and 25
- \Par and “\"
Bibliography
- Bib style packages: harvard, natbib
- With
\nocite{*}, every entry in all the databases will be included, something that is useful when producing a list of all entries and their keys. aux: reference auxiliary;bib: original bib;bst: bib style;bblformatted bib;blg: log
Table of contents, index and glossary
-
.toc: table of contents,*.lotlist of tables,*.loflist of figures -
Edit the .toc , lof , lot files and use a \nofiles command to suppress the writing of new versions of the files
is the last resort for you to fine-tune TOC
-
Use
\addtocontents{ file }{ text }or\addcontentsline{ file }{ type }{ text }to add sections marked with*(will be omitted by default) (Actually\addcontentslineis invoked by\sectionorcaption) -
Fragile argument: What is the difference between Fragile and Robust commands
-
minitocfor mini TOC -
makeidxto make index (*.idxfile) -
\makeglossaryto make glossary (*.glofile)
Displayed text
- Quotation
\begin{quote} \end{quote}or (for multiple paragraphs)\begin{quotation} \end{quotation} verseenvironment to quote poem. Use\\*to put it within a page. Use\\[n pt]to specify line space{\renewcommand{\labelitemi}{$\triangleright$}(for example,\labelitemi,\labelitemiv, etc.) to replace default itemize bullets. Use{}to enclose\renewcommandand anything else for local effect only- Package
enumeratefor customized enumerate bullets and other formatting styles \renewcommand{\descriptionlabel}[1]{\hspace{1cm}\textsf{#1}}example to customize descriptionenumeratecan also include description
Rows and columns
-
tabbingenvironment for vertical alignment inenumerate -
Use parbox to format column cells
-
\multicolumn{1}can override the position specification of any column set at the beginning of the environment. -
\arraystretchto stretch columns -
Use
r@{--}lfor range. Example:\begin{center} \begin{tabular}{|c|r@{--}l|} \hline Height & \multicolumn{2}{c|}{Ideal weight}\\ (cm) & \multicolumn{2}{c|}{(kg)}\\ \hline 155 & 53.5 & 64\\ 160 & 56 & 67\\ ............... 190 & 78 & 92.5\\ \hline \end{tabular} \end{center} -
Enhancement:
array,multirow,multicol,longtable,hhline,delarray,tabularxetc.
Mathematics
-
Text placed within
$$is in math italic -
TeX has its own spacing rules in math mode
-
Inline math: in LaTeX:
\( ... \)or\begin{math}\end{math}); in TeX:$$ -
Independent line: in LaTeX:
\[\]or\begin{displaymath}\end{displaymath}, in TeX:$$$$ -
\;: thickspace,\,thinspace -
\ldots: ellipsis (...) -
Binary operator:
\mathbin; relation operator:\mathrelx\Box y % produces x\Boxy x\mathbin\Box y % produces x \Box y -
\newcommand{\vect}[1]{(#1_1,#1_2,\dots,#1_n)}% use \vect{sth}will substitute 1 to sth (2 and #2, 3 and #3… is the same) -
The
amsmathpackage:-
Multi-line equation:
multlineenv; usesplitenv and&for alignment -
Multi equations:
gatherenv pralignenv -
An example: gather two groups of equations together
-
\begin{equation*} \begin{aligned} \cosˆ2x+sinˆ2x & = 1\\ \cosˆ2x-\sinˆ2x & = \cos 2x \end{aligned} \qquad\text{and}\qquad \begin{aligned} \coshˆ2x-\sinhˆ2x & = 1\\ \coshˆ2x+\sinhˆ2x & = \cosh 2x \end{aligned} \end{equation*}
-
-
\tag{}for customized equation label;\notagto suppress -
pmatrixis enclosed in parentheses,bmatrixis in square brackets,Bmatrixis in braces, andvmatrixis for determinant -
\dotscfor dots to be used with commas,\dotsbfor dots with binary operations (or relations), and\dotsmfor multiplication dots. There is also a\dotsifor dots with integrals -
smallmatrixenv for inline matrices (use\left \rightfor appropriate alignment for brackets) -
\bigl, \bigr; \biggl, \biggr; \Biggl, \Biggrto control bracket sizes (if you find using\left \rightproduces too large brackets) -
\tfraca “tiny” version of\frac,\genfracfor a customized frac. Note, binomial coefficients\binomis a special case of\genfrac -
\versetfor putting symbols overhead. e.g.$\overset{\circ}{a}$ -
\displaystylechanges inline expressions to displayed style (as in env). -
\substackfor multi-line subscripts. -
Refer to “Log-like symbols” for math notations that should be typed in Roman (other than usual italic)
-
\DeclareMathOperator*{\new_operator}{statement} -
“The TEX Book”: more on typing math
-
-
\newtheorem{user_difined}{displayed_test}[numbering_style]
, foruserdefined` env -
Customized theorem:
amsthmpackage
Boxes
-
A box is an object that is treated by TEX as a single character. A box cannot be split and broken across lines or pages.
-
3 types of boxes:
- LR: (left-right) The content of this box are typeset from left to right.
- Par: (paragraphs) This kind of box can contain several lines, which will be typeset in paragraph mode just like normal text. Paragraphs are put one on top of the other. Their widths are controlled by a user specified value.
- Rule: A thin or thick line that is often used to separate various logical elements on the output page, such as between table rows and columns and between running titles and the main text.
-
LR boxes:
-
\mbox{ text } % without frame \makebox{ width }{ pos }{ text } % without frame \fbox{ text } % with frame \framebox{ width }{ pos }{ text } % with frame % pos arguments: l for left, r for right, c for center, s for stretch (in-text spaces) -
\fboxrule,\fboxsep, and\raiseboxfor determining frame style, box positions(or rotations)
-
-
Par boxes:
- Use either
\parboxorminipageenv (minipageis a page itself, i.e., it has footnotes, contains tabular, etc.) \parbox{ pos }{ height }{ inner pos }{ width }{ text }or\begin{minipage}{ pos }{ height }{ inner pos }{ width }, witht,b,c,sfor top, bottom, center, stretch
- Use either
-
A rule box is basically a filled-in black rectangle.
-
It is also possible to have a rule box of zero width. This creates an invisible line with the given height. Such a construction is called a strut and is used to force a horizontal box to have a desired height or depth that is different from that of its contents.
Floats
-
Figures:
-
\begin{figure} \includegraphics{figure.eps} \caption{This is an inserted EPS graphic} % use \caption[lof]{description} to produce concise description in list of figures \label{fig1} \end{figure}- Figures are not allowed in boxes (
\parboxorminipage) - Positional arguments: h for here, t for top, b for bottom and p for page containing only floats (default
[tbp]) \clearpage: This command places unprocessed floats and starts a new page.\FloatBarrier: This command causes all unprocessed floats to be processed. This is provided by theplaceinspackage. It does not start a new page, unlike\clearpage.- To place figures within a section:
\usepackage[section]{placeins}, a less-restrictive one:\usepackage[below]{placeins} - The
afterpagepackage provides the \afterpage command which executes a command at the next naturally-ocurring page break. (\afterpage{\clearpage}causes all unprocessed floats to be cleared at the next page break.) - Use float placement counters to control number of floats per page:
\setcounter{totalnumber/topnumber/bottomnumber}{n} - Adjust float coverage per page using
\textfractionetc. - Add graphics search path:
\graphicspath{{dir1/}{dir2/}} \rotateboxand\scaleboxprovided bygraphicxpackage can rotate and boxes and floats
- Figures are not allowed in boxes (
-
tabularis actually aminipage-
The
tabularenv: -
`\begin{ tabular }[ pos ]{ cols } rows \end{ tabular }``
-
``\begin{ tabular* }{ width }[ pos ]{ cols } rows \end{ tabular* }`
-
Column positioning arguments:
cols meaning l left r right c center { wd } The text in this column is set into lines of width wd and the top line is aligned with the other columns. In fact, the text is set in a parbox with the command \parbox[ t ]{ wd }{ column text } . * { num }{ cols } The column format contained in cols is reproduced num times, so that *{3}{|c|}| is the same as |c|c|c| .
-
Cross references
- “cross” means both backward AND forward
- Use
~in your cross reference to avoid breaking lines - In floats,
\labelcommand should be given after the\captioncommand or in its argument \pageref{ key }refer to page number- Package
varioref(\vref{key}) produces “full” reference (position, page number, etc.) using some rules. (producerefand/or\pagerefdepending on the current page) - Use package
xrfor external reference:\usepackage{xr} \externaldocument{ other.tex }
Footnotes, marginpars, and endnotes
- Use
tabularx,longtableor wraptabularinminipageif you want to use footnote inside atabular. Another package calledthreeparttableis also helpful. \setcounter{footnote}{0}for resetting footnote counter (or use\@addtoreset{footnote}{section}in\makeatletteror\makeatotherpreamble)\marginparfor marginal notes. A better version (macro):\newcommand{\marginlabel}[1] {\mbox{}\marginpar{\raggedleft\hspace{0pt}#1}}- Create query for margin notes:
\def\query#1#2{\underline{#1}\marginpar{#2}} - Package
endnotesfor endnotes.