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::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_salt, #element, #equation_element, #hyperrefs, #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)


260
261
262
263
264
265
# File 'lib/polytexnic/literal.rb', line 260

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)


282
283
284
285
286
# File 'lib/polytexnic/literal.rb', line 282

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)


268
269
270
271
# File 'lib/polytexnic/literal.rb', line 268

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’



277
278
279
# File 'lib/polytexnic/literal.rb', line 277

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

#math_environment?Boolean

Returns true if self matches a valid math environment.

Returns:

  • (Boolean)


289
290
291
# File 'lib/polytexnic/literal.rb', line 289

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