maranget / hevea

Hevea is a fast latex to html translator
http://hevea.inria.fr
Other
97 stars 12 forks source link

Remove `height` and `width` from class `horizontal-rule` #48

Closed cspiel closed 3 years ago

cspiel commented 3 years ago

Alternative title: "The Optimizer Strikes Back!"

The current definition of CSS class horizontal-rule sets both height and width. Macro \@hr uses class horizontal-rule, but overrides height and width with a style attribute to control the shape of the rule as requested by the macros' actual arguments.

If the optimizer decides to hoist this style and convert it to a CSS class the precedence rules change: Classes are applied in their order of definition. The optimizer sorts all classes into alphabetical order and uses the prefix c for its own classes. That way the style hoisted into class c### always ends up before class horizontal-rule and the style's height and width thus are shadowed.

The last item of the following example generates different horizontal rules depending whether translated with or without -O.

\documentclass{article}
\usepackage{hevea}
\begin{document}
  \begin{itemize}
  \item 10em/0.0625em: \@hr{10em}{0.0625em}
  \item 1em/1em: \@hr{1em}{1em}
  \item 0.0625em/3em: \@hr{0.0625em}{3em}
  \item 50\% linewidth/2pt: \@hr{0.5\linewidth}{2pt}
  \item $2\times$ 5em/5pt: \@hr{5em}{5pt}. \@hr{5em}{5pt}.
  \end{itemize}
\end{document}

This P/R suggests to drop both height and width from class horizontal-rule to recover consistent behavior.

maranget commented 3 years ago

Unfortunately, this PR introduces a regression, consider the following latex code:

\documentclass{article}
\usepackage[utf8]{inputenc}
\begin{document}

\begin{center}
\begin{tabular}{c}
\hline
Coucou coucou coucou coucou\\
Coucou coucou\\
\hline
\end{tabular}
\end{center}
\end{document}

Previous rendering is like this (\hline's are apparent): PREV While the new rendering is like that (\hline's have disappeared): NEW

cspiel commented 3 years ago

@maranget - THX for checking!

It looks like we always have had two distinct cases of horizontal rules. A standalone case (e.g. \hline) and another, where a style attribute is active alongside with the class (\@hr). The last patch honors this distinction.