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

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


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

是否有一个设置,我可以改变,以获得显示模式方程是在他们自己的线和中心,就像他们是在文字?由于我有大量的Word文档,所以我不想单独修改这些文档。
如果没有,是否有可供选择的文字处理程序来正确地显示方程?
发布于 2018-02-27 17:09:46
我已经承认,Linux不太可能有具有此功能的字处理器,所以我决定通过创建Ruby脚本来自动化Jim的答案。
问题的根源在于LibreOffice忽略了m:oMathPara XML元素,这也是单词将显示模式方程封装在中间并放在它自己的段落中的内容。
下面的Ruby脚本使用Nokogiri解析库将m:oMathPara的所有出现替换为标准的w:p段落,这些段落也被格式化为中心对齐。它做了以下工作:
/tmp,解压缩它,并打开document.xml。m:oMathPara元素w:p元素替换它们/tmp中这还没有经过太多的测试,所以你应该备份你使用它的任何文件以防万一。请注意,它只在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."
endhttps://askubuntu.com/questions/1008990
复制相似问题