Skip to content

Latest commit

 

History

History
58 lines (40 loc) · 1.24 KB

README_RAILS.rdoc

File metadata and controls

58 lines (40 loc) · 1.24 KB

RTeX for Rails

Installation

sudo gem install rtex

Rails 2.0.X, 2.1+ in vendor/plugins (not recommended):

rtex --install /path/to/rails/app

Or, as a Rails 2.1+ gem dependency, just add the following to your config/environment.rb:

config.gem 'rtex'

Dependencies

  • Rails >= 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

Example

With the following:

# In config/initializers/mime_types.rb (or environment.rb in older Rails)
Mime::Type.register "application/pdf", :pdf

# app/controllers/items_controller.rb
def index
  @items = Item.find(:all)
  respond_to do |format|
    format.html # We support the normal HTML view as well
    format.pdf
  end
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 %> \\

# app/layouts/application.pdf.rtex
\documentclass[12pt]{article}
\begin{document}
  <%= yield %>
\end{document}

If you hit /items.pdf, you end up with a nice PDF listing of items.

Obviously a simplistic example.