Skip to content

Add option to preserve uppercase / force lowercase for title and sentence casing #40

@eltos

Description

@eltos

I would like to request an option "force-lowercase" to control whether to keep uppercase letters or not in the titlecase and sentencecase functions. The main use case for this is acronyms and proper names in titles/headings, and also sentence continuation in ambiguous cases (see #39).

With force-lowercase: false (default) these two functions would only transform lowercase to uppercase letters as required, but not vice-verca (i.e. keep what is already uppercase). This is the current behaviour of the titlecase function.

With force-lowercase: true both functions would additionally transform uppercase letters to lowercase as per the styling rules, so as to fix ALL UPPERCASE INPUTS. This is the current behaviour of the sentencecase function.

Example (using typst):

#import "@preview/decasify:0.9.0": sentencecase, titlecase
#set text(lang: "en")

#sentencecase[Typst supports export to PDF and HTML.]
// Output: Typst supports export to PDF and HTML.

#titlecase[Typst supports export to PDF and HTML.] // current behaviour
// Output: Typst Supports Export to PDF and HTML.

#sentencecase(force-lowercase: true)[TYPST SUPPORTS EXPORT TO PDF AND HTML.] // current behaviour
// Output: Typst supports export to pdf and html.

#titlecase(force-lowercase: true)[TYPST SUPPORTS EXPORT TO PDF AND HTML.]
// Output: Typst Supports Export to Pdf and Html.

Note that in principle force-lowercase: true in the above example could then also be achieved with #sentencecase(lowercase[TYPST ...]) once the default behaviour has been altered to preserve uppercase letters

I would favour if the default setting was force-lowercase: false consistently for both titlecase and sentencecase, i.e. preserving the current behaviour of the titlecase function. Alternatively, force-lowercase: false could be the default for the titlecase function and force-lowercase: true the default for the sentencecase function to keep the respective current behaviour of either function as-is, while allowing to change it to the respective opposite behaviour if desired.
As a bonus, there could be a clever force-lowercase: auto as default for either function, which would translate to force-lowercase: true if more than 50% of characters in the input are already uppercase, and translate to force-lowercase: false otherwise.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions