title: Generating a PDF in Rails with MathJax and wkhtmltopdf
body: <p>I'm writing a website using Rails 3.2.6 and it needs to be able to display maths formatting on the website. To do this job I am using the mathjax-rails gem which works perfectly rendering the maths on, for example, questions/1. However, I would like the user to be able to download the question containing the maths content as a PDF. I have done a lot of searching and fiddling with my app and the closest I have come to a solution is wkhtmltopdf and the wicked_pdf gem. This works, in that a PDF is created which is saved to the user's computer. However, the maths is not rendered properly because, I presume, mathjax is not actually processing it.</p>
  
  <p>Having done a bit of reading, I thought I found the answer elsewhere where it said to add a delay to the controller to give mathjax a chance to do its magic:</p>
  
  <pre><code>format.pdf do
      render :pdf =&gt; 'filename',
            :javascript_delay=&gt;5000
    end
  </code></pre>
  
  <p>However this doesn't work either and I end up with a PDF covered in things like:</p>
  
  <p>[itex]3H_{2~(g)} + 2N_{2~(g)} ⇌ NH_{3~(g)}[/itex]</p>
  
  <p>Rather than formatted maths. Has anyone got any clues on how I can get this to work?</p>
  
  <p>Thanks in advance.</p>