1textutil::adjust(n)Text and string utilities, macro processintgextutil::adjust(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       textutil::adjust - Procedures to adjust, indent, and undent paragraphs
9

SYNOPSIS

11       package require Tcl  8.2
12
13       package require textutil::adjust  ?0.7.3?
14
15       ::textutil::adjust::adjust string ?option value...?
16
17       ::textutil::adjust::readPatterns filename
18
19       ::textutil::adjust::listPredefined
20
21       ::textutil::adjust::getPredefined filename
22
23       ::textutil::adjust::indent string prefix ?skip?
24
25       ::textutil::adjust::undent string
26
27______________________________________________________________________________
28

DESCRIPTION

30       The  package textutil::adjust provides commands that manipulate strings
31       or texts (a.k.a. long strings or string with embedded newlines or para‐
32       graphs), adjusting, or indenting them.
33
34       The complete set of procedures is described below.
35
36       ::textutil::adjust::adjust string ?option value...?
37              Do  a justification on the string according to the options.  The
38              string is taken as one big  paragraph,  ignoring  any  newlines.
39              Then  the  line  is formatted according to the options used, and
40              the command returns a new string with enough  lines  to  contain
41              all  the printable chars in the input string. A line is a set of
42              characters between the beginning of the string and a newline, or
43              between  2  newlines,  or  between  a newline and the end of the
44              string. If the input string is small enough, the returned string
45              won't contain any newlines.
46
47              Together  with ::textutil::adjust::indent it is possible to cre‐
48              ate properly wrapped paragraphs with arbitrary indentations.
49
50              By default, any occurrence of space or tabulation characters are
51              replaced  by a single space so that each word in a line is sepa‐
52              rated from the next one by exactly one space character, and this
53              forms  a real line.  Each real line is placed in a logical line,
54              which has exactly a given length (see the option -length below).
55              The  real line may be shorter. Again by default, trailing spaces
56              are ignored before returning the string (see  the  option  -full
57              below).
58
59              The  following  options  may be used after the string parameter,
60              and change the way the command places a real line in  a  logical
61              line.
62
63              -full boolean
64                     If  set to false (default), trailing space characters are
65                     deleted before returning the string. If set to true,  any
66                     trailing space characters are left in the string.
67
68              -hyphenate boolean
69                     If  set  to false (default), no hyphenation will be done.
70                     If set to true, the command will  try  to  hyphenate  the
71                     last  word  of a line. Note: Hyphenation patterns must be
72                     loaded prior, using the command ::textutil::adjust::read‐
73                     Patterns.
74
75              -justify center|left|plain|right
76                     Sets  the  justification of the returned string to either
77                     left (default), center, plain or right. The justification
78                     means  that  any line in the returned string but the last
79                     one is build according to the value.  If  the  justifica‐
80                     tion is set to plain and the number of printable chars in
81                     the last line is less than 90% of the length  of  a  line
82                     (see  the  option  -length),  then this line is justified
83                     with the left value, avoiding the expansion of this  line
84                     when it is too small. The meaning of each value is:
85
86                     center The  real line is centered in the logical line. If
87                            needed, a set of space characters are added at the
88                            beginning  (half of the needed set) and at the end
89                            (half of the needed set) of the line  if  required
90                            (see the option -full).
91
92                     left   The  real  line  is set on the left of the logical
93                            line. It means that there are no  space  chars  at
94                            the  beginning  of  this  line.  If  required, all
95                            needed space chars are added at  the  end  of  the
96                            line (see the option -full).
97
98                     plain  The  real line is exactly set in the logical line.
99                            It means that there are  no  leading  or  trailing
100                            space  chars. All the needed space chars are added
101                            in the real line, between 2 (or more) words.
102
103                     right  The real line is set on the right of  the  logical
104                            line.  It  means  that there are no space chars at
105                            the end of this line, and there may be some  space
106                            chars  at  the  beginning,  despite  of  the -full
107                            option.
108
109              -length integer
110                     Set the length of the logical line in the string to inte‐
111                     ger.   integer must be a positive integer value. Defaults
112                     to 72.
113
114              -strictlength
115                     boolean] If set to false (default), a line can exceed the
116                     specified  -length  if  a  single  word  is  longer  than
117                     -length. If set to  true,  words  that  are  longer  than
118                     -length  are  split so that no line exceeds the specified
119                     -length.
120
121       ::textutil::adjust::readPatterns filename
122              Loads the internal storage for  hyphenation  patterns  with  the
123              contents  of  the  file  filename.  This has to be done prior to
124              calling  command  ::textutil::adjust::adjust  with   "-hyphenate
125              true", or the hyphenation process will not work correctly.
126
127              The package comes with a number of predefined pattern files, and
128              the command ::textutil::adjust::listPredefined can  be  used  to
129              find out their names.
130
131       ::textutil::adjust::listPredefined
132              This  command returns a list containing the names of the hyphen‐
133              ation files coming with this package.
134
135       ::textutil::adjust::getPredefined filename
136              Use this command to query the package for the full path name  of
137              the  hyphenation file filename coming with the package. Only the
138              filenames   found   in   the   list   returned    by    ::textu‐
139              til::adjust::listPredefined  are  legal  arguments for this com‐
140              mand.
141
142       ::textutil::adjust::indent string prefix ?skip?
143              Each line in the string is indented by adding the string  prefix
144              at  its beginning. The modified string is returned as the result
145              of the command.
146
147              If skip is specified the first skip lines  are  left  untouched.
148              The  default  for  skip  is  0,  causing the modification of all
149              lines. Negative values for skip are treated  like  0.  In  other
150              words, skip > 0 creates a hanging indentation.
151
152              Together  with ::textutil::adjust::adjust it is possible to cre‐
153              ate properly wrapped paragraphs with arbitrary indentations.
154
155       ::textutil::adjust::undent string
156              The command computes the common prefix for all lines  in  string
157              consisting solely out of whitespace, removes this from each line
158              and returns the modified string.
159
160              Lines containing only whitespace  are  always  reduced  to  com‐
161              pletely  empty lines. They and empty lines are also ignored when
162              computing the prefix to remove.
163
164              Together with ::textutil::adjust::adjust it is possible to  cre‐
165              ate properly wrapped paragraphs with arbitrary indentations.
166

BUGS, IDEAS, FEEDBACK

168       This  document,  and the package it describes, will undoubtedly contain
169       bugs and other problems.  Please report such in the  category  textutil
170       of  the Tcllib Trackers [http://core.tcl.tk/tcllib/reportlist].  Please
171       also report any ideas for enhancements you may have for either  package
172       and/or documentation.
173
174       When proposing code changes, please provide unified diffs, i.e the out‐
175       put of diff -u.
176
177       Note further that  attachments  are  strongly  preferred  over  inlined
178       patches.  Attachments  can  be  made  by  going to the Edit form of the
179       ticket immediately after its creation, and  then  using  the  left-most
180       button in the secondary navigation bar.
181

SEE ALSO

183       regexp(n), split(n), string(n)
184

KEYWORDS

186       TeX,  adjusting,  formatting,  hyphenation,  indenting,  justification,
187       paragraph, string, undenting
188

CATEGORY

190       Text processing
191
192
193
194tcllib                               0.7.3                 textutil::adjust(n)
Impressum