typst_library/text/
smallcaps.rs

1use crate::foundations::{Content, elem};
2
3/// Displays text in small capitals.
4///
5/// # Example
6/// ```example
7/// Hello \
8/// #smallcaps[Hello]
9/// ```
10///
11/// # Smallcaps fonts
12/// By default, this uses the `smcp` and `c2sc` OpenType features on the font.
13/// Not all fonts support these features. Sometimes, smallcaps are part of a
14/// dedicated font. This is, for example, the case for the _Latin Modern_ family
15/// of fonts. In those cases, you can use a show-set rule to customize the
16/// appearance of the text in smallcaps:
17///
18/// ```typ
19/// #show smallcaps: set text(font: "Latin Modern Roman Caps")
20/// ```
21///
22/// In the future, this function will support synthesizing smallcaps from normal
23/// letters, but this is not yet implemented.
24///
25/// # Smallcaps headings
26/// You can use a [show rule]($styling/#show-rules) to apply smallcaps
27/// formatting to all your headings. In the example below, we also center-align
28/// our headings and disable the standard bold font.
29///
30/// ```example
31/// #set par(justify: true)
32/// #set heading(numbering: "I.")
33///
34/// #show heading: smallcaps
35/// #show heading: set align(center)
36/// #show heading: set text(
37///   weight: "regular"
38/// )
39///
40/// = Introduction
41/// #lorem(40)
42/// ```
43#[elem(title = "Small Capitals")]
44pub struct SmallcapsElem {
45    /// Whether to turn uppercase letters into small capitals as well.
46    ///
47    /// Unless overridden by a show rule, this enables the `c2sc` OpenType
48    /// feature.
49    ///
50    /// ```example
51    /// #smallcaps(all: true)[UNICEF] is an
52    /// agency of #smallcaps(all: true)[UN].
53    /// ```
54    #[default(false)]
55    pub all: bool,
56    /// The content to display in small capitals.
57    #[required]
58    pub body: Content,
59}
60
61/// What becomes small capitals.
62#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
63pub enum Smallcaps {
64    /// Minuscules become small capitals.
65    Minuscules,
66    /// All letters become small capitals.
67    All,
68}