MathJax和相关的Latex语法。

慢慢补:)
##0.语法及常见错误

所有公式都需要被一个或两个美元符号$括起来(下面的有些语句可能会省略两边的$),例如$x=a$ x = a x=a x=a$$x=a$$ x = a x=a x=a 它们分别代表行内公式和行间公式。有一些特定的样式可以由\begin{}\end{}括起来,例如数组,矩阵,等等。此处{}里填的就是这些样式的名字,例如数组,就是用\begin{array}\end{array}括起来表示的,像是这样\begin{array} {c|c} \text{this}&\text{is}\ \hline
\text{an}&\text{array}\end{array}对,array也可以用来表示表格!

上述代码是

\begin{
   array} {
   c|c} \text{
   this}&\text{
   is}\\ 
\hline
\text{
   an}&\text{
   array}\end{
   array}

语法上要注意的是,{}代表括起来的东西作为一个整体,如果没有这个括号,例如\begin array,就会被理解成\begin a,而这又是一个不存在的命令,就无法解析。另外的例子还有,在表示下标时用$x_{abc}$的结果为 x a b c x_{abc} xabc而用$x_abc$的结果为 x a b c x_abc xabc。以及如果\begin{array}\end{array}之间存在了一个空行,那么它们就没法括在一起,也是语法错误。

1. 公式样式、表格、图表和矩阵

1.1. 公式

1.1.1. 基本排版

公式的基本排版有行中和行间两种。行中公式放在文中与其它文字混编,行间公式单独成行。有点像css样式里的block和inline block
行中公式用一个美元符号括起:\$数学公式\$
行间公式则用两个美元符号括起:\$\$数学公式\$\$
例1:
$y=x^2$ ----- y = x 2 y=x^2 y=x2
$$y=x^2$$ ----- y = x 2 y=x^2 y=x2

1.1.2. 对齐的公式
1.1.3. 分类表达式
1.1.4. 方程组
1.1.5. 标签和引用

For longer calculations (or referring to other post’s results) it is convenient to use the tagging/labelling/referencing system. To tag an equation use \tag{yourtag}, and if you want to refer to that tag later on, add \label{somelabel} right after the \tag. It is not necessary that yourtag and somelabel are the same, but it usually is more convenient to do so:

KaTeX parse error: Expected 'EOF', got '\label' at position 22: …x^2-y^3 \tag{*}\̲l̲a̲b̲e̲l̲{*}
a:=x2−y3(*)
In order to refer to an equation, just use \eqref{somelabel}

KaTeX parse error: Expected '}', got '\eqref' at position 18: …+y^3 \stackrel{\̲e̲q̲r̲e̲f̲{*}}= x^2
a+y3=(*)x2
or \ref{somelabel}

Equations are usually referred to as KaTeX parse error: Expected 'EOF', got '\eqref' at position 1: \̲e̲q̲r̲e̲f̲{*}, but you can also use KaTeX parse error: Expected 'EOF', got '\ref' at position 1: \̲r̲e̲f̲{*}.
Equations are usually referred to as (*), but you can also use *.

As you can see, references are even turned into hyperlinks, which you can use externally as well, e.g. like this. Note that you can also reference labels in other posts as long as they appear on the same site, which is especially useful when referring to a question with multiple equations, or when commenting on a post.

Due to a bug blocks containing a \label will break in preview, as a workaround you can put \def\label#1{} in your post while editing and remove that on submission - unfortunately this means you won’t spot misspelled references before submitting… Just don’t forget to remove that \def again
###1.1.6. 高亮公式
To highlight an equation, \bbox can be used. E.g,

KaTeX parse error: Expected 'EOF', got '\bbox' at position 2: \̲b̲b̲o̲x̲[yellow] { e^x=…
produces

ex=limn→∞(1+xn)n(1)
By default, the bounding box is “tight”, so it doesn’t extend beyond the characters used in the formula. You can add a little space around the equation by adding a measurement after the color. E.g.,

KaTeX parse error: Expected 'EOF', got '\bbox' at position 2: \̲b̲b̲o̲x̲[yellow,5px] { …
produces

ex=limn→∞(1+xn)n(1)
To add a border, use

KaTeX parse error: Expected 'EOF', got '\bbox' at position 2: \̲b̲b̲o̲x̲[5px,border:2px…
produces

ex=limn→∞(1+xn)n(2)
You can do both border and background, as well:

KaTeX parse error: Expected 'EOF', got '\bbox' at position 2: \̲b̲b̲o̲x̲[yellow,5px,bor…
produces

ex=limn→∞(1+xn)n(1)

1.2. 表格

mathjax实际上不支持Latex的这里的表格,在mathjax中其实是数组,但是它能实现类似表格的排版功能,因此也把它归类于表格吧。可以使用$$\begin{array}{列样式}...\end{array}$$这样的形式来创建表格,列样式clr分别表示居中,左,右对齐,还可以使用|表示一条竖线。表格中各行使用\\分隔,各列使用&分隔,使用\hline在本行前加入一条直线。

 $$\begin{
   array}
 {
   c|lcr} n & \text{
   Left} & \text{
   Center} & \text{
   Right} \\
 2 & -1 & 189 & -8 \\
 3 & -20 & 2000 & 1+10i \\
 \end{
   array}$$

n Left Center Right 1 0.24 1 125 2 − 1 189 − 8 3 − 20 2000 1 + 10 i \begin{array}{c|lcr} n & \text{Left} & \text{Center} & \text{Right} \\ \hline 1 & 0.24 & 1 & 125 \\ 2 & -1 & 189 & -8 \\ 3 & -20 & 2000 & 1+10i \\ \end{array} n123Left0.24120Center11892000Right12581+10i
一个复杂的例子如下:

$$\begin{
   array} {
   c}
% inner horizontal array of arrays
\begin{
   array} {
   cc}
% inner array of minimum values
\begin{
   array} {
   c|cccc}
\text{
   min} & 0 & 1 & 2 & 3\\
\hline
0 & 0 & 0 & 0 & 0\\
1 & 0 & 1 & 1 & 1\\
2 & 0 & 1 & 2 & 2\\
3 & 0 & 1 & 2 & 3
\end{
   array}
&
% inner array of maximum values
\begin{
   array} {
   c|cccc}
\text{
   max}&0&1&2&3\\
\hline
0 & 0 & 1 & 2 & 3\\
1 & 1 & 1 & 2 & 3\\
2 & 2 & 2 & 2 & 3\\
3 & 3 & 3 & 3 & 3
\end{
   array}
\end{
   array}
\\
% inner array of delta values
\begin{
   array} {
   c|cccc}
\Delta&0&1&2&3\\
\hline
0 & 0 & 1 & 2 & 3\\
1 & 1 & 0 & 1 & 2\\
2 & 2 & 1 & 0 & 1\\
3 & 3 & 2 & 1 & 0
\end{
   array}
\end{
   array}$$

min 0 1 2 3 0 0 0 0 0 1 0 1 1 1 2 0 1 2 2 3 0 1 2 3 max 0 1 2 3 0 0 1 2 3 1 1 1 2 3 2 2 2 2 3 3 3 3 3 3 Δ 0 1 2 3 0 0 1 2 3 1 1 0 1 2 2 2 1 0 1 3 3 2 1 0 \begin{array} {c} % inner horizontal array of arrays \begin{array} {cc} % inner array of minimum values \begin{array} {c|cccc} \text{min} & 0 & 1 & 2 & 3\\ \hline 0 & 0 & 0 & 0 & 0\\ 1 & 0 & 1 & 1 & 1\\ 2 & 0 & 1 & 2 & 2\\ 3 & 0 & 1 & 2 & 3 \end{array} & % inner array of maximum values \begin{array} {c|cccc} \text{max}&0&1&2&3\\ \hline 0 & 0 & 1 & 2 & 3\\ 1 & 1 & 1 & 2 & 3\\ 2 & 2 & 2 & 2 & 3\\ 3 & 3 & 3 & 3 & 3 \end{array} \end{array} \\ % inner array of delta values \begin{array} {c|cccc} \Delta&0&1&2&3\\ \hline 0 & 0 & 1 & 2 & 3\\ 1 & 1 & 0 & 1 & 2\\ 2 & 2 & 1 & 0 & 1\\ 3 & 3 & 2 & 1 & 0 \end{array} \end{array} min01230

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值