1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > LaTeX公式转成word公式(LaTeX公式转MathML / latex2mathml的使用)

LaTeX公式转成word公式(LaTeX公式转MathML / latex2mathml的使用)

时间:2022-10-15 02:16:02

相关推荐

LaTeX公式转成word公式(LaTeX公式转MathML / latex2mathml的使用)

3月10日更新 批量一键转换公式

因为又遇到了不得不往Word里放一大堆公式的作业,一个一个弄太慢了,决定弄一个一键执行的版本,效果如下。

只需要在input.txt里放入LaTeX公式,执行python脚本即可在output.txt里得到Word公式,那么一长串复制粘贴进Word里就是Word里就是Word里的公式,复制粘贴效果:

但是当公式很长的时候,想看一下公式长什么样,可以用通过.tex文件转换,在vscode的LaTeX环境预览公式,如下图那一长串就是对应下面预览的公式:

复制粘贴进Word里的效果看起来不理想,但问题不大的样子,稍微改改就行了(或者在公式里把operatorname改改):

总结

复制下列代码

import latex2mathml.converter as converterword=[]with open("input.tex", "r") as file:for text in file:text = text.split("\n")for line in text:if line !="" and line[0] == "$":equation = line[1:len(line)-1]word.append(converter.convert(equation))with open("output.txt", "w") as file:for ans in word:ans+="\n\n"file.write(ans)

import latex2mathml.converter as converterword=[]with open("input.txt", "r") as file:for line in file:line = line.split("\n")for equation in line:if equation != "":word.append(converter.convert(equation))with open("output.txt", "w") as file:for ans in word:ans+="\n\n"file.write(ans)

把公式放进input.txt或input.tex中

f(I)=I^\gamma\Omegaf=f(x)

\documentclass[a4paper]{article}\begin{document}$ \Omega $$ \alpha_{u}=\operatorname{softmax}\left(w_{a 2} \tanh \left(W_{a 1} \mathbf{H}_{u}^{T}\right)\right) $\end{document}

运行对应的python脚本从output.txt中逐公式复制粘贴进Word,把下面的这段复制进Word之后就是下面的公式,可以试一下,最后稍微改改就行了

<math display="inline" xmlns="/1998/Math/MathML"><mrow><msub><mi>&#x003B1;</mi><mrow><mi>u</mi></mrow></msub><mo>&#x0003D;</mo><mi>\operatorname</mi><mrow><mi>s</mi><mi>o</mi><mi>f</mi><mi>t</mi><mi>m</mi><mi>a</mi><mi>x</mi></mrow><mrow><mo fence="true" form="prefix" stretchy="true">&#x00028;</mo><mrow><msub><mi>w</mi><mrow><mi>a</mi><mn>2</mn></mrow></msub><mi>\tanh</mi><mrow><mo fence="true" form="prefix" stretchy="true">&#x00028;</mo><mrow><msub><mi>W</mi><mrow><mi>a</mi><mn>1</mn></mrow></msub><msubsup><mi>&#x1D407;</mi><mrow><mi>u</mi></mrow><mrow><mi>T</mi></mrow></msubsup></mrow><mo fence="true" form="postfix" stretchy="true">&#x00029;</mo></mrow></mrow><mo fence="true" form="postfix" stretchy="true">&#x00029;</mo></mrow></mrow></math>

下面是分割线

毕业设计要求翻译一篇英文论文,翻译后要写在word里,无奈论文里公式太复杂,用word的公式编辑器一个一个编太慢了,而且有些符号还找不到。曾经使用过一个工具,可以将LaTeX数学公式直接转换成可以粘贴成word的公式,那个工具还有很多功能,但过了几年忘了叫什么了,找到了一个在线转换的网站,可以供需要将LaTeX打好的数学公式放进word里的人参考。

打开网站/latex-para-word/在第一个框里打数学公式,显示的效果在第二部分,然后复制第三个框内的所有内容,以纯文本的方式粘贴到word里。

粘贴到word之后就是word插入公式的格式。

有其它方便的工具记不起来是什么了,留待补充

.4.4更新

上面的网站上不去了,而中期答辩将近,需要写报告,latex公式转word急需新工具。

思路是:MathML代码可以直接粘贴进word显示成数学公式,所以只需要一个工具将LaTeX代码转换成MathML就行了。接下来就是使用方法。

安装Python3.5以上环境进入latex2mathml包的官网,不进官网可以看这里,首先安装latex2mathml包pip install latex2mathml创建个.py文件,写好下面的代码,然后按需修改引号内的LaTeX代码

import latex2mathml.converterlatex_input = "f(I)=I^\gamma" #latex代码写在这里!!!!!mathml_output = latex2mathml.converter.convert(latex_input)print(mathml_output)

运行写好的.py文件,将下图的输出结果复制粘贴进word即可

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。