Document title metadata does not respect text casing

Hi!

I have an issue where the metadata title is not well set when casing is set dynamically.

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

#let title = "Hello world"
#let title_case = titlecase(title)
#set document(title: title_case)

title is #title_case

Metadata title of the pdf is "Hello world" instead of "Hello World", while title_case actually is "Hello World".

Interestingly, if I set the title to be "hello world", the metadata title will be "hello world". It seems like “dynamic” casing does not work for the metadata title (I haven’t tried with other metadata parameters).

Is there a reason why the latest word does not have the expected case? Did I miss something else?

EDIT: I haven’t explicited it, but #set document(title: "Hello World") works perfectly fine!

This may well be related to Contextual content doesn't appear in PDF document title and bookmarks/outline · Issue #3424 · typst/typst · GitHub

as titleize.titlecase() returns content.

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

#let title = "Hello world"
#let title_case = titlecase(title)

#type(title_case) // -> Outputs `content` 

The titlecase function does not return a string, but it returns styled content. So this is either a bug or missing feature depending on what the development team thinks. We can read the titlecase function’s code:

#let titlecase(body, limit: 4) = {
  show regex(".{" + str(limit) + ",}"): it => string-to-titlecase(it.text)

  body
}

We don’t need to understand the code to see that it’s just styled content (take body as content and apply a style with a show-regex rule).

However, it looks like if you would use the function string-to-titlecase instead, you receive a string. I think document.title will have no problems with that.


If we would read the titlecase function we see that it’s written to be appropriate to use with show: titlecase and similar, so it can handle a whole document. It finds text using regex, finding only words strings of 4 letters longer or more. (This will have the usual limitations of regex rules, like not being able to match across two word halves with different style, but that’s a digression.)

1 Like

I used it in the IJIMAI template:

I’m not sure how titlecase works, if it supposedly only matches long words, but in a test title it also capitalizes “a” after a colon, which is correct, AFAIK.