2

i'm trying to convert a Latex document into an ebook using tex4ht. The document contains many tables, which are way too large and complex for an ebook. After some research i found the "pic-tabular" option, which looks promising, except graphics aren't displayed in the tabel. Is there a way to include graphics when using the pic-tabular option?

Latex file:

\documentclass{book}
\begin{document}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{units}


\usepackage{graphicx}
\usepackage{booktabs}


\begin{table}[h]
\centering
\caption{caption}
\begin{tabular}{|l|l|l|}
\hline
text & \includegraphics[width=\linewidth]{picture} & text \\
\hline
\end{tabular}
\end{table}

\end{document}

config.cfg:

\Preamble{xhtml,pic-tabular}
\Configure{graphics*}
    {jpg}
    {%  
       \Picture[pict]{\csname Gin@base\endcsname .jpg
          \space width="\the\dimexpr \expandafter\csname
Gin@req@width\endcsname * 1.5"
}%  
     }
\Configure{graphics*}
    {png}
    {%  
       \Picture[pict]{\csname Gin@base\endcsname .png
          \space width="\expandafter\the\csname Gin@req@width\endcsname"
}%  
     }

\Configure{graphics*}  
     {pdf}  
     {\Needs{"convert '\csname Gin@base\endcsname.pdf'  
                           '\csname Gin@base\endcsname.png'"}%  
      \Picture[pict]{\csname Gin@base\endcsname.png}%  
      \special{t4ht+@File: \csname Gin@base\endcsname.png}
     }  


\begin{document}
\CssFile[custom.css] 
/* css.sty */
\EndCssFile
\Configure{CoverMimeType}{image/jpg}
\EndPreamble

custom.css

div.figure img {
text-align:center; 
 }

body {
font-family: "Georgia", Times, serif; 
font-size: 1em; 
line-height: 1.35em; 
}

body
{
font-family: "Georgia", serif; 
font-size: 1em; 
line-height: 1.35em;
hyphens: auto; 
text-align: left;
}

h2.titleHead
{
line-height: 1.5em;
}

h1,
h2,
h3,
h4
{
text-align: left;
}

table
{
width: 100%
margin-top: 1em;
margin-bottom: 1em;
/*font-family: "Arial Narrow";  use a narrow font, if space is an issue*/
}

div.caption
{
margin-bottom: 1em;
font-style: italic;
}
1

The issue is that the pictures need to be processed by DVI processing command, like Dvipng or Dvisvgm. This means that the images must be inserted in the way they understand, the tex4ht configurations cannot be used in this case. It also means that all images must be converted to the EPS format (I also tried TIFF, but it doesn't seem to work correctly).

Because tex4ht redefines \includegraphics in the way it cannot be used inside the pictures, my solution is to save the original \includegraphics definition and use it in the \Picture* command. Here is the full configuration:

\let\origincludegraphics\includegraphics
\Preamble{xhtml,pic-tabular}
\Configure{graphics*}
    {jpg}
    {%  
       \Picture[pict]{\csname Gin@base\endcsname .jpg
          \space width="\the\dimexpr \expandafter\csname
Gin@req@width\endcsname * 1.5"
}%  
      \special{t4ht+@File: \csname Gin@base\endcsname.jpg}
     }
\Configure{graphics*}
    {png}
    {%  
       \Picture[pict]{\csname Gin@base\endcsname .png
          \space width="\expandafter\the\csname Gin@req@width\endcsname"
}%  
      \special{t4ht+@File: \csname Gin@base\endcsname.png}
     }

\Configure{graphics*}  
     {pdf}  
     {\Needs{"convert '\csname Gin@base\endcsname.pdf'  
                           '\csname Gin@base\endcsname.png'"}%  
      \Picture[pict]{\csname Gin@base\endcsname.png}%  
      \special{t4ht+@File: \csname Gin@base\endcsname.png}
     }  

\Configure{Picture*}{\let\includegraphics\origincludegraphics}{}
\Configure{Picture+}{\let\includegraphics\origincludegraphics}{}
\begin{document}
\CssFile[custom.css] 
/* css.sty */
\EndCssFile
\Configure{CoverMimeType}{image/jpg}
\EndPreamble

The important lines are these:

\let\origincludegraphics\includegraphics
...
\Configure{Picture*}{\let\includegraphics\origincludegraphics}{}
\Configure{Picture+}{\let\includegraphics\origincludegraphics}{}

It saves the \includegraphics as \origincludegraphics and then redefines tex4ht version of \includegraphics back to the original version inside the pictures.

I've also updated your configuration for pictures to use the \special{t4ht+@File: \csname Gin@base\endcsname.ext}, because all files which should be packaged in the Epub needs to be registered in this way. The HTML and CSS files works out of the box, but picture configurations need to register explicitly. In fact, tex4ht include similar configuration already, so your \Configure{graphics*} aren't really necessary.

This is the result:

enter image description here

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.