2

While using the solution to this question make4ht/ODT: resizing of images, I observed that the solution and defaults behaviours worked, but this would break down if the images were placed in a sub folder.

\documentclass{article}
\usepackage{graphicx}
\begin{document}
    \noindent
    %\includegraphics[width=2cm]{example-image-a.jpg}
    \includegraphics[width=2cm]{Lenna.png}
    \includegraphics[width=2cm]{./images/Lenna.png}

    \noindent
    %\includegraphics[width=8cm]{example-image-a.png}
    \includegraphics[width=8cm]{Lenna.png}
    \includegraphics[width=8cm]{./images/Lenna.png}

    will compile with all images of a default size if there is no xbb file

    will compile with properly sized images if Lenna.png \& Lenna.xbb are in the root folder

    will not compile with images if Lenna.png \& Lenna.xbb are in a sub folder

    will not compile with images if Lenna.png is in a sub folder but Lenna.xbb is in the root folder

\end{document}

Relative to the original linked question, I observed the make4ht filter is no longer necessary, but the manual creation of the *.xbb files still are.

Is anything special needed to patch or ensure that the full relative file name (+path) are preserved using make4ht?

Side note: I never got example-image-a.jpg to resize properly, I assume because there was no xbb file, let alone one in the root level of the file.

  • I Will be offline for next two weeks, so it will take some time before I will be able to answer – michal.h21 Jul 27 at 5:34
1

I guess that this may depend on operating system and web browser. Your example works for me in Firefox on Linux. tex4ht doesn't attempt to change the image names in the HTML mode, other than changing the image extension in the case of conversion from EPS to SVG, etc. I would suggest to drop the leading ./ and use just

 \includegraphics{images/Lenna.png}

instead.

Regarding the image size issue, you can try the following config file:

\Preamble{xhtml}
\makeatletter
\def\ifboundingbox#1#2{%
\ifdim\Gin@req@width=\Gin@nat@width\ifx\noBoundingBox\UnDefined#1\else#2\fi\else#1\fi
}
\def\int@pt#1.#2!*?: {#1}
   \Configure{Gin-dim}
     {\ifboundingbox{width="\expandafter\int@pt\the\Gin@req@width!*?: " height="\expandafter\int@pt\the\Gin@req@height!*?: "}{}}
\makeatother
\begin{document}
\EndPreamble

Here is a modified sample:

% https://tex.stackexchange.com/q/501648/2891
\documentclass{article}
\usepackage{graphicx}
\begin{document}
    \noindent
    %\includegraphics[width=2cm]{example-image-a.jpg}
    \includegraphics[width=2cm]{Lenna.png}
    \includegraphics[width=2cm]{./images/Lenna.png}

    \noindent
    %\includegraphics[width=8cm]{example-image-a.png}
    \includegraphics[width=8cm]{Lenna.png}
    \includegraphics[width=8cm]{./images/Lenna.png}

    \noindent
    \includegraphics[]{Lenna.png}
    \includegraphics[]{images/Lenna.png}

\end{document}

In this example, I've put the xbb file to the images subdir

enter image description here

This is the generated HTML code:

<!--l. 5--><p class="noindent" ><img 
src="Lenna.png" alt="PIC"  
width="56" height="56"  /> <img 
src="./images/Lenna.png" alt="PIC"  
width="56" height="56"  />
</p><!--l. 10--><p class="noindent" ><img 
src="Lenna.png" alt="PIC"  
width="227" height="227"  /> <img 
src="./images/Lenna.png" alt="PIC"  
width="227" height="227"  />
</p><!--l. 15--><p class="noindent" ><img 
src="Lenna.png" alt="PIC"  
 /> <img 
src="images/Lenna.png" alt="PIC"  
width="513" height="513"  />

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.