Class: Mathtype3::RecordTmpl

Inherits:
BinData::Record
  • Object
show all
Includes:
Snapshot
Defined in:
lib/records3/tmpl.rb

Constant Summary collapse

EXPOSED_IN_SNAPSHOT =
%i(options selector variation template_specific_options nudge
subobject_list)
SCRIPT_SELECTOR =
{
  0 => "tmSUP",
  1 => "tmSUB",
  2 => "tmSUBSUP"
}
SELECTORS =
{
  0 => "tmANGLE",
  1 => "tmPAREN",
  2 => "tmBRACE",
  3 => "tmBRACK",
  4 => "tmBAR",
  5 => "tmDBAR",
  6 => "tmFLOOR",
  7 => "tmCEILING",
  8 => "tmINTERVAL",
  9 => "tmINTERVAL",
  10 => "tmINTERVAL",
  11 => "tmINTERVAL",
  12 => "tmINTERVAL",
  13 => "tmROOT",
  14 => "tmFRACT",
  15 => "tmSCRIPT",
  16 => "tmUBAR",
  17 => "tmOBAR",
  18 => "tmARROW",
  19 => "tmARROW",
  20 => "tmARROW",
  21 => "tmINTEG",
  22 => "tmINTEG",
  23 => "tmINTEG",
  24 => "tmINTEG",
  25 => "tmINTEG",
  26 => "tmINTEG",
  27 => "tmHBRACE",
  28 => "tmHBRACE",
  29 => "tmSUM",
  30 => "tmSUM",
  31 => "tmPROD",
  32 => "tmPROD",
  33 => "tmCOPROD",
  34 => "tmCOPROD",
  35 => "tmUNION",
  36 => "tmUNION",
  37 => "tmINTER",
  38 => "tmINTER",
  39 => "tmLIM",
  40 => "tmLDIV",
  41 => "tmFRACT",
  42 => "tmINTOP",
  43 => "tmSUMOP",
  44 => "tmSCRIPT",
  45 => "tmDIRAC",
  46 => "tmVEC",
  47 => "tmVEC",
  48 => "tmBOX"
}
FENCE_BOTH =
[
 "tvFENCE_L",
 "tvFENCE_R"
]
FENCE_VARIATIONS =
{
  0 => FENCE_BOTH,
  1 => ["tvFENCE_L"], # left fence is present
  2 => ["tvFENCE_R"] # right fence is present
}
BAR_VARIATIONS =
{
  0 => ["tvBAR_SINGLE"],
  1 => ["tvBAR_DOUBLE"] #  bar is doubled, else single
}
VARIATIONS =
{
  # Fences (parentheses, etc.):
  0 => FENCE_VARIATIONS,
  1 => FENCE_VARIATIONS,
  2 => FENCE_VARIATIONS,
  3 => FENCE_VARIATIONS,
  4 => FENCE_VARIATIONS,
  5 => FENCE_VARIATIONS,
  6 => {
    0 => FENCE_BOTH
  },
  7 => {
    0 => FENCE_BOTH
  },
  # Intervals:
  # 0x0000 => "tvINTV_LEFT_LP", #  left fence is left parenthesis
  # 0x0001 => "tvINTV_LEFT_RP", #  left fence is right parenthesis
  # 0x0002 => "tvINTV_LEFT_LB", #  left fence is left bracket
  # 0x0003 => "tvINTV_LEFT_RB", #  left fence is right bracket
  # 0x0004 => "tvINTV_RIGHT_LP", # right fence is left parenthesis # WARNING: DOCUMENTATION SAYS 0x0000?
  # 0x0010 => "tvINTV_RIGHT_RP", # right fence is right parenthesis
  # 0x0020 => "tvINTV_RIGHT_LB", # right fence is left bracket
  # 0x0030 => "tvINTV_RIGHT_RB", # right fence is right bracket
  # Replaced above to match MathML translator
  8 => {
    0 => FENCE_BOTH
  },
  9 => {
    0 => FENCE_BOTH
  },
  10 => {
    0 => FENCE_BOTH
  },
  11 => {
    0 => FENCE_BOTH
  },
  12 => {
    0 => FENCE_BOTH
  },

  # Radicals (square and nth roots):
  13 => {
    0 => ["tvROOT_SQ"], # square root
    1 => ["tvROOT_NTH"] # nth root
  },

  # Fractions:
  14 => {
    #TODO: full-size slots?
    0 => ["tvFR_FULL"],
    1 => ["tvFR_SMALL"] #  subscript-size slots (piece fraction)
  },

  # Over and Underbars:
  16 => BAR_VARIATIONS,
  17 => BAR_VARIATIONS,

  # Arrows:
  18 => {
    0 => [
      "tvAR_SINGLE",
      "tvAR_LEFT",
      "tvAR_TOP",
    ], # single arrow
    1 => [
      "tvAR_SINGLE",
      "tvAR_LEFT",
      "tvAR_BOTTOM"
    ]
  },

  19 => {
    0 => [
      "tvAR_SINGLE",
      "tvAR_RIGHT",
      "tvAR_TOP"
    ],
    1 => [
      "tvAR_SINGLE",
      "tvAR_RIGHT",
      "tvAR_TOP"
    ]
  },

  20 => {
    0 => [
      "tvAR_SINGLE",
      "tvAR_RIGHT",
      "tvAR_LEFT",
      "tvAR_TOP"
    ],
    1 => [
      "tvAR_SINGLE",
      "tvAR_RIGHT",
      "tvAR_LEFT",
      "tvAR_TOP"
    ]
  },

  # Integrals (see Limit Variations):
  21 => {
    0 => [
      "tvINT_1" # single integral sign
    ],
    1 => [
      "tvINT_1",
      "tvBO_LOWER"
    ],
    2 => [
      "tvINT_1",
      "tvBO_LOWER",
      "tvBO_UPPER"
    ],
    3 => [
      "tvINT_1",
    ],
    4 => [
      "tvINT_1",
      "tvBO_LOWER"
    ]
  },

  22 => {
    0 => [
      "tvINT_2" # double integral sign
    ],
    1 => [
      "tvINT_2",
      "tvBO_LOWER"
    ],
    2 => [
      "tvINT_2",
      "tvBO_LOWER",
      "tvBO_UPPER"
    ],
    3 => [
      "tvINT_2",
    ],
    4 => [
      "tvINT_2",
      "tvBO_LOWER"
    ]
  },

  23 => {
    0 => [
      "tvINT_3" # triple integral sign
    ],
    1 => [
      "tvINT_3",
      "tvBO_LOWER"
    ],
    2 => [
      "tvINT_3",
      "tvBO_LOWER",
      "tvBO_UPPER"
    ],
    3 => ["tvINT_3"],
    4 => [
      "tvINT_3",
      "tvBO_LOWER"
    ]
  },

  24 => {
    0 => [
      "tvINT_1", # single integral sign
      "tvBO_SUM",
      "tvBO_LOWER",
      "tvBO_UPPER"
    ],
    1 => [
      "tvINT_1",
      "tvBO_SUM",
      "tvBO_LOWER"
    ],
    2 => [
      "tvINT_1",
      "tvBO_SUM",
      "tvBO_LOWER",
    ]
  },

  25 => {
    0 => [
      "tvINT_2", # double integral sign
      "tvBO_SUM",
      "tvBO_LOWER",
    ],
    1 => [
      "tvINT_2",
      "tvBO_SUM",
      "tvBO_LOWER"
    ]
  },

  26 => {
    0 => [
      "tvINT_3", # triple integral sign
      "tvBO_SUM",
      "tvBO_LOWER"
    ],
    1 => [
      "tvINT_3",
      "tvBO_SUM",
      "tvBO_LOWER"
    ]
  },

  # Horizontal braces and brackets:
  27 => {
    0 => ["tvHB_TOP"] # slot is on the top
  },

  28 => {
    #  default on the bottom
    0 => ["tvHB_BOT"]
  },

  # Sums, products, coproducts, unions, intersections, etc.:
  29 => {
    0 => [
      "tvBO_LOWER", # lower limit is present
      "tvBO_SUM" # summation-style limit positions,
    ],
    1 => [
      "tvBO_LOWER", # lower limit is present
      "tvBO_UPPER", # upper limit is present
      "tvBO_SUM"
    ],
    2 => ["tvBO_SUM"]
  },

  30 => {
    0 => [
      "tvBO_LOWER" # lower limit is present
    ],
    1 => [
      "tvBO_LOWER", # lower limit is present
      "tvBO_UPPER" # upper limit is present
    ]
  },

  31 => {
    0 => [
      "tvBO_LOWER", # lower limit is present
      "tvBO_SUM" # summation-style limit positions,
    ],
    1 => [
      "tvBO_LOWER", # lower limit is present
      "tvBO_UPPER", # upper limit is present
      "tvBO_SUM"
    ],
    2 => ["tvBO_SUM"]
  },

  32 => {
    0 => [
      "tvBO_LOWER" # lower limit is present
    ],
    1 => [
      "tvBO_LOWER", # lower limit is present
      "tvBO_UPPER" # upper limit is present
    ]
  },

  33 => {
    0 => [
      "tvBO_LOWER", # lower limit is present
      "tvBO_SUM" # summation-style limit positions,
    ],
    1 => [
      "tvBO_LOWER", # lower limit is present
      "tvBO_UPPER", # upper limit is present
      "tvBO_SUM"
    ],
    2 => ["tvBO_SUM"]
  },

  34 => {
    0 => [
      "tvBO_LOWER" # lower limit is present
    ],
    1 => [
      "tvBO_LOWER", # lower limit is present
      "tvBO_UPPER" # upper limit is present
    ]
  },

  35 => {
    0 => [
      "tvBO_LOWER", # lower limit is present
      "tvBO_SUM" # summation-style limit positions,
    ],
    1 => [
      "tvBO_LOWER", # lower limit is present
      "tvBO_UPPER", # upper limit is present
      "tvBO_SUM"
    ],
    2 => ["tvBO_SUM"]
  },

  36 => {
    0 => [
      "tvBO_LOWER" # lower limit is present
    ],
    1 => [
      "tvBO_LOWER", # lower limit is present
      "tvBO_UPPER" # upper limit is present
    ]
  },

  37 => {
    0 => [
      "tvBO_LOWER", # lower limit is present
      "tvBO_SUM" # summation-style limit positions,
    ],
    1 => [
      "tvBO_LOWER", # lower limit is present
      "tvBO_UPPER", # upper limit is present
      "tvBO_SUM"
    ],
    2 => ["tvBO_SUM"]
  },

  38 => {
    0 => [
      "tvBO_LOWER" # lower limit is present
    ],
    1 => [
      "tvBO_LOWER", # lower limit is present
      "tvBO_UPPER" # upper limit is present
    ]
  },

  39 => {
    0 => [
      "tvBO_UPPER" # upper limit is present
    ],
    1 => [
      "tvBO_LOWER" # lower limit is present
    ],
    2 => [
      "tvBO_LOWER", # lower limit is present
      "tvBO_UPPER" # upper limit is present
    ]
  },

  # Long division:
  40 => {
    0 => ["tvLD_UPPER"]
  },

  # Frac with Slash:
  41 => {
    0 => ["tvFR_SLASH"],
    1 => [
          "tvFR_SLASH",
          "tvFR_BASE"
         ],
    2 => [
          "tvFR_SLASH",
          "tvFR_SMALL"
         ]
  },

  # Big integral-style operators:
  42 => {
    0 => ["tvBO_LOWER"],
    1 => ["tvBO_UPPER"],
    2 => [
          "tvBO_LOWER",
          "tvBO_UPPER"
         ]
  },

  # Big summation-style operators:
  43 => {
    0 => [
          "tvBO_SUM",
          "tvBO_LOWER"
         ],
    1 => [
          "tvBO_SUM",
          "tvBO_UPPER"
         ],
    2 => [
          "tvBO_SUM",
          "tvBO_LOWER",
          "tvBO_UPPER"
         ]
  },

  44 => {
    0 => ["tvSU_PRECEDES"],
    1 => ["tvSU_PRECEDES"],
    2 => ["tvSU_PRECEDES"],
    3 => ["tvSU_PRECEDES"]
  },

  45 => {
    0 => [
          "tvDI_LEFT",
          "tvDI_RIGHT"
         ],
    1 => ["tvDI_LEFT"],
    2 => ["tvDI_RIGHT"]
  },

  46 => {
    0 => [
          "tvVE_UNDER",
          "tvVE_LEFT"
          ],
    1 => [
          "tvVE_UNDER",
          "tvVE_RIGHT"
          ],
    2 => [
          "tvVE_UNDER",
          "tvVE_LEFT",
          "tvVE_RIGHT"
          ],
  },

  47 => {
    0 => ["tvVE_LEFT"],
    1 => ["tvVE_RIGHT"],
    2 => [
          "tvVE_LEFT",
          "tvVE_RIGHT"
          ],
  },

  # Selectors with empty variation:
  15 => {0=>nil,1=>nil,2=>nil,3=>nil,4=>nil},
  48 => {0=>nil,1=>nil,2=>nil,3=>nil,4=>nil}
}
DIGIT_MODE_VARIATIONS =

When options overlap in the binary space, ordinary bitmasks are not the correct tool to use for detection. We use digit position and presence instead.

[9]

Instance Method Summary collapse

Methods included from Snapshot

#snapshot

Instance Method Details

#is_script(sel) ⇒ Object



744
745
746
# File 'lib/records3/tmpl.rb', line 744

def is_script(sel)
  return sel == 44 || sel == 15
end

#selectorObject



736
737
738
739
740
741
742
743
# File 'lib/records3/tmpl.rb', line 736

def selector
  if is_script _selector 
      #SCRIPT has to be handled separate
    SCRIPT_SELECTOR[_variation]
  else
    SELECTORS[_selector]
  end
end

#variationObject



747
748
749
# File 'lib/records3/tmpl.rb', line 747

def variation
  VARIATIONS[_selector][_variation]
end