Skip to content

Commit 9b5fc6f

Browse files
authored
Merge pull request #12288 from benkeks/fix-katex-crossref-previews
Fix KaTeX rendering in crossref previews
2 parents c1c4c6f + 4d47af1 commit 9b5fc6f

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

news/changelog-1.8.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@ All changes included in 1.8:
22

33
## Formats
44

5+
### `html`
6+
7+
- ([#12259](https://github.com/quarto-dev/quarto-cli/issues/12259)): Fix conflict between `html-math-method: katex` and crossref popups (author: @benkeks).
8+
59
### `revealjs`
610

711
- ([#12598](https://github.com/quarto-dev/quarto-cli/pull/12598)): Ensure `.fragment` on an image with caption applies to whole figure.
812

913
### `docx`
1014

11-
- ([#8392](https://github.com/quarto-dev/quarto-cli/issues/8392)): Fix `docx` generation issues in tables
15+
- ([#8392](https://github.com/quarto-dev/quarto-cli/issues/8392)): Fix `docx` generation issues in tables
1216

1317
## Projects
1418

src/resources/formats/html/pandoc/template.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
var macros = [];
3232
for (var i = 0; i < mathElements.length; i++) {
3333
var texText = mathElements[i].firstChild;
34-
if (mathElements[i].tagName == "SPAN") {
34+
if (mathElements[i].tagName == "SPAN" && texText && texText.data) {
3535
window.katex.render(texText.data, mathElements[i], {
3636
displayMode: mathElements[i].classList.contains('display'),
3737
throwOnError: false,
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
title: "Reproducible Quarto Document"
3+
format: html
4+
html-math-method: katex
5+
---
6+
7+
:::{#thm-with-math}
8+
### Theorem with math
9+
10+
Text with math $\mathcal P (\mathbb N) ≠ \varnothing$.
11+
:::
12+
13+
:::{#thm-without-math}
14+
### Theorem without math
15+
16+
Just text!
17+
:::
18+
19+
Reference to @thm-with-math. (Popup does not render correctly)
20+
21+
Reference to @thm-without-math. (Popup does render.)

tests/integration/playwright/tests/html-math-katex.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,15 @@ test.describe('KaTeX math rendering in Jupyter engine document', () => {
1515
});
1616
}
1717
});
18+
19+
20+
test('KaTeX does not prevent crossref pop to be rendered', async ({ page }) => {
21+
await page.goto('html/math/katex/crossref-popup.html');
22+
const Thm1Ref = page.getByRole('link', { name: 'Theorem 1' });
23+
await expect(Thm1Ref).toBeVisible();
24+
await Thm1Ref.hover();
25+
// hover box should be visible
26+
await expect(page.getByRole('tooltip', { name: 'Theorem 1 (Theorem with math' })).toBeVisible();
27+
// Katex Math should be rendered in the hover box
28+
await expect(page.getByRole('tooltip', { name: 'Theorem 1 (Theorem with math' })).toContainText('∅');
29+
})

0 commit comments

Comments
 (0)