2

I've been trying to follow a tutorial here: github.com/michal-h21/helpers4ht/wiki/tex4ht-tutorial

My MWE files below produce a valid output with the text from the command, but I was expecting the class (i.e. the document style for this text) to be assigned in accordance with the command used, similar to the way this (Customizing ODT output from mk4ht oolatex) example used environments to change the class which corresponded to a style name in the associated word file (referenced in the build instruction odttemplate). I can't, however, tell if the code is unable to interrupt the body text style or whether the style is not being assigned because of an error in the code.

Main.tex

\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc} 
\usepackage{testpkg}
\begin{document} 

    Test

    Some text in English, 

    \SectionTitleTest{Test}

    More text

\end{document}

testpkg.sty

\ProvidesPackage{testpkg} 

    \RequirePackage{xparse,expl3}
    \DeclareDocumentCommand{\SectionTitleTest}{m}{#1}

\endinput

testpkg.cfg

\Preamble{xhtml}

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

\Configure{SectionTitleTest}{\HCode{<span class="SectionTitleTest">}\NoFonts}{\EndNoFonts\HCode{</span>}}% tried without NoFonts code to no avail either
\Css{.SectionTitleTest{font-style:SectionTitleTest;}}

\begin{document}

\EndPreamble

testpkg.4ht

% provide configure for new command. we can choose any name
% but most convenient is to name hooks after redefined command
% we declare two hooks, to be inserted before and after the command

\NewConfigure{SectionTitleTest}{2}

% now we need to redefine \SectionTitleTest. save it to tmp command
% note that `:` can be part of command name in `.4ht` files.
\let\tmp:SectionTitleTest\SectionTitleTest

% now insert the hooks. they are named as \a:hook, \b:hook, ..., \h:hook
% depending on how many hooks were declared

\renewcommand\SectionTitleTest{\a:SectionTitleTest\tmp:SectionTitleTest\b:SectionTitleTest} 
2

There are several issues with your configuration. Fist of all, in testpkg.4ht:

\renewcommand\SectionTitleTest{\a:SectionTitleTest\tmp:SectionTitleTest\b:SectionTitleTest} 

The original \SectionTitleTest takes one argument, but you redefine it as argument free. Because of this, all content of the configuration is inserted before the text you pass as argument to \SectionTitleTest. The correct redefinition would look like this:

% provide configure for new command. we can choose any name
% but most convenient is to name hooks after redefined command
% we declare two hooks, to be inserted before and after the command

\NewConfigure{SectionTitleTest}{2}

% now we need to redefine \SectionTitleTest. save it to tmp command
% note that `:` can be part of command name in `.4ht` files.
\let\tmp:SectionTitleTest\SectionTitleTest

% now insert the hooks. they are named as \a:hook, \b:hook, ..., \h:hook
% depending on how many hooks were declared

\renewcommand\SectionTitleTest[1]{\a:SectionTitleTest\tmp:SectionTitleTest{#1}\b:SectionTitleTest}

The second issue is that you use HTML tags. In the ODT output, you must use OpenDocument tags. Also, ODT doesn't support CSS, it uses special XML instead.

The updated .cfg file:

\Preamble{xhtml}

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

\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>}

\begin{document}

\EndPreamble

The <text:p> element is used for paragraphs. It needs to use the text:style-name attribute to select the paragraph style.

The paragraph style is defined using \NewConfigureOO and configured using \ConfigureOO. I've used the same name as in text:style-name, but it is not necessary. The correct style name must be used <style:style style:name="section-title"> though.

The provided style configures the section title to produce underlined text. Use <style:text-properties> attributes to change the formatting according to your needs.

This is the result in LO:

enter image description here

|improve this answer|||||

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.