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, 0,
13        Some(vec![ArgType::Size]),
14        true,  // allowed_in_argument
15        true, true, false, false,
16        handle_kern,
17    );
18}
19
20fn handle_kern(
21    ctx: &mut FunctionContext,
22    args: Vec<ParseNode>,
23    _opt_args: Vec<Option<ParseNode>>,
24) -> ParseResult<ParseNode> {
25    let dimension = if let ParseNode::Size { value, .. } = &args[0] {
26        value.clone()
27    } else {
28        Measurement {
29            number: 0.0,
30            unit: "em".to_string(),
31        }
32    };
33
34    Ok(ParseNode::Kern {
35        mode: ctx.parser.mode,
36        dimension,
37        loc: None,
38    })
39}