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, #math_environments_starred

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)


270
271
272
273
274
275
# File 'lib/polytexnic/literal.rb', line 270

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)


292
293
294
295
296
# File 'lib/polytexnic/literal.rb', line 292

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)


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

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’



287
288
289
# File 'lib/polytexnic/literal.rb', line 287

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

#math_environment?Boolean

Returns true if self matches a valid math environment.

Returns:

  • (Boolean)


299
300
301
# File 'lib/polytexnic/literal.rb', line 299

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

#starred?Boolean

Returns true if the environment is starred.

Returns:

  • (Boolean)


304
305
306
# File 'lib/polytexnic/literal.rb', line 304

def starred?
  self[-2..-1] == '*}'
end