typst_macros

Macro symbols

source
symbols!() { /* proc-macro */ }
Expand description

Defines a list of Symbols.

The #[call(path)] attribute can be used to specify a function to call when the symbol is invoked. The function must be NativeFunc.

โ“˜
const EMOJI: &[(&str, Symbol)] = symbols! {
    // A plain symbol without modifiers.
    abacus: '๐Ÿงฎ',

    // A symbol with a modifierless default and one modifier.
    alien: ['๐Ÿ‘ฝ', monster: '๐Ÿ‘พ'],

    // A symbol where each variant has a modifier. The first one will be
    // the default.
    clock: [one: '๐Ÿ•', two: '๐Ÿ•‘', ...],

    // A callable symbol without modifiers.
    breve: #[call(crate::math::breve)] 'ห˜',

    // A callable symbol with a modifierless default and one modifier.
    acute: [
        #[call(crate::math::acute)] 'ยด',
        double: 'ห',
    ],

    // A callable symbol where each variant has a modifier.
    arrow: [
        #[call(crate::math::arrow)] r: 'โ†’',
        r.long.bar: 'โŸผ',
        #[call(crate::math::arrow_l)] l: 'โ†',
        l.long.bar: 'โŸป',
    ],
}

Note: While this could use macro_rules! instead of a proc-macro, it was horribly slow in rust-analyzer. The underlying cause might be this issue.