目录

1 基于工具的转换

1.1 获取mathml源码

1.2 将mathml代码转换为latex

1.3 latex向mathml的转换

1.4 mathml粘贴到word

1.5 word转mathml

1.5.1 干法

1.5.2 注意要点

2 离线工具

2.1 mathml2latex

2.2 latex转word

2.2.1 一个前端开源项目

2.2.2 一个pyqt的界面程序

2.2.3 使用神器typora

2.3 从word获取mathml

3 其他参考连接


通过science direct阅读论文时,看到有别人写好的公式,不想自己敲怎么办?这篇小文章带你快速将生成公式代码,并粘贴到word中。

首先在SD中随便打开一篇文章,随便选择一个公式,如下图的约束3:

1 基于工具的转换

 1.1 获取mathml源码

我们可以得到如下源码:

<math xmlns="http://www.w3.org/1998/Math/MathML"><mtable displaystyle="true" is="true"><mtr is="true"><mtd is="true" /><mtd columnalign="left" is="true"><mrow is="true"><munder is="true"><mo is="true">∑</mo><mrow is="true"><mo is="true">(</mo><mi is="true">i</mi><mo is="true">,</mo><mi is="true">j</mi><mo is="true">)</mo><mo is="true">∈</mo><mi is="true">A</mi></mrow></munder><msubsup is="true"><mi is="true">x</mi><mrow is="true"><mi is="true">i</mi><mi is="true">j</mi></mrow><mi is="true">k</mi></msubsup><mo is="true">−</mo><munder is="true"><mo is="true">∑</mo><mrow is="true"><mo is="true">(</mo><mi is="true">n</mi><mo is="true">+</mo><mi is="true">i</mi><mo is="true">,</mo><mi is="true">j</mi><mo is="true">)</mo><mo is="true">∈</mo><mi is="true">A</mi></mrow></munder><msubsup is="true"><mi is="true">x</mi><mrow is="true"><mi is="true">n</mi><mo is="true">+</mo><mi is="true">i</mi><mo is="true">,</mo><mi is="true">j</mi></mrow><mi is="true">k</mi></msubsup><mo is="true">=</mo><mn is="true">0</mn><mspace width="1em" is="true" /><mo is="true">∀</mo><mi is="true">i</mi><mo is="true">∈</mo><mi is="true">P</mi><mo is="true">,</mo><mo is="true">∀</mo><mi is="true">k</mi><mo is="true">∈</mo><mi is="true">K</mi><mo is="true">,</mo></mrow></mtd></mtr></mtable>
</math>

 1.2 将mathml代码转换为latex

转换网站

网站的操作也很简单,步骤如下:

  • 将代码粘贴到左侧框内
  • 选择原类型
  • 选择目标类型
  • 点击convert按钮

刚才提取的公式转换结果如下:

\begin{array}{cl} & {\sum\limits_{(i,j) \in A}x_{ij}^{k} - \sum\limits_{(n + i,j) \in A}x_{n + i,j}^{k} = 0\quad\forall i \in P,\forall k \in K,} \\ \end{array}

显示如下:

这样我们就完美的实现mathml向latex的转换

1.3 latex向mathml的转换

同样是这个网站,我们将原类型和目标类型换换,就可以实现latex到mathml的转换

1.4 mathml粘贴到word

由于并不是每个人都精通latex,一部分小伙伴还是喜欢word那种简单粗暴的方式,有没有办法将这个公式搞到word里边吗?当然有,我们直接把mathml源码粘贴到word中,然后选择只保留文本即可。

不过貌似不太好玩,里边的空格还需要咱自己拖拖拽拽。没办法,能偷的懒已经偷了;如有高手能一步到位,欢迎指教。

1.5 word转mathml

1.5.1 干法

如果一个公式是word敲的,你还想偷懒直接干成latex,有没办法呢?也有,咱慢慢来。

操作也不难,直接选中公式,找个记事本粘贴一下,你会得到如下内容:

<mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"><mml:mtable><mml:mtr><mml:mtd></mml:mtd><mml:mtd><mml:mrow><mml:munder><mml:mo stretchy="true">∑</mml:mo><mml:mrow><mml:mo>(</mml:mo><mml:mi>i</mml:mi><mml:mo>,</mml:mo><mml:mi>j</mml:mi><mml:mo>)</mml:mo><mml:mo>∈</mml:mo><mml:mi>A</mml:mi></mml:mrow></mml:munder><mml:mrow><mml:msubsup><mml:mrow><mml:mi>x</mml:mi></mml:mrow><mml:mrow><mml:mi>i</mml:mi><mml:mi>j</mml:mi></mml:mrow><mml:mrow><mml:mi>k</mml:mi></mml:mrow></mml:msubsup></mml:mrow></mml:mrow><mml:mo>-</mml:mo><mml:mrow><mml:munder><mml:mo stretchy="true">∑</mml:mo><mml:mrow><mml:mfenced separators="|"><mml:mrow><mml:mi>n</mml:mi><mml:mo>+</mml:mo><mml:mi>i</mml:mi><mml:mo>,</mml:mo><mml:mi>j</mml:mi></mml:mrow></mml:mfenced><mml:mo>∈</mml:mo><mml:mi>A</mml:mi></mml:mrow></mml:munder><mml:mrow><mml:msubsup><mml:mrow><mml:mi>x</mml:mi></mml:mrow><mml:mrow><mml:mi>n</mml:mi><mml:mo>+</mml:mo><mml:mi>i</mml:mi><mml:mo>,</mml:mo><mml:mi>j</mml:mi></mml:mrow><mml:mrow><mml:mi>k</mml:mi></mml:mrow></mml:msubsup></mml:mrow></mml:mrow><mml:mo>=</mml:mo><mml:mn>0</mml:mn><mml:mo>,</mml:mo><mml:mo>∀</mml:mo><mml:mi>i</mml:mi><mml:mo>∈</mml:mo><mml:mi>P</mml:mi><mml:mo>,</mml:mo><mml:mo>∀</mml:mo><mml:mi>k</mml:mi><mml:mo>∈</mml:mo><mml:mi>K</mml:mi><mml:mo>,</mml:mo></mml:mtd></mml:mtr></mml:mtable></mml:math>

这一坨是啥,咱也看不懂,也不敢问,干就是了。还是前面那个网站,设置如下:

  • 原类型选mathml
  • 目标类型选tex

我们得到了如下tex代码:

\begin{matrix}& {{\sum\limits_{(i,j) \in A}x_{ij}^{k}} - {\sum\limits_{{({n + i,j})} \in A}x_{n + i,j}^{k}} = 0,\forall i \in P,\forall k \in K,} \\
\end{matrix}

显示一下这个公式:

也能正常显示,但是两个代码的还是有区别的:

  • 使用SD提供的mathml源码得到的latex用的是array环境
  • 使用word干出来的mathml源码得到的latex用的是matrix环境

1.5.2 注意要点

看我操作的贼溜,有些小伙伴可能从word粘贴公式到记事本,并不是mathml源码。这里要做一个设置:

2 离线工具

上面一通操作,都是必须得有网。没网就瞎了,这时候,我们的python神器就排上用场了。

2.1 mathml2latex

这里要使用一个github的一个开源项目:

GitHub - oerpub/mathconverter: Converts from AsciiMath, LaTeX, MathML to LaTeX, MathMLConverts from AsciiMath, LaTeX, MathML to LaTeX, MathML - GitHub - oerpub/mathconverter: Converts from AsciiMath, LaTeX, MathML to LaTeX, MathMLhttps://github.com/oerpub/mathconverter

实现的源码也贼简单:

import os
from lxml import etreedef mathml2latex_yarosh(equation):""" MathML to LaTeX conversion with XSLT from Vasil Yaroshevich """xslt_file = os.path.join('xsl_yarosh', 'mmltex.xsl')dom = etree.fromstring(equation)xslt = etree.parse(xslt_file)transform = etree.XSLT(xslt)newdom = transform(dom)return newdommathml = """<mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"><mml:mtable><mml:mtr><mml:mtd></mml:mtd><mml:mtd><mml:mrow><mml:munder><mml:mo stretchy="true">∑</mml:mo><mml:mrow><mml:mo>(</mml:mo><mml:mi>i</mml:mi><mml:mo>,</mml:mo><mml:mi>j</mml:mi><mml:mo>)</mml:mo><mml:mo>∈</mml:mo><mml:mi>A</mml:mi></mml:mrow></mml:munder><mml:mrow><mml:msubsup><mml:mrow><mml:mi>x</mml:mi></mml:mrow><mml:mrow><mml:mi>i</mml:mi><mml:mi>j</mml:mi></mml:mrow><mml:mrow><mml:mi>k</mml:mi></mml:mrow></mml:msubsup></mml:mrow></mml:mrow><mml:mo>-</mml:mo><mml:mrow><mml:munder><mml:mo stretchy="true">∑</mml:mo><mml:mrow><mml:mfenced separators="|"><mml:mrow><mml:mi>n</mml:mi><mml:mo>+</mml:mo><mml:mi>i</mml:mi><mml:mo>,</mml:mo><mml:mi>j</mml:mi></mml:mrow></mml:mfenced><mml:mo>∈</mml:mo><mml:mi>A</mml:mi></mml:mrow></mml:munder><mml:mrow><mml:msubsup><mml:mrow><mml:mi>x</mml:mi></mml:mrow><mml:mrow><mml:mi>n</mml:mi><mml:mo>+</mml:mo><mml:mi>i</mml:mi><mml:mo>,</mml:mo><mml:mi>j</mml:mi></mml:mrow><mml:mrow><mml:mi>k</mml:mi></mml:mrow></mml:msubsup></mml:mrow></mml:mrow><mml:mo>=</mml:mo><mml:mn>0</mml:mn><mml:mo>,</mml:mo><mml:mo>∀</mml:mo><mml:mi>i</mml:mi><mml:mo>∈</mml:mo><mml:mi>P</mml:mi><mml:mo>,</mml:mo><mml:mo>∀</mml:mo><mml:mi>k</mml:mi><mml:mo>∈</mml:mo><mml:mi>K</mml:mi><mml:mo>,</mml:mo></mml:mtd></mml:mtr></mml:mtable></mml:math>"""
tex = mathml2latex_yarosh(mathml)
print(tex)

转换结果如下:

$ \begin{array}{cc}& \sum _{(i,j)\in A}{x}_{ij}^{k}-\sum _{\left(n+i,j\right)\in A}{x}_{n+i,j}^{k}=0,\forall i\in P,\forall k\in K,\end{array}$

2.2 latex转word

2.2.1 一个前端开源项目

可以通过github的一个开源项目可以直接粘贴到word

2.2.2 一个pyqt的界面程序

 生成的mathml代码:

<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mi>$</mi><mtable><mtr><mtd columnalign="center" /><mtd columnalign="center"><msub><mo>∑</mo><mrow><mo stretchy="false">(</mo><mi>i</mi><mo>,</mo><mi>j</mi><mo stretchy="false">)</mo><mo>∈</mo><mi>A</mi></mrow></msub><msubsup><mrow><mi>x</mi></mrow><mrow><mi>i</mi><mi>j</mi></mrow><mrow><mi>k</mi></mrow></msubsup><mo>−</mo><msub><mo>∑</mo><mrow><mrow><mo stretchy="true" fence="true" form="prefix">(</mo><mi>n</mi><mo>+</mo><mi>i</mi><mo>,</mo><mi>j</mi><mo stretchy="true" fence="true" form="postfix">)</mo></mrow><mo>∈</mo><mi>A</mi></mrow></msub><msubsup><mrow><mi>x</mi></mrow><mrow><mi>n</mi><mo>+</mo><mi>i</mi><mo>,</mo><mi>j</mi></mrow><mrow><mi>k</mi></mrow></msubsup><mo>=</mo><mn>0</mn><mo>,</mo><mo>∀</mo><mi>i</mi><mo>∈</mo><mi>P</mi><mo>,</mo><mo>∀</mo><mi>k</mi><mo>∈</mo><mi>K</mi><mo>,</mo></mtd></mtr></mtable><mi>$</mi></mrow></math>

2.2.3 使用神器typora

直接在公式上右键,复制为mathml源码

注意这里的公式不能是行内公式,即通过如下方式插入的公式块

2.3 从word获取mathml

word公式中做如下设置:

相当于之前的拟操作

3 其他参考连接

公式图片转latex神器Mathpix以及latex公式与word公式的相互转换 - 简书 (jianshu.com)https://www.jianshu.com/p/66ed4c8edfd4

https://binb.droppages.com/https://binb.droppages.com/GitHub - xiaoyvyv/LatexToMathML: Latex转Word格式的公式Latex转Word格式的公式. Contribute to xiaoyvyv/LatexToMathML development by creating an account on GitHub.https://github.com/xiaoyvyv/LatexToMathML

Latex语法学习08:打通latex、mathml和word公式转换相关推荐

  1. LaTeX语法学习(一):数学公式篇

    LaTeX语法学习(一):数学公式篇 文章目录 LaTeX语法学习(一):数学公式篇 一.前言 二.数学模式 1.行内公式 2.行间公式 3.公式手动编号 4.公式加粗 5.更改公式字母颜色 三.数学 ...

  2. Latex语法学习04:参考文献的引用

    目录 首先准备bib文件: 1 数字标号型参考文献 2 基于natbib包的参考文献引用 2.1 案例 2.2 命令解析 2.2.1 数字引用格式 2.2.2 错误处理 2.2.3 命令解析 3 引用 ...

  3. latex语法学习(二)

    文档和语言的结构 如果排版风格反映了内容的逻辑和语义结构,读者就能看见和感觉到文章的这种脉络. 在latex中段落是最重要的文档单位,我们之所以称之为"文档单位",因为段落是反映一 ...

  4. Latex语法学习10:盒子的使用(fbox, tcolorbox, boitee),支持设置颜色和换页

    目录 1 \fbox 2 彩色的盒子(可换页) 3 boitee环境 1 \fbox 这段代码主要用到了三个命令: \noindent:表示取消缩进 \textwidth:表示设置盒子宽度为页面宽度 ...

  5. CSDN-markdown写博客使用LaTeX语法编写数学公式(再也不怕手写公式,以后博客手写复杂公式就靠它了!)

    LaTeX数学公式语法目录 一.希腊字母表 二.常用函数举例 三.集合 四.常用逻辑与箭头 五.括号 六.矩阵.多行列式 七.常用戴帽.矢量符号 八.微积分运算符 九.字体种类 十.关系符号 十一.更 ...

  6. Latex——Word公式转换

    文章目录 1.Word to Latex 2. Latex to Word 3.MathType安装 4.MathType下载链接   Word通常使用MathType作为公式编辑器,MathType ...

  7. Word公式键入——UnicodeMath语法对照简表

    一个简单的目录 前言(你想知道的都在这里) 分式.声调.上下标 希腊字母 几何与简单运算 根号 积分 微分 带圈.带框运算符,点与省略号 特殊符号 大型运算符与极限 矩阵.方程组.等式对齐.公式编号 ...

  8. 07LaTeX学习系列之---Latex源文件的结构

    目录 目录: (一)Latex源文件的结构: (二)基础语法: 2.空行: 3.document: 4.数学公式: 5.latex的文件格式分类: 目录: 本系列是有关LaTeX的学习系列,共计19篇 ...

  9. latex语法_【研创基地科研实训】关于举办第27期“LaTeX使用技巧交流分享会” 线上科研实训交流活动的通知...

    关于举办第27期"LaTeX使用技巧交流分享会" 线上科研实训交流活动的通知 LaTeX是一种基于TeX的排版系统,在数学式的处理上有着得天独厚的优势,能快速生成很多具有书籍质量的 ...

最新文章

  1. SoapUi测试,测试相关问答知识
  2. 数据结构与算法笔记(十二)—— 查找算法(顺序查找、二分法查找)
  3. c语言程序怎么颠倒数据,急求如何将下列C语言程序数据存储到文件中?
  4. 设置、查看环境变量值
  5. linux写一个脚本杀进程,linux下如何自动检测并重新启动一个死掉的进程,然后再把它杀死:)(shell脚本实现)...
  6. jupyter可以打开HTML文件吗,Jupyter ~ 像写文章般的 Coding (附:同一个ipynb文件,执行多语言代码)...
  7. 甲骨文推出新的云服务 协助企业顺利迁移至云端
  8. 2017.5.5上午
  9. C# ComboBox自动完成功能的例子
  10. 199. Binary Tree Right Side View
  11. Linux下C++ Socket编程实例
  12. 计算虚继承中对象占用的空间
  13. win10无法执行vbs脚本
  14. 四 国内IP核相关企业及其分析
  15. 借助WPS将Word文档转换为PPT文档
  16. 60 个神级 VS Code 插件,助你打造最强编辑器
  17. linux 串口操作
  18. Module and Component
  19. 鸿蒙应用开发 | 文本框(Text)和编辑框(TextField)的功能与用法
  20. python中x、y=y、x_浅谈 (x, y) = (y, x)

热门文章

  1. 暨南大学网络空间安全专业跨考上岸经验贴
  2. EMID|FDX-B格式134.2KHZ低频RFID标签编码器读写器CK-A05性能与写卡操作说明
  3. 学习淘淘商城第八十一课(SSO 系统分析)
  4. html做一个抽奖游戏,js实现大转盘抽奖游戏实例
  5. matlab程序闭合导线网程序,【求助】闭合导线简易平差Matlab代码需要大神帮忙
  6. Unity 工具栏功能介绍
  7. Fiddler(五)设置代理 HTTPS 请求
  8. 联邦学习开山之作代码解读与收获
  9. 设计模式-责任链模式
  10. exportExcel