Changes

Jump to navigation Jump to search
4,522 bytes added ,  12:26, 14 September 2017
add link to \startTEXpage
< [[Visuals]] |
 
== Cropping text ==
There are some rare cases in which it is useful to crop truncate a givenline of text line and loose part discard some of its informationit.
=== <tt>\doboundtext</tt> ===
Sometimes there is not enough room to show the complete
(line of) text. In such a situation we can strip of some
argument (<tt>sentinel</tt>) is appended. As much text as possible is printed.
An example:
<texcode>
\framed{\doboundtext{My entire inheritance goes to my beloved cat Pussy!}{62mm60mm}{...}}
</texcode>
 
and it's result
<context>
\framed{ss\x\doboundtext{My entire inheritance goes to my beloved cat Pussy!}{62mm60mm}{...}}
</context>
=== <tt>\limitatetext</tt> ===
A bit more beautiful alternative for the previous command is <tt>\limitatetext</tt>.
This command takes care of '''word''' boundaries, so that only complete words will
\limitatetext {text} {width} {sentinel}
\limitatetext {text} {-width} {prelude}
\limitatetext {text} {width1 , width2} {symbol}
</texcode>
When no <tt>width</tt> is given, the whole <tt>text</tt> becomes available.
A negative value crops the beginning and the text starts with
the <tt>prelude</tt>. Sentinel and prelude are both optional.Just look at the example, to see what happens, if you call the macro withtwo positive dimensions...
Example:
<texcode>
\framedlimitatetext {Pussy is the name of the cat!}{38mm}{...}\par\limitatetext {Pussy is the name of the cat!}{50mm-38mm}{...}}\par\framed{\limitatetext {Pussy is the name of the cat!}{-50mm12mm, 12mm}{...}}
</texcode>
 
leads to
<context>
\framedlimitatetext {\ss\x Pussy is the name of the cat!}{38mm}{...}\par\limitatetext {\ss\x Pussy is the name of the cat!}{50mm-38mm}{...}}\par\framedlimitatetext {\limitatetext {ss\x Pussy is the name of the cat!}{-50mm10mm, 10mm}{...}}
</context>
Both commands have their range of application.
<tt>\limitatetext</tt> is more robust(using grouping tokens like<tt>\underbar</tt> is possible), while <tt>\doboundtext</tt> worksbetterbetter on text that cannot be hyphenated. === <tt>\limitatefirstline</tt> ===In ConTeXt versions newer than 07.09.2005 there is also a commandcalled <tt>\limitatefirstline</tt>, which acts nearly like <tt>\doboundtext</tt>,but at a more robust level. This macro first tries to break the given textat character level. It uses nearly the same breaking mechanism as <tt>\limitatetext</tt>,so it shares the problem with nonbreakable text.But in contrast to <tt>\limitatetext</tt> it has a second mechanism, that is only used,if the prior one fails or if the result of breaking is wasting too much space.This fail safe mechanism "simply" clips (no breaking at all) the text to the desiredmeasures. This is done without any consideration to character boundaries.So you must live with the fact, that the last character can be cut off at any possibleplace. <texcode>\limitatefirstline {text} {width} {sentinel}</texcode> Example: <texcode>\limitatefirstline {\underbar{Mr.~Drofnats was happiest when he was at work% typesetting beautiful documents.}{109mm}{\unknown}</texcode>  <context>\unprotect  \def\limitatefirstline#1#2#3% {\hbox\bgroup\strut\dontcomplain \setbox\scratchbox\hbox{\begstrut#1\endstrut}% \ifdim\wd\scratchbox>#2\relax \setbox\scratchbox\hbox{#3}% \hsize#2\relax \advance\hsize-\wd\scratchbox \setbox\scratchbox\vbox{\forgetall\veryraggedright#1}% \setbox\scratchbox\vsplit\scratchbox to \lineheight \vbox {\unvbox\scratchbox \global\setbox\plusone\lastbox \global\setbox\plusone\hbox{\strut\unhbox\plusone}% \hbox % to #2 {\ifx\clip\undefined \box\plusone \else\ifdim\wd\plusone>\hsize \lower\strutdepth\hbox{\clip[\c!width=\hsize,\c!height=\lineheight]{\hbox{\raise\strutdepth\box\plusone}}}% \else\ifdim\wd\plusone<\dimexpr\hsize-6ex\relax% tolerance for "successful" breaking \lower\strutdepth\hbox{\clip[\c!width=\hsize,\c!height=\lineheight]{\hbox{\raise\strutdepth\hbox{\begstrut#1\endstrut}}}}% \else \box\plusone \fi\fi\fi \removeunwantedspaces#3}}% \removeunwantedspaces\hss#3}}% \else #1% \fi \egroup} \protect  \limitatefirstline {\ss\x\underbar{Mr.~Drofnats was happiest when he was at work typesetting beautiful documents.}}{107mm}{\unknown}</context>  In this example breaking is successful (right after the word typesetting),but the gap between the breaking point and the given width is too big.So clipping is used here. === A direct comparison === {| border="0" cellpadding="5" cellspacing="0"||It's all in the garden.|0123456789|\underbar{In a bar, under the sea}|-|<tt>'''\doboundtext'''</tt>|<context>\ss\x\doboundtext{It's all in the garden.}{30mm}{...}</context>|<context>\ss\x\doboundtext{0123456789}{15mm}{...}</context>|align=center|not possible|-|<tt>'''\limitatetext'''</tt>|<context>\ss\x\limitatetext{It's all in the garden.}{30mm}{...}</context>|<context>\ss\x\limitatetext{0123456789}{15mm}{...}</context>|<context>\ss\x\limitatetext{\underbar{In a bar, under the sea}}{31mm}{...}</context>|-|<tt>'''\limitatefirstline'''</tt>|<context>\ss\x\limitatefirstline{It's all in the garden.}{30mm}{\red...}</context>|<context>\ss\x\limitatefirstline{0123456789}{15mm}{...}</context>|<context>\ss\x\limitatefirstline{\underbar{In a bar, under the sea}}{31mm}{...}</context>|} == Fitting text ==You can fit text into a box by: <texcode>\def\HowStrange#1{#1\ifx#1\blankspace\else\allowbreak\fi} \framed [width=2cm,align={normal,verytolerant,stretch}] {\handletokens There are some rather long titles that needs to be typeset.\with\HowStrange}</texcode> <context>\def\HowStrange#1{#1\ifx#1\blankspace\else\allowbreak\fi} \framed [width=2cm,align={normal,verytolerant,stretch}] {\handletokens There are some rather long titles that needs to be typeset.\with\HowStrange}</context> There is also similar facility for verbatim text in [[Verbatim_with_line_breaks]] section. == See also == * If you meant to crop a page ''to'' some text, see {{cmd|startTEXpage}}
TODO: <tt>\limitatefirstline</tt>{{Getting started navbox}}

Navigation menu