# Using ODT styles in a reference template to format make4ht

Following my recent question Customizing ODT output from mk4ht oolatex and a improved process alternative described here: Use ODT Template for make4ht (which makes use of direct formatting by using existing / created styles stored in a odt document/template) I'd like to ask what needs to be done on the tex/compilation side with make4ht to connect a style in the odt template to a custom command or environment in a latex file.

For example:

I create a style called test in a odt file called basic.odt.

I compile a tex file (see below for MWE) with "C:\texmfs\install\miktex\bin\make4ht.exe" -f odt+odttemplate "test.tex" "odttemplate=./refTemplates/basic.odt" which compiles my tex file with make4ht with a pointer to the template odt file.

MWE:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{xcolor}
\definecolor{specialtextcolor}{rgb}{0,0,1}

\newenvironment{test}
{\par\begin{color}{specialtextcolor}}
{\end{color}}

\begin{document}
This is a normal paragraph.

\section{Custom style access test}

test text in the first level of section hierarchy

more text
\medskip

\begin{test}
This is a test environment.
\end{test}

\medskip

more text

\end{document}


The main concern is that the output files don't reflect that they used the test style.

The first point to clarify:

1. What does make4ht require to let the lua script take over and extract the required css formatting from the style in the template odt file? I was hoping to use these odt template files and move away from the Configure commands in the cfg files, which I never successfully modified to work for other styles (see quote example in Customizing ODT output from mk4ht oolatex... I couldn't even rename all instances in tex and cfg files from quote to cmdquote without compile errors).

2. Since certain styles (like section) are accessible without any interface cfg manually created or customized I assume either

a) no custom cfg files are needed and my test commands/environments are to minamalistic or b) these have already been pre-configured (like in a class or sty file)? If it is the latter where are these documented or stored so I can learn from these pre-existing examples?

You must still configure the test environment to use the test style. And to make it more difficult, if you want to use the paragraph style, you must configure the paragraph handling for the environment. Try this configuration:

\Preamble{xhtml}
% to simplify the things
\def\myendpar{\ifvmode\IgnorePar\fi\EndP}

% configure the environment
\ConfigureEnv{test}
{\myendpar\bgroup%
% when you want to modify the paragraph style, you must redefine the paragraph configuration to
% use the test style name
\Configure{HtmlPar}%
{\EndP \HCode{<text:p text:style-name="test">}}%
{\EndP \HCode{<text:p text:style-name="test">}}%
{\HCode{</text:p>}}{\HCode{</text:p>}}%
\par\ShowPar}
{\myendpar\egroup}{}{}

\begin{document}

\EndPreamble


As you can see, you must configure the HtmlPar configuration, to insert <text:p text:style-name="desired style name">. It cannot be inserted automatically. Normally, you would insert style for the test style using \NewConfigureOO and \ConfigureOO commands, but as you configure it in the template file, you don't need it in this case and I will not show that. Some information about usual styling for the ODT output can be found here.

The default styles used by tex4ht aren't unfortunately documented, you can only search for \ConfigureOO in the literate sources of the ODT output.

I've also updated the odttemplate extension to actually join the styles from the template and the generated file, because you would lose additional styles added by tex4ht if you used just basic ODT file created by LibreOffice.

This is a result from empty ODT file with declared test style:

• Thanks, I can't wait to try this out! I've cloned the make4ht project into my scripts folder, replacing the one miktex created but when I compile my tex file I just get a corrupted odt file, so I assume I just need to wait until the binary aspects of the package get updated with miktex. – EngBIRD Jan 23 at 0:48
• @EngBIRD ah, do you get any errors towards the end of compilation? Especially with Xtpipes? Or some zip error? – michal.h21 Jan 23 at 8:01
• @EngBIRD new version of make4ht should be available in few days in distributions. – michal.h21 Jan 23 at 11:35
• I do remember seeing a zip error go past, but I didn't think that was anything new... I seem to remember getting that message all the time in the past but with no ultimate consequence. I could just be remembering snippets from the console during debug efforts as I've been trying a lot of things in the last year or so with mk4ht and make4ht. – EngBIRD Jan 23 at 12:43
• @EngBIRD usually the corrupted ODT file means that there is a XML error, so something must be wrong with either styles or the main text – michal.h21 Jan 23 at 12:50