Scale long line of text down

There are two ways to handle text which is longer than a certain width when you don’t want to start a new line.

The first method is to scale the text down when it exceeds a certain length, you can set the limit for your text with the maxwidth key for the \scale command.

\setuplayout[width=8cm]

\starttext

\scale[maxwidth=\textwidth]{Short title.}

\scale[maxwidth=\textwidth]{A very very very very very very very very very very very long title.}

\stoptext

Use of the \scale command to limit the text width.

The second method is cut the text after a certain length with the \limitatetext command and display a text or symbol which indicates the rest of the text.

\setuplayout[width=8cm]

\starttext

\limitatetext{Short title.}{\textwidth}{\unknown}

\limitatetext{A very very very very very very very very very very very long title.}{\textwidth}{\unknown}

\stoptext

Use of the \limitatetext command to limit the text width.


Note: Metafox's answer is better. Use that instead.

Here is a basic implementation of Barbara's idea:

\define[1]\ScaleToTextwidth
    {\setbox\scratchbox\hbox{#1}%
     \ifdim\wd\scratchbox>\textwidth%
        \scale[width=\textwidth]{\unhbox\scratchbox}%
     \else
       \unhbox\scratchbox
    \fi}

\starttext
\ScaleToTextwidth{Ward}

\ScaleToTextwidth{\input ward\endgraf}

\stoptext

which gives

enter image description here

I scaled everything to \textwdith; if you wish, you can keep that configurable as well.

Tags:

Context