1

tex4ht mess up code alignment when using basicstyle=\small (with or without font family being given) compare to when not using basicstyle. This only happens in the HTML. The pdf is correct. Here is a MWE

\documentclass[12pt]{article}
\usepackage{listings}

\begin{document}

\begin{lstlisting}[language={},keepspaces=true,basicstyle=\small]
local case_one_gamma_entry := module()
    option object;
    export pole_location := 0;
    export pole_order    := 0;
    export sqrt_r        := 0;
    export alpha_plus    := 0;
    export alpha_minus   := 0; 
    export b             := 0;
end module;
\end{lstlisting}

\begin{lstlisting}[language={},keepspaces=true]
local case_one_gamma_entry := module()
    option object;
    export pole_location := 0;
    export pole_order    := 0;
    export sqrt_r        := 0;
    export alpha_plus    := 0;
    export alpha_minus   := 0; 
    export b             := 0;
end module;
\end{lstlisting}

\end{document}

compiled with

 make4ht -ulm default -a warning foo2.tex "mathjax,htm"

This is the HTML

enter image description here

Compare to the pdf where using smaller font did not change the source code alignment

enter image description here

I like to use smaller font size in the HTML. Is there a way to make tex4ht not change the source code when using smaller font size? I also tried basicstyle=\ttfamily\small but no effect.

TL 2022.

>which tex4ht
/usr/local/texlive/2022/bin/x86_64-linux/tex4ht
>make4ht --version
make4ht version v0.3l

Ticket added to tex4ht

1 Answer 1

2

I think this issue will be caused by the fact that the smaller font size causes the listings text to be styled using CSS, but only the text, not spaces, which remain to be larger. This issue is already fixed in the development version of make4ht, but for now, you can try this configuration file:

\Preamble{xhtml}
\makeatletter
\lst@AddToHook{Init}{%
\ifx\@currsize\small%
\Css{\#listing-\listingN{font-size:small;}}%
\fi%
\normalsize}
\makeatother
\begin{document}
\EndPreamble

It adds a code that is executed at the beginning of listings, and which switches to the normal fonts size, to prevent wrong spacing. But before the switch, it tests if the current font is \small. If it is, it inserts CSS instruction to display the current listing in the smaller font size.

this is the result:

enter image description here

You must log in to answer this question.

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