RTeX has been updated for Rails 2. The v1 branch (supporting Rails 1) is available from Subversion at Rubyforge.

Current Version:
2.0.1

Using RTeX as a Rails plugin

RTeX can be used as a “Template Handler,” similar to HAML or Markaby, but generating PDFs.

Rails Version Dependency

  • >= 2.0.1

Usage

Create files pdf.rtex extensions (eg, index.pdf.rtex) using standard LaTeX markup.

  • Layouts are supported, eg: application.pdf.rtex
  • Partials are supported, eg: _item.pdf.rtex

For information on learning LaTeX, see the related FAQ entry.

Example

With the following:

app/controllers/items_controller.rb

  def index
    @items = Item.find(:all)
  end

app/views/items/index.pdf.rtex

  \section*{Items}
  \begin{itemize}
    <%= render :partial => @items %>
  \end{itemize}

app/views/items/_item.pdf.rtex

  \item <%=l item.name %> \\

Note the l (or latex_escape) helper used above. It escapes LaTeX command sequences (similar to how h escapes HTML in normal Rails views).

app/layouts/application.pdf.rtex

  \documentclass[12pt]{article}
  \begin{document}
    <%= yield %>
  \end{document}

If you hit http://the.server.url/items.pdf, you end up with a nice PDF listing of items.

Note: This documentation needs significantly more complex/complete examples

Customizing Options

Note you can set certain options for RTeX by passing additional options to render. Here is a short list:

:filename
The name of the PDF the user will be prompted to download (otherwise it uses a filename based on the URL)
:preprocess and :preprocessor
Whether to run the raw source through a preprocessor, and the executable to use (for generating TOCs, etc). Defaults are false and 'latex', respectively.
:processor
The executable used for final generation (default: 'pdflatex'); note this must currently produce a PDF file.
:shell_redirect
Additional string to be tacked onto system calls, generally used to redirect STDERR to keep logs clean, ie '> /dev/null 2>&1') (default nil)
:tmpdir
The temporary directory to use (default RAILS_ROOT/tmp)

Example

  def index
    @items = Item.find(:all)
    render :filename => 'item-listing.pdf'
  end