ratex_parser/functions/
styling.rs1use std::collections::HashMap;
2
3use crate::error::ParseResult;
4use crate::functions::{define_function_full, FunctionContext, FunctionSpec};
5use crate::parse_node::{ParseNode, StyleStr};
6
7pub fn register(map: &mut HashMap<&'static str, FunctionSpec>) {
8 define_function_full(
9 map,
10 &[
11 "\\displaystyle",
12 "\\textstyle",
13 "\\scriptstyle",
14 "\\scriptscriptstyle",
15 ],
16 "styling",
17 0,
18 0,
19 None,
20 true, true,
22 true,
23 false,
24 false,
25 handle_styling,
26 );
27}
28
29fn handle_styling(
30 ctx: &mut FunctionContext,
31 _args: Vec<ParseNode>,
32 _opt_args: Vec<Option<ParseNode>>,
33) -> ParseResult<ParseNode> {
34 let break_on = ctx.break_on_token_text.clone();
35 let body = ctx.parser.parse_expression(true, break_on.as_deref())?;
36
37 let style = match ctx.func_name.as_str() {
38 "\\displaystyle" => StyleStr::Display,
39 "\\textstyle" => StyleStr::Text,
40 "\\scriptstyle" => StyleStr::Script,
41 "\\scriptscriptstyle" => StyleStr::Scriptscript,
42 _ => StyleStr::Text,
43 };
44
45 Ok(ParseNode::Styling {
46 mode: ctx.parser.mode,
47 style,
48 body,
49 loc: None,
50 })
51}