Giter Site home page Giter Site logo

iona's Introduction

Iona

Build Status Hex.pm Hex.pm Hex.pm

Document generation from Elixir, using LaTeX.

Highlighted Features

  • Generate professional-quality typeset .pdf (and .dvi) documents using LaTeX, and support defining your own TeX processors for different formats.
  • Built-in support for EEx templating with automatic escaping and a custom helpers
  • Preprocessing support (multiple runs for bibliographies, etc)
  • Optionally generating a prepared directory with a build.sh script for final processing.

Prerequisites

While features are on the roadmap to ease authorship of .tex documents, at the current time knowledge of LaTeX is assumed (or at least a basic willingness to wade into that very deep topic).

We recommend you start your knowledge quest at the LaTeX homepage.

Installation

The package can be installed by adding iona to your list of dependencies in mix.exs:

def deps do
  [
    {:iona, "~> 0.4"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. The docs can be found at https://hexdocs.pm/iona.

LaTeX

Of course you need a TeX system installed, including latex, pdflatex, or any other variants you'd like to use to process your .tex source into final documents. (The default configuration assumes pdflatex is installed for PDF generation and latex is installed for DVI generation. See "Configuration," below.)

You can download and install a TeX system at the LaTeX Project website -- or using the the package management system of your choice.

Examples

From TeX source

Generate a PDF from an existing .tex source:

Iona.source(path: "simple.tex")
|> Iona.write!("/path/to/document.pdf")

You can also use a binary string:

Iona.source("\documentclass[12pt]{article} ...")
|> Iona.write!("/path/to/simple.pdf")

More complex preprocessing needs for citations and bibliographies? Define the prepocessing pipeline:

Iona.source(path: "academic.tex")
|> Iona.write!("/path/to/academic.pdf",
               preprocess: ~w(latex bibtex latex))

To generate a directory with a build script that can be run to finalize the build, use prepare:

Iona.source(path: "academic.tex")
|> Iona.prepare!("/path/to/build/directory", :pdf, preprocess: ~w(latex bibtex latex))

Want to get the raw document content as a binary? Use to:

Iona.source(path: "fancy.tex")
|> Iona.to(:pdf)
|> MyModule.do_something_with_pdf_string

Complex preprocessors

You can provide functions in the preprocessing pipeline too. The function will be invoked, given the temporary directory processing is occuring and the basename of the original file (eg, "source.tex"):

Iona.source(path: "source.tex")
|> Iona.write!("/path/to/source.pdf",
               preprocess: [fn (directory, filename) -> :ok end])

Function preprocessors should return:

  • :ok if processing should continue
  • {:shell, command} to indicate a command should be run as a preprocessor (see example below)
  • {:error, reason} if processing should halt

If given {:shell, command}, Iona will execute that command as a preprocessor. This is especially useful for interpolation, eg:

knitr = fn (_, filename) ->
  {:shell, "R -e 'library(knitr);knitr(\"#{filename}\");'" }
end

Iona.source(path: "graphs.Rnw")
|> Iona.write!("/path/to/graphs.pdf",
               preprocess: [knitr])

Important: As always, only interpolate trusted input into shell commands.

From an EEx TeX template

%{title: "My Document"}
|> Iona.template!(path: "/path/to/template.tex.eex")
|> Iona.write("/path/to/my_document.pdf")

Values are inserted into EEx with, eg, <%= @title %> after being automatically escaped by Iona.Template.Helper.escape/1.

If you're confident values are safe for raw insertion into your LaTeX documents (or you'd like to support insertion of LaTeX commands), use raw/1, made available by default as part of Iona.Template.Helper:

For instance, if you wanted to style @title as boldface, you could pass it as "{\bf My Document}" and insert it as a raw string:

<%= raw @title %>

With Custom Helpers

You can import additional helper modules for use in your templates by two methods.

The first (and preferred) method is by overriding the :helpers application configuration setting (see "Configuration," below).

You can also pass a :helpers option to Iona.template/2 with a list of additional helpers:

%{title: "My Document"}
|> Iona.template!(path: "/path/to/template.tex.eex",
                 helpers: [My.Custom.HelperModule])
|> Iona.write("/path/to/my_document.pdf")

Note in this case the setting is additive; the list is concatenated with the :helpers defined in the application configuration.

Configuration

The default, out-of-the-box settings for Iona are equivalent to the following Mix config:

config :iona,
  helpers: [Iona.Template.Helper],
  preprocess: [],
  processors: [pdf: "pdflatex", dvi: "latex"]

Note you can also pass a :preprocess and :processor options to define a preprocessing pipeline on a case-by-case basis. See the examples above or the documentation for Iona.to/3 and Iona.write/3.

License

See LICENSE.

LaTeX

LaTeX is free software, and is not distributed with this (unaffiliated) project. Please see the LaTeX homepage for more information.

iona's People

Contributors

maennchen avatar bruce avatar drueck avatar pierrevdb avatar mad42 avatar benwilson512 avatar lowks avatar

Stargazers

Marius Bora avatar Rahul Rajput avatar Markus J. Pflaum avatar tyoc213 avatar  avatar Gianni Chiappetta avatar Sebastian Bachmann avatar Stefan Wintermeyer avatar Alejandro avatar Pedro Lara Campos avatar Mu avatar  avatar Maximilian Stauss avatar Aswin Mohan avatar IndiePaper avatar rickl avatar Charles Sirois avatar Kevin Hughes avatar Alexander Buch avatar David Staehler avatar  avatar Steve Qian avatar Edwin Bühler avatar John Athayde avatar Jesper Andre Lyngesen Pedersen avatar matt avatar Nate-Wilkins avatar Furkan avatar Jason Underdown avatar Kent Gruber avatar Thorsten Deinert avatar Max Salminen avatar  avatar Christian Meunier avatar  avatar Christoph Grabo avatar Petrică Clement Chiriac avatar

Watchers

Richard Kilmer avatar  avatar James Cloos avatar  avatar CargoSense Developer avatar  avatar  avatar

iona's Issues

Remove Porcelain Dependency

Porcelain seems to be unmaintained and fills the console with warnings, the dependency should be removed.

The template based calls fail

test template simple interpolation (Test.Iona)
    test/lib/iona_test.exs:46
    ** (ArgumentError) argument error
 stacktrace:
   (stdlib) erl_anno.erl:318: :erl_anno.set(:file, 'nofile', -1)
   (stdlib) erl_parse.yrl:1516: anonymous fn/3 in :erl_parse.map_anno/2
   (stdlib) erl_parse.yrl:1635: :erl_parse.modify_anno1/3
   (stdlib) erl_parse.yrl:1637: :erl_parse.modify_anno1/3
   (stdlib) erl_parse.yrl:1658: :erl_parse.modify_anno1/3
   (stdlib) erl_parse.yrl:1659: :erl_parse.modify_anno1/3
   (stdlib) erl_parse.yrl:1632: :erl_parse.modify_anno1/3
   (stdlib) erl_parse.yrl:1636: :erl_parse.modify_anno1/3
   (stdlib) erl_parse.yrl:1637: :erl_parse.modify_anno1/3
   (stdlib) erl_parse.yrl:1658: :erl_parse.modify_anno1/3
   (stdlib) erl_parse.yrl:1632: :erl_parse.modify_anno1/3
   (stdlib) erl_parse.yrl:1636: :erl_parse.modify_anno1/3
   (stdlib) erl_parse.yrl:1658: :erl_parse.modify_anno1/3
   (stdlib) erl_parse.yrl:1659: :erl_parse.modify_anno1/3
   (stdlib) erl_parse.yrl:1632: :erl_parse.modify_anno1/3
   (stdlib) erl_parse.yrl:1517: :erl_parse.map_anno/2
   (stdlib) erl_lint.erl:703: :erl_lint."-set_file/2-lc$^0/1-0-"/2
   (stdlib) erl_lint.erl:448: :erl_lint.exprs_opt/3
   (stdlib) erl_eval.erl:173: :erl_eval.check_command/2
   (elixir) src/elixir.erl:216: :elixir.erl_eval/3

This is a typical response if I use any kind of interpolation in the template.

Add binary include option

As stated in documentation for additional external files for processing:

When providing a file path, you can also define additional files needed for processing. They will be copied to the temporary directory where processing will take place.

Iona.source(path: "/path/to/document.tex",
            include: ["/path/to/document.bib",
                      "/path/to/documentclass.sty"])

I have an use-case where I can pass the includes only as binary, to avoid creating temporary files on my end, I think an option like the following should be added:

Iona.source(path: "/path/to/document.tex",
            include: [path: "/path/to/document.bib",
                      binary: {binary, "virtualpath/documentname.sty"}])

Package Maintainer

Follow up from https://github.com/CargoSense/iona/pull/17#issuecomment-558161077

I'd be willing to take over ownership of that repository and try to push it to stable. If you're agreeing to it, I'd propose to move the repository to the jshmrtn organisation and the hex.pm ownership to the user maennchen.

I'll be using this package to build some complex documents for a customer of ours and will contribute back bugfixes / tests etc. and hopefully release it stable ( v1) afterwards.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.