Class: Antex::Job

Inherits:
Object
  • Object
show all
Includes:
LiquidHelpers
Defined in:
lib/antex/job.rb

Overview

This class is the beating heart of Antex.

The simplest usage of this gem involves three steps:

# 1. Get a LaTeX snippet and initialize a job.
job = Antex::Job.new snippet: "Hello, \TeX world!"
# 2. Run the job!
job.run!
# 3. Do something neat with your new SVG file and its typesetting metrics.
job.files(:svg) # => "./.antex-cache/eb64793dafe3bbd963dc663385a22096.svg"
job.set_box.measures # => {:ex=>1, :wd=>17.03..., :mt=>-0.05..., ...}

The DEFAULTS are tuned to work with a basic latexmk/dvisvgm pipeline. To get started with customization. you’ll want to read the (not yet well documented) YAML source loaded into the constant at the github repo.

Constant Summary collapse

DEFAULTS =
YAML.load_file(File.join(File.dirname(__FILE__), 'defaults.yml'), permitted_classes: [Regexp]).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from LiquidHelpers

#liquid_render

Constructor Details

#initialize(snippet: '', options: Antex::Job::DEFAULTS) ⇒ Job

Returns a new instance of Job.

Parameters:

  • snippet (String) (defaults to: '')

    TeX code snippet to render

  • options (Hash) (defaults to: Antex::Job::DEFAULTS)

    job options



52
53
54
55
56
57
58
59
60
# File 'lib/antex/job.rb', line 52

def initialize(snippet: '', options: Antex::Job::DEFAULTS)
  @options = options
  @snippet = snippet

  prepare_code
  prepare_hash
  prepare_dirs
  prepare_files
end

Instance Attribute Details

#dirsHash (readonly)

Returns the dirs paths rendered from the options.

Returns:

  • (Hash)

    the dirs paths rendered from the options



39
40
41
# File 'lib/antex/job.rb', line 39

def dirs
  @dirs
end

#filesHash (readonly)

Returns the files paths rendered from the options.

Returns:

  • (Hash)

    the files paths rendered from the options



42
43
44
# File 'lib/antex/job.rb', line 42

def files
  @files
end

#hashString (readonly)

Returns the unique hash identifying the job.

Returns:

  • (String)

    the unique hash identifying the job



45
46
47
# File 'lib/antex/job.rb', line 45

def hash
  @hash
end

#optionsHash (readonly)

Returns the initialization options.

Returns:

  • (Hash)

    the initialization options



36
37
38
# File 'lib/antex/job.rb', line 36

def options
  @options
end

#set_boxSetBox? (readonly)

Returns the SetBox calculated by the #run!.

Returns:



48
49
50
# File 'lib/antex/job.rb', line 48

def set_box
  @set_box
end

Instance Method Details

#run!Object

Run the job, compile the TeX snippet and calculate the #set_box.



63
64
65
66
67
68
# File 'lib/antex/job.rb', line 63

def run!
  create_dirs
  write_code
  run_pipeline!
  load_set_box
end