HTML with Mathjax to PDF bind

1,079 views
Skip to first unread message

Chris Ferrall

unread,
May 7, 2019, 10:51:42 AM5/7/19
to MathJax Users
I posted earlier about reducing the size of PDFs when using print to PDF.  No help on that so far.

This is a related post. Maybe it might get some response. I face a conundrum when creating a PDF when using MathJax.

1.  In Chrome or other browsers, "print to PDF".  This works and renders the document fine, but
  • the file is huge (4MB for a 50 page paper) 
  • links to sections, references, equations etc.  in the HTML file do not survive in the PDF
2.  In Acrobat Pro, create PDF from a file (or webpage) .  The problem here is that Mathjax never gets to finish rendering the math.  It varies, but anywhere from 50% to 90% of the TeX is shown unrendered in the generated PDF.    I don't understand how to get Acrobat to wait for the MathJax script to finish.  So I have tried the following:
  • change MathJax configurations
  • remove "async"
  • move the ,mathjax <script >  from the header to the body
  • install mathjax on a server so it is a local script (hoping it will finish faster)
None of these things help.  Is there some to make Acrobat wait inside Javascript (I'm asking the same thing over at adobe ...)?

Again, I understand MathJax is about HTML, but I can't imagine that academics don't need full-function PDFs from the their documents. So I'm surprised there is so little discussion of this.


David Farmer

unread,
May 7, 2019, 11:05:13 AM5/7/19
to MathJax Users

> Again, I understand MathJax is about HTML, but I can't imagine that academics don't need full-function PDFs from the
> their documents. So I'm surprised there is so little discussion of this.

They author in LaTeX, which is designed specifically to produce PDFs.
The syntax for math inside LaTeX is almost identical to what MathJax
expects.

There is no hope approaching the quality of PDF you get from
LaTeX if you go via HTML. (That is a comment on HTML,
not of the output of MathJax.)

Regards,

David

Chris Ferrall

unread,
May 7, 2019, 11:30:01 AM5/7/19
to MathJax Users
I have been writing in plain TeX since 1990, so I'm not ignorant of this, and you are right for just writing a paper I could just TeX it, 

But I find most work now is a combination of documentation, presentation, teaching and eventually submitting. And in this environment TeX or LaTeX alone has limitations, which is why I am here (and you probably are too ...)

If the file could just make Acrobat wait until MathJax was done the PDF would be just fine.  So it is approaching the required quality ... just keep going!  That seems to be a specific issue that I would think someone could help with.

Davide Cervone

unread,
May 8, 2019, 9:55:21 AM5/8/19
to mathja...@googlegroups.com
I don't know how to tell Acrobat to wait, but I do know how to make wkhtmltopdf wait for MathJax to finish.  A command like

wkhtmltopdf [url-for-math=page] --run-script 'MathJax.Hub.Queue(function () {window.status="finished"})' \
            --window-status finished --no-stop-slow-scripts [output-file].pdf

will make wkhtmltopdf wait until MathJax is finished before it creates the pdf file.  It does seem to preserve the links that MathJax creates for `\ref` and `\eqref` calls, so I assume other links will also be preserved.  I don't know how large your files will become.  I assume that embedding the fonts into the pdf is probably the culprit, here.  I don't know how efficient the process is (e.g., is the entire font encoded, or just the characters that are needed in the file).  That might be one place that reductions can be made, but I don' know how to go about it.  Perhaps using Acrobat after the fact could optimize it?  Or one of the on-line pdf optimizers?

Davide



-- 
You received this message because you are subscribed to the Google Groups "MathJax Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mathjax-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mathjax-users/1d4431c8-a65f-4f4f-9bde-a71029d27468%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Chris Ferrall

unread,
May 8, 2019, 2:03:29 PM5/8/19
to MathJax Users

Thanks very much.  This does the trick!   If I can get Acrobat to work it would be more convenient, but at least now there is a solution.

The file size seems to be determined by the MathJax configuration.  In particular "SVG" creates the big files (but nicest looking output).   But "CHTML" produces nice enough output but 1/10th the size.  I thought I had experimented with this before posting the question, but maybe I missed something.
To unsubscribe from this group and stop receiving emails from it, send an email to mathja...@googlegroups.com.

Davide Cervone

unread,
May 8, 2019, 2:26:09 PM5/8/19
to mathja...@googlegroups.com
Glad it worked out for you.  The SVG output uses paths rather than fonts, so that is probably the source of the larger size.

Davide


To unsubscribe from this group and stop receiving emails from it, send an email to mathjax-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mathjax-users/efdc8619-c061-48af-9235-c29a0f13c7c5%40googlegroups.com.
Message has been deleted

clafordv...@gmail.com

unread,
Jun 8, 2020, 1:00:25 PM6/8/20
to MathJax Users
I came here to thank you from a year later! Thank you for saving my day!
To unsubscribe from this group and stop receiving emails from it, send an email to mathja...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages