LaTeXML
LaTeXML copied to clipboard
restore viewBox in pgf pictures
Fix #2376 for PGF/TikZ.
The commit that removed @viewBox said 'AVOID scaling, in particular viewBox so that text size matches containing document'. I can't quite tell what issue was being addressed: if @viewBox and @width, @height agree, no scaling happens. Rather, having the correct @viewBox enables CSS to change width and height, and that can only happen intentionally. So I am guessing this PR is fine.
No, sadly just adding the viewbox line alone doesn't work, even though you'd reasonably think that it should. When there are graphics and text combined into the figure, somehow, somewhere, inconsistencies between the dimensions & ems used in the TeX processing clashes with the dimensions & ems used by the browser, and stuff ends up looking sometimes quite horrible. I'll have to go dig through my sample set to find an example.
Forcing px and omitting the viewbox was the only way I got things to look decent, although I'll freely admit that I doubt this is the Correct solution. Maybe rem is part of it?
sadly just adding the
viewboxline alone doesn't work, even though you'd reasonably think that it should. When there are graphics and text combined into the figure, somehow, somewhere, inconsistencies between the dimensions & ems used in the TeX processing clashes with the dimensions & ems used by the browser, and stuff ends up looking sometimes quite horrible. I'll have to go dig through my sample set to find an example
Thanks, the example would be really helpful! I really struggle to see how adding the viewbox can affect the output (or rather, how omitting it helps in any way). As far as I understand, the viewbox 0 0 width height is essentially the 'default' value of the SVG anyway, so it is a no-op. Provided CSS is not manipulating the images further.
(I have enabled the viewbox in BookML a few weeks ago with no problems, but it's not too significant... most of my few users are still using dvisvgm for TikZ so they won't notice the difference.)
Forcing px and omitting the viewbox was the only way I got things to look decent, although I'll freely admit that I doubt this is the Correct solution. Maybe
remis part of it?
PS: I have done some tweaks in BookML about this by saving the 8/9/10/11/12pt class option, the dpi (default 100 in LaTeXML), and readjusting the SVGs in CSS (requires viewbox). The results are reasonable as long as the fonts are similar enough. I specifically tested with Latin Modern in both PDF and HTML, and got a perfect match, of course.
I also need to learn more about viewBox and the CSS interplay. This PR is likely to have very significant impact over arXiv, where almost 10% of current user reports have to deal with SVG not fitting its precomputed size (although I'm sure there are multiple separate causes in different articles and packages).
Having more opportunity for CSS customization would be a net good, if we could pull it off...
Looks good! Thanks!!