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
// Copyright © 2026 Mikhail Hogrefe
//
// This file is part of Malachite.
//
// Malachite is free software: you can redistribute it and/or modify it under the terms of the GNU
// Lesser General Public License (LGPL) as published by the Free Software Foundation; either version
// 3 of the License, or (at your option) any later version. See <https://www.gnu.org/licenses/>.
use crate;
use String;
use Vec;
use ;
/// A scheme that names variables with names the caller supplies.
///
/// The names are given in order, so that the first is variable 0, the second is variable 1, and so
/// on, and the scheme's [`capacity`](VarScheme::capacity) is how many there are. This is the scheme
/// to reach for when the variables mean something — `n` and `t`, say, or `price` and `quantity`
/// — and none of the alphabetical schemes says it.
///
/// The names are checked once, when the scheme is made, so that the scheme itself cannot fail:
/// [`new`](ListVars::new) panics on a list that would break the [`VarScheme`] contract.
///
/// A name of a single ASCII letter is written bare in LaTeX and Typst, so that both set it in math
/// italics, as a variable should be. A longer name is set upright, since that is what a name of
/// more than one letter should be, and is escaped for the language it is written in.
///
/// # Examples
/// ```
/// use malachite_base::strings::latex::ToLatex;
/// use malachite_base::strings::typst::ToTypst;
/// use malachite_base::vars::VarScheme;
/// use malachite_base::vars::list::ListVars;
///
/// let vars = ListVars::new(["t", "price"]);
/// assert_eq!(vars.capacity(), Some(2));
/// assert_eq!(vars.var(0).to_string(), "t");
/// assert_eq!(vars.var(1).to_string(), "price");
/// assert_eq!(vars.var(0).to_latex_string(), "t");
/// assert_eq!(vars.var(1).to_latex_string(), r"\text{price}");
/// assert_eq!(vars.var(1).to_typst_string(), "\"price\"");
/// assert_eq!(vars.parse_var("price"), Some(1));
/// assert_eq!(vars.parse_var("cost"), None);
/// ```