In German typography, Sperrsatz (letterspacing) is the traditional way to emphasize text – as italics are in English.
The rules are:
The spacing between letters is increased (e.g. by 0.125em, standard)
The word spacing before and after the emphasized word is increased by the same amount
A compensating space equal to the tracking value is added before the first letter and after the last letter of the spaced text – but not before punctuation
Problem: tracking adds space after every letter except the last one. So the compensating space before the first letter and after the last letter is missing.
Problem: This adds the compensating space before the first letter, but also adds it after the last letter – which causes an unwanted gap after punctuation. That is, the tracking handles the punctuation correctly (so there is no additional space between a letter and punctuation), but after the punctuation the additional space is added.
Is there a way to achieve the correct Sperrsatz in Typst? Does anyone have a solution or workaround?
#set page(height: auto)
#set page(margin: 1em)
#set page(width: 20em)
#let ls(content) = {
set text(
tracking: 0.125em,
spacing: 125%
)
let sp = box(stroke: 0.25pt + yellow, height: .5em, h(0.125em))
let neg-sp = h(-0.125em)
//Add space before and after each word
show regex(`\w+`.text): word => box(stroke: 0.25pt + blue, [#sp#word#sp])
//Remove any spacing before punctuation
show regex(`\p{P}`.text): punctuation => box(stroke: 0.25pt + orange, [#neg-sp#punctuation])
box(
stroke: 0.25pt + red,
{
content
}
)
}
Fischer Fritz fischt #ls[fresche] Fisch.\
Fischer Fritz fischt fresche #ls[Fisch].\
Fischer Fritz fischt fresche #ls[Fisch.]\
Fischer Fritz fischt #ls[fresche Fisch].\
Fischer Fritz fischt #ls[fresche Fisch.]\
#ls[Fischer Fritz fischt fresche Fisch. Fischer Fritz fischt fresche Fisch.]\
Function without debugging:
#let ls(content, space-size: 0.125em) = {
set text(
tracking: space-size,
spacing: 125%
)
//Add space before and after each word
show regex(`\w+`.text): word => [#h(space-size)#word#h(space-size)]
//Remove any spacing before punctuation
show regex(`\p{P}`.text): punctuation => [#h(-space-size)#punctuation]
content
}