Skip to main content

ratex_parser/functions/
kern.rs

1use std::collections::HashMap;
2
3use crate::error::ParseResult;
4use crate::functions::{define_function_full, ArgType, FunctionContext, FunctionSpec};
5use crate::parse_node::{Measurement, ParseNode};
6
7pub fn register(map: &mut HashMap<&'static str, FunctionSpec>) {
8    define_function_full(
9        map,
10        &["\\kern", "\\mkern", "\\hskip", "\\mskip"],
11        "kern",
12        1,
13        0,
14        Some(vec![ArgType::Size]),
15        true, // allowed_in_argument
16        true,
17        true,
18        false,
19        false,
20        handle_kern,
21    );
22}
23
24fn handle_kern(
25    ctx: &mut FunctionContext,
26    args: Vec<ParseNode>,
27    _opt_args: Vec<Option<ParseNode>>,
28) -> ParseResult<ParseNode> {
29    let dimension = if let ParseNode::Size { value, .. } = &args[0] {
30        value.clone()
31    } else {
32        Measurement {
33            number: 0.0,
34            unit: "em".to_string(),
35        }
36    };
37
38    Ok(ParseNode::Kern {
39        mode: ctx.parser.mode,
40        dimension,
41        loc: None,
42    })
43}