# why does tex4ht not rotate images?

This MWE works ok with lualatex

\documentclass[]{article}
\usepackage{mwe}
\begin{document}

\includegraphics[angle=90]{example-image}

\end{document}


The image is rotated by 90 degrees

By make4ht does not rotate it

make4ht foo.tex


The HTML shows the image as is.

What does one have to do to make tex4ht rotate the image? These images are part of TeXLive 2017.

ls /usr/local/texlive/2017/texmf-dist/tex/latex/mwe/example-image.*
/usr/local/texlive/2017/texmf-dist/tex/latex/mwe/example-image.eps
/usr/local/texlive/2017/texmf-dist/tex/latex/mwe/example-image.jpg
/usr/local/texlive/2017/texmf-dist/tex/latex/mwe/example-image.pdf
/usr/local/texlive/2017/texmf-dist/tex/latex/mwe/example-image.png
/usr/local/texlive/2017/texmf-dist/tex/latex/mwe/example-image.tex


Update

Found the error. Problem fixed.

What I need is to keep the \DeclareGraphicsExtensions{.svg,.png,.eps,.jpg} but remove the \Configure{graphics*}

To make it clear, here is the final .cfg

\Preamble{xhtml}

\DeclareGraphicsExtensions{.svg,.png,.eps,.jpg}

\makeatletter
\Configure{GraphicsAlt}{ALT\ifdefined\Grot@angle\Css{img[src="\PictureFile"]{transform: rotate(-\Grot@angle deg);}}\fi}
\makeatother

\begin{document}

\EndPreamble


And now make4ht -c ./nma.cfg foo.tex finds p1.svg and also rotates it.

\documentclass[]{article}
\usepackage{mwe}
\begin{document}

\includegraphics[width=\textwidth,angle=130]{p1}  %SVG image

\end{document}


Thank to michal.h21 for his help and support.

• you could always just rotate the svg and and then include the rotated image then neither latex nor tex4ht need rotate – David Carlisle Jan 21 '18 at 0:15
• @DavidCarlisle Yes. I do that now for those images I want to rotate. But it will nice to eliminate this manual step and do it in the code. Also, if I later want to rotate it back, I have to manually do it again. – Nasser Jan 21 '18 at 0:32
• you don't need the configurations for \Configure{graphics*} in your config file anymore, SVG support is included in tex4ht. I can get the rotated SVG image with my configuration – michal.h21 Jan 21 '18 at 16:44

tex4ht indeed doesn't support the image rotation, but the support can be added using some hacks. Try the following config file:

\Preamble{xhtml}
\makeatletter
\Configure{GraphicsAlt}{ALT\ifdefined\Grot@angle\Css{img[src="\PictureFile"]{transform: rotate(-\Grot@angle deg);}}\fi}
\makeatother
\begin{document}
\EndPreamble


I used the fact that the GraphicsAlt configuration is called for every image type, so we need to provide it only once. The \Grot@angle macro contains the requested angle. We can provide a CSS declaration for the current picture when it is defined. Your example will produce following CSS code:

img[src="sample0x.png"]{transform: rotate(-90deg);}


It will be rendered in this way (together with two more samples):

As you can see the rotated pictures are cropped, which is not good and it is a reason why I don't want to add this feature to tex4ht at the moment. If anybody knows how to rotate the images correctly using CSS, please let me know.

• Thanks. But this did not work in my main makefile. After looking on into it, I found why. Will add this information to my main question at the bottom as an update to make it more clear now. – Nasser Jan 20 '18 at 23:43