latex to pdf or html to pdf or ??

598 views
Skip to first unread message

aRbEr

unread,
Mar 1, 2012, 5:18:41 PM3/1/12
to mathja...@googlegroups.com
Hi there,

I am working in the on a project where users (students) can view an exam questions on the browser online, however if they wish they should be given the option to print the whole exam.
At the moment all questions are stored in a mysql db (they have latex content). My question is what would be easier to follow:

a. Find and use the right tools to create a PDF file on the server ?!

or

b. Open a new window where all questions would be listed and rendered with mathjax and then calling "Print" ( I feel like this one might take longer to render depending on the amount of questions and latex included in them). I also found something close to what I am trying to achieve, however it was a little bit confusing (or may be I wasn't able to understand it): http://groups.google.com/group/mathjax-users/browse_thread/thread/6bafb82493c48dc7/dd4af2f148254689?lnk=gst&q=pdf#dd4af2f148254689


any feedback would be appreciated,
Arber

Thomas Leathrum

unread,
Mar 1, 2012, 7:49:11 PM3/1/12
to mathja...@googlegroups.com
MathJax printing is still somewhat sensitive to the browser from which you issue the print job.  Some browsers just do a better job of laying out the math expressions for the printable page.  (For that matter, some browsers just do a better job of making any page print in a way that actually looks like the browser window contents.  Don't get me started.)  If you can live with the inconsistencies, just printing the page from the browser should give readable math output.

On the other hand, if you can do some server-side processing and PHP (or something similar), there is another option:  you can query the question with its LaTeX content from the MySQL database, wrap it in a bit of document-level LaTeX formatting in a temporary text file, run it through pdflatex, and send the resulting PDF file.  There is very little of MathJax which is not LaTeX-compatible (and vice versa as long as you don't use any custom LaTeX macros), so this approach should work in a large majority of cases.

aRbEr

unread,
Mar 2, 2012, 9:27:19 AM3/2/12
to mathja...@googlegroups.com
Thank you Thomas,

I think that is what I am going with: the server side processing.


I am sure I could find it by searching/googling, but if it's easy for you (if you have it handy) and if there is one, can you give me a link to the documentations regarding "very little of MathJax which is not LaTeX-compatible".

aRbEr

unread,
Mar 2, 2012, 10:08:25 AM3/2/12
to mathja...@googlegroups.com
Another question:

I was doing a little reading (note I don't have much knowledge on LaTeX or anything related to it) since this is my first project that involves it:
The web app I am working on will run on linux, while my own machine where I am developing is a Windows one (not by my choice): What is the best way to install pdflatex on Windows (it's an XP one if it matters) so that it's closest to pdflatex for linux ?! Some quick research tells me that I should go with http://miktex.org/ -- any advice/recommendation ?!

Davide P. Cervone

unread,
Mar 2, 2012, 10:18:26 AM3/2/12
to mathja...@googlegroups.com
The discussion you site is actually about trying to do your option (a), not (b).  To do (b), you simply open a window with the usual HTML in it that calls in MathJax, and use

MathJax.Hub.Queue(function () {Print()})

to queue the Print command to occur after MathJax has finished rendering the page.  Personally, I think that is probably the easiest approach.

The link that you give discusses using wkhtmltopdf in order to create a pdf version of the page on the server and ship that back to the user.  That is a little more elegant from the user's point of view, but the timing problems are more difficult and less reliable.  In any case, that is one way to do your (a).  Tom's suggestion of using pdflatex is another approach, but requires a larger installation (TeX is a big package), and you do have the compatibility issues to worry about in case anyone uses some of the non-standard MathJax TeX macros.  (Of course, you could include your own definitions for these in TeX if you wanted.)

Davide

Davide P. Cervone

unread,
Mar 2, 2012, 10:20:31 AM3/2/12
to mathja...@googlegroups.com
This is no longer in our field of expertise.  I do know that MikTeX is a popular one, but I don't know anything about how you access command-line programs from within other programs, nor what MikTeX offers in the way of command-line versions of its programs.  If they allow it, then it should be pretty much the same as what you will get for your linux installation (TeX is very well standardized).

Davide

Duane Nykamp

unread,
Mar 17, 2012, 1:50:44 AM3/17/12
to MathJax Users
I've tried to do as you suggest, so that I have the lines

<script type="text/x-mathjax-config">
MathJax.Hub.Queue(function () {Print()});
</script>
<script type="text/javascript" src="/MathJax/MathJax.js?config=TeX-
AMS_HTML-full,local/midefault"></script>

I'm not sure what this is supposed to do, if it is supposed to make a
print happen automatically or make sure that a user initiated print
doesn't happen until Mathjax is finished. I assume the latter. But,
sometimes when I print right away, I get the box "Typesetting Math:
100%" to print on top the text. It seems Mathjax should get rid of
that box before allowing the printing to go through.

Also, at least in Firefox on Ubuntu, the math is bigger than the space
allowed for it, so that it often overlaps the text following it. I
don't know if that is the problem Thomas Leathrum alluded to, above.
I haven't tried with other browsers. Is that not something that can
be fixed on the Mathjax side of things? It reduces the utility of the
printed output.

Duane
> > be I wasn't able to understand it):http://groups.google.com/group/mathjax-users/browse_thread/thread/6ba...

Davide P. Cervone

unread,
Mar 19, 2012, 7:11:40 AM3/19/12
to mathja...@googlegroups.com

On Mar 17, 2012, at 1:50 AM, Duane Nykamp wrote:

> I've tried to do as you suggest, so that I have the lines
>
> <script type="text/x-mathjax-config">
> MathJax.Hub.Queue(function () {Print()});
> </script>
> <script type="text/javascript" src="/MathJax/MathJax.js?config=TeX-
> AMS_HTML-full,local/midefault"></script>
>
> I'm not sure what this is supposed to do, if it is supposed to make a
> print happen automatically or make sure that a user initiated print
> doesn't happen until Mathjax is finished. I assume the latter.

Unfortunately, it is the former. I don't think you can prevent the
user from printing it before MathJax runs. (Maybe you can override
the Print command, but I doubt it.)

This pushes a Print() command onto the MathJax command queue, so as
soon as MathJax finishes processing the page, it will be printed.

> But, sometimes when I print right away, I get the box "Typesetting
> Math:
> 100%" to print on top the text. It seems Mathjax should get rid of
> that box before allowing the printing to go through.

Ah, right, hadn't thought of that. You could do

<script type="text/x-mathjax-config">
MathJax.Hub.Queue(
["Clear",MathJax.Message,0,0],


function () {Print();}
);
</script>
<script type="text/javascript" src="/MathJax/MathJax.js?config=TeX-
AMS_HTML-full,local/midefault"></script>

to clear the message area before printing. I think that should do
what you need. (Not that MathJax can't prevent printing from
occurring, as your comment "before allowing the printing to go
through" suggests. You can only try to coordinate timing with get
MathJax to get the printing to occur properly.)


> Also, at least in Firefox on Ubuntu, the math is bigger than the space
> allowed for it, so that it often overlaps the text following it.

Are you using MathJax v1.1 or v2.0? And are you using MathJax's
NativeMML renderer in Firefox, or MathJax's HTML-CSS output? If it is
NativeMML with v1.1, then the problem may be due to the fact that FF
doesn't report the size of MathML correctly, and usually the size is
too small.

Alternatively, are you using a different font for printing than you
are for the screen? Since the sizes of things in MathJax are given in
em's that is font-dependent, so if you change the font, that will
affect the size of the spaces reserved by MathJax. If you have CSS
for print media, you might try removing that and seeing if that helps.

> Is that not something that can
> be fixed on the Mathjax side of things?

Not very easily, but I'll give it some thought.

Davide

Duane Nykamp

unread,
Mar 19, 2012, 6:21:47 PM3/19/12
to MathJax Users
I am using MathJax 2.0.

I have not succeeded in getting


> > <script type="text/x-mathjax-config">
> > MathJax.Hub.Queue(function () {Print()});
> > </script>

> <script type="text/x-mathjax-config">
> MathJax.Hub.Queue(
> ["Clear",MathJax.Message,0,0],
> function () {Print();}
> );
> </script>

to automatically get a Print command to occur after loading the
page. (That's why I figured that it must have a different action.)
I am using Firefox 11 under Linux. It seems to ignore the command.
I'd be great to have the page be printed immediately after the MathJax
finishes rendering.

I got the box "Typesetting Math: 100%" only when I did the print
command by hand before it finished typsetting the math. On a page
with more Math to typeset, I would get a page with still the Latex
code in it. So I think that result was just my misunderstanding what
the command did.

I don't have a separate css file for printing. I have MathJax
configured for HTML-CSS. However, not only does the math overlap with
the text at times, the math when printing looks very different (and
worse) from the math that is displayed on the screen. For example,
the integral signs are small. I changed the MathJax renderer to
MathML, and printing left off half the math symbols, so that made the
print out completely unusable.

It's strange how the print out is so different than what is shown on
the screen.

Duane

Duane Nykamp

unread,
Mar 19, 2012, 6:23:50 PM3/19/12
to MathJax Users
The first part show have read

I have not succeeded in getting

<script type="text/x-mathjax-config">
MathJax.Hub.Queue(function () {Print()});
</script>

or

<script type="text/x-mathjax-config">
MathJax.Hub.Queue(
["Clear",MathJax.Message,0,0],
function () {Print();}
);
</script>

(I didn't try a page with both commands at the same time!)

Davide P. Cervone

unread,
Mar 19, 2012, 6:36:13 PM3/19/12
to mathja...@googlegroups.com
I have not succeeded in getting

<script type="text/x-mathjax-config">
MathJax.Hub.Queue(function () {Print()});
</script>

       <script type="text/x-mathjax-config">
       MathJax.Hub.Queue(
         ["Clear",MathJax.Message,0,0],
         function () {Print();}
       );
       </script>

to automatically get a Print command to occur after loading the
page.

OOPS, my fault.  The Print() should be print() (not capitalized).

I don't have a separate css file for printing.  I have MathJax
configured for HTML-CSS.  However, not only does the math overlap with
the text at times, the math when printing looks very different (and
worse) from the math that is displayed on the screen.  For example,
the integral signs are small.  I changed the MathJax renderer to
MathML, and printing left off half the math symbols, so that made the
print out completely unusable.

Ah, I think I know what it is.  Firefox isn't able to print web fonts, so it is substituting other fonts for them.  That means the characters probably aren't the same size as the originals, and that accounts for the change in size.  There is essentially nothing that MathJax can do to get around that bug.  But if you install either the STIX fonts or MathJax's fonts, then they should get used instead of the web fonts, and that should allow them to print.  (Since I have these fonts installed locally, I didn't see the print problems when I tested things, and just remembered it when you described what you were seeing).  See https://bugzilla.mozilla.org/show_bug.cgi?id=468568 for the FIrefox bug tracker for this issue.

Firefox also has a printing bug with MathML when there are web-fonts on the page.  This is the error you are running into.  See https://github.com/mathjax/MathJax/issues/137 for details.

Both of these are Firefox bugs, and I do not know of any way to work around them (other than installing the fonts I mentioned above).  On the other hand, the SVG output should print more reliably.

Davide

Duane Nykamp

unread,
Mar 19, 2012, 10:27:07 PM3/19/12
to MathJax Users
Thanks. Now with

<script type="text/x-mathjax-config">
MathJax.Hub.Queue(
["Clear",MathJax.Message,0,0],
function () {print();}
);
</script>

it does send a print command after the math is typeset. However, on
pages 2 and following, it still has the "Typesetting Math: 100%" box
obscuring the lower left corner. It doesn't seem like the
["Clear",MathJax.Message,0,0],
is doing anything. Is there another command that might remove the
box? Otherwise, I could just remove the command and hope folks don't
execute the print command before the math is rendered.

Unfortunately, although I could install the fonts, I wouldn't expect
most users to have them installed. At least now I know I could
recommend folks try the SVG output if they report printing problems.
I hope the Firefox bugs get stamped out eventually.

Duane
> on the page.  This is the error you are running into.  Seehttps://github.com/mathjax/MathJax/issues/137

Duane Nykamp

unread,
Mar 20, 2012, 9:44:18 AM3/20/12
to MathJax Users
This seems to work, forcing it to wait a second before sending print
command so that the box is gone.

<script type="text/x-mathjax-config">
MathJax.Hub.Queue(
function () {setTimeout(function () {print();},1000)}
);
</script>

But, given that I don't know javascript (I just tried to modify code
from the MathJax example page), I'm not sure I have the syntax
correct.

Duane

Davide P. Cervone

unread,
Mar 20, 2012, 2:00:20 PM3/20/12
to mathja...@googlegroups.com
Right, you might need to let the browser have time to update the
screen after taking down its message. But if you clear the message,
it will not need to be as long a delay. But there does have to be
SOME delay, it seems. You could use

MathJax.Hub.Queue({
["Clear",MathJax.Message,0,0],
["Delay",MathJax.Callback,100],
print
});

That should clear the message, delay for a short time, and then do the
print.

Davide

Duane Nykamp

unread,
Mar 20, 2012, 2:47:35 PM3/20/12
to MathJax Users
Thanks, that's a simpler way to write it, though I had to remove the
curly braces.

At least on my system (Firefox 11, Linux), I cannot notice that

["Clear",MathJax.Message,0,0],

does anything.

The command

MathJax.Hub.Queue(
["Delay",MathJax.Callback,600],
print
);

works to clear the message while

MathJax.Hub.Queue(
["Clear",MathJax.Message,0,0],
["Delay",MathJax.Callback,500],
print
);

does not. It seems the message wants to stay there for a half-second
no matter what I do. I don't mind waiting the extra half second, but
thought I'd let you know.

Duane

Davide P. Cervone

unread,
Mar 20, 2012, 4:43:53 PM3/20/12
to mathja...@googlegroups.com
> Thanks, that's a simpler way to write it, though I had to remove the
> curly braces.

Right. Sorry about that. (I was writing quickly without testing it
out -- never a smart thing to do).

> At least on my system (Firefox 11, Linux), I cannot notice that
>
> ["Clear",MathJax.Message,0,0],
>
> does anything.

OK, how about

["Remove",MathJax.Message]

instead?

> The command
>
> MathJax.Hub.Queue(
> ["Delay",MathJax.Callback,600],
> print
> );
>
> works to clear the message while
>
> MathJax.Hub.Queue(
> ["Clear",MathJax.Message,0,0],
> ["Delay",MathJax.Callback,500],
> print
> );
>
> does not.

The default message delay before it is cleared is 600 milliseconds, so
that is why 600 works but 500 doesn't.

Davide

Duane Nykamp

unread,
Mar 20, 2012, 5:50:14 PM3/20/12
to MathJax Users
Making the configuration block

<script type="text/x-mathjax-config">
MathJax.Hub.Queue(
["Remove",MathJax.Message],
print
);
</script>

makes it print without that message box appearing in the output and
without having to introduce a delay. Eventually we got it right!

Thanks,
Duane
Reply all
Reply to author
Forward
0 new messages