One-liner is a package containing helper functions to fit text to the available width, without wrapping, by adjusting the text size based upon the context. This is useful in templates where you don’t know the length of text that is supposed to fit in specific locations in your template.
Example
The current version(0.3.0) one-liner contains 3 functions: fit-to-width that can used as follows:
#import "@preview/one-liner:0.3.0": fit-to-width
#block(
height: 3cm,
width: 10cm,
fill: luma(230),
inset: 8pt,
radius: 4pt,
align(horizon + center,fit-to-width(lorem(2))),
)
#block(
height: 3cm,
width: 10cm,
fill: luma(230),
inset: 8pt,
radius: 4pt,
align(horizon + center,grow-to-width(lorem(2))),
)
#block(
height: 3cm,
width: 10cm,
fill: luma(230),
inset: 8pt,
radius: 4pt,
align(horizon + center,shrink-to-width(lorem(2))),
)
Here we have a block of specific dimensions. Using fit-to-width will change the font-size of the content passed to fit-to-width so it will fit the full width without wrapping the content.

CAUTION
This package currently only works for target paged(for PDF, PNG, and SVG export). Target HTML will result in an empty div element
fit-to-width function
Besides content the function has two parameters:
max-text-size of type length. It has a default of 3 times the current text size. When fit-to-width is limited by the max-text-size you will see that not the entire width of space will be used.
min-text-size of type length. It has a default of 0.33 times the current text size. When fit-to-width is limited by the min-text-size you will see that the text will wrap, because the min-text-size is bigger than the size that would be required to prevent wrapping.
Changelog
0.3.0
- changed the default values of max-text-size and min-text-size to a relative of current text-size instead of fixed pt sizes.
- added functions shrink-to-width and grow-to-width
0.2.0
- Also take available height into consideration when calculating scale ratio.
0.1.0
- Initial version
Disclaimer
This package was only tested in a few of my own documents and only to fit text. Not tested with other content yet.