2

As an extension to this question: Creating new single line classes in ODT output from mk4ht oolatex

I've been attempting to use this approach to reassign the style assigned in existing commands that have already been configured. The initial guidance provided in the comments of the linked question suggested starting from the \Configure{section} command found in ooffice.4ht

\Configure{section}
   {\IgnorePar\EndP \HCode{<!--start of section-->}}
   {\IgnorePar\EndP \HCode{<!--end of section-->}}
   {\HCode{<text:h
            text:style-name="\csname a:Heading-2\if@rl-rtl\fi
\endcsname"
                   \text:outlinelevel="2" ><text:span
                   text:style-name="section" >}\TitleMark\space
    \HCode{</text:span>}\IgnoreIndent}
   {\HCode{</text:h>\Hnewline}\par\ShowPar}

So I started playing around with this block as a starting point. But I've been unable to get this block to compile let alone customize with my own style names. I've tried to many permutations and scope changes to detail each here, but in short, I've tried:

  1. simplifying the csname line to only contain my desired section name.
  2. I've removed TeX code like the \TitleMark and \space.
  3. I've also tried replacing the HCode portions with the customized HCode text inspired from the answer to the related question.
  4. My setup seems sensitive to spaces so I've been playing around with this and % on line endings as well.

I get error messages at times complaining about the :h and the associated > character, but in general it only reports the typical Missing \begin{document} in myconfig.cfg

MWE:

test.tex

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

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

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


\usepackage[parfill]{parskip}

\usepackage{longtable}

\usepackage{graphicx}
\usepackage[export]{adjustbox}
    
\begin{document}
    
This is a normal paragraph.

\section{Custom style access test}

test text in the first level of section hierarchy 

more text

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

more text

This is a blockquote environment

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

myconfig.cfg

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

% configure the single line commands in Tex against their corresponding style in the template

\Configure{section}%
{\IgnorePar\EndP \HCode{<!--start of section-->}}%
{\IgnorePar\EndP \HCode{<!--end of section-->}}%
{\HCode{<text:h
        text:style-name="Heading-2">
        text:outlinelevel="2" ><text:span
        text:style-name="section" >}%
    %\TitleMark\space%
    \HCode{</text:span>}%
    %\IgnoreIndent%
}%
{\HCode{</text:h>\Hnewline}\par\ShowPar}%


% configure the environments in Tex against their corresponding style in the template
\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}{}{}%


\ConfigureEnv{quote}%
{%
    \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="quote">}}%
        {\EndP \HCode{<text:p text:style-name="quote">}}%
        {\HCode{</text:p>}}%
        {\HCode{</text:p>}}%
    \par\ShowPar%
}{\myendpar\egroup}{}{}%




\begin{document}

\EndPreamble

The example is compiled against a sample ODT template file with the command:

  • as part of a linux shell script: make4ht -u --config "myconfig.cfg" --format "odt+odttemplate" "$FILE" odttemplate="$BASEDIR/refTemplates/basic.odt"
  • or as part of a bat file on windows: "%MikTexPath%%htxCompiler%" --config "myconfig.cfg" --format "odt+odttemplate" "%%~nxA" odttemplate="./refTemplates/basic.odt"

If I've completely missed the mark, how else could I change the mapping of styles in existing commands?

4
  • What should \Configure{SectionTitleTest} do? It isn't defined anywhere and it gives you the compilation error. There are also other issues that I will investigate, but this one can be fixed just by removing of this line. – michal.h21 Aug 17 '20 at 19:17
  • do you want to use the section-title style in \Configure{section}? – michal.h21 Aug 17 '20 at 19:31
  • @michal.h21 Ah, my apologies, it can be removed at the moment, it was part of the file as inspired by the first and linked question. I kept it because I was using it as an example of what the Hcode blocks might have needed to look like as I modified the \Configure{section} block to look more like it. I think I must have messed up the MWE as on my computer if I comment out the \Configure{section} block it compiles fine. – EngBIRD Aug 17 '20 at 19:38
  • I think I've identified the issues, will post my answer soon. – michal.h21 Aug 17 '20 at 19:47
1

I get errors with your mwe.cfg mainly because: you use undeclared \Configure{SectionTitleTest} and because of missing fifth argument for \Configure{section}.

I can compile your file with the following fixes:

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

% configure the single line commands in Tex against their corresponding style in the template

%\Configure{SectionTitleTest}{\myendpar\HCode{<text:p text:style-name="section-title">}}{\HCode{</text:p>}}
\NewConfigureOO{section-title}
\ConfigureOO{section-title}{<style:style style:name="section-title" style:family="paragraph" style:class="text">
    <style:text-properties style:text-underline-style="solid"   
    style:text-underline-width="auto"
    style:text-underline-color="font-color"   
    />
    </style:style>}


\Configure{section}%
{\IgnorePar\EndP \HCode{<!--start of section-->}}%
{\IgnorePar\EndP \HCode{<!--end of section-->}}%
{\HCode{<text:h
        text:style-name="Heading 1"
        text:outlinelevel="2" ><text:span
        text:style-name="section" >}%
    %\TitleMark\space%
    \HCode{</text:span>}%
    %\IgnoreIndent%
}{\HCode{</text:h>}}%

% \Configure{section}
%    {\IgnorePar\EndP \HCode{<!--start of section-->}}
%    {\IgnorePar\EndP \HCode{<!--end of section-->}}
%    {\HCode{<text:h
%             text:style-name="\csname a:Heading-2\if@rl-rtl\fi\endcsname"
%                    text:outlinelevel="2" ><text:span
%                    text:style-name="section" >}\TitleMark\space
%     \HCode{</text:span>}\IgnoreIndent}
%    {\HCode{</text:h>\Hnewline}\par\ShowPar}


% configure the environments in Tex against their corresponding style in the template
\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}{}{}%


\ConfigureEnv{quote}%
{%
    \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="quote">}}%
        {\EndP \HCode{<text:p text:style-name="quote">}}%
        {\HCode{</text:p>}}%
        {\HCode{</text:p>}}%
    \ShowPar%
}{\myendpar\egroup}{}{}%


\begin{document}

\EndPreamble

Another fix I've added was that I removed \par from \ConfigureEnv{quote}, because this resulted in spurious empty paragraph that showed in the document.

This is the rendered document:

enter image description here

16
  • Thanks! I've updated my question with {\HCode{</text:h>\Hnewline}\par\ShowPar}% - the 5th argument from my MWE that I mistakenly deleted when I was clearing out commented out code from past attempts in my actual config file. Unfortunately I'm still getting errors: Paragraph ended before \HCode was complete, LaTeX Error: Missing \begin{document} in myconfig.cfg, and Too many }s.. Since this is a copy paste from your cfg file, I know the error must be else where, so I'll report back when I've looked for brace mismatches elsewhere in the file. – EngBIRD Aug 17 '20 at 22:04
  • @EngBIRD maybe you still have the \Configure{SectionTitleTest} in your config file? This may cause the 'missing \begin{document}` error. – michal.h21 Aug 17 '20 at 22:16
  • Thanks for the suggestion. In light of the config file you provided in your answer though I started from a clean file which has removed this mistake. – EngBIRD Aug 17 '20 at 23:21
  • @EngBIRD can you post your updated .cfg file? It seems the one provided in your question still has the \Configure{SectionTitleTest} line. – michal.h21 Aug 18 '20 at 11:20
  • Thanks again for all your amazing help and work on this package, it's working now. I didn't change anything from last night, just a clean reboot of the computer... So something must have changed. Only thing I can think of is if somehow, and I feel stupid theorizing things that make no sense against how computers work, but I'm wondering if in memory the SectionTitleTest was still in memory somewhere and not finding the necessary 4ht files, as I did remove this file the when starting from your complete, new cfg file without this residual custom command. – EngBIRD Aug 18 '20 at 15:14

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.