| Class TeX::Hyphen |
|
TeX::Hyphen -- hyphenate words using TeX's patterns
require 'tex/hyphen'
hyp = TeX::Hyphen.new(:file => 'hyphen.tex', :style => 'czech',
:leftmin => 2, :rightmin => 2)
hyp = TeX::Hyphen.new
word = "representation"
points = hyp.hyphenate(word) #=> [3, 5, 8, 10]
puts hyp.visualize(word) #=> rep-re-sen-ta-tion
Constructor new() creates a new Hyphen object and loads the file with patterns into memory. Then you can ask it for hyphenation of a word by calling a method of this object. If no file is specified, the default Donald E. Knuth's hyphen.tex, that is included in this module, is used instead.
| Copyright: | Copyright (c) 2003 Martin DeMello and Austin Ziegler |
| Version: | 0.2 |
| Based On: | Perl's TeX::Hyphen [search.cpan.org/author/JANPAZ/TeX-Hyphen-0.140/lib/TeX/Hyphen.pm] Copyright (c) 1997--2002 Jan Pazdziora |
| Licence: | Ruby's |
| Methods |
| Attributes |
| :min_left | [RW] | Allows modification of the minimal starting substring for hyphenation. |
| :min_right | [RW] | Allows modification of the minimal ending substring for hyphenation. |
| Classes and Modules |
| Public Class methods |
| new(arg = nil, &block) |
A TeX hyphenation object can be constructed using a few different calling methods. Any method may also take a constructor block, allowing direct access to @file, @style, @min_left, and @min_right.
arg may be one of Array, Hash, String, or nil:
:file (or: 'file')
:style (or: 'style')
:min_left (or: :leftmin, 'min_left', 'leftmin')
:min_right (or: :rightmin, 'min_right', 'rightmin')
The parameters are:
will be loaded and the resulting object will be able to
hyphenate according to patterns in that file. If the
file is not specified or is +nil+, the default
hyphen.tex will be used (and is included in the module
definition).
patterns. Instead of doing the full TeX expansion, we
use Ruby code to parse the patterns. The style options
requires a module found at "tex/hyphen/#{@style}" and
uses the parsing functions found in it.
Currently, the default Czech (works for English as
well) and German are available. See TeX::Hyphen::Czech
for more information, especially if you want to support
other languages and styles.
hyphenated. This overrides the default specified in the
style file.
hyphenated. This overrides the default specified int he
style file.
| Reference: | "Object Construction and Blocks" <www.pragmaticprogrammer.com/ruby/articles/insteval.html> |
| Public Instance methods |
| hyphenate(word) |
Returns a list of places where the word can be divided, as
hyp.hyphenate('representation')
returns [3, 5, 8, 10].
| visualise(word) |
Returns a visualization of the hyphenation points, so:
hyp.visualize('representation')
should return rep-re-sen-ta-tion, at elast for English patterns.
| hyphenate_to(word, size) |
This function will hyphenate a word