Class: String
- Inherits:
-
Object
- Object
- String
- 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
-
#begin_literal?(literal_type = nil) ⇒ Boolean
Returns true if self matches begin… where …
-
#begin_math? ⇒ Boolean
Returns true if self begins a math environment.
-
#end_literal?(literal_type) ⇒ Boolean
Returns true if self matches end… where …
-
#literal_type ⇒ Object
Returns the type of literal environment.
-
#math_environment? ⇒ Boolean
Returns true if self matches a valid math environment.
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.
268 269 270 271 272 273 |
# File 'lib/polytexnic/literal.rb', line 268 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.
290 291 292 293 294 |
# File 'lib/polytexnic/literal.rb', line 290 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.
276 277 278 279 |
# File 'lib/polytexnic/literal.rb', line 276 def end_literal?(literal_type) return false unless include?('\end') match(/^\s*\\end{#{Regexp.escape(literal_type)}}\s*$/) end |
#literal_type ⇒ Object
Returns the type of literal environment. ‘beginverbatim’ => ‘verbatim’ ‘beginequation’ => ‘equation’ ‘[’ => ‘display’
285 286 287 |
# File 'lib/polytexnic/literal.rb', line 285 def literal_type scan(/\\begin{(.*?)}/).flatten.first || 'display' end |
#math_environment? ⇒ Boolean
Returns true if self matches a valid math environment.
297 298 299 |
# File 'lib/polytexnic/literal.rb', line 297 def math_environment? match(/(?:#{math_environment_regex})/) end |