t

titleize

@preview

Turn strings into title case

v0.1.1
MIT

Package Information

Last Updated
Categories
textscriptingutility

1. Get the package

Download the package using the TPIX CLI:

tpix get @preview/titleize:0.1.1

2. Import in your Typst file

Add this to your .typ file:

#import "@preview/titleize:0.1.1": *

Version History

0.1.1
7fb4f4fbe15d...
0.1.0
2f6e5df0c19c...

titleize

Small wrapper around the titlecase library to convert text to title case.
It follows the rules defined by John Gruber.
For more details, refer to the library.

titlecase applies a show rule, that by default transforms every string of at least four characters.
This limit can be changed with the limit parameter.
Especially with equations, the results can be a bit unpredictable, so proceed with care.

#import "@preview/titleize:0.1.1": titlecase

#for s in (
  "Being productive on linux",
  "Finding an alternative to Mac OS X — part 2",
  [an example with small words and sub-phrases: "the example"],
) [
  #s => #titlecase(s) \
]

#let debug-print(x) = {
  if type(x) == content {
    let fields = x.fields()
    let func = x.func()
    [
      #repr(func)
      #for (k, v) in fields [
        - #k: #debug-print(v)
      ]
    ]
  } else {
    if type(x) == array [
      array
      #for y in x [
        - #debug-print(y)
      ]
    ] else [
      #repr(type(x)) (#repr(x))
    ]
  }
}

#show: titlecase

= This is a test, even with math $a = b + c$

In math, text can appear in various places:

$
  a_"for example in a subscript" &= "or in a longer text" \
  f(x) &= sin(x)
$

example