Fix a number of line-breaking problems in tables and elsewhere. (mathjax/MathJax#3416) #1338
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR addresses a number of problems with line breaking, particular in tables. Issue mathjax/MathJax#3416 pointed out a bad bounding box for SVG output, but this also affects CHTML output. For example:
produces
in SVG output and
in CHTML. The vertical positioning is not correct in either, due to improperly handling the change in height/depth of the cells with broken lines.
Worse, if a cell isn't broken, then the width can be set to 0, as in
which produces
for CHTML and
in SVG.
When
intentshift
is specified (as it is by default in the alignment environments), that width may not be taken into account in CHTML (here I'm breaking the one manually):generates
though it is OK in SVG output.
Finally, when a width is specified via
\hsize
, tables don't break to the proper width (they use the full container width):This PR fixes all these issues, resolving mathjax/MathJax#3416 (and other issues not mentioned there).
Make sure line breaking is enabled when testing this PR.
The change in
chtml/Wrappers/mrow.ts
fixes the issue with theindentshift
in CHTML (the relative positioning doesn't change the box's width, as is needed to get the width correct).The
chtml/Wrappers/mtr.ts
change fixes the height of a table with line breaks in CHTML.The change in
common/Wrapper.ts
andcommon/Wrappers/mpadded.ts
are the changes needed to get the\hsize
to be respected. The\vbox
and related boxes are implemented throughmpadded
elements, and in order to allow tables to know the width they have to work with, thecontainerWidth
getter now looks through the parents and either uses the width from the metrics, or if there is an interveningmpadded
with an absolutewidth
attribute anddata-overflow
set tolinebreak
(which will only happen for boxes with\hsize
specified), the specified width is used.The changes to
common/Wrappers/mrow.ts
allow the row'sbbox.w
to be adjusted if the shifting of lines makes the width wider than when the lines aren't shifted.The changes to
common/Wrappers/mtable.ts
are the biggest modifications. It turns out that the row heights and depths weren't being adjusted properly for changes when cells have line breaks, but also therowalign
values weren't being properly handled, either.The
extendHD()
function that was supposed to adjust the height and depth of rows according to the alignments was not correct, and has been removed in favor of a new approach, which occurs now within theupdateHDW()
method. TheupdateHDW()
function used to computeH
andD
as though the row always had baseline alignment, but now it uses a newadjustHD
array of functions to properly adjust theH
andD
values according to the row alignment attributes. We no longer need theM
value.The new
updateHDW()
function (at the bottom of the file) is now used in thebreakColumn()
function to get the correct alignments (the old version didn't take the alignment attributes into account), and now includes the scaling factor, likeupdateHWD()
does. BothbreakColumn()
andgetTableData()
now update the rowbbox
height and depth to match the computed values.