首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >LibreOffice没有正确地显示“显示”模式的单词方程;是否有一个Linux字处理器可以?

LibreOffice没有正确地显示“显示”模式的单词方程;是否有一个Linux字处理器可以?
EN

Ask Ubuntu用户
提问于 2018-02-23 09:57:12
回答 1查看 597关注 0票数 3

在Microsoft中,有两种显示公式的方法:内联和显示。内联方程与文本(顾名思义)是一致的,因此方程和文本可以混合。显示方程出现在自己的直线上,并自动以中心为中心,如下所示:

这是三个独立的方程,但由于它们被设置为显示模式,所以它们都显示为中心,并处于各自的直线上。如果它们的模式更改为内联,则它们都出现在同一条线上,而不是居中:

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

是否有一个设置,我可以改变,以获得显示模式方程是在他们自己的线和中心,就像他们是在文字?由于我有大量的Word文档,所以我不想单独修改这些文档。

如果没有,是否有可供选择的文字处理程序来正确地显示方程?

EN

回答 1

Ask Ubuntu用户

发布于 2018-02-27 17:09:46

我已经承认,Linux不太可能有具有此功能的字处理器,所以我决定通过创建Ruby脚本来自动化Jim的答案。

问题的根源在于LibreOffice忽略了m:oMathPara XML元素,这也是单词将显示模式方程封装在中间并放在它自己的段落中的内容。

下面的Ruby脚本使用Nokogiri解析库将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

代码语言:javascript
复制
    #!/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
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/1008990

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档