WrapText - Maple Help

StringTools

 WrapText
 wrap long lines of text

 Calling Sequence WrapText( text, width, opts  )

Parameters

 text - string; Maple string width - posint; (optional) width opts - options

Description

 • The WrapText(text, width) calling sequence attempts to wrap long lines in the string text to a specified width width by inserting line breaks in the text to break lines longer than width bytes. Line breaks inserted by the command are inserted between "words" in the input; a word is defined to be a maximal contiguous sequence of non-space characters. Any word longer than width is not broken, but appears on a line by itself in the output.
 • The width argument is optional, and is equal to $80$ by default. It must be a positive integer.
 • Tab characters in the input string text are expanded, by default. An option of the form tabs = n or tabs = loi may be passed to control tab expansion, where n is a positive integer and loi is a strictly increasing sequence of positive integers. See StringTools[ExpandTabs].
 • The obeylines option controls whether WrapText will respect newlines present in the input.  If obeylines = true is passed, then newlines in the input text are preserved in the output.  The default is obeylines = false.
 • The obeyspaces option controls whether space characters in the input are preserved in the output.  By default, where obeyspaces = false, contiguous sequences of space characters are replaced by a single space.
 • The expandtabs option controls whether TAB characters ("\t") are expanded as spaces or output literally.  The default is expandtabs = true.
 • Note that if text has length less than or equal to width, it is returned unchanged if none of the obeylines, obeyspaces and expandtabs options are set.
 • All of the StringTools package commands treat strings as (null-terminated) sequences of $8$-bit (ASCII) characters.  Thus, there is no support for multibyte character encodings, such as unicode encodings.

Examples

 > $\mathrm{with}\left(\mathrm{StringTools}\right):$
 > $\mathrm{WrapText}\left("To break a string into 20 byte lines, use this command.",20\right)$
 ${"To break a string into 20 byte lines, use this command."}$ (1)

Note the effect of the obeylines option.

 > $\mathrm{WrapText}\left("This text\ncontains newlines\nthat may or may not\nbe respected",30\right)$
 ${"This text contains newlines that may or may not be respected"}$ (2)
 > $\mathrm{WrapText}\left("This text\ncontains newlines\nthat may or may not\nbe respected",30,'\mathrm{obeylines}'\right)$
 ${"This text contains newlines that may or may not be respected"}$ (3)

Again, the obeyspaces option causes some differences in output as illustrated here:

 > $\mathrm{WrapText}\left("a b",10\right)$
 ${"a b"}$ (4)
 > $\mathrm{WrapText}\left("a b",10,'\mathrm{obeyspaces}'\right)$
 ${"a b"}$ (5)