Class: TeXMath::Converter
- Inherits:
-
Object
- Object
- TeXMath::Converter
- Defined in:
- lib/texmath/converter.rb
Overview
A Converter
represents a single texmath
command to which data
can be piped. For example, a Converter
that converts LaTeX to
MathML can be reused for different input expressions, although all
would have to be valid LaTeX.
Constant Summary collapse
- READERS =
The available readers and their corresponding names.
{ 'tex' => 'LaTeX', 'mathml' => 'MathML', 'omml' => 'Office Math Markup Language', 'native' => 'texmath native' }
- WRITERS =
The available writers and their corresponding names.
{ 'tex' => 'LaTeX', 'mathml' => 'MathML', 'omml' => 'Office Math Markup Language', 'xhtml' => 'XHTML', 'pandoc' => 'pandoc native', 'native' => 'texmath native' }
Instance Attribute Summary collapse
-
#executable ⇒ Object
readonly
Returns the value of attribute executable.
-
#reader ⇒ Object
Returns the value of attribute reader.
-
#writer ⇒ Object
Returns the value of attribute writer.
Instance Method Summary collapse
-
#convert(data) ⇒ String
Convert
data
between formats. -
#initialize(options = {}) ⇒ Converter
constructor
Create a new Converter.
Constructor Details
#initialize(options = {}) ⇒ Converter
Create a new Converter.
36 37 38 39 40 |
# File 'lib/texmath/converter.rb', line 36 def initialize( = {}) @executable = .fetch(:executable, 'texmath') self.reader = .fetch(:from, :tex) self.writer = .fetch(:to, :mathml) end |
Instance Attribute Details
#executable ⇒ Object (readonly)
Returns the value of attribute executable.
42 43 44 |
# File 'lib/texmath/converter.rb', line 42 def executable @executable end |
#reader ⇒ Object
Returns the value of attribute reader.
60 61 62 |
# File 'lib/texmath/converter.rb', line 60 def reader @reader end |
#writer ⇒ Object
Returns the value of attribute writer.
60 61 62 |
# File 'lib/texmath/converter.rb', line 60 def writer @writer end |
Instance Method Details
#convert(data) ⇒ String
Convert data
between formats.
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/texmath/converter.rb', line 47 def convert(data) Open3.popen3(command) do |stdin, stdout, stderr| stdin.puts(data) stdin.close output = stdout.read error = stderr.read raise ConversionError, error unless error.empty? return output.strip end rescue Errno::ENOENT raise NoExecutableError, "Can't find the '#{executable}' executable." end |