bdtc / lwarp

The LaTeX lwarp package — Convert LaTeX to HTML.
https://ctan.org/pkg/lwarp
31 stars 0 forks source link

Some unicode characters in math are not passed through #21

Closed alexrwatson closed 6 months ago

alexrwatson commented 6 months ago

Consider this example, which uses the comparatively obscure Unicode character ⚠ (U+26A0 : WARNING SIGN)

\documentclass{article}

\usepackage{fontspec}
\setmainfont{Deja Vu Sans}

\usepackage[mathjax]{lwarp}

\begin{document}

$a ⚠ b$

\end{document}

The character is contained in Deja Vu Sans, and when compiled by lualatex, the math expression renders correctly. (I don't think it is contained in the default math font, so some kind of fallback magic must be happening here, but I suppose that's not the point.)

When compiled by lwarpmk, it says

Missing character: There is no ⚠ (U+26A0) in font [lmmono8-regular]:!

and the character is replaced in the HTML output by � (U+FFFD : REPLACEMENT CHARACTER).

Since (as I understand it) the fallback mechanism in lualatex is not very advanced, it makes sense that when lwarp is rendering math and producing images, this might fail, but when the mathjax option is used, it would make more sense to pass this through since mathjax is perfectly capable of rendering it.

Incidentally, the problem seems not to occur outside math mode, at least not with this character.

A workaround on the user side is to write, e.g., \unicode{x26A0} instead of the literal character.

bdtc commented 6 months ago

Add:

\setmonofont{Deja Vu Sans Mono}

The MathJax (and HTML) is printed in mono space fixed-width to help preserve white space. If no mono space font is selected, the default Latin Modern is used, which may not contain the same characters.

I shall add notes to the documentation to this effect. And maybe even a warning if the sans or serif font is set but the monospace font is still Latin Modern.

alexrwatson commented 6 months ago

Very nice. Thanks! That makes sense, but is a bit surprising, so a warning would probably help a lot.

bdtc commented 6 months ago

v0.916 now includes a note in the documentation regarding this issue, along with some troubleshooting index entries.

I did not include the package warning because of false positives, since in most cases this is not an issue. At this point, if the problem occurs, a quick check in the troubleshooting index will refer to the solution.