2

I need to scale some math using tex4ht. I assume this will only work when compiling latex to HTML when telling tex4ht to use svg for math equations and not mathjax.

ps. (if math can scale using mathjax mode, then that would be even better, but when I tried the MWE below with make4ht and using mathjax mode, it also did not scale, I think this is because mathjax does not support these scaling commands).

But I am not able to get it to work. I tried \scalebox and \resizebox and \adjustbox. None of them worked. But they all work in PDF with lualatex.

Am I doing something wrong, or is this just not supported in tex4ht? Here is MWE and the command and the .cfg I used

\documentclass[12pt]{article}     
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{adjustbox}

\newcommand*{\mycell}{%
\begin{minipage}{\linewidth}
\begin{align*}y''+(y')^{2}+y' +  y''+(y')^{2}+y'+y''+(y')^{2}+y' +y'' + (y')^{2}+y' + y''+(y')^{2}+y' +  y''+(y')^{2}+y'+y''+(y')^{2}+y' +y''+(y')^{2}+y' &= 0 
\end{align*}
\end{minipage}
}

\begin{document}   

\mycell 

\scalebox{0.3}{\mycell}

\resizebox{2in}{!}{\mycell}

\adjustbox{width=3in}{\mycell} 

\end{document}

Now lualatex foo2.tex gives

enter image description here

So it worked. Now compiled to HTML using

make4ht -ulm  default -a debug -c svg.cfg foo2.tex "htm"

Where svg.cfg is small version of my old svg.cfg file I used to used before switching to mathjax for math, which I am not sure now it needs any changes or not.

\Preamble{ext=htm,charset="utf-8",p-width,pic-align}
\DeclareGraphicsExtensions{.svg,.png,.jpg}
\Configure{Picture}{.svg}

\Configure{VERSION}{}
\Configure{DOCTYPE}{\HCode{<!DOCTYPE html>\Hnewline}}
\Configure{HTML}{\HCode{<html>\Hnewline}}{\HCode{\Hnewline</html>}}
\Configure{@HEAD}{}
\Configure{@HEAD}{\HCode{<meta charset="utf-8"/>\Hnewline}}

\DeclareGraphicsExtensions{.svg,.png}

%need this below for MATH.
\Configure{Picture}{.svg}

\begin{document}
%add any custome \Css or HTML commands here as needed.

%These to tell tex4ht to make inline math images also
\Configure{$}{\PicMath}{\EndPicMath}{}
\Configure{PicMath}{}{}{}{class="math";align="absmiddle"}

The generated HTML shows the math as svg images, but all the math is same size. No scaling was done as when compiled to pdf.

Question is: Does tex4ht supports scaling of math equations, even if one is using images for math and not mathjax?

TL 2021 on Linux.

1 Answer 1

2

You need to change font size in your math to make the text smaller. Any box resizing doesn't work, because only math contents are transformed to pictures, not the transformations that take place outside of math. Try this:

\documentclass[12pt]{article}     
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{adjustbox}

\newcommand\smallermath[1]{\begingroup\footnotesize #1\endgroup}
\newcommand*{\mycell}{%
\begin{minipage}{\linewidth}
\begin{align*}y''+(y')^{2}+y' +  y''+(y')^{2}+y'+y''+(y')^{2}+y' +y'' + (y')^{2}+y' + y''+(y')^{2}+y' +  y''+(y')^{2}+y'+y''+(y')^{2}+y' +y''+(y')^{2}+y' &= 0 
\end{align*}
\end{minipage}
}

\begin{document}   

\mycell 

\scalebox{0.3}{\mycell}

\resizebox{2in}{!}{\mycell}

\adjustbox{width=3in}{\mycell} 

\smallermath{\mycell}

\end{document}

I've added a new command, \smallermath, that selects the \footnotesize font size. This is the result:

enter image description here

For MathJax mode, you need to resize font size using CSS. Try this .cfg file:

\Preamble{xhtml,mathjax}
\renewcommand\smallermath[1]{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="smallermath">}#1\HCode{</div>}}
\Css{.smallermath{font-size:0.8em;}}
\begin{document}
\EndPreamble

It redefines \smaallermath to produce <div class="smallermath"> and then defines the font size using CSS.

Result:

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .