Class: Numerals::Format::LatexNotation

Inherits:
Notation
  • Object
show all
Defined in:
lib/numerals/format/notations/latex.rb

Instance Attribute Summary

Attributes inherited from Notation

#format

Instance Method Summary collapse

Methods inherited from Notation

#disassemble, #initialize

Constructor Details

This class inherits a constructor from Numerals::Format::Notation

Instance Method Details

#assemble(output, text_parts) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/numerals/format/notations/latex.rb', line 7

def assemble(output, text_parts)
  # 1.23\overline{456}\times10^{9}
  # TODO: padding
  if text_parts.special?
    output << text_parts.special
  else
    output << text_parts.sign
    if format.symbols.base_prefix
      output << format.symbols.base_prefix
    end
    output << text_parts.integer # or decide here if empty integer part is shown as 0?
    if text_parts.show_point?(format)
      output << format.symbols.point
    end
    output << text_parts.fractional
    if text_parts.repeat?
      output << "\\overline{#{text_parts.repeat}}"
    end
    if format.symbols.base_suffix || format.base != 10
      if format.symbols.base_prefix
        output << format.symbols.base_suffix
      else
        # show base suffix as a subscript
        subscript = format.symbols.base_suffix || base.to_s
        output << "_{#{subscript}}"
      end
    end
    if text_parts.exponent_value != 0 || format.mode.mode == :scientific
      output << "\\times"
      output << text_parts.exponent_base
      output << "^"
      output << "{#{text_parts.exponent}}"
    end
  end
end