3

I use the command mk4ht oolatex to convert a simple latex document to odt. So far, it works quite well with a basic document. However, tex4ht inserts a section break before and after some environments, e.g. \begin{quote} and \end{quote} will produce section breaks. A <text:section ...> tag in the converted odt-file, or the contents.xml more precisely, seems to be responsible for this.

Minimal Example:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\begin{document}
This is a normal paragraph.

\begin{quote}
This is an blockquote.
\end{quote}

Another paragraph.
\end{document}

If we compile this with mk4ht oolatex we end up with this (in content.xml):

<text:p text:style-name="Text-body">This is a normal paragraph.&#xD;
   </text:p> 
<text:section
 text:style-name="begin-end-env" text:name="begin-end-env-1"><text:p text:style-name="begin-env-p"/>
     <!--l. 10
--><text:p text:style-name="quote">This is an blockquote.</text:p>
<text:p text:style-name="end-env-p"/></text:section>
<!--l. 13
--><text:p text:style-name="First-line-indent">   Another paragraph.&#xD;
   </text:p> 

In contrast, these passages in a similar document written with Libreoffice looks like this (in content.xml):

<text:p text:style-name="P1">This is a normal paragraph.</text:p>
<text:p text:style-name="Quotations">This is an blockquote. </text:p>
<text:p text:style-name="P1">Another normal paragraph.</text:p>

In ooffice.4ht we find the following definition that seems responsible for this behaviour:

\ConfigureEnv{quote}
   {\ifvmode \IgnorePar\fi \EndP
\ifnum \BegEnd:D=0
   \gHAdvance\BegEnd:N by 1
\HCode{<text:section
        text:style-name="begin-end-env"
        text:name="begin-end-env-\BegEnd:N"
       >%
       <text:p text:style-name="begin-env-p" ></text:p>}%
%
\else
   \gHAdvance\BegEnd:N by 1
\hbox{\HCode{<text:p><draw:frame
                draw:name="begin-end-env-\BegEnd:N"
                 draw:style-name="env-frame"
                 text:anchor-type="as-char"
%                 fo:min-width="0.14in"
                 svg:width="90\%"
                 draw:z-index="0"
       >
       <draw:text-box
%           fo:min-height="0.14in"
       >}}%
%
\fi
\gHAdvance\BegEnd:D by 1
}
   {\gHAdvance\BegEnd:D by -1
\ifvmode \IgnorePar\fi\EndP
\ifnum \BegEnd:D=0
   \HCode{<text:p text:style-name="end-env-p" ></text:p></text:section>}%
%
\else
   \hbox{\HCode{</draw:text-box>
</draw:frame></text:p> }}%
%
\fi
\par\ShowPar}
   {\EndP \ifvmode \IgnorePar\fi
    \bgroup \Configure{HtmlPar}
   {\EndP \HCode{<!--l. \the\inputlineno-->%
%
                 <text:p text:style-name="quote\if@rl-rtl\fi
"
                         >}}
   {\EndP \HCode{<!--l. \the\inputlineno-->%
%
                 <text:p text:style-name="quote\if@rl-rtl\fi
"
                          >}}
   {\HCode{</text:p>}}
   {\HCode{</text:p>}}%
%
   }
   {\IgnorePar\EndP \egroup \ShowPar \ShowIndent}

So, I guess we should change that definition, but how? How can we suppress those unwanted section breaks?

  • Welcome to TeX.sx! Could you please add an minimal working example? Why don't you like <text:section> elements? – michal.h21 May 23 '17 at 15:10
  • I don't like those elements because they don't correspond to what Libreoffice produces. By the way, my goal is to convert the odt-file produced by tex4ht to doc, docx, or rtf. So, I'd also be happy to learn if there is a simpler way to do that. – Denis May 23 '17 at 19:35
3

The \ConfigureEnv{quote} configuration does two main things. It inserts section around the the contents of the whole environment and configures HtmlPar to insert <text:p text:style-name="quote"> for each paragraph. So solution to your problem is simple: just remove the code which insert section and leave the paragraph configuration.

Save the following code as myconfig.cfg:

\Preamble{xhtml}

  \makeatletter
\ConfigureEnv{quote}
   {\ifvmode \IgnorePar\fi \EndP}
   {\ifvmode \IgnorePar\fi\EndP\par\ShowPar}
   {\EndP \ifvmode \IgnorePar\fi
    \bgroup \Configure{HtmlPar}
   {\EndP \HCode{<!--l. \the\inputlineno-->%
   <text:p text:style-name="quote\if@rl-rtl\fi">}}
   {\EndP \HCode{<!--l. \the\inputlineno-->%
   <text:p text:style-name="quote\if@rl-rtl\fi">}}
   {\HCode{</text:p>}}
   {\HCode{</text:p>}}%
   }
   {\IgnorePar\EndP \egroup \ShowPar \ShowIndent}
\makeatother
\begin{document}

\EndPreamble

And compile the document using

mk4ht oolates filename myconfig

It will produce the following result:

<!--l. 5--><text:p text:style-name="Text-body">This is a normal paragraph.
  </text:p>
 <!--l. 8--><text:p text:style-name="quote">This is an blockquote.</text:p>
<!--l. 11--><text:p text:style-name="First-line-indent">   Another paragraph. </text:p>

To configure the appearance of your quote, you can modify \ConfigureOO{quote} which can be found in ooffice.4ht. You can make this modification in the config file as well:

\Preamble{xhtml}

  \makeatletter
\ConfigureEnv{quote}
   {\ifvmode \IgnorePar\fi \EndP}
   {\ifvmode \IgnorePar\fi\EndP\par\ShowPar}
   {\EndP \ifvmode \IgnorePar\fi
    \bgroup \Configure{HtmlPar}
   {\EndP \HCode{<!--l. \the\inputlineno-->%
   <text:p text:style-name="quote\if@rl-rtl\fi">}}
   {\EndP \HCode{<!--l. \the\inputlineno-->%
   <text:p text:style-name="quote\if@rl-rtl\fi">}}
   {\HCode{</text:p>}}
   {\HCode{</text:p>}}%
   }
   {\IgnorePar\EndP \egroup \ShowPar \ShowIndent}
\ConfigureOO{quote}{\Hnewline
<style:style style:name="quote"
             style:family="paragraph"
             style:parent-style-name="Text-body"
             style:next-style-name="Text-body">\Hnewline
<style:paragraph-properties  fo:margin-left="2cm"
             fo:margin-right="1cm"
             fo:margin-top="0.199cm"
             fo:margin-bottom="0.199cm"
             fo:text-indent="0cm"
             style:auto-text-indent="false"/>\Hnewline
</style:style>
\Hnewline <style:style style:name="quote-trl"
             style:family="paragraph"
             style:parent-style-name="Text-body-trl"
             style:next-style-name="Text-body-trl">\Hnewline
<style:paragraph-properties  fo:margin-left="1cm"
             fo:margin-right="1cm"
             fo:margin-top="0.199cm"
             fo:margin-bottom="0.199cm"
             fo:text-indent="0cm"
             style:auto-text-indent="false"
             fo:text-align="end"
             style:writing-mode="rl-tb"  />\Hnewline
</style:style>
\Hnewline
}
\makeatother
\begin{document}

\EndPreamble

I've set the left margin to 2cm in this example:

enter image description here

  • Great! That works, Thank you. I guess we will have to make those changes to every environment (verse, quotation, itemize, etc.), right? Or can we get rid of those section breaks in multiple environments with a single definition? – Denis May 26 '17 at 9:46
  • @Denis you could modify the literate source code for ooffice, tex4ht-ooffice.tex. You would need to download it using subversion from the source repository and search for \<sectioned env\> piece. This is then copied to various places in the generated .4ht file. – michal.h21 May 26 '17 at 10:26

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.