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 op‐
107                            tion.
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 boolean
115                     If set to false (default), a line can exceed  the  speci‐
116                     fied  -length if a single word is longer than -length. If
117                     set to true, words that are longer than -length are split
118                     so that no line exceeds the specified -length.
119
120       ::textutil::adjust::readPatterns filename
121              Loads  the  internal  storage  for hyphenation patterns with the
122              contents of the file filename. This has  to  be  done  prior  to
123              calling   command  ::textutil::adjust::adjust  with  "-hyphenate
124              true", or the hyphenation process will not work correctly.
125
126              The package comes with a number of predefined pattern files, and
127              the  command  ::textutil::adjust::listPredefined  can be used to
128              find out their names.
129
130       ::textutil::adjust::listPredefined
131              This command returns a list containing the names of the hyphena‐
132              tion files coming with this package.
133
134       ::textutil::adjust::getPredefined filename
135              Use  this command to query the package for the full path name of
136              the hyphenation file filename coming with the package. Only  the
137              filenames   found   in  the  list  returned  by  ::textutil::ad‐
138              just::listPredefined are legal arguments for this command.
139
140       ::textutil::adjust::indent string prefix ?skip?
141              Each line in the string is indented by adding the string  prefix
142              at  its beginning. The modified string is returned as the result
143              of the command.
144
145              If skip is specified the first skip lines  are  left  untouched.
146              The  default  for  skip  is  0,  causing the modification of all
147              lines. Negative values for skip are treated  like  0.  In  other
148              words, skip > 0 creates a hanging indentation.
149
150              Together  with ::textutil::adjust::adjust it is possible to cre‐
151              ate properly wrapped paragraphs with arbitrary indentations.
152
153       ::textutil::adjust::undent string
154              The command computes the common prefix for all lines  in  string
155              consisting solely out of whitespace, removes this from each line
156              and returns the modified string.
157
158              Lines containing only whitespace  are  always  reduced  to  com‐
159              pletely  empty lines. They and empty lines are also ignored when
160              computing the prefix to remove.
161
162              Together with ::textutil::adjust::adjust it is possible to  cre‐
163              ate properly wrapped paragraphs with arbitrary indentations.
164

BUGS, IDEAS, FEEDBACK

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

SEE ALSO

181       regexp(n), split(n), string(n)
182

KEYWORDS

184       TeX,  adjusting,  formatting,  hyphenation,  indenting,  justification,
185       paragraph, string, undenting
186

CATEGORY

188       Text processing
189
190
191
192tcllib                               0.7.3                 textutil::adjust(n)
Impressum