Skip to main content

ratex_parser/functions/
mathchoice.rs

1use std::collections::HashMap;
2
3use crate::error::ParseResult;
4use crate::functions::{define_function_full, FunctionContext, FunctionSpec};
5use crate::parse_node::ParseNode;
6
7pub fn register(map: &mut HashMap<&'static str, FunctionSpec>) {
8    define_function_full(
9        map,
10        &["\\mathchoice"],
11        "mathchoice",
12        4, 0, None,
13        false, false, true, false, true,
14        handle_mathchoice,
15    );
16}
17
18fn handle_mathchoice(
19    ctx: &mut FunctionContext,
20    args: Vec<ParseNode>,
21    _opt_args: Vec<Option<ParseNode>>,
22) -> ParseResult<ParseNode> {
23    let mut args = args.into_iter();
24    let display = ParseNode::ord_argument(args.next().unwrap());
25    let text = ParseNode::ord_argument(args.next().unwrap());
26    let script = ParseNode::ord_argument(args.next().unwrap());
27    let scriptscript = ParseNode::ord_argument(args.next().unwrap());
28
29    Ok(ParseNode::MathChoice {
30        mode: ctx.parser.mode,
31        display,
32        text,
33        script,
34        scriptscript,
35        loc: None,
36    })
37}