maranget / hevea

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

SVG-based macro \rule #50

Closed cspiel closed 3 years ago

cspiel commented 3 years ago

Implement macro \rule with SVG. Its properties nicely match the LaTeX original as it is rendered inline and zero-width width or height lead to an invisible "strut".

Try it for example with

\documentclass{article}

\usepackage{hevea}

\newenvironment{markerbar}{\begingroup$|$}{$|$\endgroup}

\begin{document}
\section{Rules}

\texttt{\textbackslash rule}; size is indicated as width/height and
optionally followed by a signed offset.

\begin{itemize}
\item 10em/0.0625em: \rule{10em}{0.0625em}
\item 1em/1em: \rule{1em}{1em}
\item 0.0625em/3em: \rule{0.0625em}{3em}
\item 50\% linewidth/2pt: \rule{0.5\linewidth}{2pt}
\end{itemize}

\noindent Struts (zero width or zero height) -- extents indicated with marker bars

\begin{itemize}
  \item 10em/0pt: \begin{markerbar}\rule{10em}{0pt}\end{markerbar}
  \item 0pt/3em: \begin{markerbar}\rule{0pt}{3em}\end{markerbar}
\end{itemize}

\noindent Raised or lowered rules.

\begin{itemize}
\item 10em/0.0625em$+12$pt: \rule[12pt]{10em}{0.0625em}
\item 1em/1em$+6$pt: \rule[6pt]{1em}{1em}
\item 0.0625em/3em$-12$pt: \rule[-12pt]{0.0625em}{3em}
\end{itemize}

\ifhevea
  \noindent Comparison with \texttt{\textbackslash\char64 hr} (HeVeA only).

  \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}
\fi
\end{document}

The implementation is not backward compatible. It breaks the previously valid call \rule{}{} (which is invalid LaTeX code, though). Replacing those calls with a suitably tailored \@hr restores the old behavior and is fully backward compatible.

If we ever should merge this P/R the OCaml compiler guys may want to apply

--- a/manual/manual/allfiles.etex
+++ b/manual/manual/allfiles.etex
@@ -24,7 +24,7 @@

 \begin{htmlonly}
 \begin{quote}
-\rule{}{}
+\@hr{\linewidth}{0.75pt}
 This manual is also available in
 \ahref{https://ocaml.org/releases/\ocamlversion/ocaml-\ocamlversion-refman.pdf}{PDF},
 \ahref{https://ocaml.org/releases/\ocamlversion/ocaml-\ocamlversion-refman.txt}{plain text},
@@ -32,7 +32,7 @@ as a
 \ahref{https://ocaml.org/releases/\ocamlversion/ocaml-\ocamlversion-refman-html.tar.gz}{bundle of HTML files},
 and as a
 \ahref{https://ocaml.org/releases/\ocamlversion/ocaml-\ocamlversion-refman.info.tar.gz}{bundle of Emacs Info files}.
-\rule{}{}
+\@hr{\linewidth}{0.75pt}
 \end{quote}
 \end{htmlonly}
cspiel commented 3 years ago

@maranget: chapter 4.2 will be wrong when this P/R gets merged. :roll_eyes:

maranget commented 3 years ago

Hi, I'll keep 4.2, adding that the \rule command now works as in latex. Do you have an idea of a command that hevea does not implement completely and that you would refrain from implementing?

cspiel commented 3 years ago

@maranget: As of today, I'm not aware of any such LaTeX command, but my "active subset" of LaTeX consistes mainly of macros needed for writing program documentation.