TeX

Table of Contents

1. TeX

\(\rm\TeX\) is first designed and written by Donald Ervin Knuth and released in 1978. Knuth also developed a font format METAFONT and a typeface Computer Modern in METAFONT format for \(\mathrm{\TeX}\).

1.1. Modes

mode description
Horizontal mode paragraph (\(\rm\LaTeX\) Paragraph mode)
Restricted Horizontal mode in a mbox (\(\rm\LaTeX\) LR mode)
Math mode inline math
Display math mode display math
Vertical mode document structure
Internal vertical mode in a vbox

1.2. TeX Control Sequences

  • Control words : escape character + sequence of alphabets
  • Control symbols : escape character + a non-alphabetical symbol

1.2.1. TeX Primitives

  • These are the commands that are not decomposable into simpler ones. e.g. \kern, \input, …
  • \show<\command> to display <\command> in its primitive form.

1.2.2. General

control sequence description
\par new paragraph. \parskip\indent
\indent insert Hspace of \parindent
\noindent cancel the \indent, \hskip-\parindent
\hfil[l] Hglue that stretches (more)
\vfil[l] Vglue that stretches (more)
\(left,center,right)line align a line to the left/center/right
\break break line
\obeylines break lines verbatim
\kern<dimen> set the kerning of current location to <dimen>
\(raise,lower)<dimen> raise or lower the following box by <dimen>
\hang hanging is to indent every line in a paragraph except the first one
\hangindent[=]<dimen> set indentation of hanging text
\hangafter[=]<number> hang strictly after line number <number>, but if negative, hang before and including line number <number>
\parshape=<number>*(1+2<number>) set <number> lines to have each indentation and length
\relax stop absorbing tokens
\eject end current page
\end enter endgame routine
\bye \vfill\eject\end
\hrule width <dimen> Hrule width width <dimen>
\item indent as an item
\bull insert a bullet
~ a non breaking space
\(begin,end)display begin and end a display text
{ } \(begin,end)group begin and end a group
\penalty<number> extra badness if break at current location
\hbadness=<number> threshold for how badly a line is spread out or shrinked down, defaults to 1000. \(\rm{\TeX}\) breaks line by minimizing badness
\tolerance=<number> overfull boxes are not reported up to the badness of tolerance.
\hfuzz=<dimen> threshold to be considered overfull, defaults to 0.1pt
\raggedright don't align right side of the lines
\def<sequence>{<definition>} define a sequence

1.2.3. Boxes

control sequence description
\hbox{#1} a box that arranges #1 horizontally, with width <dim> or <dim> more than its natural width, every line is a \hbox
\vbox [(to,spread)<dim>]{#1} a box that arranges #1 vertically, with height <dim> or <dim> more than its natural height
\smash{#1} renders #1 normally, but treat it like it has height and depth of zero, even lowering and raising won't affect anything
\phantom{#1} make a blank box of size #1
\vphantom{#1} make a blank box of height and depth of #1, and width zero
\setbox<number>=#1 set \box<number> register to #1, which can be logged by \showbox<number>
\line{#1} a line box, \hbox to \hsize{#1}

It is similar to the tranditional way of typesetting:

  1. Choose types from type cases (uppercase and lowercase) and stack them in a composing stick.
  2. Adjust the spacing.
  3. Transfer to chase where stacks multiple lines.
  4. Lock the spacing with wedges called quoin.

1.2.4. Lengths

control sequence description
\newlength{#1} define a new length
\setlength{#1}{#2} set the value of the length
\addtolength{#1}{#2} increment the value of the length
\settowidth{#1}{#2} \settoheight{#1}{#2} \settodepth{#1}{#2} set the length to the width/height/depth of the text
control sequence description
\textwidth the width of the body of a page
\textheight the height of the body of a page
\parskip extra vertical space between paragraphs, default is 0
\parindent indentation at the beginning of a normal paragraph
\baselineskip vertical distance between baselines within a paragraph

1.2.5. Skips and Glues

  • A glue <glue> is defined as <dimen> plus<dimen> minus<dimen> where plus<dimen> defines the stretchability and minus<dimen> defines shrinkability.
  • A dimension <dimen> is <number><unit> where <unit> can be fractional units: fil, fill, filll
control sequence description
\(small,med,big)skip insert Vspace
\vskip<glue> insert Vspace of <glue>
\hskip<glue> insert Hspace of <glue>
\baselineskip=<glue> distance between baselines
\lineskip=<glue> distance between line boxes if \baselineskip shrinked to the point \lineskip is less than \lineskiplimit
\topskip=<dimen1> plus<dimen2> distance form the top of a page to the first baseline, if the height of the first line is greater than <dimen1> just skip by <dimen2>
\vss Vglue shrinkable and stretchable
\hss Hglue shrinkable and stretchable
\thinspace insert a thin Hspace for spacing quotation marks

1.2.6. Fonts

  • A font command changes the current font, so that the text after it appears as this font. To specify the scope of this command, use with braces: {\rm text}.
control sequence description
\rm Roman font
\it italic
\bf boldface
\sl slanted
\tt code
  • \<number in english><font> changes current font to \<font> with the size of <number in english>, for example, \tenrm, while \<number in english>point only changes the fontsize.
  • \font<\font>=<common fontname> [at <dimen>, scaled <1000*scale>] = sets =\<font> to be the command for said font. \<number in english><font>=<common fontname> is also possible. One can use \magstep(0,half,1,2,...,5) instead of <1000*scale>, where \magstepN is equal to \(1000\cdot 1.2^{N}\). Magnification can also set by \magnification=<1000*scale>, in such case the total magnification will be the product of the two.
  • \/ for italic correction. A Little space after italics.

1.2.7. Special Characters

control sequence description
\" \(\text{\"a}\)
\' \(\text{\'a}\)
<code>\=</code> \(\text{\=a}\)
\frac#1/#2 ½
   

1.3. Math Mode

1.3.1. General

control sequence symbol description
#1 \over #2 \(\displaystyle {a\over b}\)  
#1 \atop #2 \(\displaystyle {a\atop b}\)  
#1 \choose #2 \(\displaystyle {a \choose b}\)  
#1 \above<dimen> #2 \(\displaystyle {a \above2pt b}\)  
\limits \nolimits \(\sum\limits_{k=0}^n\ \displaystyle\sum\nolimits_{k=0}^{n}\) Must come after a \mathop{#1}

1.3.2. Styles

control sequence symbol description
\displaystyle \(\displaystyle A\) Default in display math mode
\textstyle \(\textstyle A\) Default in math mode
\scriptstyle \(\scriptstyle A\) Default for the super- and subscripts
\scriptscriptstyle \(\scriptscriptstyle A\)  

1.4. Compilation Process

The Knuth's TeX is considered here.

  • {} is a empty thing. \relax does nothing.
  • Keys are defined within a scope, so that it can be used as options. A key can do most of the things.

1.4.1. Decoding

  • \( \rm \TeX \) convert the text to internal code.

1.4.2. Tokenization

  • Individual characters are tokenized with their category codes attached.
  • The spaces after a control sequence are discarded.
  • \string<token> convert the command token back into the character tokens
  • \csname<tokens>\endcsname create a command token with character tokens, where the <tokens> should expand into characters.
  • Control code ^^<char> can be used to specify the ASCII control characters, as characters.
  • #₆<token> is parsed into a single token with no category code, that represents a paramter.
    • ## becomes #₆ token that can again be used to construct recursive definition of macro.
1.4.2.1. Category Codes

The non-unicode TeX only recognizes 256 characters that are categorized into the followings.

Category Code Meaning Attached Character by Default
0 Escape character \
1 Beginning of group {
2 End of Group }
3 Math shift $
4 Alignment tab &
5 End of line <return>
6 Parameters #
7 Superscript ^
8 Subscript _
9 Ignored character <null>
10 Space
11 Letter alphabets
12 Other character numbers and others
13 Active character ~
14 Comment character %
15 Invalid character <delete>
  • TeX primitive \catcode[<decimal ascii code>|'<octal>|"<hexadecimal>|`<char>]=<catcode> to set the category code henceforth
    • `<char> is likely to be taking the character code of the <char>
1.4.2.2. TeX Tokens

The exact token value varies depending on the implementation.

  • Character Token: 256 * category code + character (ASCII) code
  • Command Token: curcs (current control sequence) + 4095 (256 * 16 - 1)
    • Control Word: curcs = hash(character codes)
      • Escape character + sequence of character with category code 11.
    • Control Symbol: curcs = character code + 256 + 1
      • Escape character + a character with category code other than 11.
    • Active Character: curcs = character coide + 1

The original string of the control sequence is stored during the hashing process into the string pool in order to provide the human readable name on debugging or \string.

1.4.2.3. Command Code

The cursc is used to look up for command code and modifier in the equivalents table in which the eq_level the level of grouping, eq_type the command code, and equiv the command modifier are stored.

  • The command code specifies the functionality group of commands and modifier then specifies the exact command.
    • Type 1 modifier is an index of the command
    • Type 2 modifier is an memory address for the macro definition, and more.
  • The command code and modifier for current command is stored in the variable curcmd and curchr.
command command code command modifier
\box 20  
\hbox 20  
\vbox 20  
\vtop 20  
\def 97 0
\gdef 97 1
\edef 97 2
\xdef 97 3
Macro 111 memory address
Long Macro 112 memory address
Outer Macro 113 memory address
Long Outer Macro 114 memory address
  • Non-expandable Command: Command codes less than or equal to 100
  • Expandable Command: Command code greater than 100
    • e.g. macros, \csname, \expandafter, \the
1.4.2.4. Token List

Token list is created typically when a macro is defined.

  • Token list can also be explicitly created in register N:
    • \toksdef<command token>=N and <command token>={<tokens>}
    • \toksN={<tokens>}

1.4.3. Processing

The tokens are then manipulated. The tokens can come from three source: text file, standard input, and token list.

  • \expandafter expand the second next token
  • \noexpand to not expand the next token
1.4.3.1. Definition
  • Macro
    • \def<cs><parameters>{<replacement>} the braces are not used for grouping.
    • \long\def to include \par as part of parameter
    • \outer\def to prevent the usage within other macros, mostly due to the category code pollution.
    • \global\def to define the macro globally, as the macro is group scoped by default.
  • Character
    • \chardef<cs>=<character code> define the <cs> to represent the character.
    • \mathchardef<cs>="kfab where k is the atom type, f is the math group (font family), ab is the slot in the font.
      • "kfab is called the math code of the math character.
      • Escape is needed for \mathcode`\<char>

1.5. CLI

  • -shell-escape to run shell commands internally.

2. LaTeX

2.1. Control Sequences

2.1.1. Documentclass

  • article
  • standalone
    • convert={<options>}
      • the default is density=300,noresize,outext.png
      • This uses the convert from imagemagick
      • -shell-escape option must be given for the LaTeX to run the conversion.

2.1.2. Paragraph Mode

2.1.2.1. Boxes
  • \parbox[pos][height][contentpos]{width}{text} sets the position of a paragraph
  • \makebox[width][pos]{text} controls the underlying width. \mbox{text} for short.
  • \framebox[width][pos]{text} frames the box. \fbox{text} for short.
2.1.2.2. Colors
  • \color{<color>}
    • Package: color, xcolor
    • Set global color.
  • \textcolor{<color>}{<text>}

2.1.3. Math Mode

2.1.3.1. General
control sequence symbol description
\frac#1#2 \frac{#1}{#2} \(\frac12\) Only take one character with no braces
\tfrac#1#2 \tfrac{#1}{#2} \(\tfrac12\) Apply textstyle
\dfrac#1#2 \dfrac{#1}{#2} \(\dfrac12\) Apply displaystyle
\mod{#1} \(\mod{n}\) It is spaced in front
\pmod{#1} \(\pmod{n}\)
\stackrel{#1}{#2} \(\stackrel{\rm def}{=}\) #2 is spaced with mathrel
\overset{#1}{#2} \(\overset{.}{,}\) No spacing modification
\underset{#1}{#2} \(\underset{L}{=}\)
\tag{#1} \(\dots\quad \text{(tag)}\) Only works in display mode
\cancel{#1} \(\cancel{a}b = \cancel{a}c\)  
\cancelto{#1}{#2} \(a\hskip-10pt\nearrow^0\) Package: cancel, #2 to #1
\centernot \(\not\phantom{0}\hskip-16.5pt\implies\) Package: centernot
Group: array \(\begin{array}{cc} 1& 0\\0&1 \end{array}\)  
Group: matrix \(\begin{matrix} 1& 0 \\ 0 & 1 \end{matrix}\)  
Group: pmatrix \(\begin{pmatrix} 1& 0 \\ 0 & 1 \end{pmatrix}\)  
Group: bmatrix \(\begin{bmatrix} 1& 0 \\ 0 & 1 \end{bmatrix}\)  
Group: vmatrix \(\begin{vmatrix} 1& 0\\0&1 \end{vmatrix}\)  
Group: smallmatrix \(\begin{smallmatrix} 1& 0 \\ 0 & 1 \end{smallmatrix}\)  
2.1.3.2. Symbols
control sequence symbol description
\mathrm{#1} \(\mathrm{A}\)  
\mathbf{#1} \(\mathbf{A}\)  
\boldsymbol{#1} \(\boldsymbol{\alpha\beta}\) Package: amsbsy
\pmb{#1} \(\pmb{\alpha\beta}\) Package: amsbsy, keeps the width
\bm{#1} \(\bm{\alpha\beta}\) Package: bm, less width than \boldsymbol, recommended
\mathbb{#1} \(\mathbb{A}\)  
\mathcal{#1} \(\mathcal{A}\)  
\mathfrak{#1} \(\mathfrak{A}\)  
\mathsf{#1} \(\mathsf{A}\)  
\sim \(\sim\)  
\simeq \(\simeq\)  
\approx \(\approx\)  
\cong \(\cong\)  
\equiv \(\equiv\)  
\vcentcolon \(\vcentcolon\) For use in \(\vcentcolon=\)
\ll, \gg \(\ll\), \(\gg\)  
\lesssim, \gtrsim \(\lesssim\), \(\gtrsim\)  
\prec, \succ \(\prec\), \(\succ\)  
\asymp \(\asymp\)  
\smile, \frown \(\smile\), \(\frown\)  
\propto \(\propto\)  
\div \(\div\)  
\ast * \(\ast\)  
\star \(\star\)  
\bullet \(\bullet\)  
\circ \(\circ\)  
\triangleleft \(\triangleleft\)  
\rtimes, \ltimes \(\rtimes\), \(\ltimes\)  
\vartriangle \(\vartriangle\)  
\dagger \(\dagger\)  
\infty \(\infty\)  
\varnothing \(\varnothing\)  
\emptyset \(\emptyset\)  
\forall \(\forall\)  
\exists \(\exists\)  
\in \(\in\)  
\ni \(\ni\)  
\subset{eq} \(\subset\), \(\subseteq\)  
\supset{eq} \(\supset\), \(\supseteq\)  
\sqsubset{eq} \(\sqsubset\), \(\sqsubseteq\)  
\cup \(\cup\)  
\cap \(\cap\)  
\setminus \(\setminus\) Spaced more than \backslash
\mid \(\mid\) Spaced more than \vert
\nmid \(\nmid\)  
\iff \(\iff\)  
\implies \(\implies\)  
\land \wedge \(\land\)  
\lor \vee \(\lor\)  
\lnot \neg \(\lnot\)  
\vdash \(\vdash\)  
\vDash \models \(\vDash\)  
\to \rightarrow \(\to\)  
\xrightarrow{#1} \(\xrightarrow{\tiny \mathsf{B}}\)  
\twoheadrightarrow \(\twoheadrightarrow\) surjection, projection
\rightarrowtail \(\rightarrowtail\) injection
\hookrightarrow \(\hookrightarrow\) inclusion
\twoheadrightarrowtail \(\rightarrowtail\kern-10pt\twoheadrightarrow\) Package: stix
\rightrightarrows \(\rightrightarrows\)  
\rightharpoonup \(\rightharpoonup\)  
\leftrightharpoons \(\leftrightharpoons\)  
\Rightarrow \(\Rightarrow\)  
\nRightarrow \(\nRightarrow\)  
\leadsto \rightsquigarrow \(\leadsto\)  
\vec{#1} \(\vec{A}\)  
\overrightarrow{#1} \(\overrightarrow{AB}\)  
\bar{#1} \(\bar{A}\)  
\overline{#1} \(\overline{AB}\)  
\underline{#1} \(\underline{AB}\)  
\hat{#1} \(\hat{A}\)  
\widehat{#1} \(\widehat{AB}\)  
\check{#1} \(\check{A}\)  
\widecheck{#1} \(\widecheck{A}\)  
\dot{#1} \(\dot{A}\)  
\ddot{#1} \(\ddot{A}\)  
\vert \(\vert\)  
\Vert \⎸ \(\Vert\)  
\sum \(\sum\)  
\prod \(\prod\)  
\coprod \(\coprod\)  
\bigcup \(\bigcup\)  
\bigcap \(\bigcap\)  
\bigsqcup \(\bigsqcup\)  
\bigoplus \(\bigoplus\)  
\bigotimes \(\bigotimes\)  
\weierp \(\weierp\)  
\varphi \(\varphi\)  
\varepsilon \(\varepsilon\)  
\vartheta \(\vartheta\)  
\varsigma \(\varsigma\)  
\varrho \(\varrho\)  
\varpi \(\varpi\)  
\Box \(\Box\)  
\square \(\square\)  
\triangle \(\triangle\)  
\triangledown \(\triangledown\)  
  • D'Alembertian
% Preamble
\usepackage{amsmath,amssymb}

\makeatletter
\newcommand{\dalembertian}{\mathop{\mathpalette\dalembertian@\relax}}
\newcommand{\dalembertian@}[2]{%
  \begingroup
  \sbox\z@{$\m@th#1\square$}%
  \dimen0=\fontdimen8
    \ifx#1\displaystyle\textfont\else
    \ifx#1\textstyle\textfont\else
    \ifx#1\scriptstyle\scriptfont\else
    \scriptscriptfont\fi\fi\fi3
  \makebox[\wd\z@]{%
    \hbox to \ht\z@{%
      \vrule width \dimen0
      \kern-\dimen0
      \vbox to \ht\z@{
        \hrule height \dimen0 width \ht\z@
        \vss
        \hrule height 2\dimen0
      }%
      \kern-2.5\dimen0
      \vrule width 2.5\dimen0
    }%
  }%
  \endgroup
}
\makeatother
2.1.3.3. Spacing
control sequence description
\! space of -3mu
= = no space
\, space of 3mu
\: space of 4mu
\; space of 5mu
=\ = normal space
\quad space of 18mu
\qquad space of 36mu
2.1.3.3.1. Spacing of Symbols
  • Eight types of atoms
    • Ord: \mathord{#1}
    • Op: \mathop{#1}
    • Bin: \mathbin{#1}
    • Rel: \mathrel{#1}
    • Open
    • Close
    • Punct: \mathpunct{#1}
    • Inner
  • Operators are a little bit spaced from others, and sets subscript and superscript below and above the argument.
  • Binary operators(\(+,-,\times, \dots\)) use \medmuskip.
  • Relational operators(\(<,>,=,\dots\)) use \thickmuskip.
  • \mathop{#1}
    • It makes its argument a little bit spaced from others, and sets subscript and superscript below and above the argument.
  • \operatorname{#1}
    • Typesets the argument to the style of an operator with mathrm.
    • \operatorname*{#1} will underset and overset when in display mode.
  • The full matrix of spacing is specified in The TeXbook.[1]
2.1.3.4. Others
control sequence symbol description
\overbrace{#1}^{#2}, \underbrace{#1}_{#2} \(\overbrace{a\times a\times \cdots \times a}^{n\text{ times}}\)  
\overbracket{#1}^{#2}, \underbracket{#1}_{#2} \(\underbracket{\nabla \times \nabla \mathbf{F}}_{0}\) Package: mathtools, or stix

2.1.4. Environments

  • The variables within the namespace of the environments becomes available?
    • e.g. ENVIRONMENT/NAME
2.1.4.1. figure
  • Options:
    • h: Here. Approximately where it occurs in the source.
    • t: Top. At the top of the page.
    • b: Bottom. At the bottom of the page.
    • p: Page. On an isolated page.
    • !: Override internal parameters.
    • H: Here. Precisely where it occurs in the source. Somewhat equivalent to h!.
      • Provided by the float package.
  • Content
  • Environment: subfigure
    • Content
    • \caption
    • \label
  • \caption
  • \label
2.1.4.2. table
  • \multirow{n}{width}{text}
    • set width to * for the natural width
  • \multicolumn{n}{format}{text}

- =format is same as for the tabular

2.1.5. Math Environment

2.2. Packages

2.2.1. tikz

  • PStricks only generates PostScript, but TikZ works both on PostScript and PDF.
2.2.1.1. Commands
  • \coordinate (<name>) at <coord>;
  • \draw[<options>] <coord> <pathop> {<pathop> ..};: Make strokes.
    • Options
      • ->: Arrow tip
      • red, blue, orange, …
      • thick, very thick
      • dashed
  • \fill[<color>, <options>] ...;
  • \filldraw[fill=<color>, draw=<color>, <options>] ...;
  • \shade[<options>] ...;
    • top color=<color>, bottom color=<color>
    • left color=<color>, right color=<color>
    • inner color=<color>, outer color=<color>
    • ball color=<color>
  • \node (<name>) at <coord> [<options>]{<text>}; <coord> node[<options>] (<name>) {<text>}
    • [<options>] and (<name>) can be omitted.
2.2.1.2. Coordinate Specification
  • (<xdim>, <ydim>)
    • When the unit is not given it is assumed to be cm.
  • (<and>:<rdim>)
    • Polar form
  • (<name>)

    • Center of the node, or its anchors. Anchors are defined by

    the node itself.

    • Anchors
      • left center right up down
      • north east north eastn e s w
        • It is not a relative direction, the anchor is defined by

    the component.

    • <angle>
      • The angle as in the polar coordinate
    • e.g. C, C.in
  • +<coord> is relative position to the previous specified point.
  • ++<coord> is also relative position but it sets the current point the new specified point.
  • Mathematical expression can be within the coordinates: (1,{tan(30)}).

    • Note that braces are necessary whenever the expression

    contains paranthesis.

  • (<p> |- <q>)

    • <p> and <q> are <name> or the <xdim>,<ydim> and

    such.

    • <p> can also be calculated using calc: {$(A)!.5!(B)$}
2.2.1.3. Path Operations
  • -- <coord>: Straight line
    • -- cycle: Close the loop.
  • circle[radius=<dim>]
  • ellipse[x radius=<dim>, y radius=<dim>]
  • rectangle <coord>
  • [step=<dim>] grid <coord>
  • arc[start angle=<ang>, end angle=<ang>, radius=<dim>]
  • .. controls <coord> and <coord> ..
  • node <at <coord>> [<options>] {<text>}

    • anchor: Position of the path the node is attached to.
      • north south east west
      • center: Center the boxes.
      • base: Center the baseline.
      • mid: Center the half-x-height.
    • above below left right: Position of the node with

    respect to the path.

    • pos=<fraction>: Place node within of a path.
      • midway: Same as pos=0.5.
    • auto=<direction>: The position is automatically

    calculated.

    • swap: Reverse left and right in automatic placement.
    • sloped: The node rotate to match the tangent line of the

    path.

  • plot[<options>]

    • coordinates {<coord>, ..}
    • file {<filename>}
      • The file needs to be separated by spaces and newlines.

    Gnuplot set table produces this.

    • <coordinate expression>
      • (\x, {sin(\x r)})
      • It can contain variables and mathematical expressions.
      • Variable \x is provided by default.
      • /tikz/variable=<macro> /tikz/samples=<num>,

    /tikz/domain=<start>:<end>, /tikz/samples at=<sample list>

    • /tikz/smooth: Use Bezier curve to interpolate points.
2.2.1.4. Configurations
  • \tikz[<options>], \begin{tikzpicture}[<options>] ... \end{tikzpicture}
    • The TikZ command
    • color=<color>
      • It sets the color of the text and draw.
  • \tikzset{options}

    • The name is checked in order: <key>, /tikz/<key>,

    /pgf/<key>, color=<key>, arrows=<key>, shape=<key>, error.

    • With few exceptions?
    • <name>/.style={<options>}

    <name>/.append style={<options>}: Set styles for specific elements

    • Curly braces can be omitted for a single option.
  • scope Environment

    • Apply the option set by \tikzset to every objects within

    the environment: \begin{scope}[<options>] ... \end{scope}.

2.2.1.5. TikZ Library

\usetikzlibrary{<library>} for TikZ, or \usepgflibrary{<library>} for pgf

  • decorations Set the decoration globally and use it with decorate local option
    • decorations.pathmorphing
      • straight zigzag, random steps, saw, zigzag, bent, bump, coil, snake
    • decorations.pathreplacing
      • border, brace, expanding wave, ticks
    • decorations.markings
      • markings
        • mark connection node = <node name> (the node is defined by mark)
        • mark = at position <pos> with <code>
        • mark = between positions <start pos> and <end pos> step <stepping> with <code>
    • decorations.footprints
    • decorations.shapes
      • crosses, triangles
      • shape width, shape height, shape size, shape, anchor, shape sep, …
    • decorations.text
      • text along path
        • text, text color, text align
        • text effects
          • every word, word separator, …
    • decorations.fractals
2.2.1.5.1. intersections
  • Create invisible paths with \path[name path=<name>] ... ;.
  • The intersection point can be referenced with \draw[name intersections={of=<name> and <name>, by=<coord name>}] .. (<coord name>) .. ;.
2.2.1.5.2. angle
  • pic[draw=<color>, fill=<color>, <options>, angle eccentricity=<num>, angle radius=<dim>, "$\alpha$"] {angle = <name>--<name>--<name>}

    • It is one of the path operation.
    • The <name> are in the anticlockwise order.
    • angle eccentricity controls the position of the label,

    as the multiple of the angle radius.

    • The unit of the angle radius must be provided.
    • Pic Type: right angle is also possible.
2.2.1.5.3. quotes
  • Add labels and pins directly in the options.
  • "<text>"<options>
    • Internally equivalent to the node option label={[<options>]<text>} (or pin={[<options>]<text>}).
  • Global Option: quotes mean label quotes mean pin.
2.2.1.5.4. calc
  • ([<options>]$<coordinate computation>$)
  • Coordinate computation is in the form <factor>*<coord><modifier> {+|- <coordinate computation>}.
2.2.1.5.4.1. Modifiers
  • !<num>!<angle>:<coord>: Partway modifier
  • !<dim>!<angle>:<coord>: Distance modifier
2.2.1.5.5. through
  • Node Option: circle through={<coord>}
2.2.1.5.6. topaths
  • Autoload by TikZ
  • <coord> to[<options>] <coord>

    • line to
    • move to
    • curve to: The default behavior
      • out=<ang>
      • in=<ang>
      • relative: The angle is measured relative to the line

    being drawn. The default is absolute.

    • bend left bend right
    • It is mostly likely the cubic Bezier.
    • looseness=<num>
    • loop: Return to the same point.
  • pgfmanual 836p.
2.2.1.5.7. circuits
  • .ee .logic
    • .IEC .US
  • Keys are defined that can be used for to[<options>] or node[<options>], and any others.
  • /tikz/resistor

2.2.2. circuitikz

  • Draw circuits in tikz.
  • It is a special tikz environment.
2.2.2.1. Configurations
  • \usepackage[<options>]{circuitikz} \begin{circuitikz}[<options>]
    • american european
    • siunitx
      • Label with units
        • e.g. 1<\kilo\ohm>, $\SI{1}{\kilo\ohm}$
    • voltage dir
      • voltage dir=RP RPvoltages
        • Rising Potential Voltages
        • The manual itself is typeset with this.
      • voltage dir=EF EFvoltages
        • Electric Field Voltages
      • voltage dir=old oldvoltagedirection
      • voltage dir=noold nooldvoltagedirection
      • See the manual p. 196.
  • \ctikzset{<options>}
    • Both global and local command
    • logic ports=ieee: ieeestd version of the logic gates.
      • american european ieeestd versions exists
    • logic ports/fill=<color>
2.2.2.2. Path-Style Components
  • <coord> to[<name>=<label>, <options>] <coord>
  • Name
    • short
    • resistor or R
      • R=$R_1$ to label it.
    • rmeter: Unspecified Meter
      • t=A to add a symbol in the middle.
  • Options

    • o- *- o-o o-* *-*
    • l_=<label> l2_=<line1> and <line2>
      • =_=(right, down), or =^=(left, up) to control which side

    the label lies.

    • l2 valign={l|c|r} l2 halign={b|c|t}
    • a a2 annotation, in addition to the label
2.2.2.3. Node-Style Components
  • and port or port nand port nor port xor port not port buffer port

    • Anchors
      • in 1 in 2 bin 1 bin 2 out bout body left

    body right

    • b is for body, while it is the outermost parts without

    b or body.

    • Options
      • fill
  • dipchip Dual-in-Line Package chip pin N, bpin N is the anchor name.
    • num pins=NUM
    • hide numbers
    • external pins width=N
  • circleinv the inversion circle for a chip pin.
  • seven segment
    • val=1 it can be alphanumerical character and few symbols.
    • bits=0110011 set each segment from a(the top) to g(the middle).
    • dot on/off the decimal point
    • box on/off the bounding box
  • op amp
    • Anchors: +, -, up, down, out

2.2.3. tikz-cd

  • Draw commutative diagrams in tikz.
  • tikzcd Environment

    • Options
      • diagrams={<options>}
      • cells={<options>}
        • shape=<shape>
      • column sep=<size>, row sep=<size>
        • small, tiny, <dimen>?
    • &, \\ to separate nodes.
      • |[alias=<name>]| before the label
    • \arrow[<options>]{<direction>}<labels> ( where

    <labels> : [<label options>]{<label text>}<labels>=) is also allowed.

    • Options
      • r, l, d, u, …, dll, …
      • <color>
      • {from | to}={<direction> | <row number>-<column number>}
      • "<label>"{name=<name>, <pos>} {<color>} {near start | near end} {marking | description}
      • hook dashed two heads
      • crossing over
      • shift {left=<dimen> | right=<dimen>}

    {x|y}shift=<dimen>

    • bend {left=<num>|right=<num>}
    • {start|end} anchor={[<options>]}
    • phantom
    • shorten
    • controls={<coord> and <coord>} to path=<tikz path>
    • loop <direction>

2.2.4. tkz-base

2.2.5. tkz-euclide

  • {} is for the symbol being defined
  • () is for the arguments
  • [] is for options
2.2.5.1. Calculation
  • tkzPointResult, or tkzPointFirstResult and tkzPointSecondResult refers to the returned points of some macro. \tkzGetPoint{<ref>}, \tkzGetPoints{<ref1>}{<ref2>}, or \tkzGetFirstPoint{<ref1>} and \tkzGetSecondPoint{<ref2>} are used to store them.
  • Point
    • \tkzDefPoint[<options>](<x,y>){<ref>} or (<a:d>){<ref>} Define a point
      • The reference can contain subscript using _
      • \tkzDefShiftPoint[<point>](<x,y>){<ref>} or (<a:d>){<ref>}
      • \tkzDefPoint[<options>]{<x1/y1/n1,x2/y2/n2,...>}
    • \tkzDefMidPoint(<pt1,pt2>) -> pt
    • \tkzDefBarycentricPoint(<pt1=a1,pt2=a2,...>) -> pt
    • \tkzInterLL(<A,B>)(<C,D>) -> pt intersection of two lines
    • \tkzInterLC[<options>](<A,B>)(<O,C>) or (<O,r>) or (O,C,D) -> pt1,pt2 intersection of line and circle
      • N, R, with nodes respectively
    • \tkzInterCC[<options>](<O,A>)(<O',A'>) or (<O,r>)(<O',r'>) or (<O,A,B>)(<O',C,D>) -> pt1,pt2 intersection of two circles
  • Circle
    • \tkzDefCircle[<options>](<A,B>) or (<A,B,C>)
      • R center and radius, diameter two points on diameter, circum triangle, in triangle, ex triangle, …
2.2.5.2. Drawing
  • Point
    • \tkzDrawPoint[<options>](<name>)
    • \tkzDrawPoints[<options>](<list>)
  • Line
    • \tkzDrawLine[<options>](<pt1,pt2>) \tkzDrawLines[<options>](<pt1,pt2 pt3,pt4 ...>)
    • \tkzDrawSegment[<options>](<pt1,pt2>) \tkzDrawSegments[<options>](<pt1,pt2 pt3,pt4 ...>)
    • \tkzDrawPolygon[<options>](<pt list>)
  • Circle
    • \tkzDrawCircle[<options>](<A,B>) \tkzDrawCircles[<options>](<A,B C,D ...>)

2.2.6. pgfplots

2.2.7. chemfig

TikZ based

  • Use chemfig since others are not great, especially XyMTeX is not maintained since 2013. There's also the professional software ChemDraw.
  • \chemfig[<options>]{<formula>}
2.2.7.1. Formula
  • X-X
  • Bonds
    • -, =, ~, >, <, >:, <:, <|, >|
    • *N(<formula>)
  • Positions
    • [n] multiple of angle-increment [:<ang>] absolute
    • [::<ang>] relative
    • [<ang>, <pathmorphing>, <start atom>, <end atorm>, <tikz code>]
  • Nests
    • (<formula>)
    • ?[<name>, <bond>, <tikz>] hooks

2.2.8. graphicx

  • Part of the graphics bundle. See texdoc graphics.
  • \includegraphics[<options>]{<file>}

    • *: Add clip to the options. (for graphicx package)
    • trim=<left> <bottom> <right> <top>: adjust the boundary of the image used for the layout.
    • clip actually discard the images outside the boundary.
    • The margin may be surrounded by the braces.
      • angle=<degree>: Rotate, Set origin to set the origin of

    rotation.

    • width, height
    • scale=<factor>
    • clip

2.2.9. siunitx

  • \qty{<num>}{<unit>}
    • 1.0e10
    • 1.0\pm 0.5
  • \num{<num>}
  • \unit{<unit>}
  • \qtyrange{<start num>}{<end num>}{<unit>}
  • \numrange{<start num>}{<end num>}
  • \SI{<num>}{<unit>} is deprecated.
  • In case of the conflict with physics package, include the following.
    • latex \AtBeginDocument{\RenewCommandCopy\qty\SI}

2.2.10. tipa

2.2.11. physics

2.2.11.1. Brakets
  • \qty(), \pqty{ }, \bqty{ }, \vqty{ }, \Bqty{ }
  • \abs{a}, \norm{a}, \eval{x}_a^b
2.2.11.2. Vectors
  • \vb{a} \vectorbold{a} \(\mathbf{a}\), \va{a} \vectorarrow{a} \(\vec{a}\), \vu{a} \vectorunit{a} \(\mathbf{\hat{a}}\). * for italic/Greek.
  • \vdot, \cross
2.2.11.3. Calculus
  • \div, \grad, \curl \laplacian
  • \dd[N]{x}, \dv[N]{f}{x}, \pdv[N]{f}{x}
2.2.11.4. Matrices
  • \mqty(<table>), \smqty(<table>), \mdet{<table>}, \smdet{<table>},
  • \imat{N}, \zmat{N}{M}, \dmat[<fill>]{<diagonal entries>}, \admat{<diagonal entries>}
  • \pmat{n}: n-th Pauli matrix, \(n\in \{0,1,2,3, x, y, z\}\).
  • Alternatively, physics2
  • boldsymbol with unicode-math, no \qty clash, clean modular code.
2.2.11.5. Modules
  • \usephysicsmodule{<module>}

2.2.12. Algorithm

2.2.12.1. algorithm

It provides the float wrapper algorithm.

2.2.12.2. algorithmicx

It is an extensible version of the legacy algorithmic package, which defines the tools for writing algorithms and the algorithmic environment.

2.2.12.2.1. algpseudocode

A algorithm style of the algorithmicx package.

It can be used by itself, implicitly including the algorithmicx.

2.2.12.2.2. algxpar

Extended style of the algpseudocode.

It supports multiline and many options for the commands.

2.2.12.2.3. algcompatible

The style of algorithmicx that is compatible with the legacy algorithmic style.

2.2.12.3. algpseudocodex

Separate package that also provides the algorithmic environment in which the algpseudocode style is used.

It has better guideline setting, boxing and multiline support.

2.2.12.4. algorithm2e

Algorithm package with different syntax from algorithmic. It defines the algorithm environment.

2.2.13. arabtex

  • arabxetex, arabluatex
  • \RL, \begin{RLtext} ... \end{RLtext}

2.2.14. Musical Notation

2.2.15. wrapfig

  • \begin{wrapfigure}[number of narrow lines]{placement}[overhang]{width} ... \end{wrapfigure}
    • lineheight:
    • placement: r l i o right, left, inside, outside exactly; R, L, I, O
    • overhang: it is not required.
    • width: When overhang is explicit, \width can be used for the width of figure.

3. BibTeX

3.1. Format

3.2. BibLaTeX

  • @online
    • title
    • author
    • year
    • url
    • urldate: Must be in the format YYYY-MM-DD

3.3. Biber

Biber is an external program

4. Renderers

  • KaTeX
    • Website
    • Javascript library that renders \(\rm\LaTeX\) expressions.
  • MathJax

5. TeX distributions

5.1. TeX Live

https://wiki.archlinux.org/title/TeX_Live

  • TeX distribution for Linux.
  • Download the texlive group, and texlive-langkorean for kotex.

5.1.1. texlive-doc

  • Provides offline documentations that is accessed in command line via texdoc.

5.2. MiKTeX

The TeX distribution for windows.

  • miktex The command line utility
    • packages
      • update

5.3. Troubleshooting

  • If latex.fmt is not found the format file is not properly installed.
  • If some .sty is missing, look it up via pacman: pacman -F style.sty, and install it.

6. See also

6.1. Take notes in LaTeX

7. References

Created: 2025-05-06 Tue 23:25