5
tlmgr revision 35841 (2014-12-16 20:11:15 +0100)
tex4ht revision:    34624

I was using this package for test the tex4ht functions. However, I found out if the image is under subforder, oolatex cannot process the figures correctly (the image in ODT file will display as 'read error' in both libreoffice and openoffice 4.1.1). If we move the figures out, the image can be correctly embedded into odt file. Any reason why this is happening, is there any additional config I should do to fix this?

1
  • 2
    it seems that pictures in the odt file must be only in the Pictures folders, not any subfolders. tex4ht apparently copies subfolders here and it doesn't work – michal.h21 Jan 13 '15 at 14:35
5

This looks like a bug in tex4ht support for ODT. I submitted a bug report.

All pictures should be placed in Pictures directory in the odt file, but subdirectories are created for files which were originally in subdirectory of the compiled document.

To fix that, we need to modify configuration of image handling and some commands in tex4ht.env. We need to change links to images from Pictures/subdir/imagename to Pictures/imagename. At the same time, we need to track path to the actual image file, so it can be copied to the correct location.

You linked some test package, I will use that as basis for tests. There is a config file, myconfig.cfg.

Basic configuration for handling image inclusion is \Configure{graphics*}:

\Configure{graphics*}
   {png}
{\Picture[IMG]{imagename.png}}

we need to provide such configuration for each graphics type. imagename is saved in \Gin@base macro by graphicx package, but it contains full path. \Picture command is responsible for printing image element and we need only base name here. To strip path out, we can use etoolbox list processing commands:

\RequirePackage{etoolbox}
\Preamble{xhtml}
\DeclareListParser{\getImgFileParser}{/}

\makeatletter
\newcommand\getImgFile[2]{%
  \def\do##1{\def\imgBaseName{##1.#2}\def\imgBase{##1}}
  \def\ImgFullName{#1.#2}
  \getImgFileParser{#1}
}

we declared \getImgFile command, with two parameters, file name and suffix, we save full path in \ImgFullName, we will pass this to the copy command later. \getImgFileParser process each part of path delimited by / and save it with and without suffix to two macros. Since imagename is the last part, it will be saved after processing.

We can use this macro in a following way:

\Configure{graphics*}
   {png}
{\expandafter\getImgFile\expandafter{\Gin@base}{png}
   \Picture[IMG]{\imgBase.png}}

we need to use \expandafter to expand \Gin@base contents.

Now we need to configure image element, with \Configure{IMG}:

\catcode`\:=11
\Configure{IMG}
  {\ht:special{t4ht>\ImgFullName.4og}%
\ht:special{t4ht*>}%
\ht:special{t4ht<\ImgFullName.4og}%
\OOmanifest{<manifest:file-entry
    manifest:full-path="Pictures/\imgBaseName"/>\Hnewline
}%
%
   \ht:special{t4ht=<draw:frame
      draw:name="\imgBaseName"
      text:anchor-type="as-char"  % "paragraph"
%      svg:width="...pt"
%      svg:height="...pt"
      draw:z-index="0"
    >%
      <draw:image\Hnewline
         xlink:href="Pictures/}}
  {\ht:special{t4ht=" \Hnewline
         xlink:type="simple"
        xlink:show="embed"
        xlink:actuate="onLoad"
\ifx\noBoundingBox\UnDefined
   \string svg:width="\the\Gin@req@width"
   svg:height="\the\Gin@req@height"
\fi
        /><!--draw:name="}}
  {" }
  {\ht:special{t4ht=" }}
  {\ht:special{t4ht=--></draw:frame>}}
\catcode`\:=12

this configuration is copied from ooffice.4ht, I only changed file paths utilising \ImgFullName and \imgBaseName. I also added code for image dimensions.

Full contents of mychonfig.cfg with configurations for all supported image formats:

\RequirePackage{etoolbox}
\Preamble{xhtml}
\DeclareListParser{\getImgFileParser}{/}


\makeatletter
\newcommand\getImgFile[2]{%
  \def\do##1{\def\imgBaseName{##1.#2}\def\imgBase{##1}}
  \def\ImgFullName{#1.#2}
  \getImgFileParser{#1}
}
  \Configure{graphics*}  
      {pdf}  
      {\Needs{"convert \csname Gin@base\endcsname.pdf  
                            \csname Gin@base\endcsname.png"}%  
\expandafter\getImgFile\expandafter{\Gin@base}{png}
   \Picture[IMG]{\imgBase.png }}  
\Configure{graphics*}
   {gif}
   {\expandafter\getImgFile\expandafter{\Gin@base}{gif}
\Picture[IMG]{\imgBase.gif }}
\Configure{graphics*}
   {png}
{\expandafter\getImgFile\expandafter{\Gin@base}{png}
   \Picture[IMG]{\imgBase.png}}
\Configure{graphics*}
   {jpg}
   {\expandafter\getImgFile\expandafter{\Gin@base}{jpg}
\Picture[IMG]{\imgBase.jpg}}
\Configure{graphics*}
   {jpeg}
   {\expandafter\getImgFile\expandafter{\Gin@base}{jpeg}
\Picture[IMG]{\imgBase.jpeg }}
\Configure{graphics*}
   {svg}
   {\expandafter\getImgFile\expandafter{\Gin@base}{svg}
\Picture[IMG]{\imgBase.svg }}
\catcode`\:=11
\Configure{IMG}
  {\ht:special{t4ht>\ImgFullName.4og}%
\ht:special{t4ht*>}%
\ht:special{t4ht<\ImgFullName.4og}%
\OOmanifest{<manifest:file-entry
    manifest:full-path="Pictures/\imgBaseName"/>\Hnewline
}%
%
   \ht:special{t4ht=<draw:frame
      draw:name="\imgBaseName"
      text:anchor-type="as-char"  % "paragraph"
%      svg:width="...pt"
%      svg:height="...pt"
      draw:z-index="0"
    >%
      <draw:image\Hnewline
         xlink:href="Pictures/}}
  {\ht:special{t4ht=" \Hnewline
         xlink:type="simple"
        xlink:show="embed"
        xlink:actuate="onLoad"
\ifx\noBoundingBox\UnDefined
   \string svg:width="\the\Gin@req@width"
   svg:height="\the\Gin@req@height"
\fi
        /><!--draw:name="}}
  {" }
  {\ht:special{t4ht=" }}
  {\ht:special{t4ht=--></draw:frame>}}
\catcode`\:=12
\makeatother
\begin{document}
\ConfigureEnv{tabular}
    {\HCode{}}{\HCode{}}{}{}
\ConfigureEnv{figure} 
    {\HCode{}}{\HCode{}}{}{}    
% This one removes the rulers. Taking a look at html4.4ht should make 
% clear what has been changed.
\Configure{float}
   {\ifOption{refcaption}{}{\csname par\endcsname\ShowPar \leavevmode}}
   {\HCode{}}
{\ifvmode \IgnorePar \fi\EndP \HCode{}\csname par\endcsname\ShowPar}
\EndPreamble

Now we need to modify contents of tex4ht.env. Find location of the file with

kpsewhich tex4ht.env 

and copy it to the current directory. On unix systems, change following lines:

.4og mkdir -p              sxw-%%0.dir/Pictures/%%1
.4og rmdir                 sxw-%%0.dir/Pictures/%%1
.4og cp    %%1             sxw-%%0.dir/Pictures/%%1

to

.4og cp    %%1             sxw-%%0.dir/Pictures/

on Windows, some other commands are used, but changes should be similar.

Now we are done with image inclusion, there is just small issue with your example. tex4ht can't find bounding box of the image and it is rendered too small. Use

ebb imagename

command to create bounding box info and in the TeX file change

\usepackage{graphicx}

to

\usepackage[dvipdfm]{graphicx}

after compilation with

mk4ht oolatex test_case_mk4ht myxhtml

the result is following:

enter image description here

4
  • The bug seems to still persist in the current MikTeX distribution. I have my images in a subfolder "img" (which is declare using \graphicspath{ {./img/} } . The images are included using e.g. ´\includegraphics{testimg.png}` Compiling my tex file with htlatex %MANUALNAME% "xhtml,ooffice" "ooffice/! -cmozhtf" "-coo" "--enable-pipes" leads to the following log output System call: copy ./img/testimg.png sxw-testfile.dir\Pictures\./img/testimg.png Syntax error If I put the image in the directory of the tex file, the image is found and everything works as it should. – Mik Aug 4 '16 at 16:20
  • @Mik ahh, could you please try to locate tex4ht.env file (it should be in texmf-dist/tex4ht/base/windows/tex4ht.env, find the line starting .4og copy... and change it to .4og copy %%1 sxw-%%0.dir\Pictures\%%~n1.%%~x1. I am not sure whether it will work – michal.h21 Aug 4 '16 at 17:21
  • No, unfortunately it doesn't work like this. The system output is System call: copy testimg.png sxw-testfile.dir\Pictures\~n1.~x1 which is probably not quite what you wanted to achieve... – Mik Aug 4 '16 at 19:47
  • @Mik that's bad. I don't have access to Windows currently, so I can't fix it, I can take a look next week. – michal.h21 Aug 4 '16 at 20:41

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.