Skip to content

Render KaTeX by default #1720

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/model/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ enum BoolGlobalSetting {
upgradeWelcomeDialogShown(GlobalSettingType.internal, false),

/// An experimental flag to toggle rendering KaTeX content in messages.
renderKatex(GlobalSettingType.experimentalFeatureFlag, false),
renderKatex(GlobalSettingType.experimentalFeatureFlag, true),

/// An experimental flag to enable rendering KaTeX even when some
/// errors are encountered.
Expand Down
4 changes: 2 additions & 2 deletions test/model/content_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ class ContentExample {
static final mathInline = ContentExample.inline(
'inline math',
r"$$ \lambda $$",
expectedText: r'\lambda',
expectedText: r'λ',
'<p><span class="katex">'
'<span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>λ</mi></mrow>'
'<annotation encoding="application/x-tex"> \\lambda </annotation></semantics></math></span>'
Expand All @@ -532,7 +532,7 @@ class ContentExample {
static const mathBlock = ContentExample(
'math block',
"```math\n\\lambda\n```",
expectedText: r'\lambda',
expectedText: r'λ',
'<p><span class="katex-display"><span class="katex">'
'<span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>λ</mi></mrow>'
'<annotation encoding="application/x-tex">\\lambda</annotation></semantics></math></span>'
Expand Down
29 changes: 27 additions & 2 deletions test/widgets/content_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,11 @@ void main() {
group('MathBlock', () {
testContentSmoke(ContentExample.mathBlock);

testWidgets('displays KaTeX source; experimental flag default', (tester) async {
testWidgets('displays KaTeX source; experimental flag disabled', (tester) async {
addTearDown(testBinding.reset);
final globalSettings = testBinding.globalStore.settings;
await globalSettings.setBool(BoolGlobalSetting.renderKatex, false);

await prepareContent(tester, plainContent(ContentExample.mathBlock.html));
tester.widget(find.text(r'\lambda', findRichText: true));
});
Expand Down Expand Up @@ -1102,6 +1106,23 @@ void main() {
});

testWidgets('maintains font-size ratio with surrounding text, when showing TeX source', (tester) async {
const html = '<span class="katex">'
'<span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>λ</mi></mrow>'
'<annotation encoding="application/x-tex"> \\lambda </annotation></semantics></math></span>'
'<span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6944em;"></span><span class="mord mathnormal">λ</span></span></span></span>';
await checkFontSizeRatio(tester,
targetHtml: html,
targetFontSizeFinder: mkTargetFontSizeFinderFromPattern(r'λ'));
}, skip: true // TODO(#46): adapt this test
// (it needs a more complex targetFontSizeFinder;
// see other uses in this file for examples.)
);

testWidgets('maintains font-size ratio with surrounding text, when showing TeX source', (tester) async {
addTearDown(testBinding.reset);
final globalSettings = testBinding.globalStore.settings;
await globalSettings.setBool(BoolGlobalSetting.renderKatex, false);

const html = '<span class="katex">'
'<span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>λ</mi></mrow>'
'<annotation encoding="application/x-tex"> \\lambda </annotation></semantics></math></span>'
Expand All @@ -1111,7 +1132,11 @@ void main() {
targetFontSizeFinder: mkTargetFontSizeFinderFromPattern(r'\lambda'));
});

testWidgets('displays KaTeX source; experimental flag default', (tester) async {
testWidgets('displays KaTeX source; experimental flag disabled', (tester) async {
addTearDown(testBinding.reset);
final globalSettings = testBinding.globalStore.settings;
await globalSettings.setBool(BoolGlobalSetting.renderKatex, false);

await prepareContent(tester, plainContent(ContentExample.mathInline.html));
tester.widget(find.text(r'\lambda', findRichText: true));
});
Expand Down