Cropping text

From Wiki
Revision as of 16:29, 8 September 2005 by Mojca Miklavec (talk | contribs) (\underline has to be \underbar; you can simply paste some definitions at the top and remove them again after the new version is online)
Jump to navigation Jump to search

Cropping text

There are some rare cases in which it is useful to crop a given text line and loose part of its information.

Sometimes there is not enough room to show the complete (line of) text. In such a situation we can strip of some characters by using

\doboundtext {text} {width} {sentinel}

When the text is wider than the given width, it's split and the third argument (sentinel) is appended. As much text as possible is printed.

An example

\doboundtext{My entire inheritance goes to my beloved cat Pussy!}{70mm}{...}

and it's result


A bit more beautiful alternative for the previous command is \limitatetext. This command takes care of word boundaries, so that only complete words will appear in the final (cropped) text.

\limitatetext {text}  {width} {sentinel}
\limitatetext {text} {-width} {prelude}

When no width is given, the whole text becomes available. A negative value crops the beginning and the text starts with the prelude. Sentinel and prelude are optional.

Example:

\limitatetext {Pussy is the name of the cat!}{50mm}{...}\par
\limitatetext {Pussy is the name of the cat!}{-50mm}{...}

leads to


Both commands have their range of application. \limitatetext is more robust (using grouping tokens like \underbar is possible), while \doboundtext works better on text that cannot be hyphenated.

In ConTeXt versions newer than 07.09.2005 there is also a command called \limitatefirstline, which acts like \doboundtext, but at a more robust level.

\limitatefirstline {text} {width} {sentinel}

Example:

\limitatefirstline {\underbar{The garden's version of \CONTEXT is too old.}{65mm}{\unknown}