Style Guideline

Indentation

Cons: It might causes a line too long, so you lost the end in the right border or you get a soft line break if wrapping is activated.

Pros: know the begin and end of an environment.

Fast compiling

  1. Photographic images saved as .png can also result in very large file sizes: .jpg is usually a much more space-efficient format for photographs. Line drawings, plots and diagrams are better saved as .png or .pdf, in general. .pdf images can also compile faster compared to .png files if their file sizes are comparable, as the compile process then doesn’t need to call libpng.

  2. The “draft” option can often help reduce compilation time, which is useful when working on large documents.

    The draft option will be passed to all packages that recognize it, further speeding up the compilation process. Packages have different behaviors with the option.

    For instance, if the option is specified for the hyperref package, all hypertext options are turned off and no hyperlinking is performed.

    How to set draft option?

    • You can turn on “draft” mode on Overleaf. Or,
    • Write \documentclass[draft]{…} in your document class declaration.

    How to turn off the draft mode?

    • Toggle off the option on Overleaf. Or,
    • Write \documentclass[final]{…} or simply \documentclass{}.

    draft mode will replace images with a framebox (placeholder) the size of the image and the name of the image in the box. If your text depends on the images, then the function will be inconvenient.

    In this case, you can override the compilation mode for the graphics package.

    \documentclass[draft]{article} % set global 
    \usepackage[final]{graphicx} % set graphics package
    

    The draft option will also disable the micro-typographic extensions of the microtype package and in the process cause different line and page breaks. One useful feature of the draft option is marking overfull boxes; this may also be achieved with

    \setlength{\overfullrule}{5pt}
    

Add .cls or .sty to TeXshop

home directory

  1. Paste style files .cls or .sty into /usr/local/texlive/texmf-local/tex/latex/local/

  2. and run sudo texhash.

.cls are class files; .sty are style files or packages.

  • Loading a class via \documentclass is mandatory, and may only appear once in a LaTex document. In the ideal case, a class file will completely define the structure of the document.
  • Packages are optional and as many of them may be loaded as one could wish. Used to provide anything else that the class doesn’t accommodate.

bst defines bibliography style.

Global images path for Latex

/usr/local/texlive/texmf-local/tex/latex/local/images

Use custom .bst bibliography file.

If want to be a global template.

  1. put file in /usr/local/texlive/texmf-local/bibtex/bst
  2. run sudo texhash.

Or if you just want to use the template for one local project, can just put .bst file with other .tex files.

Vim command

Save and quit :wq

Bibtex

Latex编译reference出现“I couldn’t open file name reference.aux”错误

我们在写论文管理参考文献时,可以在.tex文件同级目录下建立.bib文件来管理。 具体方法为: 在正文最后的 \end{document} 前加上下述两句代码:

  • \bibliographystyle{IEEEtran格式}
  • \bibliography{bibtex文件}

今天犯了一个错误,就是直接对reference.bib文件使用bibtex进行编译,出现了错误“I couldn’t open file name reference.aux”。具体流程如下:

  1. 首先对“main.tex”使用latex或者pdflatex进行编译,产生“main.aux”;
  2. 然后使用bibtex编译“main.aux”(注意这里不是编译“ref.bib”);
  3. 最后使用latex或者pdflatex编译“main.tex”两次

Commands:

  1. pdflatex filename (with or without extensions)
  2. bibtex filename (without extensions)
  3. pdflatex filename (with or without extensions)
  4. pdflatex filename (with or without extensions)

bib engine:

  • need to specify biber when using biblatex.
  • bibtex is for natbib.

Hyperref

Both color and box

https://tex.stackexchange.com/questions/383534/box-around-reference-and-citation

The hyperref package explicitly checks at \begin{document} whether colorlinks is set to true, and if so, the package automatically set pdfborder to {0 0 0} (which means no border).

One way to go around this is to pass \AtBeginDocument{\hypersetup{pdfborder={0 0 1}}}so that this behaviour is negated, like so:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\usepackage{hyperref} 
\hypersetup{backref=true,       
    pagebackref=true,               
    hyperindex=true,                
    colorlinks=true,                
    breaklinks=true,                
    urlcolor=black,                
    linkcolor=blue,                
    bookmarks=true,                 
    bookmarksopen=false,
    filecolor=black,
    citecolor=blue,
    linkbordercolor=blue
}

\AtBeginDocument{\hypersetup{pdfborder={0 0 1}}}% <-----------

PDF-specific display package options

  • bookmarks default true, a set of bookmarks are written, in a manner similar to the TOC.
  • bookmarksnumbered default false, when bookmarks are requested, if include section numbers.
  • pdfpagemode=UseOutlines determine how the file is openning. Available options: UseNone, UseThumbs (show thumbnails), UseOutlines (show bookmarks, this is the default when bookmarks set to true), FullScreen.

Show Unnumbered Sections in pdf Outline

Issue: Unnumbered sections such as \section*{Acknowledgements} won’t be inserted into the TOC.

Fix: Add \phantomsection\addcontentsline{toc}{section}{Acknowledgements} before your unnumbered sections.

The \phantomsection command creates a link to a place in the document that is not a figure, equation, table, section, subsection, chapter, etc.

This is mostly used in conjunction with \addcontentsline or with \label and \hyperref. For example, the following code will create a contents line and a link to somewhere in the document.

\phantomsection\addcontentsline{toc}{section}{Some place in the document}
\label{some}
This is just \hyperref[some]{some place} in the document.

Without the \phantomsection line, both the contents line and the link would point to the beginning of the current section (or subsection, etc.)

In an APA reference or citation, n.d. stands for “no date.”

Troubleshoot

Q: References are all [0].

A: Use style=numeric instead of style=numeric-comp.

Format bibtex items

Some people use the LaTeX-mathmode inside of BibTeX tags for various reasons. Latex math mode commands could be put inside $$. E.g., some wish for a numeration like 2nd and 3rd for instance to describe

“The 20th annual meeting of BibTeX-users”.

Title = "The $20^{th}$ annual meeting of {BibTeX}--users"

Text enclodesd in braces {} will not be formatted in any ways. For instance, when a style defines the title to become depicted using only lowercase, italic letters, the enclosed part will be left untouched. “An Introduction To {BibTeX}” would become “an introduction to the BibTeX” when such a style is applied. Nested braces are ignored.

Escaping Special Symbols and escapes

LaTeX provides means to describe special characters like accents or umlauts using a special notation, which can be used just the same inside of BibTeX Entries.

specialsymbols.png

As well as these accents, some characters can not be put directly into a BibTeX-entry, as they would conflict with the format description, like {, ", or $. They need to be escaped using a backslash \.

Font

Computer Modern

https://tug.org/FontCatalogue/cmrfonts.html

\RequirePackage{mlmodern}  % blacker Latin Modern
\RequirePackage{lmodern}   % 

Font Size

image-20210512202245288

Typeface

image-20210520120254672

Bullet List

enumitem package

Enumerate bullet/numbered lists

enumerate margin.png

Q: How the label is aligned?

A: Use align=left|right|parleft. The default is right.

labelsep=* the item body begins at a fixed place (namely, leftmargin).

leftmargin=* the item body begins at a variable place depending on the label (but always the same within a list, of course).

Whitespace

  • To create vertical space/ a blank line, use &nbsp; (followed by a blank line). This command works like \vspace{12pt} for latex.
  • To create horizontal space, use \quad, \qquad, \; or \hspace{20pt}.
  • Non-breaking spaces
    • in LaTex use ~
    • in html use &nbsp;

Hard Line break

A hard line break can help control text flow when a carriage return won’t work.
It creates a new line without starting a paragraph. Hard line breaks are useful for separating the lines at specific positions.

  • In html, <br/> (or <br /> with a space before /, or simply <br>) and \ (single backslash) give a single line break.
    • If it doesn’t work, add a black line above and below.
    • </br> is nonsense. Don’t use that.
  • In Markdown,
    • two or more spaces (␣␣) at the end of the line create a single line break.
    • or add \ (single backslash) at the end of the line and then hit shift + enter (soft break).
  • In latex, there are three commands:
    • \\ (two backslashes)
    • \newline
    • \hfill \break

New paragraph

  • Inserting a blank line
  • \par

Description of spacing commands

LATEX code Description
\quad space equal to the current font size (= 18 mu)
\qquad twice of \quad (= 36 mu)
\, 3/18 of \quad (= 3 mu)
\: 4/18 of \quad (= 4 mu)
\; 5/18 of \quad (= 5 mu)
\! -3/18 of \quad (= -3 mu)
\␣(space after backslash!) equivalent of space in normal text

\\ gives a line break.

Starting a new par:

  • insert a blank line; or
  • use \par

Length unit

pt point size. A point is about 0.3515 mm .

\p@ is a LaTeX2e kernel dimension, equal to 1 pt. It is used to save tokens in the kernel.

px pixel size; 16 px = 12 pt = 1em = 100%; use px whenever possible for best screen display;

Relative units: em and ex relative to the current front size.

em roughly the width of an ‘M’ (uppercase) in the current font (it depends on the font used)最大,对应当前字体大小;px 最小;1pt=1.3px.

  • If your font is 11px, then 1em equals 11px.

ex roughly the height of an ‘x’ (lowercase) in the current font (it depends on the font used)

in inch

cm 1 in = 2.54 cm

“Rubber lengths”: a length plus a degree of elasticity.

For instance, \fill length command has a natural length of zero but is infinitely stretchable, so that a space of width \fill will try to stretch as much as possible.

Multiplying a rubber length by a fixed factor destroys its elasticity: 0.5\fill becomes a rigid length with a value of zero.

Colored text

  1. \textcolor{<color>}{...} is a command that does NOT allow paragraph breaks (it is defined with \def instead of \long\def). 不是很灵活,不能有多个段落。换行需要用soft break \\.

  2. You must use {\color{<color>}...} instead when you want to color multiple paragraphs. {\color{red}...} can be used to color equations. 更加灵活,支持多个段落。

    E.g., Color text in a table using \color.

    {\color{red}\begin{tabular}{cc}
    a & b \\
    1 & 2
    \end{tabular}}
    

Quotes and Dashes

  • Single quotation marks are produced in LaTeX using ` and '.
  • Double quotation marks are produced by typing `` and ''.
  • The undirected double quote character " produces double right quotation marks: it should never be used where left quotation marks are required. In other words, undirected double quotes " should only be used in paris.

  • LaTeX allows you to produce dashes of various length, known as “hyphens”, “en-dashes” and “em-dashes”. Hyphens are obtained in LaTeX by typing -, en-dashes by typing -- and em-dashes by typing ---.

Email and phone links

[example@example.com](mailto:example@example.com) example@example.com

[111 11](tel:111111) 111 111

Orphan and Widow Lines

Orphan: at the bottom of the page, or Widow: at the top of the page

Prevent page breaks before an itemize list

beginpenalty=⟨integer⟩ midpenalty=⟨integer⟩ endpenalty=⟨integer⟩ Set the penalty at the beginning of a list, between items and at the end of the list. Refer to your LATEX or TEX manual about how penalties control page breaks.

  • Unlike other parameters, when a list starts their values are not reset to the default, thus they apply to the child lists.

Equations

You should italicize only variables in equations. (变量用斜体)

Everything else should be roman upright (常量用正体,计量单位,缩写). Use \rm or \text{}.

For example:

  • numerals, including roamn numerals (I, IV, XII), are always set roman no matter what the surrounding text font environment is.

  • function names (sin, cos, log, ln, min, max, etc…)

  • 计量单位 m, s, V, $^\circ \text{C}$.

    5 $\rm m\, s^{-1}$: 5 meters per second. Use negative signs for denominators.

  • dimensionless numbers (Re, Pr, Ra…) $\pi$, $\rm e$ (自然对数的底), $\rm i$ (虚数单位)

  • exact infinitesimal increments (dx, dy et… in BOTH integrals and differentials)

  • descriptive text

  • all descriptive variable indices (unless they are also variables)

Math font:

  • \mathbf for bold,
  • \mathrm for roman/text $\mathrm F$,
  • \mathcal for calligraphic/script 花体 $\mathcal F$,
  • \mathsf for Sans Serif,
  • \mathbb for balckboard bold $\mathbb F$.

~ is unbreakable space. In text mode ~=\nobreakspace; while a space isn’t unbreakable..

\text 里面是可以加 $...$ 来显示数学符号。

Guidelines

By default, the TeX processor uses the LaTeX math delimiters

  • In-line math: \(...\) (LaTeX) or $...$ (TeX)

  • displayed (block) equations:

    • unnumbered: \[...\](LaTeX), $$...$$ (TeX), or \begin{equation*}

    • numbered: \begin{equation}

      The amsmath package redefines \[ to be \begin{equation*} which is exactly an un-numbered form of the equation environment as defined by that package.

$$...$$ is said to be obsolete.

[Why is \[...\] preferable to $$...$$?]

Examples where $$ fails but \[\] succeeds.

  1. lineno does not number a paragraph when it is followed by an indented equation $$...$$.

  2. LaTeX doesn’t officially support $$. The most noticeable failure if you use the syntax is that the fleqn option will no longer affect the display of the mathematics, it will remain centered rather than being set flush left.

  3. If you use the \begin{proof}...\end{proof} environment, you occasionally end a proof with an equation. The automatic QED box then ends up on a line by itself, which is ugly. You can fix this by writing \qedhere at the end of the equation, but this doesn’t work properly with $$...$$ – you have to use \[...\] (or an environment, like equation/gather/align). To exemplify:

    Don’t:

    \begin{proof}
      This follows from
      $$e^{x+y}=e^xe^y. \qedhere$$
    \end{proof}
    

    Do:

    \begin{proof}
      This follows from
      \[e^{x+y}=e^xe^y. \qedhere\]
    \end{proof}
    

    Source

align vs. aligned

  • align consists of several equations. It is a full math display.
    • This alters the spacing above and below that. Usually you want the larger spacing around a block of several equations; therefore, align is conceptually clearer.

    • align add extra space above and below the equation.

      If a compact typesetting is preferred, one can use $$ \begin{aligned} ... \end{aligned} $$ instead. E.g.,

      Let $X \sim N(0,1)$, then we have
      $$
      \begin{aligned}
      P(X > 1.96) &= \Phi(-1.96) \\
      &= 0.025,    
      \end{aligned}
      $$
      
  • aligned is essentially a single equation which may scratch over several lines. It is an inline math or within a display setting.
    • aligned needs to be put inside another display environment, such as equation or encloded with double dollar sign $$.

align vs. equation

  align equation
Space Extra space above and below for short eqn is short, also more space between symbols More packed
QED □ appears on top of the end of the math □ appears at the end the line; behaves as desired
Single line eqn Avoid using align Use equation

Suggested practice: If you are typesetting an equation, then use equation and if you desire alignment you can use aligned blocks inside the equation.

Multi-lined equations could be achieved by using either

  • equation + split, or
  • equation + aligned.

These two will generate one centered tag for the equation. (一个 block 整体是一个 equation, 所以整体共享equation一个编号居中排列。)

align can achieve the same results. 但是默认为多个方程,一行为一个方程,对应一个编号。如果不想某一行有编号,需要用 \nonumber or \notag 来抑制输出。

If you have multiple equations displayed in a block, and you want to add one tag for each equation, then use align environment. (align 一行一个编号)

  • One can suppress labels for specific lines of align using either \nonumber or \notag, but all unaltered lines get their own label.
Using ``equation'':
 \begin{equation}
  \begin{split}
   a+b
   &= c \\
   &= c \\
   &= c \\
   &= c
  \end{split}
 \end{equation}

Using ``align'':
 \begin{align}
  a+b
  &= c \\
  &= c \notag\\
  &= c \nonumber\\
  &= c
 \end{align}

eqn

The multi-equation environments gather, align, and alignat are designed to produce a structure whose width is the full line width.

  • This means, for example, that one can NOT readily add parentheses around the entire structure.

But variants gathered, aligned, and alignedat are provided whose total width is the actual width of the contents; thus they can be used as a component in a containing expression. E.g., aligned inside equation environment.

\[
\left.\begin{aligned}
  B’&=-\partial\times E,\\
  E’&=\partial\times B - 4\pi j,
\end{aligned}
\right\}
\qquad \text{Maxwell’s equations}
\]

aligned

cases environment works best with multicase functions.

  • Saves your effort from writing braces \left\lbrace (for openning) and \right. (for closure). 优点是不用自己打括号,alignment is automatically set.

    \left\lbrace (for openning) and \right. 的缺点是:

    • The alignment character & and the line breaks \\ cannot be inside the pair \left\{, \right, 从而导致换行有问题。
    • 多行方程组需要用 \left\{\begin{array} .... \end{array} \right. 来实现。Alignment 会怪怪的,行间距过小,显示效果太过于紧凑。
    • 不能每一行添加一个编号。$\rightarrow$ 解决方式: Use numcases from the cases package.
  • cases environment automatically provide the correct column alignment. Columns should be left aligned.

\[
P_{r-j}=\begin{cases}
    0                    &  \text{if $r-j$ is odd}, \\
    r!\,(-1)^{(r-j)/2}   &  \text{if $r-j$ is even}.
\end{cases}
\]

align cases

Add separate labels to cases

You can use numcases from the cases package if you want each case labelled as a separate equation.

\begin{numcases}{f(x)=}
   1 & $x\geq0$ \label{positive}
   \\
   0 & $x<0$ \label{negative}
\end{numcases}
See the second case \ref{negative} or the first \ref{positive}
\begin{subnumcases}{f(x)=}
   1 & $x\geq0$ \label{positive-subnum}
   \\
   0 & $x<0$ \label{negative-subnum}
\end{subnumcases}
See the second case \ref{negative-subnum} or the first \ref{positive-subnum}

cases separate labels

array environment

  • Note that the curly brace { needs to be escaped using \{. Or use \lbrace instead.
\begin{align*}
F_Y(y)&=P(Y\le y)=P\left(g(X)\le y\right) \\
&=\left\{
  \begin{array}{ll}
  P\left(X\le g^{-1}(y)\right) = F_X(g^{-1}(y)) & \text{when $g(x)$ is $\uparrow$} \\
  P\left(X\ge g^{-1}(y)\right) = 1- F_X(g^{-1}(y))  & \text{when $g(x)$ is $\downarrow$}
  \end{array} \right. \\
f_Y(y) &= f_X(g^{-1}(y)) \cdot \left\vert \frac{\partial }{\partial y} g^{-1}(y) \right\vert
\end{align*}

array

Indicator variable $I_t$

\begin{align*}
I_t = \left\{
\begin{array}{ll}
1 & \text{if it is a head, with prob. } \pi \\
0 & \text{if it is a tail, with prob. } 1-\pi 
\end{array}
\right.
\end{align*}

indicator_var

[t], [b] or the default [c] are optional arguments to specify vertical positioning.

[t] for top; [b] for bottom, default [c] for center.

Align at top (before)
$\begin{aligned}[t]
  a &= b \\
  c &= d
\end{aligned}$
Align at top (after)

align at top

Align at center (before)
$\begin{aligned}[c]
  a &= b \\
  c &= d
\end{aligned}$
Align at center (after)

align at center

Align at bottom (before)
$\begin{aligned}[b]
  a &= b \\
  c &= d
\end{aligned}$
Align at bottom (after)

align at bottom

Both \[ ... \], $$ ... $$, and \begin{equations} are used to display equation blocks.

\( ... \) and $ ... $ are for inline math.

Aligning with several fixed points

\begin{equation*}
\begin{aligned}
    &               &  1a &= 1b  \\
    &\Leftrightarrow&  2a &= 2b \\
    &\Leftrightarrow&  3a &= 3b.
\end{aligned}
\end{equation*}

align1

\begin{align*}
x&=y           &  w &=z              &  a&=b+c  \\
2x&=-y         &  3w&=\frac{1}{2}z   &  a&=b    \\
-4+5x&=2+y     &  w+2&=-1+w          &  ab&=cb
\end{align*}

align2

Use && to force align at one place.

\begin{aligned}
    p\text{-value} &= 2\,\mathbb{P}(T>|t|)   &\quad& (\text{by definition})   \\
    &= 2\left(1-\mathbb{P}(T\le|t|)\right)   & & (2 \text{ times the probability of the upper tail})  \\
    &= 2\mathbb{P}(T\le -|t|)  & & (2 \text{ times the probability of the lower tail}) .
\end{aligned}

eqn align

alignat allows the horizontal space between equations to be explicitly specified.

  • This environment takes one argument, the number of “equation columns”: count the maximum number of &s in any row, add $1$ and divide by $2$.
\begin{alignat}{2}
x& = y_1-y_2+y_3-y_5+y_8-\dots
                  &\quad& \text{by ...} \\
 & = y'\circ y^*  && \text{by ...} \\
 & = y(0) y'      && \text {by Axiom 1.}
\end{alignat}

alignat

As single eqn, use alignedat inside equation.

\[
\begin{alignedat}{2}
x& = y_1-y_2+y_3-y_5+y_8-\dots & \quad & \text{by ...} \\
 & = y'\circ y^*      				 &			 & \text{by ...} \\
 & = y(0) y'     							 &			 & \text{by Axiom 1.}
\end{alignedat}
\]

alignedat

More examples

\[
\begin{alignedat}{2}
    &               & \quad 1a &= 1b  \\
    &\Leftrightarrow&  2a &= 2b \\
    &\Leftrightarrow&  3a &= 3b.
\end{alignedat}
\qquad\text{or}\qquad
\begin{alignedat}{2}
    &               & \qquad 1a &= 1b  \\
    &\Leftrightarrow&  2a &= 2b \\
    &\Leftrightarrow&  3a &= 3b.
\end{alignedat}
\]

alignedat2

eqnarray* environment needs & on both sides of the relation. (左右都要加&)

  • In contrast to align, which aligns on the left.
\begin{eqnarray*}
\mathrm{I} &=& \mathrm{H}(x) \\
           &=& \mathrm{H}(x + 1)
\end{eqnarray*}

align_eqnarray

Align to the left

To align to the left use flalign (full length alignment) environment and place both & at the end of the equation, such as &f(x) = -1.25x^{2} + 1.5x&

\begin{flalign}
    &f(x) = -1.25x^{2} + 1.5x&
\end{flalign}
  • flalign stretches the space between the equation columns to the maximum possible width, leaving only enough space at the margin for the equation number, if present.

Something not so important

Use greyed text (<span style='color:#797D7F'>greyed text</span>) for text and ${\color{#797D7F} \alpha\beta\ldots }$ ({\color{#797D7F} \alpha\beta\ldots }) for equations.

If stationarity holds, then we have constant variance, $\sigma_t^2=\sigma_s^2=\sigma^2=\gamma_0$. And we have

\[{\color{#797D7F} \rho (k)=\frac{\gamma (k)}{\gamma_0}.}\]

Display style in math mode

Summation operators: $\displaystyle\sum_{i=1}^n$ (\displaystyle\sum_{i=1}^n) vs $\textstyle\sum_{i=1}^n$ (\textstyle\sum_{i=1}^n).

  • \textstyle apply the style used for mathematics typeset in paragraphs. The limits (the i=1 and n in that case) are pushed to the right of the operator.
  • \displaystyle apply the style used for mathematics typeset on lines by themselves. The lights are above and below the operator. The operator itself is enlarged.

Note that if you force \displaystyle for inline equations, the formula will become taller and is likely to break the appearance of your paragraph.

If you’d prefer a compromise, you can use the \limits command to force the limits to be placed above and below the operator, without changing the operator size.

  • $\sum\limits_{i=1}^n$ (\sum\limits_{i=1}^n) vs. $\sum_{i=1}^n$ (\sum_{i=1}^n)

Product operators $\displaystyle\prod_{i=1}^n$ (\displaystyle\prod_{i=1}^n) vs $\textstyle\prod_{i=1}^n$ (\textstyle\prod_{i=1}^n).

Fractions

  • Inline fraction $\frac{x}{y}$, $\frac{\sum_{i=1}^n x_i}{\sum_{i=1}^n y_i}$.

    Sum limits are always in inline mode in fractions, shown to the right of the operator.

  • Disaply fraction $\displaystyle \frac{x}{y}$ (\displaystyle \frac{x}{y}), or $\dfrac{x}{y}$ (\dfrac{x}{y}), $\dfrac{\sum_{i=1}^n x_i}{\sum_{i=1}^n y_i}$ (\dfrac{\sum_{i=1}^n x_i}{\sum_{i=1}^n y_i}).

Cross-reference to eqns

use \label{...} inside eqn and then $\ref{...}$ to cite the eqn. Don’t forget the $ $ surrounding \ref.

When citing display equations in text, use either Eq. ( ) or ( ) consistently; do not mix the two styles.

  • Automatic labels is supported only on certain markdown editors.
    Typora supports automatic labels.
    KaTeX and gh-pages do not. You have to provide the label using \tag{label} by yourself.
    Use \label{eq:return} alone inside the eqn, then use $\ref{eq:return}$ to cite in the text.

    Here is a labeled equation:
      
    $$
    \begin{align} \label{eq:return}
    R_a \approx \frac{1}{k} \sum_{j=0}^{k-1} r_{t-j}
    \end{align}
    $$
      
    This is a reference : eqn $(\ref{eq:return})$ (add the parentheses manually) or $\eqref{eq:return}$ (automatic parentheses). 
    
    \[\begin{align} \label{eq:return}\tag{1} R_a \approx \frac{1}{k} \sum_{j=0}^{k-1} r_{t-j} \end{align}\]

    This is a reference : eqn $(\ref{eq:return})$ ($\ref{eq:return}$ adds the parentheses manually) or $\eqref{eq:return}$ ($\eqref{eq:return}$ adds parentheses automatically).

  • With customized labels using \tag{your label}:

    Here is a labeled equation:
      
    $$
    x+1\over\sqrt{1-x^2}\label{ref1}\tag{customized tag}
    $$
      
    This is a reference : $\ref{ref1}$ (`$\ref{ref1}$`).
    
    \[x+1\over\sqrt{1-x^2}\label{ref1}\tag{customized tag}\]

    This is a reference : $\ref{ref1}$ ($\ref{ref1}$).

    Note that only alphanumeric characters (a-z, A-Z, 0-9), -, /, and : are allowed in these labels \tag.

Equation vs align environments

  • equation is for single line eqns, if need to show multiline, need to use together with split/ aligned.

    align is for multiline eqns. In other words, align = equation + split/ aligned.

    • split is for splitting a single equation on more than one line (e.g. when the equation is too long).
    • align environment is for typesetting multiple equations (possibly related to one another) aligned in the same display environment.
  • Vertical spacing is different. equation is more compact when short lines are present before and after the display.

    • align inserts \abovedisplayskip and \belowdisplayskip above and below the environment.
    • If the line that comes immediately before the environment is short, \abovedisplayshortskip and \belowdisplayshortskip are inserted instead of \abovedisplayskip and \belowdisplayskip. Only if the preceding line is long do the latter two length parameters come into play.
  • For eqns labels

    • equation + split have a single vertically centered label.
    • align creates one label per line; use \nonumber or \notag to suppress labels for specific lines.

Normally just use equation with \label{}

\begin{equation}
    \thickbar{T}_{t+1} = \gamma_0 + \theta_1\thickbar{T}_t + \theta_2\thickbar{R}_t + \gamma_3\ln(CO_{2,t}) + \thickbar{u}_{\cdot t+1} \label{eq:5}
\end{equation}

Sub-numbering for individual eqns in one block

% \usepackage{amsmath} %maths
This shows subequations like (1a), (1b).
\newcommand{\thickbar}[1]{\mathbf{\bar{\text{$#1$}}}}

\begin{subequations}
    \begin{align}
        T_{i,t+1} &= \alpha_i + \beta_1T_{i,t} + \beta_2R_{i,t} + \phi_i\lambda_t + u_{i,t+1},  \label{eq:1} \\
        \lambda_t &= \gamma_0 + \gamma_1\thickbar{T}_{t} + \gamma_2\thickbar{R}_t + \gamma_3\ln(CO_{2,t}), \label{eq:2}  \\
        i&=1,\cdots,N \text{ and } t=1,\cdots,n \nonumber
    \end{align}
\end{subequations}

Cite like \eqref{eq:1} and \eqref{eq:2}.

This will show like:

subeqn

One numbering for the whole block

\begin{equation}
\label{eq:12}
\begin{aligned}
    W^-_{trans} = A_L + \frac{A_O}{WR} \cdot (1-0.05)  
    \\    
    W^+_{trans} = A_L + \frac{A_O}{WR} \cdot (1+0.05)
\end{aligned}
\end{equation}

one_label_eqns

Prefix Fig. Table Numbering with “S”

This is useful when writing appendix where you want to a separate numbering system than the main text.

%% prefix numbering `s` to separate from the main text
\renewcommand{\thefigure}{S\arabic{figure}}
\renewcommand{\thetable}{S\arabic{table}}
\renewcommand{\theequation}{S\arabic{equation}}

References:

  1. An essential guide to LaTeX 2ε usage

    https://ftp.fagskolen.gjovik.no/pub/tex-archive/info/l2tabu/english/l2tabuen.pdf

    Read ‘Deadly sins’ — The most severe mistakes in using LaTeX 2ε.