Class: String

Inherits:
Object
  • Object
show all
Includes:
Polytexnic::Literal
Defined in:
lib/polytexnic/literal.rb

Constant Summary

Constants included from Polytexnic::Literal

Polytexnic::Literal::CODE_INCLUSION_REGEX, Polytexnic::Literal::LANG_REGEX

Instance Method Summary collapse

Methods included from Polytexnic::Literal

#cache_display_inline_math, #cache_display_math, #cache_inline_math, #cache_literal, #cache_literal_environments, #cache_unicode, #code_error, #code_language, #code_salt, #element, #equation_element, #hyperrefs, #include_code, #literal_types, #math_environments

Instance Method Details

#begin_literal?(literal_type = nil) ⇒ Boolean

Returns true if self matches begin… where … is a literal environment. Note: Support for the ‘metacode’ environment exists solely to allow meta-discussion of the ‘code’ environment.

Returns:

  • (Boolean)


352
353
354
355
356
357
# File 'lib/polytexnic/literal.rb', line 352

def begin_literal?(literal_type = nil)
  return false unless include?('\begin')
  literal_type ||= "(?:verbatim|Verbatim|code|metacode|" +
                   "#{math_environment_regex})"
  match(/^\s*\\begin{#{literal_type}}\s*$/)
end

#begin_math?Boolean

Returns true if self begins a math environment.

Returns:

  • (Boolean)


374
375
376
377
378
# File 'lib/polytexnic/literal.rb', line 374

def begin_math?
  return false unless include?('\begin')
  literal_type = "(?:#{math_environment_regex})"
  match(/^\s*\\begin{#{literal_type}}\s*$/)
end

#end_literal?(literal_type) ⇒ Boolean

Returns true if self matches end… where … is a literal environment.

Returns:

  • (Boolean)


360
361
362
363
# File 'lib/polytexnic/literal.rb', line 360

def end_literal?(literal_type)
  return false unless include?('\end')
  match(/^\s*\\end{#{Regexp.escape(literal_type)}}\s*$/)
end

#literal_typeObject

Returns the type of literal environment. ‘beginverbatim’ => ‘verbatim’ ‘beginequation’ => ‘equation’ ‘[’ => ‘display’



369
370
371
# File 'lib/polytexnic/literal.rb', line 369

def literal_type
  scan(/\\begin{(.*?)}/).flatten.first || 'display'
end

#math_environment?Boolean

Returns true if self matches a valid math environment.

Returns:

  • (Boolean)


381
382
383
# File 'lib/polytexnic/literal.rb', line 381

def math_environment?
  match(/(?:#{math_environment_regex})/)
end