AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 1008990
Accepted
Aaron Christiansen
Aaron Christiansen
Asked: 2018-02-24 01:57:12 +0800 CST2018-02-24 01:57:12 +0800 CST 2018-02-24 01:57:12 +0800 CST

LibreOffice 无法正确显示“显示”模式的 Word 方程;有没有可以的Linux文字处理器?

  • 772

在 Microsoft Word 中,有两种显示公式的方法;内联和显示。内联方程与文本一致(顾名思义),因此方程和文本可以混合使用。一个显示方程出现在它自己的行上并自动居中,如下所示:

在此处输入图像描述

这是三个独立的等式,但由于它们被设置为显示模式,它们都显示为居中并在自己的行上。如果它们的模式更改为内联,它们都出现在同一行而不是居中:

在此处输入图像描述 在此处输入图像描述

我的问题是 LibreOffice 使用内联模式显示所有方程,即使它们在 docx 文件中设置为显示模式。如果我使用显示模式方程 Word 创建第一个示例,保存它,然后在 LibreOffice 中打开它,这些方程看起来就像是内联模式:

在此处输入图像描述

是否可以更改设置以使显示模式方程式在自己的行上并居中,就像在 Word 中一样?由于我拥有大量的 Word 文档,我宁愿不单独修改这些文档。

如果没有,是否有替代文字处理器可以正确显示方程式?

software-recommendation libreoffice microsoft-word word-processor
  • 2 2 个回答
  • 514 Views

2 个回答

  • Voted
  1. Best Answer
    Jim K
    2018-02-24T09:36:40+08:002018-02-24T09:36:40+08:00

    在 LibreOffice 中插入公式时As Character,默认情况下会锚定。

    锚作为角色

    这意味着它的行为与角色相同。因此,我们将其视为具有三个字符的相同方式,例如“abc”而不是三个方程。

    1. 格式 -> 对齐 -> 居中
    2. 将光标移到第一个方程后并按Enter。
    3. 对第二个方程重复步骤 2。

    现在,所有三个方程都集中在不同的行上。

    三个方程

    这是“abc”示例的这些说明的结果,显示公式的行为与字符相同。(按Enter自动更正为大写“A”)。

    abc 在单独的行上

    要使其在 MS Word 和 LibreOffice 中都能正常工作,或许只能使用Inline设置。但是,我没有 MS Word 的副本来验证这一点,并且 Word Online 无法编辑公式(但如果您需要的话,可以显示它们)。

    有没有像 MS Word 那样使用显示公式设置的替代文字处理器?很有可能;有许多选择,无论是付费的还是免费的。但是,无论您选择什么替代方案,都会存在某种不兼容。

    • 4
  2. Aaron Christiansen
    2018-02-28T09:09:46+08:002018-02-28T09:09:46+08:00

    我已经接受不太可能有用于 Linux 的具有此功能的文字处理器,因此我决定通过创建 Ruby 脚本来自动化 Jim K 的回答。

    问题的根源在于 LibreOffice 忽略了m:oMathParaXML 元素,这也是 Word 将显示模式方程式包装在其中以使其居中并将其放在自己的段落中的原因。

    下面的 Ruby 脚本使用 Nokogiri XML 解析库来替换所有出现的m:oMathPara标准w:p段落,这些段落也被格式化为居中对齐。它执行以下操作:

    1. 将 DOCX(指定为命令行参数)复制到/tmp、解压缩并打开document.xml
    2. 扫描 XML 中的m:oMathPara元素
    3. w:p用格式化的元素替换它们
    4. 将 DOCX 重新压缩到/tmp
    5. 在 LibreOffice 中打开生成的 DOCX
    6. 询问用户是否要保留更改;如果他们回答是,则将转换后的 DOCX 复制到原始文件上以覆盖它

    这还没有经过太多测试,因此您应该备份您使用它的所有文件以防万一。请注意,它仅适用于 Linux,并且需要unzip安装该工具。(如果你没有它,它就在宇宙中:sudo apt install unzip。)你可能也需要gem install nokogiri。

        #!/usr/bin/ruby
    # THIS IS LINUX ONLY!
    # You'll also need to install `unzip`:
    #     sudo apt install unzip
    
    require "pp"
    require "zip"
    require "fileutils"
    require "nokogiri"
    
    def error(msg)
        puts msg
        exit
    end
    
    temp_dir = "/tmp/dispeqfix/"
    
    filename = ARGV[0]
    
    error "Please pass a filename as an argument." if filename.nil?
    
    # Remove the directory if this tool has been run before
    FileUtils.remove_dir(temp_dir) if Dir.exist? temp_dir
    
    # Extract file as a zip
    %x{unzip '#{filename}' -d '#{temp_dir}'}
    
    # Get path to document.xml, the file we need to modify
    document_path = "/tmp/dispeqfix/word/document.xml"
    error "document.xml not found - are you sure this file is a DOCX?" unless File.exist? document_path
    
    xml = Nokogiri::XML(File.read(document_path))
    
    # 'm:oMathPara' is the element which LibreOffice doesn't support
    xml.search("//m:oMathPara").each do |math_para|
        # Get the paragraph containing this one
        parent_para = math_para.parent
    
        # Get the 'm:oMath' contained within the 'm:oMathPara'
        math_para.dup.children.each do |math|
            # Insert a new paragraph with contains the 'm:oMath'
            new_para = Nokogiri::XML::Node.new("w:p", xml)
            math.parent = new_para
            parent_para.after(new_para)
    
            # Centre the paragraph
            math.before("<w:pPr><w:jc w:val=\"center\"/><w:rPr/></w:pPr><w:r><w:rPr/></w:r>")
        end
    
        math_para.remove
    end
    
    # Write this temporary file
    File.write(document_path, xml.to_xml)
    
    # Re-zip and open it
    %x{ cd /tmp/dispeqfix; zip -r ../dispeqfix.docx * }
    preview = spawn("libreoffice --writer /tmp/dispeqfix.docx 2>&1 > /dev/null", out: File::NULL)
    Process.detach(preview)
    
    # Prompt for overwrite
    print "Would you like to overwrite the original document with this one? [y/n] "
    if $stdin.gets.chomp == "y"
        %x{ cp -f /tmp/dispeqfix.docx #{filename} }
        puts "Overwritten."
    else
        puts "No change made."
    end
    
    • 3

相关问题

  • 有哪些科学绘图软件可用?

  • 最好的思维导图软件是什么?

  • 服务器的最佳rootkit删除工具?

  • 从 Ubuntu 连接到 Windows 的最佳远程桌面工具是什么?[关闭]

  • 是否有 Paint.NET 替代方案?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve