Difference between revisions of "Cropping text"

From Wiki
Jump to navigation Jump to search
 
Line 14: Line 14:
 
argument (<tt>sentinel</tt>) is appended. As much text as possible is printed.
 
argument (<tt>sentinel</tt>) is appended. As much text as possible is printed.
  
An example:
+
An example
  
 
<texcode>
 
<texcode>
\framed{\doboundtext{My entire inheritance goes to my cat Pussy!}{62mm}{...}}
+
\doboundtext{My entire inheritance goes to my beloved cat Pussy!}{70mm}{...}
 
</texcode>
 
</texcode>
 +
 +
and it's result
  
 
<context>
 
<context>
\framed{\doboundtext{My entire inheritance goes to my cat Pussy!}{62mm}{...}}
+
\doboundtext{My entire inheritance goes to my beloved cat Pussy!}{70mm}{...}
 
</context>
 
</context>
  
Line 41: Line 43:
  
 
<texcode>
 
<texcode>
\framed{\limitatetext {Pussy is the name of the cat!}{50mm}{...}}
+
\limitatetext {Pussy is the name of the cat!}{50mm}{...}\par
\framed{\limitatetext {Pussy is the name of the cat!}{-50mm}{...}}
+
\limitatetext {Pussy is the name of the cat!}{-50mm}{...}
 
</texcode>
 
</texcode>
 +
 +
leads to
  
 
<context>
 
<context>
\framed{\limitatetext {Pussy is the name of the cat!}{50mm}{...}}
+
\limitatetext {Pussy is the name of the cat!}{50mm}{...}\par
\framed{\limitatetext {Pussy is the name of the cat!}{-50mm}{...}}
+
\limitatetext {Pussy is the name of the cat!}{-50mm}{...}
 
</context>
 
</context>
  
  
 
Both commands have their range of application.
 
Both commands have their range of application.
<tt>\limitatetext</tt> is more robust, <tt>\doboundtext</tt> works
+
<tt>\limitatetext</tt> is more robust (using grouping tokens like
better on text that cannot be hyphenated.
+
<tt>\underbar</tt> is possible), while <tt>\doboundtext</tt> works better
 +
on text that cannot be hyphenated.
 +
 
 +
In ConTeXt versions newer than 07.09.2005 there is also a command
 +
called <tt>\limitatefirstline</tt>, which acts like <tt>\doboundtext</tt>,
 +
but at a more robust level.
  
TODO: <tt>\limitatefirstline</tt>
+
<texcode>
 +
\limitatefirstline {text} {width} {sentinel}
 +
</texcode>
 +
 
 +
Example:
 +
 
 +
<texcode>
 +
\limitatefirstline {\underline{The gardens version of \CONTEXT is too old.}{65mm}{\unknown}
 +
</texcode>
 +
 
 +
<context>
 +
\limitatefirstline {\underline{The gardens version of \CONTEXT is too old.}}{65mm}{\unknown}
 +
</context>

Revision as of 08:11, 8 September 2005

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 {\underline{The gardens version of \CONTEXT is too old.}{65mm}{\unknown}