Module: Tioga::Utils
- Defined in:
- lib/Tioga/Utils.rb
Overview
The Utils module contains some useful functions that can help Tioga users. They are not strictly speaking part of the graphical library, but provides functionnalities Tioga users will certainly need at some point.
Constant Summary collapse
- DIMENSION_CONVERSION =
Dimension conversion constants taken straight from the TeXbook
{ "pt" => (72.0/72.27), "bp" => 1.0, "in" => 72.0, "cm" => (72.0/2.54), "mm" => (72.0/25.4), }
Class Method Summary collapse
-
.tex_dimension_to_bp(dim) ⇒ Object
Returns the value of the given TeX dimension in postscript points.
-
.tex_quote_text(text) ⇒ Object
This function returns a string that is suitable for inclusion in a TeX document: all nasty characters are escaped properly.
Instance Method Summary collapse
Class Method Details
.tex_dimension_to_bp(dim) ⇒ Object
Returns the value of the given TeX dimension in postscript points.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/Tioga/Utils.rb', line 64 def self.tex_dimension_to_bp(dim) for unit, val in DIMENSION_CONVERSION if dim =~ /^\s*([+-]?[\d.]+)\s*#{unit}$/ return $1.to_f * val end end # We take it to be centimeters by default ???? if dim =~ /^\s*([+-]?[\d.]+)\s*$/ warn "tex_dimension_to_bp: No dimension was specified, " + "using centimeters" return $1.to_f * DIMENSION_CONVERSION["cm"] end raise "'#{dim}' is not a valid TeX dimension" end |
.tex_quote_text(text) ⇒ Object
This function returns a string that is suitable for inclusion in a TeX document: all nasty characters are escaped properly. It will not work however if you redefine TeX character classes, but then you should know what you’re doing.
39 40 41 42 43 44 45 |
# File 'lib/Tioga/Utils.rb', line 39 def tex_quote_text(text) a = text.gsub("\\", "\\BS") a.gsub!(/([{}$%#_^~])/) do "\\#{$1}" end return a end |
Instance Method Details
#tex_dimension_to_bp(dim) ⇒ Object
79 80 81 |
# File 'lib/Tioga/Utils.rb', line 79 def tex_dimension_to_bp(dim) return Utils::tex_dimension_to_bp(dim) end |