TransWikia.com

Creating new single line classes in ODT output from mk4ht oolatex

TeX - LaTeX Asked by EngBIRD on August 13, 2021

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
defmyendpar{ifvmodeIgnoreParfiEndP}

Configure{SectionTitleTest}{HCode{<span class="SectionTitleTest">}NoFonts}{EndNoFontsHCode{</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.
lettmp:SectionTitleTestSectionTitleTest

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

renewcommandSectionTitleTest{a:SectionTitleTesttmp:SectionTitleTestb:SectionTitleTest} 

One Answer

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

renewcommandSectionTitleTest{a:SectionTitleTesttmp:SectionTitleTestb: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.
lettmp:SectionTitleTestSectionTitleTest

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

renewcommandSectionTitleTest[1]{a:SectionTitleTesttmp: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
defmyendpar{ifvmodeIgnoreParfiEndP}

Configure{SectionTitleTest}{myendparHCode{<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

Correct answer by michal.h21 on August 13, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP