Add a rect with dimensions of a standard bounding box for MathJax SVG output

79 views
Skip to first unread message

racoon

unread,
Jan 6, 2016, 4:39:12 AM1/6/16
to MathJax Users
MathJax renders SVG output as paths. One effect is that the bounding box from .getBbox() is tightly around the output. For example, the bounding box around a formula that contains only "x" will have less height than around a formula that contains only "X".

This is different to the standard SVG text. Here the bounding box is always the same height independent of the content.

Is there a way to set a SVG rect with the formula that has the same dimensions as the standard box?
(I don't mind that some "taller" formulas will extend beyond this rect.)

I know that the LaTeX command \bbox is supported. But I don't know how to use it to get what I want, since the \bbox's dimensions are relative to the tight SVG MathJax output. But I want a box that has fixed dimensions relative to the text baseline. So adding, for example, a padding did not help.

I can calculate a couple of values from the standard SVG text using .getBbox(). So let's say the full height of the bounding box of a SVG text element is H (to illustrate: this is roughly the height of "Äg") and the height from the baseline to the top is h (to illustrate: this is roughly the height of "Ä").

Here is an illustration of what I have (blue) and the box I want to add to the formula (red):

Any help greatly appreciated!

Davide P. Cervone

unread,
Jan 18, 2016, 7:16:28 AM1/18/16
to mathja...@googlegroups.com
Use {\strut x} to get a box that is the "standard" height and depth.  So \bbox[red]{\strut x} and \bbox[red]{\strut Ag} will both be the same height.  If the standard strut is not the right size for you, then you can define your own:

\def\myStrut{\vphantom{Äg}}

or

\def\myStrut{\Rule{0px}{1em}{.2em}}

for example.

Davide


--
You received this message because you are subscribed to the Google Groups "MathJax Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mathjax-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

racoon

unread,
Jan 20, 2016, 7:16:44 PM1/20/16
to MathJax Users, dp...@union.edu
The "standard" \strut box seems to be a bit off compared to the standard box around SVG TEXT elements. Could it be that the latter is dependent on the browser while the former is set independently?

daniel.r...@gmail.com

unread,
Jan 23, 2016, 5:44:33 PM1/23/16
to MathJax Users, dp...@union.edu
My fault. I actually had an extra space that made the \strut box come off. So it seems actually to do exactly what I described concerning the heights above. Great.

However, I did not realize before that the standard SVG TEXT also adds some more width. Unfortunately, that seems not to be done by \strut, if I see this correctly.
Reply all
Reply to author
Forward
0 new messages