1

This MWE works in pdf. It puts frame around an image. But in HTML I see no frame produces

\documentclass[12pt]{article}%
\usepackage{graphicx}
\usepackage[export]{adjustbox}%for frame option
\begin{document}
\includegraphics[width=0.5\textwidth,frame=0.1in]{A.png}
\end{document}

Compiled using lualatex foo4.tex gives

Mathematica graphics

But compiled using make4ht foo4.tex gives this. No frame and some scratch line at bottom right corner

Mathematica graphics

Source code produced looks wrong

<!DOCTYPE html> 
<html lang="en-US" xml:lang="en-US" > 
<head><title></title> 
<meta  charset="iso-8859-1" /> 
<meta name="generator" content="TeX4ht (http://www.tug.org/tex4ht/)" /> 
<meta name="viewport" content="width=device-width,initial-scale=1" /> 
<link rel="stylesheet" type="text/css" href="foo4.css" /> 
<meta name="src" content="foo4.tex" /> 
</head><body 
>
<!--l. 10--><p class="noindent" > <img 
src="A.png" alt="PIC"  
 />_
     __
</p>

</body> 
</html>

I know I can use fbox to put a frame around an image and this works in tex4ht:

 \fbox{\includegraphics[width=0.5\textwidth]{A.png}}

but I wanted to use frame instead for other purposes. I could always use fbox in tex4ht mode and use frame in pdf mode. So I have a workaround for this, but was hoping to avoid this complication and use same code for both if possible.

Is there a way to make frame work in tex4ht also?

ps. I could not use the example images that come with latex for the MWE above, since these do not work with tex4ht for some reason. Path issue it seem, so I used my own image. Here is copy of A.png if you need to use it or any other image can be used.

https://www.12000.org/tmp/051119/A.png

1

You can try this version of adjustbox.4ht:

\NewConfigure{AdjustboxValignTop}{1}
\NewConfigure{AdjustboxValignMiddle}{1}
\NewConfigure{AdjustboxValignCenter}{1}
\NewConfigure{AdjustboxValignBottom}{1}
\pend:def\adjbox@valign@t{\a:AdjustboxValignTop}
\pend:def\adjbox@valign@t{\a:AdjustboxValignTop}
\pend:def\adjbox@valign@T{\a:AdjustboxValignTop}
\pend:def\adjbox@valign@M{\a:AdjustboxValignMiddle}
\pend:def\adjbox@valign@m{\a:AdjustboxValignMiddle}
\pend:defI\adjbox@valign@c{\a:AdjustboxValignCenter}
\pend:def\adjbox@valign@b{\a:AdjustboxValignBottom}
\pend:def\adjbox@valign@B{\a:AdjustboxValignBottom}

% make an unique ID for each adjustbox environment
\newcounter{adjustbox@4ht}
\def\update:adjustbox:id{\stepcounter{adjustbox@4ht}\def\AdjustboxId{adjustbox-\arabic{adjustbox@4ht}}}

\NewConfigure{Adjustbox}{2}
\def\:tempa#1#2#3#4{\update:adjustbox:id\a:Adjustbox\o:adjbox@@frame:{#1}{#2}{#3}{#4}\b:Adjustbox}
\HLet\adjbox@@frame\:tempa

% suppress trying to draw the frame
\def\adjbox@boxframe#1#2#3{}

% we should redefine all adjustbox environments, they may produce unvanted artifacts, math mode, etc.
% keys are set, so it should be possible to extract  colors or frame size in theory
% I just haven't found a working solution yet
\renewenvironment{adjustbox}[1]{\update:adjustbox:id\adjbox@setkeys{#1}\a:Adjustbox}{\b:Adjustbox}

% definitions for macros
% we don't save any colors and just use one configuration for all box types.  
\def\@bgcolorbox#1{\update:adjustbox:id\a:Adjustbox\BOXCONTENT\b:Adjustbox}
\def\@foregroundbox#1#2#3{\update:adjustbox:id\leavevmode\a:Adjustbox\BOXCONTENT\b:Adjustbox}
\def\@backgroundbox#1#2#3{\update:adjustbox:id\leavevmode\a:Adjustbox\BOXCONTENT\b:Adjustbox}

\Hinput{adjustbox}

It generates unique ID for each adjust box, so it can be then styled using CSS. The configuration can look like this:

\Preamble{xhtml}

\Configure{halignTR}{}
\Configure{AdjustboxValignTop}{\Css{\#TBL-\TableNo-\HRow-{vertical-align:top;}}}
\Configure{AdjustboxValignMiddle}{\Css{\#TBL-\TableNo-\HRow-{vertical-align:middle;}}}
\Configure{AdjustboxValignCenter}{\Css{\#TBL-\TableNo-\HRow-{vertical-align:middle;}}}
\Configure{AdjustboxValignBottom}{\Css{\#TBL-\TableNo-\HRow-{vertical-align:bottom;}}}
\makeatletter
\def\pttoem#1{\strip@pt\dimexpr#1/\f@size em}
\Configure{Adjustbox}
 {\IgnorePar\EndP\IgnorePar\HCode{<div class="adjustbox" id="\AdjustboxId">}}
 {\Css{\#\AdjustboxId{border: \pttoem{\fboxrule} solid black;padding: \pttoem{\fboxsep};}}\ifvmode\IgnorePar\fi\EndP\HCode{</div>}}
\makeatother
\begin{document}
\EndPreamble

The interesting part is this:

\def\pttoem#1{\strip@pt\dimexpr#1/\f@size em}
\Configure{Adjustbox}
 {\IgnorePar\EndP\IgnorePar\HCode{<div class="adjustbox" id="\AdjustboxId">}}
 {\Css{\#\AdjustboxId{border: \pttoem{\fboxrule} solid black;padding: \pttoem{\fboxsep};}}\ifvmode\IgnorePar\fi\EndP\HCode{</div>}}

It defines command \pttoem that converts TeX dimensions to em, because it is better to use relative units in CSS. <div class="adjustbox"> with unique ID from \AdjusboxID is constructed for each adjustbox. CSS with border size and padding is created for each box.

This is the result:

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.