Try   HackMD

title: "
LaTeX
語法筆記"
path: "LaTeX 語法筆記"

此頁歡迎共筆。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

學海無涯,思境無維;數乃六藝,理之始也。
或有一得足矣 愚千慮

HackMD 是透過 MathJax 支援

LATEX ,雖未支援所有語法,對多數人應已足夠,一起把 Web 上醜死的公式換成美美的吧~

LATEX
語法筆記

LATEX

\LaTeX % 大小寫須正確

$\textstyle$
$$\displaystyle$$
%comment

a`pple

\grave apple % 標重音

AB

{\bf AB} % 粗體 boldface

A¯

\bar{A}

{a+bc+d}

{ a+b \brace c+d }

AB

\overline{AB}

v

\vec{v}

ba

\frac{b}{a}
% 或
{b \over a}

ba

\dfrac{b}{a}  % d for \displaystyle
\tfrac{b}{a}  % t for \textstyle

90

90^\circ

eθi

e^{\theta i}

Sn

S_{n}

limn

\lim\limits_{n\to \infty}

x=0kx2

\sum\limits_{x = 0}^k{x^2}

i=1Ui

\bigcup\limits_{i = 1}^{\infty}{U_i}

i=1Ui

\bigcap\limits_{i = 1}^{\infty}{U_i}

×i=1nUi

\mathop{\vcenter{\huge\times}}_\limits{i=1}^n{U_i}

abx2dx

\int_a^b x^2  \mathrm{d} x

1+x+x2+x3++xnn

\sqrt[n]{1+x+x^2+x^3+\dots+x^n}
% 或
\root n \of {1+x+x^2+x^3+\dots+x^n}

AB

A \implies B

AB

A \impliedby B

AB

A \iff B

f:AB

f: A \to B

AB

A \leftarrow B

 

\xrightarrow{中文亦可}\ \xleftarrow{中文亦可}

a=?b

a\,\overset{?}{=}\,b

xX,xb

\forall x \in X, \exists x \in b

,,,

\not\in, \not\gt, \not\lt, \not=   % 利用 \not 組合表示否定

|a|,a

\vert a \vert, \Vert a \Vert % absolute value and norm

a1,a2,,an

a_{1}, a_{2}, \ldots, a_{n}

a1+a2++an

a_{1} + a_{2} + \cdots + a_{n}

(a11a12a1na21a22a2nam1amn)

\begin{pmatrix}
  a_{11} & a_{12} & \cdots & a_{1n}\\
  a_{21} & a_{22} & \cdots & a_{2n}\\
  \vdots & \vdots & \ddots & \vdots\\
  a_{m1} & \cdots & \cdots & a_{mn}
\end{pmatrix}

% ldots: low dots
% cdots: center dots
% ddots: diagonal dots
% vdots: vertical dots

{a1x+b1y+c1z=d1a2x+b2y+c2z=d2a3x+b3y+c3z=d3

\left\{ 
  \begin{array}{c}
    a_1x+b_1y+c_1z=d_1 \\ 
    a_2x+b_2y+c_2z=d_2 \\ 
    a_3x+b_3y+c_3z=d_3
  \end{array}
\right.

a+b=0a+b+c=1

\begin{align*}  # align equations using equal sign
    a + b = 0 \\ # switch line
    a + b + c = 1
\end{align*}

Operator/Relation

A×B = A\times B
ab
= a\cdot b
÷
= \div
(modn)
= \pmod n
±
= \pm (plus and minus)
= \partial
= \oplus
&
= \&
>
= \gt (greater than)
<
= \lt (less than)
= \ge (greater or equal)
= \le (less or equal)
= \lhd (normal subgroup)
= \unlhd
= \ne (not equal)
= \approx (approximate to)
= \sim (similar)
= \cong (congruent)
= \equiv (equivalent)
= \ll, much less than
= \gg, much greater than
= \nless, not less than
= \ngtr, not greater than
= \cap, 像帽子, intersection
= \cup, 像杯子, union
= \subset, or implied
= \superset, or implies
= \subseteq
= \supseteq
= \land (logical and); \wedge (wedge product)
= \lor (logical or)

List of Logic Symbols

Function

(ab) = \binom{a}{b}

Binomial :

C!n!(nk)!,where (n+k)=constant
或 \binom a b
或 { a \choose b }
\tbinom a b (t for \textstyle)
\dbinom a b (d for \displaystyle)

cosθ = \cos{\theta}
sinθ
= \sin{\theta}
logbx
= \log_{b}{x}
lnx
= \ln{x}
x
= \lceil x \rceil
x
= \lfloor x \rfloor

Matrix

(AB)

\begin{pmatrix}
  A\\B                % \\ 為 newline(換行)
\end{pmatrix}

% 或

\pmatrix{A\\B}

[AB]

\begin{bmatrix}
  A\\B
\end{bmatrix}

|AB|

\begin{vmatrix}
  A\\B
\end{vmatrix}

AB

\begin{Vmatrix}
  A\\B
\end{Vmatrix}

[abcd]

\begin{bmatrix}
  a & b \\
  c & d 
\end{bmatrix}

Greek

α = \alpha
β
= \beta
Δ
= \Delta,
δ
= \delta
ϵ
= \epsilon,
ε
= \varepsilon
γ
= \gamma
θ
= \theta
σ
= \sigma
π
= \pi
μ
= \mu
λ
= \lambda
ω
= \omega
ϕ
= \phi
φ
= \varphi
ρ
= \rho

Blod of Greek

Default size:

αβγ

\alpha \quad \beta \quad \gamma

Using \boldsymbol{}

\boldsymbolαβγ

\boldsymbol{\alpha \quad \beta \quad \gamma}

Using pmb{}

αβγαβγ

\pmb{\alpha \quad \beta \quad \gamma}
reference: How to represent bold greek letters in
LATEX
?

Misc

= \angle
= \triangle
= \square
(space)
= \quad (space)
= \propto (propotional to)

= \because
= \therefore
Z
= \mathbb{Z}
P
= \mathbb{P}
R
= \mathbb{R}
C
= \mathbb{C}
= \Im (Imaginary Space)
= \Re (Real Space)

= \emptyset
= \varnothing (以此表示空集合較好看)
= \in
= \not\in
S
= \langel S\rangle (generator)
χ
= \chi
= \circlearrowleft
= \circlearrowright
= \curvearrowleft
= \curvearrowright
= \hbar (Planck's Constant)

https://oeis.org/wiki/List_of_LaTeX_mathematical_symbols#Set_and.2For_logic_notation

Format

Style

You can't use 'macro parameter character #' in math mode

\style{background-color:#eeeeee}{\frac{x+1}{y+2}}  % 直接以 CSS 改變 style

f(x)=a\colorredx+b

f(x) = a{\color{red}{x}} + b
% 或
f(x) = a{\color{#ff0000}{x}} + b

You can't use 'macro parameter character #' in math mode

\require{color}
\colorbox{#eeeeee}{Color Box}

ABCDE12345abcde

{\cal ABCDE12345abced} % callgraphic mode

boxed text

\fbox{boxed text}      % in textstyle

boxed text

\boxed{boxed\ text}    % in displaystyle

text E=mc2

\text{text $E=mc^2$}

ABCDE12345abcde

{\frak ABCDE12345abcde}

abefg12345 abcdefg12345

{\it abefg12345}\ abcdefg12345   % italic

minn

\min\limits_{n}

If you want to represent bold greek letters.
link for Blod of Greek

Automatic Sizing

{xx>1} 與 {x|x>1}

\{x \mid x\gt 1\}     % 請用 \mid 寫 Set 才好看

(x2y3)

\left(\dfrac{x^2}{y^3}\right)

{12}

\left\{ \dfrac{1}{2} \right\}

f(x)={x+by=cdx+ey=f

f(x) = \left\{
\begin{array}{r}
   x + by = c \\
  dx + ey = f 
\end{array}
\right.

% {r} for right alignment within array
% {l} for left alignment within array
% 或

\array{
   x + by = c \\
  dx + ey = f 
}

z=xreal+iyimaginarycomplex number

z = \overbrace{
    \underbrace{x}_\text{real} + i
    \underbrace{y}_\text{imaginary}
}^\text{complex number}

Alignment

f(x)=ax+by+cz+d=2x+3y+5z+1

\begin{aligned}
f(x) &= ax + by + cz + d \\
     &= 2x + 3y + 5z + 1
\end{aligned}

% 或

\begin{align}
f(x) &= ax + by + cz + d \\
     &= 2x + 3y + 5z + 1
\end{align}

% 或

\eqalign{
f(x) &= ax + by + cz + d \\
     &= 2x + 3y + 5z + 1
}

a1+b1=c1a2+b2=c2a10+b10=c10

\begin{align}
    a_{1} + b_{1} &= c_{1} \\
    a_{2} + b_{2} &= c_{2} \\
    &\vdots  \\
    a_{10} + b_{10} &= c_{10}
\end{align}

{n/2,if n is even3n+1,if n is odd

\begin{cases}
  n/2, & \text{if $n$ is even} \\
  3n+1, & \text{if $n$ is odd}
\end{cases}

% 或

\cases{
  n/2, & \text{if $n$ is even} \\
  3n+1, & \text{if $n$ is odd}
}

(aaabbbccdd)

\begin{pmatrix}
 aaa & bbb \\
 cc & dd
\end{pmatrix}

xxxxxxxxxxxxxxxxxxababab

\begin{matrix}
  xxxxxx & xxxxxx & xxxxxx \cr
  ab & \hfil ab & ab\hfil \cr    % 以 \hfil 自動填空
\end{matrix}

x1x2s1s2s3s1011008s2110104s31100112110000

\begin{array}{rrrrrr|r}
       & x_1 & x_2 & s_1 & s_2 & s_3 &    \\ \hline
   s_1 &   0 &   1 &   1 &   0 &   0 &  8 \\
   s_2 &   1 &  -1 &   0 &   1 &   0 &  4 \\
   s_3 &   1 &   1 &   0 &   0 &   1 & 12 \\ \hline
       &  -1 &  -1 &   0 &   0 &   0 &  0
\end{array}

Advanced

\overset{上組合技}{\implies} 或 \underset{下組合技}{\impliedby}

x\xtofrom[f1]fy

\require{extpfeil}
x \xtofrom[f^{-1}]{f} y

x\xrightleftharpoons[f1]fy

\require{mhchem}
x \xrightleftharpoons[f^{-1}]{f} y

Label 'eq:eq_1' multiply defined

\require{ams}
\begin{equation}
   \tag{1}\label{eq:eq_1} E = mc^2 
\end{equation}
% MathJax 照理說已支援 Auto Number,但 HackMD 不支援。
% 只能手動自己加 \tag{1}\label{eq:equation_name}

reference equation(1)

reference\ equation\eqref{eq:eq_1}

E=mc2

\begin{equation*}
  E = mc^2
\end{equation*}
% 不加入 Auto Number,但在 HackMD 上沒差別。

(1+1n)n=k=0n(nk)1nk(1n)k=k=0n(nk)1nk=k=0nn!k!(nk)!×1nk=k=0n1k!n(n1)(n2)(nk+1) k nk=k=0n1k!(nnn1nnk+1n)

% 若命令又長又重複,可用 \def 自訂

\def \kton{\sum\limits_{k=0}^{n}}
\begin{aligned}
  (1+\frac{1}{n})^n &= \kton \binom{n}{k}1^{n-k}(\frac{1}{n})^{k}\\
  &= \kton \binom{n}{k} \frac{1}{n^{k}}\\
  &= \kton \frac{n!}{k!(n-k)!}\times\frac{1}{n^k}\\
  &= \kton \frac{1}{k!} \frac{\overbrace{n(n-1)(n-2)\ldots(n-k+1)}^{共\ k\ 項}}{n^k}\\
  &= \kton \frac{1}{k!} (\frac{n}{n}\frac{n-1}{n}\cdots\frac{n-k+1}{n})
\end{aligned}

ab(x)

\DeclareMathOperator {\total}{總計}
\total_a^b(x)
% 自訂 Operator,命名限 [a-z|A-Z],不可含數字。

xij=AiXj+bi               i=1m;  j=1n

% 加入多個空格在數學公式後面
x_{ij} = A_{i}X_{j} + b_{i} ~~~~~~~~~~~~~~~ i=1 \ldots m; ~~ j = 1 \ldots n

微調字體、字距

Font

ABCDE12345abcde

\mathbb - Used to turn on blackboard-bold for uppercase letters and lowercase 'k'.

ABCDE12345abcde

\mathbf - Used to turn on boldface for uppercase and lowercase letters and digits.

ABCDE12345abcde

\mathit - forces the math italic mode.

ABCDE12345abcde

\mathcal - Used to turn on calligraphic font for uppercase letters and digits.

ABCDE12345abcde

\mathfrak - turn on fraktur font for uppercase and lowercase letters and digits (and a few other characters).

ABCDE12345abcde

\mathrm - Used to turn on roman typestyle for uppercase and lowercase letters.

ABCDE12345abcde

\mathscr - Used to turn on script typestyle for uppercase letters. If lowercase script letters are not available, then they are typeset in a roman typestyle.

ABCDE12345abcde

\mathsf - Used to turn on sans serif typestyle for uppercase and lowercase letters and digits; also affects uppercase greek.

ABCDE12345abcde

\mathtt - Used to turn on typewriter typestyle for uppercase and lowercase letters and digits.

ABCDE12345abcde

\oldstyle - Used to turn on oldstyle font.

If you want to represent bold greek letters.
link for Blod of Greek

Operator (Class Assignment)

\mathord - forces the argument to be treated in the 'ordinary' class.
\mathrel - forces the argument to be treated in the 'relation' class.
\mathinner - forces the argument to appear 'inside' other formulas, and should be surrounded by additional space in certain circumstances.
\mathbin - Used to give the correct spacing to make an object into a binary operator.
\mathstrut - Used to achieve more uniform appearance in adjacent formulas as an invisible box whose width is zero.
\mathpunct
\mathopen
\mathclose
\mathop

\mathxxx{argument}

\mathchoice - provides content that is dependent on the current style (display, text, script, or scriptscript).

\mathchoice{D}{T}{S}{SS}

More

tags: LaTeX