1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
//! Utility functions for LaTeX rendering
//!
//! This module provides helper functions for LaTeX generation including
//! character escaping and LaTeX environment/command generation.
use ;
/// Escape LaTeX special characters in text
///
/// This function converts plain text to LaTeX-safe text by escaping all
/// special characters that have meaning in LaTeX. This is essential for
/// preventing LaTeX compilation errors and ensuring text displays correctly.
///
/// # LaTeX Special Characters
///
/// The following characters are escaped:
/// - `\` → `\textbackslash{}`
/// - `{` → `\{`
/// - `}` → `\}`
/// - `$` → `\$`
/// - `&` → `\&`
/// - `%` → `\%`
/// - `#` → `\#`
/// - `^` → `\textasciicircum{}`
/// - `_` → `\_`
/// - `~` → `\textasciitilde{}`
///
/// # Examples
///
/// ```rust
/// # use markdown_ppp::latex_printer::util::escape_latex;
/// assert_eq!(escape_latex("Hello & goodbye"), "Hello \\& goodbye");
/// assert_eq!(escape_latex("Price: $100"), "Price: \\$100");
/// assert_eq!(escape_latex("50% off"), "50\\% off");
/// ```
/// Create a LaTeX environment with begin/end blocks
///
/// This function generates a complete LaTeX environment with proper
/// `\begin{env}` and `\end{env}` markers, optional parameters, and content.
///
/// # Arguments
///
/// * `arena` - The pretty-printer arena for document generation
/// * `name` - The environment name (e.g., "itemize", "verbatim")
/// * `options` - Optional environment parameters (e.g., "\[htbp\]")
/// * `content` - The content to place inside the environment
///
/// # Examples
///
/// ```rust
/// # use pretty::{Arena, DocAllocator};
/// # use markdown_ppp::latex_printer::util::environment;
/// let arena = Arena::new();
/// let content = arena.text("Hello world");
/// let env = environment(&arena, "quote", None, content);
/// // Generates: \begin{quote}\nHello world\n\end{quote}
/// ```
///
/// With options:
/// ```rust
/// # use pretty::{Arena, DocAllocator};
/// # use markdown_ppp::latex_printer::util::environment;
/// let arena = Arena::new();
/// let content = arena.text("Column 1 & Column 2");
/// let env = environment(&arena, "tabular", Some("lc"), content);
/// // Generates: \begin{tabular}[lc]\nColumn 1 & Column 2\n\end{tabular}
/// ```
/// Create a LaTeX command with optional arguments and content
///
/// This function generates a LaTeX command with optional square-bracket
/// arguments and curly-brace content.
///
/// # Arguments
///
/// * `arena` - The pretty-printer arena for document generation
/// * `name` - The command name (without backslash)
/// * `args` - Optional square-bracket arguments
/// * `content` - The content to place in curly braces
///
/// # Examples
///
/// Basic command:
/// ```rust
/// # use pretty::{Arena, DocAllocator};
/// # use markdown_ppp::latex_printer::util::command;
/// let arena = Arena::new();
/// let content = arena.text("bold text");
/// let cmd = command(&arena, "textbf", &[], content);
/// // Generates: \textbf{bold text}
/// ```
///
/// Command with arguments:
/// ```rust
/// # use pretty::{Arena, DocAllocator};
/// # use markdown_ppp::latex_printer::util::command;
/// let arena = Arena::new();
/// let content = arena.text("https://example.com");
/// let cmd = command(&arena, "href", &["target=_blank"], content);
/// // Generates: \href[target=_blank]{https://example.com}
/// ```