网页上输入数学公式TeX
来源:互联网 发布:淘宝官方旗舰店可信吗 编辑:程序博客网 时间:2024/05/16 18:37
项目中需要在文本输入框中可以输入一些复杂的数学公式,网上调研了一下,发现一个好东西TeX 。
TeX 是Knuth 教授开发的一种优秀的桌面电子排版系统。它提供了一套功能强大并且十分灵活的排版语言,有多达900多条指令,并且具有宏功能,用户可以不断地定义自己适用的新命令来扩展TeX系统的功能。
使用办法很简单,先在网上下载ASCIIMathMLwFallback.js 或 ASCIIMathTeXImg.js 存放到网站根目录,然后在网页中写入
<script type="text/javascript" src="ASCIIMathMLwFallback.js"></script>
或
<script type="text/javascript" src="ASCIIMathTeXImg.js"></script>
我在试验时,ASCIIMathMLwFallback.js不能用,图片显示不出来,不知道什么原因,所以用了ASCIIMathTeXImg.js
然后在想输出公式的地方书写Tex语言就可以显示相关公式,比如想显示根号3,则写`sqrt3`
参考:http://www.pierce.ctc.edu/dlippman/asciimathtex/AMT.html
可以直接将下面的代码保存为html看效果
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>数学公式</title>
<script type="text/javascript" src="ASCIIMathMLwFallback.js"></script>
<script type="text/javascript" src="ASCIIMathTeXImg.js"></script>
</head>
<body>
<table><tr>
<TD>`x^2+y_1+z_12^34`</TD>
<tr></table>
</body>
</html>
下面还有一个sample:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>数学公式</title>
<script type="text/javascript" src="ASCIIMathMLwFallback.js"></script>
<script type="text/javascript" src="ASCIIMathTeXImg.js"></script>
<SCRIPT>
function showTeX(){
sel=document.activeElement;
t = sel.value;
document.getElementById('showTeXs').innerHTML = t;
ASCIIMathDisplay = document.getElementById('showTeXs');
AMprocessNode(ASCIIMathDisplay);
}
function showTxt(){
sel = document.activeElement;
txt2.value = txt2.value + sel.id;
}
</SCRIPT>
</head>
<body>
<TABLE width="50%" border=0>
<TD id=showTeXs></TD></TR>
<TD><TEXTAREA id=txt2 onkeyup=showTeX() onclick=showTeX() name=textarea rows=6 cols=50></TEXTAREA> </TD></TR>
<TR>
<TABLE width="50%" border=0>
<TR>
<TD id=x^2 onmouseover="this.style.backgroundColor='#dddddd'" style="BACKGROUND-COLOR: #ffffff" onclick=showTxt() onmouseout="this.style.backgroundColor='#ffffff'" align=middle width=35>`x^2`</TD>
<TD id=a_n onmouseover="this.style.backgroundColor='#dddddd'" style="BACKGROUND-COLOR: #ffffff" onclick=showTxt() onmouseout="this.style.backgroundColor='#ffffff'" align=middle width=35>`a_n`</TD>
<TD id=a/b onmouseover="this.style.backgroundColor='#dddddd'" style="BACKGROUND-COLOR: #ffffff" onclick=showTxt() onmouseout="this.style.backgroundColor='#ffffff'" align=middle width=35>`a/b`</TD>
<TD id=sqrta onmouseover="this.style.backgroundColor='#dddddd'" style="BACKGROUND-COLOR: #ffffff" onclick=showTxt() onmouseout="this.style.backgroundColor='#ffffff'" align=middle width=35>`sqrta`</TD>
<TD id="`roota b`" onmouseover="this.style.backgroundColor='#dddddd'" style="BACKGROUND-COLOR: #ffffff" onclick=showTxt() onmouseout="this.style.backgroundColor='#ffffff'" align=middle width=35>`roota b`</TD>
<TD id="`int_a^b xdx`" onmouseover="this.style.backgroundColor='#dddddd'" style="BACKGROUND-COLOR: #ffffff" onclick=showTxt() onmouseout="this.style.backgroundColor='#ffffff'" align=middle width=35>`int_a^b xdx`</TD>
<TD id=oo onmouseover="this.style.backgroundColor='#dddddd'" style="BACKGROUND-COLOR: #ffffff" onclick=showTxt() onmouseout="this.style.backgroundColor='#ffffff'" align=middle width=35>`oo`</TD></TR>
<TR>
<TD id=* onmouseover="this.style.backgroundColor='#dddddd'" style="BACKGROUND-COLOR: #ffffff" onclick=showTxt() onmouseout="this.style.backgroundColor='#ffffff'" align=middle width=35>`*` </TD>
<TD id=** onmouseover="this.style.backgroundColor='#dddddd'" onclick=showTxt() onmouseout="this.style.backgroundColor='#ffffff'" align=middle width=35>`**`</TD>
<TD id=xx onmouseover="this.style.backgroundColor='#dddddd'" onclick=showTxt() onmouseout="this.style.backgroundColor='#ffffff'" align=middle width=35>`xx`</TD>
<TD id=-: onmouseover="this.style.backgroundColor='#dddddd'" onclick=showTxt() onmouseout="this.style.backgroundColor='#ffffff'" align=middle width=35>`-:`</TD>
<TD id="`<=`" onmouseover="this.style.backgroundColor='#dddddd'" onclick=showTxt() onmouseout="this.style.backgroundColor='#ffffff'" align=middle width=35>`<=`</TD>
<TD id="`>=`" onmouseover="this.style.backgroundColor='#dddddd'" style="BACKGROUND-COLOR: #ffffff" onclick=showTxt() onmouseout="this.style.backgroundColor='#ffffff'" align=middle width=35>`>=`</TD>
<TD id=!= onmouseover="this.style.backgroundColor='#dddddd'" style="BACKGROUND-COLOR: #ffffff" onclick=showTxt() onmouseout="this.style.backgroundColor='#ffffff'" align=middle width=35>`!=`</TD></TR>
<TR>
<TD id=in onmouseover="this.style.backgroundColor='#dddddd'" onclick=showTxt() onmouseout="this.style.backgroundColor='#ffffff'" align=middle width=35>`in`</TD>
<TD id=!in onmouseover="this.style.backgroundColor='#dddddd'" onclick=showTxt() onmouseout="this.style.backgroundColor='#ffffff'" align=middle width=35>`!in`</TD>
<TD id=sube onmouseover="this.style.backgroundColor='#dddddd'" onclick=showTxt() onmouseout="this.style.backgroundColor='#ffffff'" align=middle width=35>`sube`</TD>
<TD id=supe onmouseover="this.style.backgroundColor='#dddddd'" onclick=showTxt() onmouseout="this.style.backgroundColor='#ffffff'" align=middle width=35>`supe`</TD>
<TD id=nn onmouseover="this.style.backgroundColor='#dddddd'" onclick=showTxt() onmouseout="this.style.backgroundColor='#ffffff'" align=middle width=35>`nn`</TD>
<TD id=uu onmouseover="this.style.backgroundColor='#dddddd'" style="BACKGROUND-COLOR: #ffffff" onclick=showTxt() onmouseout="this.style.backgroundColor='#ffffff'" align=middle width=35>`uu`</TD>
<TD id=x^2 onmouseover="this.style.backgroundColor='#dddddd'" onclick=showTxt() onmouseout="this.style.backgroundColor='#ffffff'" align=middle width=35> </TD></TR></TABLE>
</body>
</html>
另外看到一个博客比较全面的介绍了输入数学公式的几种方法,可以参考:
http://www.lyyz.net/blog/user1/zyair/archives/2007/264.html
- 网页上输入数学公式TeX
- 在 CSDN 网页上插入数学公式
- CentOS 下Enable TeX数学公式备忘
- tex数学公式和字符表示方法
- 如何在博客/论坛上使用(输入)数学公式
- TeX-符号输入收集
- 网页中插入数学公式
- mathjax,网页显示数学公式
- 数学公式的输入
- Markdown输入数学公式
- Markdown输入数学公式
- 流利输入复杂数学公式
- Markdown输入数学公式
- mathtype输入latex数学公式
- 数学公式输入:mathquill
- MarkDown如何输入数学公式
- MarkDown 数学公式输入
- mathjax输入数学公式
- 学习笔记
- MySQL查询优化技术系列讲座之使用索引(二)
- 值得收藏的JAVA经典书籍。
- 一步一学Linux与Windows 共享文件Samba (v0.2b)
- 条款17:以独立语句将newed对象置入智能指针
- 网页上输入数学公式TeX
- 关于signal
- 关系数据库三大范式详细剖析
- Maven使用--setting.xml配置
- C#读取二进制文件入数据库
- A Configuration error occurred during startup.Please verify the preference field with the prompt:Cannot find a free socket for t
- PL/SQL Developer使用技巧
- 【Enhancement】--How to Find a Screen Exit for T-code
- C#从数据库中读取二进制数据,并显示图片