Module: MathML::LaTeX::BuiltinCommands

Included in:
Parser
Defined in:
lib/math_ml/latex.rb,
lib/math_ml/latex.rb

Constant Summary collapse

OVERS =
{ 'hat' => 'circ', 'breve' => 'smile', 'grave' => 'grave',
'acute' => 'acute', 'dot' => 'sdot', 'ddot' => 'nldr', 'dddot' => 'mldr', 'tilde' => 'tilde',
'bar' => 'macr', 'vec' => 'rightarrow', 'check' => 'vee', 'widehat' => 'circ',
'overline' => 'macr', 'widetilde' => 'tilde', 'overbrace' => 'OverBrace' }
UNDERS =
{ 'underbrace' => 'UnderBrace', 'underline' => 'macr' }

Instance Method Summary collapse

Instance Method Details

#cmd_backslashObject


738
739
740
# File 'lib/math_ml/latex.rb', line 738

def cmd_backslash
  @ds ? nil : XMLElement.new('br', 'xmlns' => 'http://www.w3.org/1999/xhtml')
end

#cmd_entityObject

Raises:


752
753
754
755
756
757
758
759
760
761
762
# File 'lib/math_ml/latex.rb', line 752

def cmd_entity
  param = @scanner.scan_block ? @scanner[1] : @scanner.scan(/./)
  raise ParseError, 'Need parameter.' unless param

  unless @unsecure_entity || @entities[param]
    param = @scanner.matched[/\A\{#{RE::SPACE}*(.*\})\z/, 1] if @scanner.matched =~ RE::BLOCK
    @scanner.pos = @scanner.pos - param.size
    raise ParseError, 'Unregistered entity.'
  end
  Operator.new << entitize(param)
end

#cmd_fracObject


820
821
822
823
824
# File 'lib/math_ml/latex.rb', line 820

def cmd_frac
  n = parse_any
  d = parse_any
  Frac.new(n, d)
end

#cmd_hat_etcObject


742
743
744
745
# File 'lib/math_ml/latex.rb', line 742

def cmd_hat_etc
  com = @scanner[1]
  Over.new(parse_any, Operator.new << entitize(OVERS[com]))
end

#cmd_it_etcObject


789
790
791
792
793
794
795
796
797
798
799
# File 'lib/math_ml/latex.rb', line 789

def cmd_it_etc
  case @scanner[1]
  when 'it'
    @font = Font::NORMAL
  when 'rm'
    @font = Font::ROMAN
  when 'bf'
    @font = Font::BOLD
  end
  nil
end

#cmd_mathit_etcObject


801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
# File 'lib/math_ml/latex.rb', line 801

def cmd_mathit_etc
  case @scanner[1]
  when 'mathit'
    parse_mathfont(Font::NORMAL)
  when 'mathrm'
    parse_mathfont(Font::ROMAN)
  when 'mathbf'
    parse_mathfont(Font::BOLD)
  when 'bm'
    parse_mathfont(Font::BOLD_ITALIC)
  when 'mathbb'
    parse_mathfont(Font::BLACKBOLD)
  when 'mathscr'
    parse_mathfont(Font::SCRIPT)
  when 'mathfrak'
    parse_mathfont(Font::FRAKTUR)
  end
end

#cmd_mboxObject


837
838
839
840
# File 'lib/math_ml/latex.rb', line 837

def cmd_mbox
  @scanner.scan_any
  Text.new << (@scanner.matched =~ RE::BLOCK ? @scanner[1] : @scanner.matched)
end

#cmd_quad_etcObject


770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
# File 'lib/math_ml/latex.rb', line 770

def cmd_quad_etc
  case @scanner[1]
  when ' '
    Space.new('1em')
  when 'quad'
    Space.new('1em')
  when 'qquad'
    Space.new('2em')
  when ','
    Space.new('0.167em')
  when ':'
    Space.new('0.222em')
  when ';'
    Space.new('0.278em')
  when '!'
    Space.new('-0.167em')
  end
end

#cmd_sqrtObject


826
827
828
829
830
831
832
833
834
835
# File 'lib/math_ml/latex.rb', line 826

def cmd_sqrt
  if @scanner.scan_option
    i = parse_into(@scanner[1], [])
    i = i.size == 1 ? i[0] : (Row.new << i)
    b = parse_any
    Root.new(i, b)
  else
    Sqrt.new << parse_any
  end
end

#cmd_stackrelObject


764
765
766
767
768
# File 'lib/math_ml/latex.rb', line 764

def cmd_stackrel
  o = parse_any
  b = parse_any
  Over.new(b, o)
end

#cmd_underbrace_etcObject


747
748
749
750
# File 'lib/math_ml/latex.rb', line 747

def cmd_underbrace_etc
  com = @scanner[1]
  Under.new(parse_any, Operator.new << entitize(UNDERS[com]))
end

#initializeObject


724
725
726
727
728
729
730
731
732
733
734
735
736
# File 'lib/math_ml/latex.rb', line 724

def initialize
  add_commands('\\' => :backslash)
  add_commands('entity', 'stackrel', 'frac', 'sqrt', 'mbox')
  add_multi_command(:hat_etc, *OVERS.keys)
  add_multi_command(:underbrace_etc, *UNDERS.keys)
  add_multi_command(:quad_etc, ' ', 'quad', 'qquad', ',', ':', ';', '!')
  add_multi_command(:it_etc, 'it', 'rm', 'bf')
  add_multi_command(:mathit_etc, 'mathit', 'mathrm', 'mathbf', 'bm', 'mathbb', 'mathscr', 'mathfrak')
  add_sym_cmd(Builtin::Symbol::MAP)
  add_delimiter(Builtin::Symbol::DELIMITERS)

  super
end