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?

EngBIRD
  • 3,985
  • 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 Answers1

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

michal.h21
  • 50,697
  • 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
  • @EngBIRD I am glad it works now. Bugs are sometimes just mysterious :) – michal.h21 Aug 18 '20 at 16:15
  • Speaking of mysterious bugs, I can't compile this or other past solutions on windows. Are you aware of any changes to the base of the make4ht or related that would be causing the compiler to think it or other files are on network drives? I've been getting this error for many months now. '\\?\C:\Home\Personal\Dropbox\Tex_Work\MWE-odt\COMPILE_OUTPUT' CMD.EXE was started with the above path as the current directory. UNC paths are not supported. Defaulting to Windows directory. The system cannot find the file specified. [STATUS] make4ht: Conversion finished Probably merits it's own question... – EngBIRD Aug 18 '20 at 16:33
  • @EngBIRD I don't use Windows at all, but it seems like the Windows's CMD itself thinks your files are UNC. I had even to Google what UNC is :) Anyway, have you tried some of these suggestions? https://serverfault.com/q/50085 – michal.h21 Aug 18 '20 at 17:23
  • I have googled, but no luck yet. It's interesting because I'm not using a network drive, but the compile engine things it's being run from one (see the \\?\in front of my C drive in the error message above). I haven't posted this as a distinct question because it's not probably not reproducible. It happened after an update sometime late in 2019 if memory serves, works fine on Linux, and surely would be more prevalently reported here if it was a make4ht bug. So thanks for commenting on my tangent, and for your help with my issue above! – EngBIRD Aug 18 '20 at 17:39
  • I still don't think I have enough information to post a new question, but a quick update to this UNC issue. I've managed to determine that the problem appears to be specific to the odt+template compile option. Location of the template odt file doesn't seem to matter, but if I compile on windows without this option it appears to work fine, just doesn't come with the expected style customizations other than those in the cfg file. I've tried creating my target template odt file a few different ways with no difference in the compile error and these exact template files have worked previously. – EngBIRD Sep 15 '20 at 00:43
  • @EngBIRD the strange thing is that make4ht doesn't do anything with the template filename, it just uses regular Lua functions to read that file. See https://github.com/michal-h21/make4ht/blob/3d97d239125f017a644532228c28d45d84f338fc/filters/make4ht-odttemplate.lua#L6 – michal.h21 Sep 15 '20 at 06:46
  • Indeed it's quite bizarre. I recognize this lua file, I looked at it on my own tex installations when I was checking if my linux machine and windows machines were using different versions of make4ht. I saw the regex like string matching and figured there was nothing that was adding slashes or something that could be confused with a server address. I'd be surprised if make4ht was the problem, it worked fine for years, the only thing I ever updated during that time was my open office installation. Then again, I update the linux open office way more often so maybe that's not the issue either. – EngBIRD Sep 16 '20 at 01:27
  • @EngBIRD it must be some Windows update issue, I think. Maybe try a different quotes? like make4ht -f odt+odttemplate filename.tex "odttemplate=mytemplate.odt'. – michal.h21 Sep 16 '20 at 11:21
  • Update: Looks like I didn't quite break the problem down quite far enough, the problem is actually further upstream of the template in the compile instruction, it's with --format odt. --format XXX works fine for each html5, tei, xhtml, and docbook. The odt option is the only one causing a UNC problem. Could this indicate a problem with my libre office installation? Or is the make4ht compile format independent of having libre office installed? I think I read that libre office is only needed if your using it to do a headless docx conversion. Thanks! – EngBIRD Sep 24 '20 at 00:33
  • @EngBIRD I think this is the same issue: https://tex.stackexchange.com/q/563644/2891. It doesn't happen with TeX Live on Windows, so I think it is caused by something in Miktex. – michal.h21 Sep 24 '20 at 08:39
  • @EngBIRD it may be worth to report it on Miktex issue tracker. – michal.h21 Sep 24 '20 at 10:08