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}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容