How to reset par spacing back to default?

I changed paragraph spacing for a specific part of text with

#set par(spacing: 3em)

I want to switch back to default value used before, is there a way how to do it?

1 Like

Hi there,

You can limit the scope of the set rule with curly braces:

original spacing
#{
  set par(spacing: 3em)
  [new spacing]
} 
original spacing

See the docs Scripting – Typst Documentation for more information on blocks.

EDIT: Or switch to the default value (or the original value you had set before)

#set par(spacing: 1.2em)
1 Like

Hi, thanks, but what if I want to include large part of text over several pages? Do I have to wrap it all into brackets then, or is there a way how to go back to default?

I edited my initial reply. The default in the docs is 1.2em, unless you have changed it, you can revert to that.

Thank you, but do I need to look up the default value for each single parameter, e.g. font, text size etc.? I’m looking for a general solution.

There doesn’t seem to be a “reset to defaults” for everything, no. As far as I know, you either:

  • limit the scope of the set rule; or
  • change the value to the original value.

Note: You can always make use of #include for large part of text over several pages.

EDIT: You could always access the “previous” value and save it for future usage or reset purposes…

Current spacing : #context par.spacing

Beware of context returning content should you try to use this programmatically.

1 Like

That’s actually clever, thanks! I could potentially save all the relevant default values at the start of my document to variables to be able to return to them later, without the need to look the actual values manually.

Before you do that, arm yourself with patience. Saving to variables will be more complicated than reading it. As it will require you to learn how to handle things like state or metadata.

That sounds like a good idea for a package or something. Here’s a sketch…

#let save-text(to-state) = {
  to-state.update((
    font: text.font,
    size: text.size,
    style: text.style,
    // todo: the other text properties here
  ))
}

#let restore(from-state, subset: none, body) = {
  let values = from-state.get()
  if subset != none {
    values = values.pairs().filter(((k, v)) => k in subset).to-dict()
  }
  set text(..values)
  body
}

Abc
#context save-text(state("textconfig"))

#set text(font: "DejaVu Sans Mono", size: 2em, style: "italic")
Abc

#show: it => context restore(state("textconfig"), it, subset: (font: true, size: true))
Abc

4 Likes