Download MathJax SVG using ImageMagick

113 views
Skip to first unread message

racoon

unread,
Dec 10, 2015, 2:02:03 PM12/10/15
to MathJax Users
Hi

I just wanted to inform about an experience of mine. Maybe others can profit.

I have extracted the SVG group from a div rendered by MathJax and used it in another SVG diagram.

So far I have been downloading those SVG diagrams using PHP and ImageMagick. Basically I send the SVG html code to a file containing the following:

<?php
$svg_data_as_string
= '<?xml version="1.0" encoding="UTF-8" standalone="no"?>'.filter_input(INPUT_POST, 'svghtml');
$title = filter_input(INPUT_POST, 'svgtitle');

$image = new IMagick();  
$image->setBackgroundColor(new ImagickPixel('transparent'));  
$image->readImageBlob($svg_data_as_string);  
$image->setImageFormat('png32');

$filename = $title.'.png';
header('Content-Type: application/png');
header("Content-Disposition: attachment; filename=\"$filename\"");
echo $image;

This worked fine so far. However none of the MathJax was showing up on the so downloaded png file.

The culprit of this was that the MathJax group contained attributes fill and stroke both set to currentColor. Removal of these attributes solved the problem.

Best,
Daniel

racoon

unread,
Dec 27, 2015, 2:34:25 PM12/27/15
to MathJax Users
I realized that removing the fill and stroke attributes is not a good idea. This seems to affect the MathJax blacker (http://mathjax.readthedocs.org/en/latest/options/SVG.html#the-svg-output-processor). Rather one should set the attribute explicit to the desired color, for example fill="red" stroke="red".

Best,
Daniel

Emre Koçyatağı

unread,
Jun 30, 2022, 12:30:25 PM6/30/22
to MathJax Users
Hey Daniel,
I also need to download SVG as a file using MathJax.
I have MathML codes, they are working well on the html But i really have no idea how to get this equation as a file .svg.
If you could me help me i will be appreciated.
Thanks a lot.

27 Aralık 2015 Pazar tarihinde saat 21:34:25 UTC+2 itibarıyla Daniel şunları yazdı:
Reply all
Reply to author
Forward
0 new messages