ratex_parser/functions/
sizing.rs1use std::collections::HashMap;
2
3use crate::error::ParseResult;
4use crate::functions::{define_function_full, FunctionContext, FunctionSpec};
5use crate::parse_node::ParseNode;
6
7static SIZE_FUNCS: &[&str] = &[
8 "\\tiny",
9 "\\sixptsize",
10 "\\scriptsize",
11 "\\footnotesize",
12 "\\small",
13 "\\normalsize",
14 "\\large",
15 "\\Large",
16 "\\LARGE",
17 "\\huge",
18 "\\Huge",
19];
20
21pub fn register(map: &mut HashMap<&'static str, FunctionSpec>) {
22 define_function_full(
23 map,
24 SIZE_FUNCS,
25 "sizing",
26 0,
27 0,
28 None,
29 false,
30 true, true,
32 false,
33 false,
34 handle_sizing,
35 );
36}
37
38fn handle_sizing(
39 ctx: &mut FunctionContext,
40 _args: Vec<ParseNode>,
41 _opt_args: Vec<Option<ParseNode>>,
42) -> ParseResult<ParseNode> {
43 let break_on = ctx.break_on_token_text.clone();
44 let body = ctx.parser.parse_expression(false, break_on.as_deref())?;
45
46 let size = SIZE_FUNCS
47 .iter()
48 .position(|&f| f == ctx.func_name)
49 .map(|i| i + 1)
50 .unwrap_or(6) as u8;
51
52 Ok(ParseNode::Sizing {
53 mode: ctx.parser.mode,
54 size,
55 body,
56 loc: None,
57 })
58}