Skip to content

Commit c3e72cf

Browse files
committed
fix(export): correct wkhtmltopdf MathJax sizing with minScale floor
wkhtmltopdf's old headless Qt-4 WebKit mis-measures the surrounding text's ex-height, so MathJax shrinks each equation to its minScale floor (0.5). The previous fix blindly multiplied by a magic scale of 2.5, which combined with that floor over-enlarged math to ~1.25x the surrounding text. Replace the magic 2.5 with a root-cause fix: raise MathJax's SVG minScale floor to 1.0 so math cannot be shrunk below text size, and drop scale back to its default. Scoped to the wkhtmltopdf export path only; on-screen preview and the Qt WebEngine printToPdf path are behaviorally unchanged (they emit the -1 sentinel and fall back to MathJax's default 0.5). - Plumb a new mathJaxMinScale global option exactly like mathJaxScale (MarkdownWebGlobalOptions + MarkdownParas, both generateMarkdownViewer Template copies, and toJavascriptObject()). - mathjax.js: honor window.vxOptions.mathJaxMinScale, defaulting to MathJax's documented 0.5 when absent (sentinel -1). - webviewexporter: set mathJaxMinScale = 1.0 for wkhtmltopdf and -1 otherwise; set mathJaxScale = -1 (removing the 2.5).
1 parent 11ad2cc commit c3e72cf

5 files changed

Lines changed: 17 additions & 3 deletions

File tree

src/core/htmltemplatehelper.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ QString HtmlTemplateHelper::generateMarkdownViewerTemplate(const MarkdownEditorC
211211
opts.m_bodyHeight = p_paras.m_bodyHeight;
212212
opts.m_transformSvgToPngEnabled = p_paras.m_transformSvgToPngEnabled;
213213
opts.m_mathJaxScale = p_paras.m_mathJaxScale;
214+
opts.m_mathJaxMinScale = p_paras.m_mathJaxMinScale;
214215
opts.m_removeCodeToolBarEnabled = p_paras.m_removeCodeToolBarEnabled;
215216
fillGlobalOptions(htmlTemplate, opts);
216217
}

src/core/htmltemplatehelper.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,12 @@ struct MarkdownWebGlobalOptions {
5454
// This is just a hint not mandatory. For now, PlantUML and Graphviz needs this.
5555
bool m_transformSvgToPngEnabled = false;
5656

57-
// wkhtmltopdf will make the MathJax formula too small.
57+
// wkhtmltopdf mis-measures ex-height, shrinking MathJax to its minScale floor.
58+
// m_mathJaxScale: global scale factor (-1 => MathJax default 1).
5859
qreal m_mathJaxScale = -1;
60+
// m_mathJaxMinScale: floor for MathJax's text-matching scale (-1 => MathJax default 0.5).
61+
// Set to 1 for wkhtmltopdf export so math is not shrunk below text size.
62+
qreal m_mathJaxMinScale = -1;
5963

6064
// Whether remove the tool bar of code blocks added by Prism.js.
6165
bool m_removeCodeToolBarEnabled = false;
@@ -83,6 +87,8 @@ class HtmlTemplateHelper {
8387

8488
qreal m_mathJaxScale = -1;
8589

90+
qreal m_mathJaxMinScale = -1;
91+
8692
bool m_removeCodeToolBarEnabled = false;
8793
};
8894

src/core/markdownwebglobaloptions.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ QString MarkdownWebGlobalOptions::toJavascriptObject() const {
3737
QStringLiteral("transformSvgToPngEnabled: %1,\n")
3838
.arg(Utils::boolToString(m_transformSvgToPngEnabled)) +
3939
QStringLiteral("mathJaxScale: %1,\n").arg(m_mathJaxScale) +
40+
QStringLiteral("mathJaxMinScale: %1,\n").arg(m_mathJaxMinScale) +
4041
QStringLiteral("removeCodeToolBarEnabled: %1,\n")
4142
.arg(Utils::boolToString(m_removeCodeToolBarEnabled)) +
4243
QStringLiteral("sectionNumberBaseLevel: %1\n").arg(m_sectionNumberBaseLevel) +

src/data/extra/web/js/mathjax.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ window.MathJax = {
1919
svg: {
2020
// Make SVG self-contained.
2121
fontCache: 'local',
22-
scale: window.vxOptions.mathJaxScale > 0 ? window.vxOptions.mathJaxScale : 1
22+
scale: window.vxOptions.mathJaxScale > 0 ? window.vxOptions.mathJaxScale : 1,
23+
minScale: window.vxOptions.mathJaxMinScale > 0 ? window.vxOptions.mathJaxMinScale : 0.5
2324
}
2425
};
2526

src/export/webviewexporter.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ QString generateMarkdownViewerTemplate(ConfigMgr2 &p_configMgr,
201201
opts.m_bodyHeight = p_paras.m_bodyHeight;
202202
opts.m_transformSvgToPngEnabled = p_paras.m_transformSvgToPngEnabled;
203203
opts.m_mathJaxScale = p_paras.m_mathJaxScale;
204+
opts.m_mathJaxMinScale = p_paras.m_mathJaxMinScale;
204205
opts.m_removeCodeToolBarEnabled = p_paras.m_removeCodeToolBarEnabled;
205206
fillGlobalOptions(htmlTemplate, opts);
206207

@@ -478,7 +479,11 @@ void WebViewExporter::prepare(const ExportOption &p_option) {
478479
paras.m_bodyWidth = pageBodySize.width();
479480
paras.m_bodyHeight = pageBodySize.height();
480481
paras.m_transformSvgToPngEnabled = p_option.m_transformSvgToPngEnabled;
481-
paras.m_mathJaxScale = useWkhtmltopdf ? 2.5 : -1;
482+
// wkhtmltopdf's old WebKit mis-measures the surrounding text's ex-height, so MathJax
483+
// shrinks each equation to its minScale floor (0.5). Raise that floor to 1.0 instead of
484+
// blindly multiplying by 2.5 (which over-enlarged math to 1.25x text).
485+
paras.m_mathJaxScale = -1;
486+
paras.m_mathJaxMinScale = useWkhtmltopdf ? 1.0 : -1;
482487
paras.m_removeCodeToolBarEnabled = p_option.m_removeCodeToolBarEnabled;
483488

484489
m_htmlTemplate = generateMarkdownViewerTemplate(*configMgr, config, paras);

0 commit comments

Comments
 (0)