Skip to content

Commit 61721ef

Browse files
committed
Fix problems with SVG magnification of expressions with tags, and with CHTML tags that were getting duplicated and misplaced in the magnification.
1 parent 2419bfc commit 61721ef

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

ts/a11y/explorer/Region.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,13 @@ export class HoverRegion extends AbstractRegion<HTMLElement> {
702702
'mjx-container[data-mjx-clone-container]': {
703703
padding: '2px ! important',
704704
},
705+
'mjx-math > mjx-mlabeledtr': {
706+
display: 'inline-block',
707+
'margin-right': '.5em ! important',
708+
},
709+
'mjx-math > mjx-mtd': {
710+
float: 'right',
711+
}
705712
});
706713

707714
/**
@@ -801,6 +808,7 @@ export class HoverRegion extends AbstractRegion<HTMLElement> {
801808
}
802809
mjx = container.cloneNode(false).appendChild(mjx).parentElement;
803810
mjx.style.margin = '0';
811+
mjx.style.minWidth = '';
804812
}
805813
mjx.setAttribute('data-mjx-clone-container', 'true');
806814
return mjx;
@@ -818,7 +826,10 @@ export class HoverRegion extends AbstractRegion<HTMLElement> {
818826
) {
819827
for (const child of enclosed) {
820828
if (child !== node) {
821-
mjx.appendChild(child.cloneNode(true));
829+
const id = child.getAttribute('data-semantic-id');
830+
if (!id || !mjx.querySelector(`[data-semantic-id="${id}"]`)) {
831+
mjx.appendChild(child.cloneNode(true));
832+
}
822833
}
823834
}
824835
}
@@ -856,9 +867,23 @@ export class HoverRegion extends AbstractRegion<HTMLElement> {
856867
x = X;
857868
y = Y + bbox.y;
858869
}
870+
//
871+
// Handle top-level expression with a tag
872+
//
873+
const g = container.querySelector('g');
874+
if (container.getAttribute('width') === 'full' && g.firstChild.lastChild === node) {
875+
mjx.innerHTML = '';
876+
mjx.appendChild(container.cloneNode(true).firstChild);
877+
mjx.querySelector('.mjx-selected').setAttribute('data-mjx-clone', 'true');
878+
mjx.querySelector('[data-sre-highlighter-added]')?.remove();
879+
return;
880+
}
881+
//
882+
// All other expressions
883+
//
859884
(mjx.firstChild as HTMLElement).setAttribute('transform', 'scale(1, -1)');
860-
const W = parseFloat(mjx.getAttribute('viewBox').split(/ /)[2]);
861-
const w = parseFloat(mjx.getAttribute('width'));
885+
const W = parseFloat((mjx.getAttribute('viewBox') || mjx.getAttribute('data-mjx-viewBox')).split(/ /)[2]);
886+
const w = parseFloat(mjx.style.minWidth || mjx.getAttribute('width'));
862887
mjx.setAttribute('viewBox', [x, -(y + height), width, height].join(' '));
863888
mjx.removeAttribute('style');
864889
mjx.setAttribute('width', (w / W) * width + 'ex');

ts/output/svg.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ export class SVG<N, T, D> extends CommonOutputJax<
310310
const adaptor = this.adaptor;
311311
adaptor.setStyle(svg, 'min-width', adaptor.getStyle(svg, 'width'));
312312
adaptor.setAttribute(svg, 'width', pwidth);
313+
adaptor.setAttribute(svg, 'data-mjx-viewBox', adaptor.getAttribute(svg, 'viewBox'));
313314
adaptor.removeAttribute(svg, 'viewBox');
314315
const scale = this.fixed(
315316
wrapper.metrics.ex / (this.font.params.x_height * 1000),

0 commit comments

Comments
 (0)