AMS乳胶兼容转换器,将胶乳的子集映射到标记/ MaTjax。
latex2markdown的Python项目详细描述
与AMS-LaTeX兼容 从(a子集)LaTeX到 MathJaX兼容 Markdown。
任何使用ams乳胶包编写乳胶文档的人 (amsmath,amsthm,amssymb)并希望转换这些 标记要与mathjax一起使用的格式的文档。这些标记文件 然后可以很容易地添加到任何网络平台-jekyll博客,wordpress, 基本的HTML站点等。
简而言之,如果您试图使用mathjax查看您的乳胶文档 在网上,你可能会对此感兴趣。
演示
退房 tullo.ch/projects/LaTeX2Markdown 现场演示转换器。
开始
安装
该项目在pypi上提供,因此获得它就像使用
pip install latex2markdown
或
easy_install latex2markdown
使用量
该实用程序可以从命令行调用,也可以从python中调用 脚本。
对于命令行,将乳胶文件转换为标记的语法 文件如下:
python -m latex2markdown path/to/latex/file path/to/output/markdown/file
例如,要将乳胶文件sample.tex编译为标记文件 sample.md,呼叫
python -m latex2markdown sample.tex sample.md
在python脚本中使用(扩展、修改输出等) 您可以如下使用:
import latex2markdown with open("latex_file.tex", "r") as f: latex_string = f.read() l2m = latex2markdown.LaTeX2Markdown(latex_string) markdown_string = l2m.to_markdown() with open("markdown_file.md", "w") as f: f.write(markdown_string)
最后,在加载时将以下代码片段添加到html中 文件。
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ extensions: ["tex2jax.js", "AMSmath.js"], jax: ["input/TeX", "output/HTML-CSS"], tex2jax: { inlineMath: [ ['$','$'], ["\\(","\\)"] ], displayMath: [ ['$$','$$'], ["\[","\]"] ], processEscapes: true }, }); </script> <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"> </script>
为什么不使用pandoc呢?
Pandoc 是一个优秀的文档转换器,用于不太复杂的乳胶文档。 实际上,我用它把这个自述文件转换成了rest版本 用于PYPI。
不幸的是,它不是用来处理使用 Amstex扩展-包括定理、引理、证明和 大量用于排版的练习环境, 讲稿和其他文件。
由于pandoc和mathjax都无法处理这些文档,我入侵了 一组正则表达式可以转换乳胶的子集 再使用一些小标记将其转换为 Mathjax敞篷车降价。
示例
例如,以下乳胶代码:
\section{Example Section} \begin{thm}[Euclid] There are infinitely many primes. \end{thm} \begin{proof} Suppose that $p_1 < p_2 < \dots < p_n$ are all of the primes. Let $P = 1 + \prod_{i=1}^n p_i$ and let $p$ be a prime dividing $P$. Then $p$ can not be any of $p_i$, for otherwise $p$ would divide the difference $P - \left(\prod_{i=1}^n p_i \right) - 1$, which is impossible. So this prime $p$ is still another prime, and $p_1, p_2, \dots p_n$ cannot be all of the primes. \end{proof}
转换为以下降价:
### Example Section #### Theorem 1 (Euclid) > There are infinitely many primes. #### Proof Suppose that $p_1 < p_2 < \dots < p_n$ are all of the primes. Let $P = 1 + \prod_{i=1}^n p_i$ and let $p$ be a prime dividing $P$. Then $p$ can not be any of $p_i$, for otherwise $p$ would divide the difference $P - \left(\prod_{i=1}^n p_i \right) - 1$, which is impossible. So this prime $p$ is still another prime, and $p_1, p_2, \dots p_n$ cannot be all of the primes.
支持的乳胶/阿姆斯特丹环境
- emph,textbf,texttt
- thm
- prop
- lem
- exer
- proof
- chapter
- section
- subsection
- itemize
- enumerate
以及mathjax-list支持的所有内容 online。