求latex输入下列latex 数学公式对齐时应该怎么输入,用什么数学环境

查看: 3779|回复: 1
使用自定义discuz编码实现Latex数学公式的输入
自己和同学们建了个论坛自己玩,因为都是理科生,所以一直想在论坛里加入输入公式的功能。
过去在插件区有过一个插件,可以实现这个功能,但是那个作者只更新到dz7.0,我开始用dz的时候就已经是7.2了,那个插件也没法继续用。也联系到了那位作者,想让他帮忙升级。不过最终没有使用他的插件,因为我用的服务器不支持cgi,所以不能在自己的服务器上运算公式。
当然啦,这些都不重要。总之呢,我现在搞明白怎样利用自定义discuz编码,并借用其他网站的在线公式编辑器,来实现在自己论坛的Latex数学公式的输入了。
具体操作如下(我现在用的已经是dzx1.5了,其他版本的操作应该也类似):
1,打开后台,界面&&编辑器设置&&discuz代码
2,新增标签为tex的代码。这个标签可以自定义,只要和已有的标签不冲突就可以了,只是作为编辑器识别编码的一个代号。为了让用户理解这是latex的数学公式代码,我就直接使用tex作为标签了。
3,然后为你的新增代码设置一个图片,如果懒的话可以借用其他未使用的自定义代码的图片,也可以自己做一个,上传的目录是/static/image/common/。这个很简单
4,进入新增代码的“详情”设置
5,在“替换内容”那一栏填写如下代码
&img src=&/gif.latex?{1}& title=&{1}& /&复制代码6,填写其他设置。“解释”那一栏可以填写“添加公式”,“参考提示语”一栏可以填写“请输入公式的latex编码”,选择允许使用这一编码的用户组,你可以限制某些组的用户不能使用这一编码。
8,测试。回到前台,在发帖界面测试代码,点击代码的图标在对话框里填写公式的latex排版编码,或者在[tex]和[/tex]之间输入。设置是否成功在编辑界面还看不出来,无论是否是纯文本,这个都只显示成编码的形式。只有在发帖之后,才能看到公式是否生成了。
到此就设置完毕了,我的论坛是内部论坛,就不发地址让大家去我那里体验了哈。虽然输入公式是个挺小众的功能,但毕竟对于一些数学或者物理论坛来说,也是一个必不可少的功能。所以发上来跟大家分享,希望能帮到各位学术论坛的站长。
我会在二楼稍微解释一下代码的原理,虽然挺简单的,但是说明出来应该会让更有水平的站长去改进。
谢谢大家。
本帖最后由 matengbjtu 于
21:58 编辑
先占楼,解释代码原理&img src=&/gif.latex?{1}& title=&{1}& /&复制代码这段代码是什么意思呢。
事实上,我使用的是一个在线的公式编辑器,网址是/latex/eqneditor.php
这个网站的公式编辑完成之后,仔细观察网页下方给出的html编码。格式是这样的:
&img src=&/gif.latex?公式的latex排版& title=&公式的latex排版& /&复制代码而discuz自定义代码的规则就是,把[tex]公式的latex排版[/tex]解读为上面的这一行html编码。于是就实现了借用外部的在线公式编辑器,利用discuz自定义代码,完成在本论坛的公式输入。
事实上,我在最开始提到的那个插件,利用的也是类似的方式,只不过那位作者把latex软件中的相关功能安装到了自己的主机上,而不需要借用外部的公式编辑器。但是运行latex软件需要主机支持cgi,而大部分虚拟主机都没有这个功能,所以我就采用了现在的办法。
最后要说的就是,如果哪位的虚拟主机支持cgi,不妨研究一下那位作者的插件,链接在此
另外我刚刚发现还有一位站长已经发布了公式插件,链接在此 这个功能似乎更加强大,有图形界面的编辑器。这位朋友说不确定x1.5是否能用,我也没有测试。有兴趣的站长可以测试一下。
Powered by分享给朋友:latex数学公式输入视频教程1下载至电脑扫码用手机看用或微信扫码在手机上继续观看二维码2小时内有效latex数学公式输入视频教程1扫码用手机继续看用或微信扫码在手机上继续观看二维码2小时内有效,扫码后可分享给好友没有优酷APP?立即下载请根据您的设备选择下载版本
药品服务许可证(京)-经营- 请使用者仔细阅读优酷、、、Copyright(C)2017 优酷
版权所有不良信息举报电话:LaTeX中插入数学公式
最强大的功能就是显示美丽的数学公式,
下面我们来看这些公式是怎么实现的.
1、数学公式的前后要加上$或\(和\),比如:$f(x) = 3x + 7$和\(f(x) =
3x + 7\)效果是一样的;
如果用\[和\],或者使用$$和$$,则改公式独占一行;
如果用\begin{equation}和\end{equation},则公式除了独占一行还会自动被添加序号.
如何公式不想编号则使用\begin{equation*}和\end{equation*}.
普通字符在数学公式中含义一样,除了
# $ % & ~ _ ^ \ { }
若要在数学环境中表示这些符号# $ % & _ { }, 需要分别表示为\# \$ \%
\& \_ \{ \},即在个字符前加上\。
3、上标和下标
用^来表示上标,用_来表示下标. 看一简单例子:
$$\sum_{i=1}^n
$$f(x)=x^{x^x}$$
这里有更多的
4、希腊字母
5、数学函数&
6、在公式中插入文本
可以通过\mbox{text}在公式中添加text,比如:
\documentclass{article}
\usepackage{CJK}
\begin{CJK*}{GBK}{song}
\begin{document}
$$\mbox{对任意的$x&0$}, \mbox{有 }f(x)&0.
\end{CJK*}
\end{document}
7、分数及开方
\frac{numerator}{denominator}
\sqrt{expression_r_r_r}表示开平方,\sqrt[n]{expression_r_r_r}表示开n次方。
8、省略号(3个点)
\ldots表示跟文本底线对齐的省略号;\cdots表示跟文本中线对齐的省略号,
$$f(x_1,x_x,\ldots,x_n) = x_1^2 + x_2^2 + \cdots + x_n^2
$$9、括号和分隔符
()和[ ]和|对应于自己;{}对应于\{ \}; ||对应于\|。
当要显示大号的括号或分隔符时,要对应用\left和\right,如:
\[ f(x,y,z) = 3y^2 z
\left( 3 + \frac{7x+5}{1 + y^2} \right).\]
只用与匹配,本身是不显示的,比如,要输出:
$$\left. \frac{du}{dx} \right|_{x=0}.$$
10、多行的数学公式
可以表示为:\begin{eqnarray*}
\cos 2\theta & = & \cos^2 \theta -
\sin^2 \theta \\
& = & 2 \cos^2 \theta - 1.
\end{eqnarray*}
其中&是对其点,表示在此对齐。
*使latex不自动显示序号,如果想让latex自动标上序号,则把*去掉
11、矩阵表示为:
The \emph{characteristic polynomial} $\chi(\lambda)$ of the
$3 \times 3$~matrix
\[ \left( \begin{array}{ccc}
a & b & c \\
d & e & f \\
g & h & i \end{array}
is given by the formula
\[ \chi(\lambda) = \left| \begin{array}{ccc}
\lambda - a & -b & -c \\
-d & \lambda - e & -f \\
-g & -h & \lambda - i \end{array}
\right|.\]
c表示向中对齐,l表示向左对齐,r表示向右对齐。
12、导数、极限、求和、积分(Derivatives, Limits, Sums and Integrals)
The expression_r_r_rs
are obtained in LaTeX by typing \frac{du}{dt} and
\frac{d^2 u}{dx^2} respectively. The mathematical
is produced using \partial. Thus the Heat Equation
is obtained in LaTeX by typing
\[ \frac{\partial u}{\partial t}
= h^2 \left( \frac{\partial^2 u}{\partial x^2}
+ \frac{\partial^2 u}{\partial y^2}
+ \frac{\partial^2 u}{\partial z^2} \right) \]
To obtain mathematical expression_r_r_rs such as
in displayed equations we type \lim_{x \to +\infty},
\inf_{x & s} and \sup_K
respectively. Thus to obtain
(in LaTeX) we type
\[ \lim_{x \to 0} \frac{3x^2 +7x^3}{x^2 +5x^4} = 3.\]
To obtain a summation sign such as
we type \sum_{i=1}^{2n}. Thus
is obtained by typing
\[ \sum_{k=1}^n k^2 = \frac{1}{2} n (n+1).\]
We now discuss how to obtain integrals in mathematical
documents. A typical integral is the following:
This is typeset using
\[ \int_a^b f(x)\,dx.\]
The integral sign
typeset using the control sequence \int, and the
limits of integration (in this case a and
b are treated as a subscript and a superscript on the
integral sign.
Most integrals occurring in mathematical documents begin with an
integral sign and contain one or more instances of d
followed by another (Latin or Greek) letter, as in dx,
dy and dt. To obtain the correct appearance one
should put extra space before the d, using
are obtained by typing
\[ \int_0^{+\infty} x^n e^{-x} \,dx = n!.\]
\[ \int \cos \theta \,d\theta = \sin \theta.\]
\[ \int_{x^2 + y^2 \leq R^2} f(x,y)\,dx\,dy
= \int_{\theta=0}^{2\pi} \int_{r=0}^R
f(r\cos\theta,r\sin\theta) r\,dr\,d\theta.\]
\[ \int_0^R \frac{2x\,dx}{1+x^2} = \log(1+R^2).\]
respectively.
In some multiple integrals (i.e., integrals containing more than
one integral sign) one finds that LaTeX puts too much space between
the integral signs. The way to improve the appearance of of the
integral is to use the control sequence \! to remove a
thin strip of unwanted space. Thus, for example, the multiple
is obtained by typing
\[ \int_0^1 \! \int_0^1 x^2 y^2\,dx\,dy.\]
Had we typed
\[ \int_0^1 \int_0^1 x^2 y^2\,dx\,dy.\]
we would have obtained
A particularly noteworthy example comes when we are typesetting
a multiple integral such as
Here we use \! three times to obtain suitable spacing
between the integral signs. We typeset this integral using
\[ \int \!\!\! \int_D f(x,y)\,dx\,dy.\]
Had we typed
\[ \int \int_D f(x,y)\,dx\,dy.\]
we would have obtained
The following (reasonably complicated) passage exhibits a number
of the features which we have been discussing:
One would typeset this in LaTeX by typing
In non-relativistic wave mechanics, the wave function
$\psi(\mathbf{r},t)$ of a particle satisfies the
\emph{Schr\"{o}dinger Wave Equation}
\[ i\hbar\frac{\partial \psi}{\partial t}
= \frac{-\hbar^2}{2m} \left(
\frac{\partial^2}{\partial x^2}
+ \frac{\partial^2}{\partial y^2}
+ \frac{\partial^2}{\partial z^2}
\right) \psi + V \psi.\]
It is customary to normalize the wave equation by
demanding that
\[ \int \!\!\! \int \!\!\! \int_{\textbf{R}^3}
\left| \psi(\mathbf{r},0) \right|^2\,dx\,dy\,dz = 1.\]
A simple calculation using the Schr\"{o}dinger wave
equation shows that
\[ \frac{d}{dt} \int \!\!\! \int \!\!\! \int_{\textbf{R}^3}
\left| \psi(\mathbf{r},t) \right|^2\,dx\,dy\,dz = 0,\]
\[ \int \!\!\! \int \!\!\! \int_{\textbf{R}^3}
\left| \psi(\mathbf{r},t) \right|^2\,dx\,dy\,dz = 1\]
for all times~$t$. If we normalize the wave function in this
way then, for any (measurable) subset~$V$ of $\textbf{R}^3$
and time~$t$,
\[ \int \!\!\! \int \!\!\! \int_V
\left| \psi(\mathbf{r},t) \right|^2\,dx\,dy\,dz\]
represents the probability that the particle is to be found
within the region~$V$ at time~$t$.
推荐书目:
LATEX 使用一种特殊的模式来排版数学符号和公式。段落中的数学表达式应该置于( 和), $ 和$ 或者begin{math}
和end{math} 之间。
$c^{2}=a^{2}+b^{2}$
对于较大的数学式子,最好的方法是使用显示式样来排版:将它们放置于[ 和] 或begin{displaymath}
和end{displaymath} 之间。这样排版出的公式是没有编号的。如果你希望LATEX
对其添加编号的话,可以使用equation 环境来达到这一目的。
对比一下用不同式样排版所得到的结果:
$lim_{n to infty}
sum_{k=1}^n frac{1}{k^2}
= frac{pi^2}{6}$
begin{displaymath}
lim_{n to infty}
sum_{k=1}^n frac{1}{k^2}
= frac{pi^2}{6}
end{displaymath}
下面的这些字符是LATEX 的保留字符,它们或在LATEX
中有特定的用处,或不一定包含在所有的字库中。如果你直接在文本中使用它们,通常在排版结果中将不会得到这些字符,而且还会导致LATEX
做一些你不希望发生的事情。
# $ % ^ & _ { } ~
当然,这些字符前面加上反斜线,就可以在文本中得到它们。
# $ % ^{} & _ { } ~{}
另外一些符号可以由特殊的命令或作为重音命令得到。反斜线不能够通过在其前添加另外的反斜线来得到,相反的, 是一个用来断行的命令。
1.小写希腊字母(Lowercase Greek letters )的输入命令为:alpha,
beta, gamma, . . . ,相应地,大写形式的输入命令为:Gamma, Delta,. . . 。
$lambda,xi,pi,mu,Phi,Omega$
2.指数和下标可用^ 和_ 后加相应的字符来实现。
$a_{1}$ qquad $x^{2}$ qquad
$e^{-alpha t}$ qquad
$a^{3}_{ij}$
$e^{x^2} neq {e^x}^2$
3.平方根(square root)的输入命令为:sqrt,n
次方根相应地为:sqrt[n]。方根符号的大小由LATEX自动加以调整。也可用surd
仅给出符号。
$sqrt{x}$ qquad
$sqrt{ x^{2}+sqrt{y} }$
qquad $sqrt[3]{2}$[3pt]
$surd[x^2 + y^2]$
4.命令overline 和underline 在表达式的上、下方画出水平线。
$overline{m+n}$ qquad
$underline{m+n}$
5.命令overbrace 和underbrace 在表达式的上、下方给出一水平的大括号。
$underbrace{ a+b+cdots+z }_{26}$
6.向量(Vectors)通常用上方有小箭头(arrow symbols)的变量表示。这可由vec
得到。另两个命令overrightarrow 和overleftarrow
在定义从A 到B 的向量时非常有用。
begin{displaymath}
vec aquadoverrightarrow{AB}
end{displaymath}
7.乘法算式中的圆点符可以省略。然而有时为了帮助读者解读复杂的公式,也有必要用命令cdot 将圆点符表示出来。
begin{displaymath}
v = {sigma}_1 cdot
{tau}_1 cdot {tau}_2
end{displaymath}
8.函数名通常用罗马字体正体排版,而不是像变量名一样用意大利体排版。因此,LATEX提供下述命令来排版最重要的一些函数名。
arccos cos csc exp ker limsup min
arcsin cosh deg gcd lg ln Pr
arctan cot det hom lim log sec
arg coth dim inf liminf max sin
sinh sup tan tanh
[lim_{x rightarrow 0}
frac{sin x}{x}=1]
9.分数(fraction)使用frac{...}{...} 排版。
$1frac{1}{2}$~hours
begin{displaymath}
frac{ x^{2} }{ k+1 }qquad
x^{ frac{2}{k+1} }qquad
end{displaymath}
10.排版二项系数或类似的结构可以使用命令{... choose ...} 或{... atop
...}。第二个命令与第一个命令的输出相同,只是没有括
begin{displaymath}
{n choose k}qquad {x atop y+2}
end{displaymath}
11.积分运算符(integral operator)用int 来生成。求和运算符(sum operator)由sum
生成。乘积运算符(product operator)由prod 生成。上限和下限用^ 和_ 来生成,类似于上标和下标。
begin{displaymath}
sum_{i=1}^{n} qquad
int_{0}^{frac{pi}{2}} qquad
prod_epsilon
end{displaymath}
12.对于括号(braces)和其它分隔符(delimiters),在TEX中有各种各样的符号(例如[ h k
l)。圆括号和方括号可以用相应的键输入。花括号用{。其它的分隔符用专门命令(例如updownarrow)来生成。
begin{displaymath}
{a,b,c}neq{a,b,c}
end{displaymath}
13.将三个圆点(three dots)输入公式可以使用几种命令。ldots 将点排在基线上。cdots
将它们设置为居中。除此之外,可用vdots 命令使其垂直,而用ddots 将得到对角型(diagonal dots)。
begin{displaymath}
x_{1},ldots,x_{n} qquad
x_{1}+cdots+x_{n}
end{displaymath}
14.如果公式中由TEX选择的的空格不令人满意,可以通过插入特殊的空格命令来进行调节。有几个命令用于小空格:, 对应于3/18
quad ( ),: 对应于4/18 quad ( ),; 对应于5/18 quad ( )。脱离的空格符号
生成中等大小的空格。quad ( ) 和qquad ( ) 产生大空格。quad 的大小对应于目前字体中字符‘M’ 的宽度。!
命令生成负空格-3/18 quad ( )。
newcommand{ud}{mathrm{d}}
begin{displaymath}
int!!!int_{D} g(x,y)
, ud x, ud y
end{displaymath}
instead of
begin{displaymath}
intint_{D} g(x,y)ud x ud y
end{displaymath}
15.排版arrays 使用array 环境来排版矩阵(arrays)。它有些类似于tabular环境,使用 命令来分行。
begin{displaymath}
mathbf{X} =
left( begin{array}{ccc}
x_{11} & x_{12} & ldots
x_{21} & x_{22} & ldots
vdots & vdots & ddots
end{array} right)
end{displaymath}
array 环境也可以使用“.” 作为隐藏右分隔符来排版只有一个大分隔符的表达式。
begin{displaymath}
y = left{ begin{array}{ll}
a & textrm{if $d&c$}
b+x & textrm{in the morning}
l & textrm{all day long}
end{array} right.
end{displaymath}
像在tabular 环境中一样,也可以在array 环境中画线。例如分隔矩阵中的元素。
begin{displaymath}
left(begin{array}{c|c}
end{array}right)
end{displaymath}
对于分布于几行的公式或者方程组(equation system),可以使用eqnarray 和eqnarray*
环境来代替equation。在eqnarray 中,每一行都会有一个方程编号。eqnarray* 不对方程进行编号。eqnarray
和eqnarray* 环境类似于{rcl} 形式的三列表格。中间的一列可以用作等号或不等号,或者其它看起来适合的符号。使用
命令分行。
begin{eqnarray}
f(x) & = & cos x
f'(x) & = & -sin x
int_{0}^{x} f(y)dy &
end{eqnarray}
16.在LATEX中很难得到粗体符号。这也许是故意的,因为业余排版者总是过份使用粗体。字体改变命令mathbf
给出粗体字母,但是这些是罗马字体(竖直的),而数学符号通常是斜体。有一个boldmath
命令,但是这只能用于数学模式之外。对于符号也是如此。
begin{displaymath}
mu, M qquad mathbf{M} qquad
mbox{boldmath $mu, M$}
end{displaymath}
使用工具包中的amsbsy(包括在amsmath 中)和bm 很容易办到这点,因为它们包含boldsymbol命令。
begin{displaymath}
mu, M qquad
boldsymbol{mu}, boldsymbol{M}
end{displaymath}
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。}

我要回帖

更多关于 latex 编辑数学公式 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信