|
533 | 533 |
|
534 | 534 | function elements.stackbox.output (_, _, _, _) end |
535 | 535 |
|
| 536 | +elements.phantom = pl.class(elements.stackbox) -- inherit from stackbox |
| 537 | +elements.phantom._type = "Phantom" |
| 538 | + |
| 539 | +function elements.phantom:_init (children, special) |
| 540 | + -- MathML core 3.3.7: |
| 541 | + -- "Its layout algorithm is the same as the mrow element". |
| 542 | + -- Also not the MathML states that <mphantom> is sort of legacy, "implemented |
| 543 | + -- for compatibility with full MathML. Authors whose only target is MathML |
| 544 | + -- Core are encouraged to use CSS for styling." |
| 545 | + -- The thing is that we don't have CSS in SILE, so supporting <mphantom> is |
| 546 | + -- a must. |
| 547 | + elements.stackbox._init(self, "H", children) |
| 548 | + self.special = special |
| 549 | +end |
| 550 | + |
| 551 | +function elements.phantom:shape () |
| 552 | + elements.stackbox.shape(self) |
| 553 | + -- From https://latexref.xyz: |
| 554 | + -- "The \vphantom variant produces an invisible box with the same vertical size |
| 555 | + -- as subformula, the same height and depth, but having zero width. |
| 556 | + -- And \hphantom makes a box with the same width as subformula but |
| 557 | + -- with zero height and depth." |
| 558 | + if self.special == "v" then |
| 559 | + self.width = SILE.types.length() |
| 560 | + elseif self.special == "h" then |
| 561 | + self.height = SILE.types.length() |
| 562 | + self.depth = SILE.types.length() |
| 563 | + end |
| 564 | +end |
| 565 | + |
| 566 | +function elements.phantom:output (_, _, _) |
| 567 | + -- Note the trick here: when the tree is rendered, the node's output |
| 568 | + -- function is invoked, then all its children's output functions. |
| 569 | + -- So we just cancel the list of children here, before it's rendered. |
| 570 | + self.children = {} |
| 571 | +end |
| 572 | + |
536 | 573 | elements.subscript = pl.class(elements.mbox) |
537 | 574 | elements.subscript._type = "Subscript" |
538 | 575 |
|
|
0 commit comments