Skip to main content

ratex_parser/functions/
text.rs

1use std::collections::HashMap;
2
3use crate::error::ParseResult;
4use crate::functions::{define_function_full, ArgType, FunctionContext, FunctionSpec};
5use crate::parse_node::ParseNode;
6
7pub fn register(map: &mut HashMap<&'static str, FunctionSpec>) {
8    define_function_full(
9        map,
10        &[
11            "\\text",
12            "\\textrm",
13            "\\textsf",
14            "\\texttt",
15            "\\textnormal",
16            "\\textbf",
17            "\\textit",
18            "\\textmd",
19            "\\textup",
20            "\\textsl",
21            "\\textsc",
22        ],
23        "text",
24        1,
25        0,
26        Some(vec![ArgType::Text]),
27        true, // allowed_in_argument
28        true, // allowed_in_text
29        true,
30        false,
31        false,
32        handle_text,
33    );
34}
35
36fn handle_text(
37    ctx: &mut FunctionContext,
38    args: Vec<ParseNode>,
39    _opt_args: Vec<Option<ParseNode>>,
40) -> ParseResult<ParseNode> {
41    let body = args.into_iter().next().unwrap();
42    let body_vec = ParseNode::ord_argument(body);
43
44    let font = Some(ctx.func_name.clone());
45
46    Ok(ParseNode::Text {
47        mode: ctx.parser.mode,
48        body: body_vec,
49        font,
50        loc: None,
51    })
52}