pythonpdfwkhtmltopdfmathjaxpdfkit

Converting MathJax into pdf with wkhtmltopdf yields too small maths


By using pdfkit-pythonbased on wkhtmltopdf, I have managed to convert MathJaxinto pdf. wkhtmltopdf configuration options are the following:

options = {
    'quiet': '',
    'javascript-delay' : '5000',
    'page-size': 'A4',
    'margin-top': '0.75in',
    'margin-right': '0.75in',
    'margin-bottom': '0.75in',
    'margin-left': '0.75in',
    'disable-smart-shrinking': '',
    'dpi': '400',
}

This allows to obtain the markdown text that is large as expected, however maths do not scale accordingly.

Here a snapshot of the pdf obtained :

mathJax to pdf yield tiny maths

where maths appears definitely too small.

And here how it is rendered on the browser:

enter image description here

Any idea on how to tackle the problem, in other words obtain maths scaling with the markdown text in the pdf output, will be greatly appreciated.

Here below the MathJax config:

<script type="text/x-mathjax-config">
MathJax.Hub.Config({
    TeX: {extensions: ["mhchem.js"]},
    tex2jax: {
    inlineMath: [['$','$'], ['\\(','\\)']],
    displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
    processEscapes: true
    }
});
</script>

<script type="text/javascript" async
    src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML">
</script>

Solution

  • Found a solution, by adding the following to MathJaxconfiguration:

    MathJax.Hub.Config({
        CommonHTML: {
            minScaleAdjust: 100,
        }
    });
    

    thus increasing to 100% while default value is only 50 %. Reference is here.