Class: String
- Inherits:
-
Object
- Object
- String
- Includes:
- Polytexnic::Literal
- Defined in:
- lib/polytexnic/literal.rb
Constant Summary
Constants included from Polytexnic::Literal
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.
-
#starred? ⇒ Boolean
Returns true if the environment is starred.
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.
271 272 273 274 275 276 |
# File 'lib/polytexnic/literal.rb', line 271 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.
293 294 295 296 297 |
# File 'lib/polytexnic/literal.rb', line 293 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.
279 280 281 282 |
# File 'lib/polytexnic/literal.rb', line 279 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’
288 289 290 |
# File 'lib/polytexnic/literal.rb', line 288 def literal_type scan(/\\begin{(.*?)}/).flatten.first || 'display' end |
#math_environment? ⇒ Boolean
Returns true if self matches a valid math environment.
300 301 302 |
# File 'lib/polytexnic/literal.rb', line 300 def math_environment? match(/(?:#{math_environment_regex})/) end |
#starred? ⇒ Boolean
Returns true if the environment is starred.
305 306 307 |
# File 'lib/polytexnic/literal.rb', line 305 def starred? self[-2..-1] == '*}' end |