3

Inspired by the custom environments created from the cfg file referenced during mk4ht oolatex test.tex custom.cfg compilations as demonstrated in the answer Configure tex4ht/oolatex output

I'm wondering how far this can be taken. For example, starting with the test code in the aforementioned question, I've been unable to get any actual changes like font size changes or font changes to the text of this quote environment. Some change efforts are seen below in the lightly modified MWE. Specifically, I've tried to insert: style:font-name="Times New Roman" and fo:font-size="18pt" but I see no change to my odt file. I've tried a dozen or so logical variations to "font-name" like:

  • font
  • font-name
  • fonts
  • font-face
  • font-family

but none have changed my formatting. The document compilation didn't crash either, so I'm not even sure if I'm successfully using this part of the cfg file.

Is there a list of oolatex parseable style properties anywhere in the documentation that I've missed?

custom.cfg

\Preamble{xhtml}

  \makeatletter
\ConfigureEnv{quote}
   {\ifvmode \IgnorePar\fi \EndP}
   {\ifvmode \IgnorePar\fi\EndP\par\ShowPar}
   {\EndP \ifvmode \IgnorePar\fi
    \bgroup \Configure{HtmlPar}
   {\EndP \HCode{<!--l. \the\inputlineno-->%
   <text:p text:style-name="quote\if@rl-rtl\fi">}}
   {\EndP \HCode{<!--l. \the\inputlineno-->%
   <text:p text:style-name="quote\if@rl-rtl\fi">}}
   {\HCode{</text:p>}}
   {\HCode{</text:p>}}%
   }
   {\IgnorePar\EndP \egroup \ShowPar \ShowIndent}
\ConfigureOO{quote}{\Hnewline
<style:style style:name="quote"
             style:font-name="Times New Roman" 
             fo:font-size="18pt"
             style:family="paragraph"
             style:parent-style-name="Text-body"
             style:next-style-name="Text-body">\Hnewline
<style:paragraph-properties  fo:margin-left="2cm"
             fo:margin-right="1cm"
             fo:margin-top="0.199cm"
             fo:margin-bottom="0.199cm"
             fo:text-indent="0cm"
             style:auto-text-indent="false"/>\Hnewline
</style:style>
\Hnewline <style:style style:name="quote-trl"
             style:family="paragraph"
             style:parent-style-name="Text-body-trl"
             style:next-style-name="Text-body-trl">\Hnewline
<style:paragraph-properties  fo:margin-left="1cm"
             fo:margin-right="1cm"
             fo:margin-top="0.199cm"
             fo:margin-bottom="0.199cm"
             fo:text-indent="0cm"
             style:auto-text-indent="false"
             fo:text-align="end"
             style:writing-mode="rl-tb"  />\Hnewline
</style:style>
\Hnewline
}
\makeatother
\begin{document}

\EndPreamble

test.tex

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\begin{document}
This is a normal paragraph.

\begin{quote}
This is an blockquote.
\end{quote}

Another paragraph.
\end{document}

Ultimately I'd like to be able to control:

  • fonts
  • font sizes
  • margin formatting
  • paragraph spacing and alignment type (i.e. square or ragged)
  • heading enumeration
  • continuous section breaks
  • column control (number of columns, spacing, etc)

But, baby steps in customizing styles (xml? or css?) in these office documents.

EngBIRD
  • 3,985

1 Answers1

5

I think that font changes must be done in <style:text-properties> child element of <style:style>. See a list of possible attributes, another list. I cannot find any human readable description unfortunately. Anyway, try this:

\Preamble{xhtml}

  \makeatletter
\ConfigureEnv{quote}
   {\ifvmode \IgnorePar\fi \EndP}
   {\ifvmode \IgnorePar\fi\EndP\par\ShowPar}
   {\EndP \ifvmode \IgnorePar\fi
    \bgroup \Configure{HtmlPar}
   {\EndP \HCode{<!--l. \the\inputlineno-->%
   <text:p text:style-name="quote\if@rl-rtl\fi">}}
   {\EndP \HCode{<!--l. \the\inputlineno-->%
   <text:p text:style-name="quote\if@rl-rtl\fi">}}
   {\HCode{</text:p>}}
   {\HCode{</text:p>}}%
   }
   {\IgnorePar\EndP \egroup \ShowPar \ShowIndent}
\ConfigureOO{quote}{\Hnewline
<style:style style:name="quote"
             style:family="paragraph"
             style:parent-style-name="Text-body"
             style:next-style-name="Text-body">\Hnewline
<style:paragraph-properties  fo:margin-left="2cm"
             fo:margin-right="1cm"
             fo:margin-top="0.199cm"
             fo:margin-bottom="0.199cm"
             fo:text-indent="0cm"
             style:auto-text-indent="false"/>\Hnewline
<style:text-properties 
             fo:font-size="18pt"
             style:font-name="Times New Roman" 
/>\Hnewline
</style:style>
\Hnewline <style:style style:name="quote-trl"
             style:family="paragraph"
             style:parent-style-name="Text-body-trl"
             style:next-style-name="Text-body-trl">\Hnewline
<style:paragraph-properties  fo:margin-left="1cm"
             fo:margin-right="1cm"
             fo:margin-top="0.199cm"
             fo:margin-bottom="0.199cm"
             fo:text-indent="0cm"
             style:auto-text-indent="false"
             fo:text-align="end"
             style:writing-mode="rl-tb"  />\Hnewline
</style:style>
\Hnewline
}
\makeatother
\begin{document}

\EndPreamble

This is the result:

enter image description here

Edit November 2018:

make4ht can output ODT file directly now, with filter support. So the code bellow can be simplified significantly:

local filter = require "make4ht-filter"

local process = filter {
  function(content)
    content = content:gsub("<office:font%-face%-decls>", [[<office:font-face-decls>
    <style:font-face style:name="Times New Roman" svg:font-family="&apos;Times New Roman&apos;" style:font-family-generic="roman" style:font-pitch="variable"/>]])
    return content
  end
}

Make:match("styles.4oy$", process)

It can be executed using

 make4ht -e buildfilename.mk4 -c configfile.cfg -f odt filename.tex

The styles.4oy$ file pattern matches file with ooffice styles and executes the filter which declares "Times New Roman" font to be used in the document.

Edit:

The Times New Roman is not used in the document because it is not declared. To declare new fonts, it is necessary to modify the styles.xml file. unfortunately, interface for this declaration is not provided by tex4ht, so we must use a trick involving mk4 build file:

local mkutils = require "mkutils"
local zip = require "zip"

settings_add {
  tex4ht_sty_par = ",ooffice",
  tex4ht_par =  " ooffice/! -cmozhtf",
  t4ht_par =  " -cooxtpipes -coo "
}


Make:match("tmp$", function(name, par)
  local odtname = mkutils.remove_extension(name) .. ".odt"
  local stylesname = "styles.xml"
  local odtfile = zip.open(odtname)
  local styles = odtfile:open("styles.xml")
  local content = styles:read("*all")
  styles:close()
  odtfile:close()
  content = content:gsub("<office:font%-face%-decls>", [[<office:font-face-decls>
  <style:font-face style:name="Times New Roman" svg:font-family="&apos;Times New Roman&apos;" style:font-family-generic="roman" style:font-pitch="variable"/>]])
  print(content)
  local styles_file  = io.open(stylesname,"w")
  styles_file:write(content)
  styles_file:close()
  os.execute("zip " .. odtname .. " " .. stylesname)
  os.remove(stylesname)
end)

Use it as

make4ht -e buildfilename.mk4 -c configfile.cfg filename.tex

in TL 2018, it will be possible to create odt files directly using make4ht with make4ht -f odt. because it is not readily available, the settings for the odt output need to be set explicitly.

In the Make:match function, the settings.xml is extracted from the odt file and updated with declarations for Times New Roman.

michal.h21
  • 50,697
  • Thanks for the answer. The links with the lists of commands will definitely really help. I'm able to change the font size, as your image depicts, but I unfortunately am still getting Liberation Serif fonts. – EngBIRD Apr 20 '18 at 23:36
  • @EngBIRD this is more complicated, it is necessary to define the font in styles.xml file, but tex4ht doesn't provide interface for that. I need to investigate this further. – michal.h21 Apr 21 '18 at 19:00
  • @EngBIRD I think I've found a way, please see the edit – michal.h21 Apr 21 '18 at 19:51
  • Thanks and sorry for the delay. I haven't been able to compile anything with make4ht instead of mk4ht, so I'm still troubleshooting and investigating. I'm sure I've still got much to investigate around the error make4ht:35: attempt to call field 'process_args' (a nil value) so I won't open a new question yet. I'm sure it's something silly I'm overlooking. Just wanted to leave a comment in the interim as I really appreciate your incredible contributions with this build file and configurations, and didn't want to appear to be ignoring them. Thanks again! – EngBIRD Apr 24 '18 at 03:14
  • @EngBIRD do you use make4ht from your distribution, or manually installed version? if it is provided by distribution, which distribution do you use? it seems that some files are missing on your computer. – michal.h21 Apr 24 '18 at 07:51
  • I'm using MikTeX. I've checked that make4ht and tex4ht are installed globally in the package manager. I think the last time I tried make4ht it wasn't available from MikTeX so I downloaded & installed it manually and adding it to the texmf tree (https://tex.stackexchange.com/questions/225783/install-make4ht-with-miktex). I've also added some related ebook packages. Unfortunately, similar to https://tex.stackexchange.com/questions/305882/kpsewhich-returns-blank-line, I can't validate that it's properly part of the path. It's probably ok though because I can run from cmd without a complete path. – EngBIRD Apr 26 '18 at 23:15
  • @EngBIRD it is in Miktex packages now, so you can try to remove the manually installed version – michal.h21 Apr 27 '18 at 06:44
  • This is the actual error I was getting before I reinstalled the manual version and ended up with a different error: [string "local mkutils = require "mkutils"..."]:4: attempt to index global 'settings' (a nil value) & C:/Program Files/MiKTeX 2.9/scripts/make4ht/mkutils.lua:382: assertion failed!. – EngBIRD Apr 27 '18 at 22:02
  • @EngBIRD oh, so it seems that it is broken even in Miktex (it is also broken in TeX Live) – michal.h21 Apr 28 '18 at 06:42
  • @EngBIRD it was error in the build file actually, respective in make4ht. I've updated it and it should work now. – michal.h21 May 04 '18 at 11:08
  • I have updated to version 0.2b, but running make4ht -e fonts.mk4 test.tex myconfig.cfg or make4ht -e fonts.mk4 test.tex both result in an odt file with no changes. I've now lost the size change that I was originally getting, as well as still not getting a font change. – EngBIRD May 10 '18 at 02:42
  • @EngBIRD try make4ht -e fonts.mk4 -c myconfig.cfg test.tex – michal.h21 May 10 '18 at 07:56
  • That compile sequence has restored the font size change, but I still only get the Liberation Serif font. Times New Roman isn't showing up yet. I also tried Courier New but no change there either. Sorry to have taken up so much of your time with this. THANKS! – EngBIRD May 10 '18 at 23:30
  • @EngBIRD I've added print statement that should show the modified styles. There should be "Times New Roman" somewhere – michal.h21 May 11 '18 at 06:14
  • Indeed, I can see Times new roman: <style:font-face style:name="Times New Roman" svg:font-family="&apos;Times New Roman&apos;" style:font-family-generic="roman" style:font-pitch="variable"/> </office:font-face-decls> <office:styles> and ~100 lines later <style:text-properties fo:font-size="18pt" style:font-name="Times New Roman" />. The Liberation Serif font is not mentioned anywhere in the style output. Also, I the version of LibreOffice I had been working with was 5.4.4.2. I have installed 6.0.4.2, the latest, but get the same results. Anything else I can add to facilitate debugging? – EngBIRD May 22 '18 at 13:37
  • @EngBIRD LibreOffice uses substitute font if the required font is not installed on the machine. On my machine, it displays all text in Liberation Serif, which is substitute font, but if I place the cursor inside the quotation, which should be in Times New Roman, it displays Times New Roman in italic font – michal.h21 May 22 '18 at 13:44
  • That's very interesting. On a windows installation, I can manually select and use the Times New Roman Font, so I would have guessed that it is installed. Is there a way I can output a list of fonts that are either installed or visible or just plain available to use via a properly configured path variable (i.e. Could there be a manual pointer needed to point to this font?)? I'm not sure what else to debug against unfortunately. – EngBIRD May 22 '18 at 15:08
  • @EngBIRD I don't know how to debug this either. I just tried the generated ODT file in Word on Windows and it shows the quote in Times New Roman. Can you post the styles.xml from the ODT file somewhere? – michal.h21 May 22 '18 at 15:32
  • So, still no luck getting this to work, but it makes me wonder about the possibility of circumventing some of this by issuing a tex command (begin environment probably) to work with manually named styles (only basically defined in CSS configs as above) that MSword could control through a workflow like "Select all with similar formatting" + "Reapply Style" to reformat in accordance with styles created in the template. I've been using the approach to work around this problem so far, for example bibliographies are styled with the name p-bib, but I'd like to be able to specify this name myself. – EngBIRD Nov 20 '18 at 17:58
  • @EngBIRD see the update. make4ht can output ODT file directly now, with filter support, so the build file can be simplified a lot. – michal.h21 Nov 20 '18 at 22:22
  • There’s now fo:font-family and style:font-family-generic for use within style:text-properties. – Davislor Jun 14 '19 at 23:00
  • Out of curiosity, is it possible to create a Command equivalent in the cfg file ConfigureEnv? I thought it would have been Configure with the accompanying bracket pairs (I think I remember trying 6 pairs of open close way back when), but this didn't work. I'd like to be able to set up style links using the latex commands as well as environments. I don't intend on overloading the same command, but using the example above, what would you be able to demo what the blank cfg Configure command (if this is the one) would look like to link a \quote{xxx} command with a document style? Thanks! – EngBIRD Jan 31 '20 at 13:58
  • @EngBIRD sure, configuring commands is just a little bit more difficult than configuration of environments. See https://github.com/michal-h21/helpers4ht/wiki/tex4ht-tutorial for example – michal.h21 Jan 31 '20 at 14:23