Markdown中写数学公式

Mathematical expressions

Introduction

LaTeX's features for typesetting mathematics make it a compelling choice for writing technical documents. This article shows the most basic commands needed to get started with writing maths using LaTeX.

The well known Pythagorean theorem x^2 + y^2 = z^2 was
proved to be invalid for other exponents.
Meaning the next equation has no integer solutions:

x^n + y^n = z^n

Mathematical modes

LATEX allows two writing modes for mathematical expressions: the inline math mode and display math mode:

  • inline math mode is used to write formulas that are part of a paragraph
  • display math mode is used to write expressions that are not part of a paragraph, and are therefore put on separate lines

Inline math mode

You can use any of these "delimiters" to typeset your math in inline mode:

\(...\)
$...$
\begin{math}...\end{math}

They all work and the choice is a matter of taste, so let's see some examples.

In physics, the mass-energy equivalence is stated
by the equation E=mc^2, discovered in 1905 by Albert Einstein.

In physics, the mass-energy equivalence is stated
by the equation E=mc^2, discovered in 1905 by Albert Einstein.

In physics, the mass-energy equivalence is stated
by the equation \begin{math}E=mc^2\end{math}, discovered in 1905 by Albert Einstein.

Display math mode

Use one of these constructions to typeset maths in display mode:

$$...$$
\begin{displaymath}...\end{displaymath}
\begin{equation}...\end{equation}

The mass-energy equivalence is described by the famous equation

E=mc^2

discovered in 1905 by Albert Einstein.
In natural units (c = 1), the formula expresses the identity

\begin{equation}
E=m
\end{equation}

\begin{equation}
c2=a2+b^2
\end{equation}

Reference guide

description code examples
Greek letters \alpha \beta \gamma \rho \sigma \delta \epsilon \alpha \beta \gamma \rho \sigma \delta \epsilon
Binary operators \times \otimes \oplus \cup \cap \times \otimes \oplus \cup \cap
Relation operators < > \subset \supset \subseteq \supseteq < > \subset \supset \subseteq \supseteq
Others \int \oint \sum \prod \int \oint \sum \prod

more refer

Aligning equations with amsmath

Introduction

The amsmath package provides a handful of options for displaying equations. You can choose the layout that better suits your document, even if the equations are really long, or if you have to include several equations in the same line.

Let's start with a basic example:

\begin{equation} \label{eq1}
\begin{split}
A & = \frac{\pi r^2}{2} \
& = \frac{1}{2} \pi r^2
\end{split}
\end{equation}

Writing a single equation

\begin{equation} \label{eu_eqn}
e^{\pi i} + 1 = 0
\end{equation}

The beautiful equation \ref{eu_eqn} is known as the Euler equation.

Displaying long equations

\begin{equation*}
p(x) = 3x^6 + 14x^5y + 590x4y2 + 19x3y3 \

  • 12x2y4 - 12xy^5 + 2y^6 - a3b3
    \end{equation*}

\begin{equation}
\begin{array}{r}
p(x) = 3x^6 + 14x^5y + 590x4y2 + 19x3y3 \

  • 12x2y4 - 12xy^5 + 2y^6 - a3b3
    \end{array}
    \end{equation}

\begin{equation}
\begin{aligned}
p(x) = 3x^6 + 14x^5y + 590x4y2 + 19x3y3 \

  • 12x2y4 - 12xy^5 + 2y^6 - a3b3
    \end{aligned}
    \end{equation}

Aligning several equations

\begin{align}
2x - 5y &= 8 \
3x + 9y &= -12
\end{align
}

1 \over 2

\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
}

Grouping and centering equations

\begin{gather}
2x - 5y = 8 \
3x^2 + 9y = 3a + c
\end{gather
}

Subscripts and superscripts

Introduction

Definite integrals are some of the most common mathematical expressions, so let's see an example:
\int\limits_0^1 x^2 + y^2 \ dx

The command \limits changes the way the limits are displayed in the integral, if not present the limits would be next to the integral symbol instead of being on top and bottom:
\int_0^1 x^2 + y^2 \ dx

More detailed examples

a_1^2 + a_2^2 = a_3^2
a^2_1 + a^2_2 = a^2_3

x^{2 \alpha} - 1 = y_{ij} + y_{ij}

(a^n)^{r+s} = a^{nr+ns}

Operators using subscripts and superscripts

\sum_{i=1}^{\infty} \frac{1}{n^s} = \prod_p \frac{1}{1 - p^{-s}}

Reference guide

LATEX markup Renders as
a_{n_i} a_{n_{i}}
\int_{i=1}^n \int_{i=1}^n
\sum_{i=1}^{\infty} \sum_{i=1}^{\infty}
\prod_{i=1}^n \prod_{i=1}^n
\cup_{i=1}^n \cup_{i=1}^n
\cap_{i=1}^n \cap_{i=1}^n
\oint_{i=1}^n \oint_{i=1}^n
\coprod_{i=1}^n \coprod_{i=1}^n

Integrals, sums and limits

Integrals

Integral \int_{a}^{b} x^2 \,dx inside text
\int_{a}^{b} x^2 \,dx

Multiple integrals

Example of multiple integrals
\begin{gather}
\iint_V \mu(u,v) ,du,dv
\
\iiint_V \mu(u,v,w) ,du,dv,dw
\
\iiiint_V \mu(t,u,v,w) ,dt,du,dv,dw
\
\idotsint_V \mu(u_1,\dots,u_k) ,du_1 \dots du_k
\end{gather
}
Example of integrals
\oint_V f(s) \,ds

Sums and products

Sum \sum_{n=1}^{\infty} 2^{-n} = 1 inside text
\sum_{n=1}^{\infty} 2^{-n} = 1

Product \prod_{i=a}^{b} f(i) inside text

\prod_{i=a}^{b} f(i)

Limits

Limit \lim_{x\to\infty} f(x) inside text

\lim_{x\to\infty} f(x)

Fractions and Binomials

The binomial coefficient, \binom{n}{k}, is defined by the expression:
\binom{n}{k} = \frac{n!}{k!(n-k)!}

Displaying fractions

Fractions can be used inline within the paragraph text, for
example \frac{1}{2}, or displayed on their own line,
such as this:
\frac{1}{2}

Text-style fractions

\frac{\text{numerator}}{\text{denominator}}

\frac{\verb{numerator}}{\verb{denominator}}

Without the \verb|\text{...}| command the result
looks like this:

\frac{numerator}{denominator}

Size and spacing within typeset mathematics

Fractions typeset within a paragraph typically look like this: \frac{3x}{2}. You can force \LaTeX{} to use the larger display style, such as \displaystyle \frac{3x}{2}, which also has an effect on line spacing. The size of maths in a paragraph can also be reduced: \scriptstyle \frac{3x}{2} or \scriptscriptstyle \frac{3x}{2}. For the \verb|\scriptscriptstyle| example note the reduction in spacing: characters are moved closer to the \textit{vinculum} (the line separating numerator and denominator).

Equally, you can change the style of mathematics normally typeset in display style:

f(x)=\frac{P(x)}{Q(x)}\quad \textrm{and}\quad \textstyle f(x)=\frac{P(x)}{Q(x)}\quad \textrm{and}\quad \scriptstyle f(x)=\frac{P(x)}{Q(x)}

Continued fractions

Fractions can be nested but, in this example, note how the default math styles, as used in the denominator, don't produce ideal results...

\frac{1+\frac{a}{b}}{1+\frac{1}{1+\frac{1}{a}}}

\noindent ...so we use \verb|\displaystyle| to improve typesetting:

\frac{1+\frac{a}{b}} {\displaystyle 1+\frac{1}{1+\frac{1}{a}}}

Here is an example which uses the \texttt{amsmath} \verb|\cfrac| command:

a_0+\cfrac{1}{a_1+\cfrac{1}{a_2+\cfrac{1}{a_3+\cdots}}}

Here is another example, derived from the \texttt{amsmath} documentation, which demonstrates left
and right placement of the numerator using \verb|\cfrac[l]| and \verb|\cfrac[r]| respectively:
\cfrac[l]{1}{\sqrt{2}+ \cfrac[r]{1}{\sqrt{2}+ \cfrac{1}{\sqrt{2}+\dotsb}}}

A final example

\newcommand{\contfrac}[2]{% { \rlap{$\dfrac{1}{\phantom{#1}}$}% \genfrac{}{}{0pt}{0}{}{#1+#2}% } }
a_0 + \contfrac{a_1}{ \contfrac{a_2}{ \contfrac{a_3}{ \genfrac{}{}{0pt}{0}{}{\ddots} }}}

\genfrac(]{0pt}{2}{a+b}{c+d}

\phantom{my long text}XX
a\mathrel{\rlap{\;/}{=}}b

\newcommand{\vect}[1]{{\mathbf{\boldsymbol{{#1}}}}}
This is the vector \vect{x}.

Brackets and Parentheses

Introduction

Here's an table of listing some common math braces and parentheses used in LATEX:

Type LATEX markup Renders as
Parentheses; round brackets (x+y) (x+y)
Brackets; square brackets [x+y] [x+y]
Braces; curly brackets { x+y } \{ x+y \}
Angle brackets \langle x+y \rangle \langle x+y \rangle
Pipes; vertical bars x+y| |x+y|
Double pipes \ \ |x+y\ \ \|x+y\|

常用符号


\begin{array}{r}
\sqrt{x},\sqrt[n]{y}
\end{array}

\to, \infty

\forall, \exists
\mathcal x,y,z
\mathbb R,\mathbb Z,\mathbb N
\mathbb Z,\mathbb N
\int_{a}^{b}, \frac{\partial y}{\partial x}
\sum_{i=1}^{n}, \prod_{i=1}^{n}

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,189评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,577评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,857评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,703评论 1 276
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,705评论 5 366
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,620评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,995评论 3 396
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,656评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,898评论 1 298
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,639评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,720评论 1 330
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,395评论 4 319
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,982评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,953评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,195评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 44,907评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,472评论 2 342

推荐阅读更多精彩内容