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

\usepackage[export]{adjustbox}%for frame option

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" > 
<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" /> 
<!--l. 10--><p class="noindent" > <img 
src="A.png" alt="PIC"  


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


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.



You can try this version of adjustbox.4ht:


% make an unique ID for each adjustbox environment


% suppress trying to draw the frame

% 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

% definitions for macros
% we don't save any colors and just use one configuration for all box types.  


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


\def\pttoem#1{\strip@pt\dimexpr#1/\f@size em}
 {\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>}}

The interesting part is this:

\def\pttoem#1{\strip@pt\dimexpr#1/\f@size em}
 {\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.