如何用描述替换 Libreoffice 中的所有图像

use*_*131 12 latex libreoffice

我有一个很长的文档,其中包含许多使用扩展名 TexMaths 创建的 svg 图像。此扩展使用乳胶安装来创建输入方程(或方程组)的 svg 图像。每个方程(或一组方程)的乳胶代码作为描述的一部分嵌入图像中。可以通过右键单击 svg 图像并选择选项描述来访问这样的描述。

我想通过嵌入的描述使用合适的宏替换所有 svg 图像。

例如来自

爱因斯坦著名的方程 [svg embedding equation : E = mc 2 ] 告诉我们质量可以转换为能量,反之亦然。

爱因斯坦著名的方程 E = mc^2 告诉我们质量可以转换为能量,反之亦然。

这将允许我手动将包含大量 TexMaths 方程的 odt 文件转换为 LaTeX。

use*_*.dz 2

这是不使用宏的另一种方式。因为.odt文件基本上只是压缩文件,主文件是 XML。

  1. 创建 XML 样式表texmath_raw_equation.xslt

    完整内容都在这里,以防链接中断。

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rpt="http://openoffice.org/2005/report" xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:grddl="http://www.w3.org/2003/g/data-view#" xmlns:officeooo="http://openoffice.org/2009/office" xmlns:tableooo="http://openoffice.org/2009/table" xmlns:drawooo="http://openoffice.org/2010/draw" xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0" xmlns:css3t="http://www.w3.org/TR/css3-text/" version="1.0">
    
        <xsl:template match="@* | node()">
          <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
          </xsl:copy>
        </xsl:template>
    
        <xsl:template match="draw:g">
            <xsl:value-of select="svg:desc"/>
        </xsl:template>
    
    </xsl:stylesheet>
    
    Run Code Online (Sandbox Code Playgroud)
  2. .odt将文件解压到tmp文件夹,例如texmath_test.odt

    7z x -otmp texmath_test.odt
    
    Run Code Online (Sandbox Code Playgroud)
  3. 将 TexMath 图像(由标签保存<draw:g></draw:g>)替换为其描述(由<svg:desc></svg:desc>标签保存)

    xsltproc -o content.xml texmath_raw_equation.xslt tmp/content.xml
    mv content.xml tmp/content.xml
    
    Run Code Online (Sandbox Code Playgroud)
  4. 压缩回新.odt文件

    cd tmp
    7z a -tzip ../texmath_test_new.odt *
    cd ..
    rm -r tmp
    
    Run Code Online (Sandbox Code Playgroud)

参考: