Rails-LaTeX

Description

rails-latex is a renderer for rails 3 which allows tex files with erb to be turned into an inline pdf.

Synopsis

app/helpers/application_helper.rb:

def lesc(text)
  LatexToPdf.escape_latex(text)
end

app/views/stories/show.html.erb:

...
<%= link_to "print", story_path(@story,:format => :pdf) %>

app/views/stories/show.pdf.erb:

...   
<%= lesc @story.name % >

app/views/layouts/application.pdf.erbtex:

\documentclass[12pt,a4paper,sloppy,< %= @landscape % >]{article}
...
< %= yield % >
\end{document}

config/initializers/mime_types.rb:

...     
Mime::Type.register "application/pdf", :pdf, ['text/pdf'], ['pdf']

Only the file containing the \documentclass should be of type: .pdf.erbtex . Partials and views (when there is a layout) should be of type .pdf.erb .

If a LaTeX package requires two parses then add the following to the .pdf.erbtex file:

<% @latex_parse_twice=true %>

The last log file is moved to tmp/rails-latex/input.log . If the PDF is no produced the build directory is not removed; a archive script should be written to occasionally clean up the tmp/rails-latex directory.

See the rails application under examples/rails-latex-demo/ for a working example.

Requirements

  • ruby 1.8 or 1.9

  • rails 3

Install

  • gem install rails-latex

Development

Developing rails-latex requires jeweler

  • rake test

  • rake build