1

This is related but, as far as I grasp, somewhat different from Utf-8 output from make4ht to odt format.

I'm using make4ht to convert a LaTeX document to ODT and, within it, I have some equations which contain some text with non ascii characters, and I haven't been able to obtain good results with it thus far.

Consider the following document:

\documentclass{article}

\usepackage{amstext}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{tgpagella}

\begin{document}

\[
  \frac{importação}{consumo}
\]

\[
  \frac{\text{importação}}{\text{consumo}}
\]

\[
  \frac{\text{importa\c{c}\~ao}}{\text{consumo}}
\]

\[
  \frac{\mbox{importação}}{\mbox{consumo}}
\]

\[
  \frac{\textrm{importação}}{\textrm{consumo}}
\]

\[
  \frac{\textnormal{importação}}{\textnormal{consumo}}
\]

\end{document}

Building it with:

make4ht -f odt document.tex

The result in the odt is the following:

enter image description here

Underlying it, we have:

  • For the equation without any text commands:

    • in the .odt file: {i m p o r t a ç ã o} over {c o n s u m o} (thus with a space added for every character)

    • in the content.xml for the corresponding equation within the .odt:

<math:mfrac><math:mrow><math:mi>i</math:mi><math:mi>m</math:mi><math:mi>p</math:mi><math:mi>o</math:mi><math:mi>r</math:mi><math:mi>t</math:mi><math:mi>a</math:mi><math:mi>&#xE7;</math:mi><math:mi>&#xE3;</math:mi><math:mi>o</math:mi></math:mrow> <math:mrow><math:mi>c</math:mi><math:mi>o</math:mi><math:mi>n</math:mi><math:mi>s</math:mi><math:mi>u</math:mi><math:mi>m</math:mi><math:mi>o</math:mi></math:mrow></math:mfrac> </math:math>

(My interpretation is that every letter is here considered a variable and put in the respective <math...> environment. So, this might eventually be considered correct, though it results different in output).

  • For all other forms (that is, with text commands within math mode):

    • in the .odt file: "o" over "consumo" (thus, missing braces (I'm not sure they're required though) and, most importantly, missing part of the text)

    • in the content.xml for the corresponding equation:

<math:mfrac><math:mrow><math:mstyle><math:mtext>importa&#xE7;&#xE3;o</math:mtext></math:mstyle></math:mrow> <math:mrow><math:mstyle><math:mtext>consumo</math:mtext></math:mstyle></math:mrow></math:mfrac>

Thus, the text is actually there, but doesn't get rendered by LibreOffice. If I edit any of these content.xmls with importação directly and repack, the .odt file results corrupted.

So, how could I get better results for text in math mode for ODT output, particularly with (some of) the text commands above?

1

This seems like a bug in LibreOffice, it has obviously problem with Unicode characters encoded as XML entities, as it renders only part of the word that follows the entities. Conversion of entities to characters seems to fix this, so we can reuse the code from my previous answer to do the conversion also for maths:

local filter = require "make4ht-filter"
local utfchar = unicode.utf8.char
local process =  filter {
  function(content)
    return content:gsub("%&%#x([A-Fa-f0-9]+);", function(entity)
      -- convert hexadecimal entity to Unicode
      print(entity,utfchar(tonumber(entity, 16)))
      return utfchar(tonumber(entity, 16))
    end)
  end
}

Make:match("4oo$", process)
Make:match("4om$", process)

Math is saved in files with 4om extension, so this build file executes the conversion process on files with that extension as well. The results seems fine:

enter image description here

  • Works marvelously indeed! Thank you very much once again!! – gusbrs Jun 19 '18 at 12:36
  • 1
    @gusbrs I've expected some issues with XML elements, this seems like really dumb bug on LO side. Their MathML support seems to have lots of issues. Anyway, I've updated make4ht to use this filter by default for the ODT output. – michal.h21 Jun 19 '18 at 12:46
  • It does seem so. As to the use of this filter by default, I was thinking of suggesting it, as beyond reaching a "nicer" content.xml it appears to be better handled than the Unicode as XML entities by LO. So, I thank you a ton yet again! – gusbrs Jun 19 '18 at 12:53
  • @gusbrs I've made more fixes in the ODT support, if you want to test that – michal.h21 Jun 25 '18 at 12:05
  • Michal, that's great! I'll gladly do so (but I'll only be able to do so later in the week). In what direction did the new fixes go? (so I know where to focus attention in testing). – gusbrs Jun 25 '18 at 12:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.