gotex

package module
v0.0.0-...-3c68d9b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2017 License: BSD-2-Clause Imports: 7 Imported by: 5

README

gotex

A simple Go library for rendering LaTeX documents

Install

go get -u github.com/rwestlund/gotex

Documentation

See the documentation at https://godoc.org/github.com/rwestlund/gotex

Example

package main

import "github.com/rwestlund/gotex"

func main() {
    var document = `
        \documentclass[12pt]{article}
        \begin{document}
        This is a LaTeX document.
        \end{document}
        `
    var pdf, err = gotex.Render(document, gotex.Options{
        Command: "/usr/bin/pdflatex",
        Runs: 1,
        Texinputs:"/my/asset/dir:/my/other/asset/dir"})

    if err != nil {
        log.Println("render failed ", err)
    } else {
        // Do something with the PDF file, like send it to an HTTP client
        // or write it to a file.
        sendSomewhere(pdf)
    }
}

License

This code is under the BSD-2-Clause license.

Documentation

Overview

Package gotex is a simple library to render LaTeX documents.

Example

Use it like this:

package main

import "github.com/rwestlund/gotex"

func main() {
    var document = `
        \documentclass[12pt]{article}
        \begin{document}
        This is a LaTeX document.
        \end{document}
        `
    var pdf, err = gotex.Render(document, gotex.Options{
		Command: "/usr/bin/pdflatex",
		Runs: 1,
		Texinputs:"/my/asset/dir:/my/other/asset/dir"})

    if err != nil {
        log.Println("render failed ", err)
    } else {
        // Do something with the PDF file, like send it to an HTTP client
        // or write it to a file.
        sendSomewhere(pdf)
    }
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Render

func Render(document string, options Options) ([]byte, error)

Render takes the LaTeX document to be rendered as a string. It returns the resulting PDF as a []byte. If there's an error, Render will leave the temporary directory intact so you can check the log file to see what happened. The error will tell you where to find it.

Types

type Options

type Options struct {
	// Command is the executable to run. It defaults to "pdflatex". Set this to
	// a full path if $PATH will not be defined in your app's environment.
	Command string
	// Runs determines how many times Command is run. This is needed for
	// documents that use refrences and packages that require multiple passes.
	// If 0, gotex will automagically attempt to determine how many runs are
	// required by parsing LaTeX log output.
	Runs int

	// Texinputs is a colon-separated list of directories containing assests
	// such as image files that are needed to compile the document. It is added
	// to $TEXINPUTS for the LaTeX process.
	Texinputs string
}

Options contains the knobs used to change gotex's behavior.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL