TypstDocumentation

text

Customize the look and layout of text in a variety of ways.

This function is used often, both with set rules and directly. While the set rule is often the simpler choice, calling the text function directly can be useful when passing text as an argument to another function.

Example

#set text(18pt)
With a set rule.

#emph(text(blue)[
  With a function call.
])
Preview

Parameters
Question mark

family
stringPositional
Question mark
Variadic
Question mark
Settable
Question mark

A prioritized sequence of font families.

When processing text, Typst tries all specified font families in order until it finds a font that has the necessary glyphs. In the example below, the font Inria Serif is preferred, but since it does not contain Arabic glyphs, the arabic text uses Noto Sans Arabic instead.

#set text(
  "Inria Serif",
  "Noto Sans Arabic",
)

This is Latin. \
هذا عربي.

Preview

body
contentRequiredPositional
Question mark

Content in which all text is styled according to the other arguments.

fallback
booleanSettable
Question mark

Whether to allow last resort font fallback when the primary font list contains no match. This lets Typst search through all available fonts for the most similar one that has the necessary glyphs.

Note: Currently, there are no warnings when fallback is disabled and no glyphs are found. Instead, your text shows up in the form of "tofus": Small boxes that indicate the lack of an appropriate glyph. In the future, you will be able to instruct Typst to issue warnings so you know something is up.

#set text(family: "Inria Serif")
هذا عربي

#set text(fallback: false)
هذا عربي
Preview

style
stringSettable
Question mark

The desired font style.

When an italic style is requested and only an oblique one is available, it is used. Similarly, the other way around, an italic style can stand in for an oblique one. When neither an italic nor an oblique style is available, Typst selects the normal style. Since most fonts are only available either in an italic or oblique style, the difference between italic and oblique style is rarely observable.

If you want to emphasize your text, you should do so using the emph function instead. This makes it easy to adapt the style later if you change your mind about how to signify the emphasis.

#text("IBM Plex Sans", style: "italic")[Italic]
#text("DejaVu Sans", style: "oblique")[Oblique]
Preview

weight
integerstringSettable
Question mark

The desired thickness of the font's glyphs. Accepts an integer between 100 and 900 or one of the predefined weight names. When the desired weight is not available, Typst selects the font from the family that is closest in weight.

If you want to strongly emphasize your text, you should do so using the strong function instead. This makes it easy to adapt the style later if you change your mind about how to signify the strong emphasis.

#text(weight: "light")[Light] \
#text(weight: "regular")[Regular] \
#text(weight: "medium")[Medium] \
#text(weight: 500)[Medium] \
#text(weight: "bold")[Bold]
Preview

stretch
ratioSettable
Question mark

The desired width of the glyphs. Accepts a ratio between 50% and 200%. When the desired weight is not available, Typst selects the font from the family that is closest in stretch.

#text(stretch: 75%)[Condensed] \
#text(stretch: 100%)[Normal]
Preview

size
lengthShorthand
Question mark
Settable
Question mark

The size of the glyphs. This value forms the basis of the em unit: 1em is equivalent to the font size.

You can also give the font size itself in em units. Then, it is relative to the previous font size.

#set text(size: 20pt)
very #text(1.5em)[big] text
Preview

fill
colorShorthand
Question mark
Settable
Question mark

The glyph fill color.

#set text(fill: red)
This text is red.
Preview

tracking
lengthSettable
Question mark

The amount of space that should be added between characters.

#set text(tracking: 1.5pt)
Distant text.
Preview

spacing
relative lengthSettable
Question mark

The amount of space between words.

Can be given as an absolute length, but also relative to the width of the space character in the font.

#set text(spacing: 200%)
Text with distant words.
Preview

baseline
lengthSettable
Question mark

An amount to shift the text baseline by.

A #text(baseline: 3pt)[lowered]
word.
Preview

overhang
booleanSettable
Question mark

Whether certain glyphs can hang over into the margin in justified text. This can make justification visually more pleasing.

#set par(justify: true)
In this particular text, the
justification produces a hyphen
in the first line. Letting this
hyphen hang slightly into the
margin makes for a clear
paragraph edge.

#set text(overhang: false)
In this particular text, the
justification produces a hyphen
in the first line. This time the
hyphen does not hang into the
margin, making the paragraph's
edge less clear.
Preview

top-edge
lengthstringSettable
Question mark

The top end of the conceptual frame around the text used for layout and positioning. This affects the size of containers that hold text.

#set rect(inset: 0pt)
#set text(size: 20pt)

#set text(top-edge: "ascender")
#rect(fill: aqua)[Typst]

#set text(top-edge: "cap-height")
#rect(fill: aqua)[Typst]
Preview

bottom-edge
lengthstringSettable
Question mark

The bottom end of the conceptual frame around the text used for layout and positioning. This affects the size of containers that hold text.

#set rect(inset: 0pt)
#set text(size: 20pt)

#set text(bottom-edge: "baseline")
#rect(fill: aqua)[Typst]

#set text(bottom-edge: "descender")
#rect(fill: aqua)[Typst]
Preview

lang
stringSettable
Question mark

An ISO 639-1/2/3 language code.

Setting the correct language affects various parts of Typst:

#set text(lang: "de")
#outline()

= Einleitung
In diesem Dokument, ...
Preview

region
nonestringSettable
Question mark

An ISO 3166-1 alpha-2 region code.

This lets the text processing pipeline make more informed choices.

dir
autodirectionSettable
Question mark

The dominant direction for text and inline objects. Possible values are:

When writing in right-to-left scripts like Arabic or Hebrew, you should set the text language or direction. While individual runs of text are automatically layouted in the correct direction, setting the dominant direction gives the bidirectional reordering algorithm the necessary information to correctly place punctuation and inline objects. Furthermore, setting the direction affects the alignment values start and end, which are equivalent to left and right in ltr text and the other way around in rtl text.

If you set this to rtl and experience bugs or in some way bad looking output, please do get in touch with us through the contact form or our Discord server!

#set text(dir: rtl)
هذا عربي.
Preview

hyphenate
autobooleanSettable
Question mark

Whether to hyphenate text to improve line breaking. When auto, text will be hyphenated if and only if justification is enabled.

Setting the text language ensures that the correct hyphenation patterns are used.

#set par(justify: true)
This text illustrates how
enabling hyphenation can
improve justification.

#set text(hyphenate: false)
This text illustrates how
enabling hyphenation can
improve justification.
Preview

kerning
booleanSettable
Question mark

Whether to apply kerning.

When enabled, specific letter pairings move closer together or further apart for a more visually pleasing result. The example below demonstrates how decreasing the gap between the "T" and "o" results in a more natural look. Setting this to false disables kerning by turning off the OpenType kern font feature.

#set text(size: 25pt)
Totally

#set text(kerning: false)
Totally
Preview

alternates
booleanSettable
Question mark

Whether to apply stylistic alternates.

Sometimes fonts contain alternative glyphs for the same codepoint. Setting this to true switches to these by enabling the OpenType salt font feature.

#set text(size: 20pt)
0, a, g, ß

#set text(alternates: true)
0, a, g, ß
Preview

stylistic-set
noneintegerSettable
Question mark

Which stylistic set to apply. Font designers can categorize alternative glyphs forms into stylistic sets. As this value is highly font-specific, you need to consult your font to know which sets are available. When set to an integer between 1 and 20, enables the corresponding OpenType font feature from ss01, ..., ss20.

ligatures
booleanSettable
Question mark

Whether standard ligatures are active.

Certain letter combinations like "fi" are often displayed as a single merged glyph called a ligature. Setting this to false disables these ligatures by turning off the OpenType liga and clig font features.

#set text(size: 20pt)
A fine ligature.

#set text(ligatures: false)
A fine ligature.
Preview

discretionary-ligatures
booleanSettable
Question mark

Whether ligatures that should be used sparingly are active. Setting this to true enables the OpenType dlig font feature.

historical-ligatures
booleanSettable
Question mark

Whether historical ligatures are active. Setting this to true enables the OpenType hlig font feature.

number-type
autostringSettable
Question mark

Which kind of numbers / figures to select. When set to auto, the default numbers for the font are used.

#set text(20pt, "Noto Sans")
#set text(number-type: "lining")
Number 9.

#set text(number-type: "old-style")
Number 9.
Preview

number-width
autostringSettable
Question mark

The width of numbers / figures. When set to auto, the default numbers for the font are used.

#set text(20pt, "Noto Sans")
#set text(number-width: "proportional")
A 12 B 34. \
A 56 B 78.

#set text(number-width: "tabular")
A 12 B 34. \
A 56 B 78.
Preview

slashed-zero
booleanSettable
Question mark

Whether to have a slash through the zero glyph. Setting this to true enables the OpenType zero font feature.

0, #text(slashed-zero: true)[0]
Preview

fractions
booleanSettable
Question mark

Whether to turns numbers into fractions. Setting this to true enables the OpenType frac font feature.

1/2 \
#text(fractions: true)[1/2]
Preview

features
arraydictionarySettable
Question mark

Raw OpenType features to apply.

// Enable the `frac` feature manually.
#set text(features: ("frac",))
1/2
Preview