tex2pdf

package module
v0.3.7 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2025 License: MIT Imports: 8 Imported by: 0

README

tex2pdf

Package tex2pdf provides functions to compile Tex Files into a PDF via XeLaTex engine.

Requirements

  • Install TexLive

    tex2pdf calls xelatex command which comes with installation of TexLive. Download and install TexLive("scheme-full" is recommended).

  • Install minted pacakge and pygments minted is used for code highlighting. Our test case includes compiling .tex file which uses minted for code highlighting("src/02-usage.tex").

    • Download and Install pygments which is required by minted.
    • TexLive Installation with "scheme-full" includes minted.

Docs

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrXelatexNotExist = errors.New("xelatex does not exists")
	ErrNoOutputPDF     = errors.New("xelatex compiled successfully but no output pdf found")
)

Functions

This section is empty.

Types

type Compiler added in v0.3.0

type Compiler struct {
	// contains filtered or unexported fields
}

Compiler reads main LaTex file and compiles all LaTex files to a PDF.

func New added in v0.3.0

func New(texFile, outputPDF string, options ...Option) *Compiler

New creates a new compiler.

func (*Compiler) Compile added in v0.3.0

func (c *Compiler) Compile() error

Compile compiles all LaTex files to a PDF.

Example
package main

import (
	"log"

	"github.com/northbright/tex2pdf"
)

func main() {
	texFile := "example/src/my_book.tex"
	outputPDF := "output/my_book.pdf"

	// Create a compiler with specified stdout and stderr options.
	// c := tex2pdf.New(texFile, outputPDF, tex2pdf.Stdout(os.Stdout), tex2pdf.Stderr(os.Stderr))
	// Create a compiler.
	c := tex2pdf.New(texFile, outputPDF)

	log.Printf("start compiling Tex File to PDF...\nTex file: %v\noutput PDF: %v", texFile, outputPDF)
	// Compile a Tex file to a PDF.
	if err := c.Compile(); err != nil {
		log.Printf("Compile() error: %v", err)
		return
	}

	log.Printf("compile successfully")

}

type Option added in v0.3.0

type Option func(c *Compiler)

Option represents the option of compiler.

func Stderr added in v0.3.0

func Stderr(stderr io.Writer) Option

Stderr returns option to set stderr of the cmd to run xelatex.

func Stdout added in v0.3.0

func Stdout(stdout io.Writer) Option

Stdout returns option to set stdout of the cmd to run xelatex.

Jump to

Keyboard shortcuts

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