python - 将 Microsoft Word 方程转换为 Latex

标签 python ms-word latex equation python-docx

我有一个 docx 文件,其中包含不同页面中的一些方程。使用Python和lxml,我成功地提取了内容。我现在需要将 Word 中的方程转换为 Latex。一些方程如下所示:

- eq \\f (sinx,\\r(1 - sin 2 x))

是否有任何工具的 Python 库可用于将方程转换为 Latex 格式?

这是我从 docxfile/word/document.xml 获取的 XML 文件的片段:

<w:p w:rsidR="00677018" w:rsidRPr="007D05E5" w:rsidRDefault="00677018" w:rsidP="00677018">
            <w:pPr>
                <w:pStyle w:val="w" />
                <w:jc w:val="both" /></w:pPr>
            <w:r w:rsidRPr="007D05E5">
                <w:tab/>
                <w:t>a.</w:t>
            </w:r>
            <w:r w:rsidRPr="007D05E5">
                <w:tab/></w:r>
            <w:r w:rsidR="00453EF1" w:rsidRPr="007D05E5">
                <w:fldChar w:fldCharType="begin" /></w:r>
            <w:r w:rsidRPr="007D05E5">
                <w:instrText xml:space="preserve">eq \b\bc\[(\a\co2\hs4(7,-3,-1,2))</w:instrText>
            </w:r>
            <w:r w:rsidR="00453EF1" w:rsidRPr="007D05E5">
                <w:fldChar w:fldCharType="end" /></w:r>
            <w:r w:rsidRPr="007D05E5">
                <w:tab/>
                <w:t>b.</w:t>
            </w:r>
            <w:r w:rsidRPr="007D05E5">
                <w:tab/></w:r>
            <w:r w:rsidR="00453EF1" w:rsidRPr="007D05E5">
                <w:fldChar w:fldCharType="begin" /></w:r>
            <w:r w:rsidRPr="007D05E5">
                <w:instrText xml:space="preserve">eq \f(5,8)</w:instrText>
            </w:r>
            <w:r w:rsidR="00453EF1" w:rsidRPr="007D05E5">
                <w:fldChar w:fldCharType="end" /></w:r>
            <w:r w:rsidR="00453EF1" w:rsidRPr="007D05E5">
                <w:fldChar w:fldCharType="begin" /></w:r>
            <w:r w:rsidRPr="007D05E5">
                <w:instrText xml:space="preserve">eq \b\bc\[(\a\co2\hs4(7,-3,-1,2))</w:instrText>
            </w:r>
            <w:r w:rsidR="00453EF1" w:rsidRPr="007D05E5">
                <w:fldChar w:fldCharType="end" /></w:r>
        </w:p>

最佳答案

我不确定这本身是否构成答案,但也许正在走向答案。

不久前我一直在寻找这样的工具,但没有找到,所以我认为简短的答案是否定的。

Word 支持多种方程式格式。您拥有的类型称为“Word EQ Fieldequation”。 http://office.microsoft.com/en-us/word-help/field-codes-eq-equation-field-HP005186148.aspx

我在搜索中没有找到任何针对此问题的 Python 解决方案,并且我知道某些 python-docx 不支持它。希望我有更好的消息给你:(

如果您下定决心,似乎有一些非 Python 解决方案可以执行此转换,如果您决定自己动手,它们可能是替代方案或研究示例:)

关于python - 将 Microsoft Word 方程转换为 Latex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24415378/

相关文章:

python - 全局计数器线程在 python 中安全吗?

python - 基于多个条件的 Pandas 数据框条件列仅适用于第一个条件?

java - 使用 Apache POI Java NetBeans Word 文档时出现 CTPageSZ 类错误

c# - 将 Word 转换为 HTML,然后在网页上呈现 HTML

r - 如何在 R 中的 Hmisc 中将注释附加到 latex 表?

r - 将脚注包装到第二行以适合 kable 中的表格(LaTeX .Rmd)

latex - 如何在 LaTeX 文章中进行完全对齐?

python - 使用许多@properties 扩展 Python namedtuple?

python - Dataframe - 获取最常见的值及其计数

css - 尝试在 CSS 中重现 MS Word 样式