3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
8 * Full author contact details are available in file CREDITS.
13 #include "ControlMath.h"
15 #include "funcrequest.h"
17 #include "support/lyxalgo.h" // sorted
18 #include "support/lstrings.h"
19 #include "support/filetools.h"
25 using support::compare;
26 using support::LibFileSearch;
31 ControlMath::ControlMath(Dialog & dialog)
32 : Dialog::Controller(dialog)
36 void ControlMath::dispatchFunc(kb_action action, string const & arg) const
38 kernel().dispatch(FuncRequest(action, arg));
42 void ControlMath::dispatchInsert(string const & name) const
44 dispatchFunc(LFUN_INSERT_MATH, '\\' + name);
48 void ControlMath::dispatchSubscript() const
50 dispatchFunc(LFUN_INSERT_MATH, "_");
51 dispatchFunc(LFUN_DOWN);
55 void ControlMath::dispatchSuperscript() const
57 dispatchFunc(LFUN_INSERT_MATH, "^");
58 dispatchFunc(LFUN_UP);
62 void ControlMath::dispatchCubeRoot() const
64 dispatchFunc(LFUN_INSERT_MATH, "\\root");
65 dispatchFunc(LFUN_SELFINSERT, "3");
66 dispatchFunc(LFUN_RIGHT);
70 void ControlMath::dispatchMatrix(string const & str) const
72 dispatchFunc(LFUN_INSERT_MATRIX, str);
76 void ControlMath::dispatchDelim(string const & str) const
78 dispatchFunc(LFUN_MATH_DELIM, str);
82 void ControlMath::dispatchToggleDisplay() const
84 dispatchFunc(LFUN_MATH_DISPLAY);
88 void ControlMath::showDialog(string const & name) const
90 dispatchFunc(LFUN_DIALOG_SHOW, name);
94 char const * function_names[] = {
95 "arccos", "arcsin", "arctan", "arg", "bmod",
96 "cos", "cosh", "cot", "coth", "csc", "deg",
97 "det", "dim", "exp", "gcd", "hom", "inf", "ker",
98 "lg", "lim", "liminf", "limsup", "ln", "log",
99 "max", "min", "sec", "sin", "sinh", "sup",
100 "tan", "tanh", "Pr", ""
103 int const nr_function_names = sizeof(function_names) / sizeof(char const *) - 1;
105 char const * latex_dots[] = {
106 "ldots", "cdots", "vdots", "ddots", ""
109 int const nr_latex_dots = sizeof(latex_dots) / sizeof(char const *) - 1;
111 char const * latex_deco[] = {
112 "widehat", "widetilde", "overbrace", "overleftarrow", "overrightarrow",
113 "overline", "underbrace", "underline", "underleftarrow", "underrightarrow",
114 "underleftrightarrow", "overleftrightarrow",
115 "hat", "acute", "bar", "dot",
116 "check", "grave", "vec", "ddot",
120 int const nr_latex_deco = sizeof(latex_deco) / sizeof(char const *) - 1;
122 char const * latex_arrow[] = {
123 "downarrow", "leftarrow", "Downarrow", "Leftarrow",
124 "hookleftarrow", "rightarrow", "uparrow", "Rightarrow", "Uparrow",
125 "hookrightarrow", "updownarrow", "Leftrightarrow", "leftharpoonup",
126 "rightharpoonup", "rightleftharpoons", "leftrightarrow", "Updownarrow",
127 "leftharpoondown", "rightharpoondown", "mapsto",
128 "Longleftarrow", "Longrightarrow", "Longleftrightarrow",
129 "longleftrightarrow", "longleftarrow", "longrightarrow", "longmapsto",
130 "nwarrow", "nearrow", "swarrow", "searrow", "",
133 int const nr_latex_arrow = sizeof(latex_arrow) / sizeof(char const *);
135 char const * latex_bop[] = {
136 "pm", "cap", "diamond", "oplus",
137 "mp", "cup", "bigtriangleup", "ominus",
138 "times", "uplus", "bigtriangledown", "otimes",
139 "div", "sqcap", "triangleright", "oslash",
140 "cdot", "sqcup", "triangleleft", "odot",
141 "star", "vee", "amalg", "bigcirc",
142 "setminus", "wedge", "dagger", "circ",
143 "bullet", "wr", "ddagger", ""
146 int const nr_latex_bop = sizeof(latex_bop) / sizeof(char const *);
148 char const * latex_brel[] = {
149 "leq", "geq", "equiv", "models",
150 "prec", "succ", "sim", "perp",
151 "preceq", "succeq", "simeq", "mid",
152 "ll", "gg", "asymp", "parallel",
153 "subset", "supset", "approx", "smile",
154 "subseteq", "supseteq", "cong", "frown",
155 "sqsubseteq", "sqsupseteq", "doteq", "neq",
156 "in", "ni", "propto", "notin",
157 "vdash", "dashv", "bowtie", ""
160 int const nr_latex_brel = sizeof(latex_brel) / sizeof(char const *);
162 char const * latex_greek[] = {
163 "Gamma", "Delta", "Theta", "Lambda", "Xi", "Pi",
164 "Sigma", "Upsilon", "Phi", "Psi", "Omega",
165 "alpha", "beta", "gamma", "delta", "epsilon", "varepsilon", "zeta",
166 "eta", "theta", "vartheta", "iota", "kappa", "lambda", "mu",
167 "nu", "xi", "pi", "varpi", "rho", "sigma", "varsigma",
168 "tau", "upsilon", "phi", "varphi", "chi", "psi", "omega", ""
171 int const nr_latex_greek = sizeof(latex_greek) / sizeof(char const *);
173 char const * latex_misc[] = {
174 "nabla", "partial", "infty", "prime", "ell",
175 "emptyset", "exists", "forall", "imath", "jmath",
176 "Re", "Im", "aleph", "wp", "hbar",
177 "angle", "top", "bot", "Vert", "neg",
178 "flat", "natural", "sharp", "surd", "triangle",
179 "diamondsuit", "heartsuit", "clubsuit", "spadesuit",
180 "textrm Å", "textrm Ø", "mathcircumflex", "_",
182 "mathbb N", "mathbb Z", "mathbb Q",
183 "mathbb R", "mathbb C", "mathbb H",
184 "mathcal F", "mathcal L",
185 "mathcal H", "mathcal O", ""
188 int const nr_latex_misc = sizeof(latex_misc) / sizeof(char const *);
190 char const * latex_varsz[] = {
191 "sum", "int", "oint",
192 "prod", "coprod", "bigsqcup",
193 "bigotimes", "bigodot", "bigoplus",
194 "bigcap", "bigcup", "biguplus",
195 "bigvee", "bigwedge", ""
198 int const nr_latex_varsz = sizeof(latex_varsz) / sizeof(char const *);
200 char const * latex_ams_misc[] = {
201 "digamma", "varkappa", "beth", "daleth", "gimel",
202 "ulcorner", "urcorner", "llcorner", "lrcorner",
203 "hbar", "hslash", "vartriangle",
204 "triangledown", "square", "lozenge",
205 "circledS", "angle", "measuredangle",
206 "nexists", "mho", "Finv",
207 "Game", "Bbbk", "backprime",
208 "varnothing", "blacktriangle", "blacktriangledown",
209 "blacksquare", "blacklozenge", "bigstar",
210 "sphericalangle", "complement", "eth",
211 "diagup", "diagdown", ""
214 int const nr_latex_ams_misc = sizeof(latex_ams_misc) / sizeof(char const *);
216 char const * latex_ams_arrows[] = {
217 "dashrightarrow", "dashleftarrow", "leftleftarrows",
218 "leftrightarrows", "Lleftarrow", "twoheadleftarrow",
219 "leftarrowtail", "looparrowleft", "leftrightharpoons",
220 "curvearrowleft", "circlearrowleft", "Lsh",
221 "upuparrows", "upharpoonleft", "downharpoonleft",
222 "multimap", "leftrightsquigarrow", "rightrightarrows",
223 "rightleftarrows", "rightrightarrows", "rightleftarrows",
224 "twoheadrightarrow", "rightarrowtail", "looparrowright",
225 "rightleftharpoons", "curvearrowright", "circlearrowright",
226 "Rsh", "downdownarrows", "upharpoonright",
227 "downharpoonright", "rightsquigarrow",
228 "nleftarrow", "nrightarrow", "nLeftarrow",
229 "nRightarrow", "nleftrightarrow", "nLeftrightarrow", ""
232 int const nr_latex_ams_arrows = sizeof(latex_ams_arrows) / sizeof(char const *);
234 char const * latex_ams_rel[] = {
235 "leqq", "leqslant", "eqslantless", "eqslantgtr", "gtrsim", "gtrapprox",
236 "lesssim", "lessapprox", "approxeq", "gtrdot", "ggg", "gtrless",
237 "lessdot", "lll", "lessgtr", "gtreqless", "gtreqqless", "eqcirc",
238 "lesseqgtr", "lesseqqgtr", "doteqdot", "circeq", "triangleq", "thicksim",
239 "risingdotseq", "fallingdotseq", "backsim", "thickapprox", "supseteqq", "Supset",
240 "backsimeq", "subseteqq", "Subset", "sqsupset", "succcurlyeq", "curlyeqsucc",
241 "sqsubset", "preccurlyeq", "curlyeqprec", "succsim", "succapprox", "vartriangleright",
242 "precsim", "precapprox", "vartriangleleft", "trianglerighteq", "Vdash", "shortmid",
243 "trianglelefteq", "vDash", "Vvdash", "shortparallel", "between", "pitchfork",
244 "smallsmile", "smallfrown", "bumpeq", "varpropto", "blacktriangleleft", "therefore",
245 "Bumpeq", "geqq", "geqslant", "backepsilon", "blacktriangleright", "because", ""
248 int const nr_latex_ams_rel = sizeof(latex_ams_rel) / sizeof(char const *);
250 char const * latex_ams_nrel[] = {
251 "nless", "nleq", "nleqslant", "ngeqslant", "ngeqq", "gneq",
252 "nleqq", "lneq", "lneqq", "gneqq", "gvertneqq", "gnsim",
253 "lvertneqq", "lnsim", "lnapprox", "gnapprox", "nsucc", "nsucceq",
254 "nprec", "npreceq", "precnsim","succnsim", "succnapprox", "ncong",
255 "precnapprox", "nsim", "nshortmid", "nshortparallel", "nparallel", "nvDash",
257 "nmid", "nvdash", "nvDash", "nVDash", "ntriangleright", "ntrianglerighteq",
258 "ntriangleleft", "ntrianglelefteq", "nsubseteq", "nsupseteq", "nsupseteqq", "supsetneq",
259 "subsetneq", "varsubsetneq", "subsetneqq", "varsupsetneq", "supsetneqq", "varsupsetneqq",
260 "varsubsetneqq", "ngtr", "ngeq", "", "", ""
263 int const nr_latex_ams_nrel = sizeof(latex_ams_nrel) / sizeof(char const *);
266 char const * latex_ams_ops[] = {
267 "dotplus", "smallsetminus", "Cap",
268 "Cup", "barwedge", "veebar",
269 "doublebarwedge", "boxminus", "boxtimes",
270 "boxdot", "boxplus", "divideontimes",
271 "ltimes", "rtimes", "leftthreetimes",
272 "rightthreetimes", "curlywedge", "curlyvee",
273 "circleddash", "circledast", "circledcirc",
274 "centerdot", "intercal", ""
277 int const nr_latex_ams_ops = sizeof(latex_ams_ops) / sizeof(char const *);
288 bool operator<(XPMmap const & lhs, XPMmap const & rhs)
290 return compare(lhs.key, rhs.key) < 0;
294 struct CompareKey : public std::unary_function<XPMmap, bool> {
295 CompareKey(string const & name) : name_(name) {}
296 bool operator()(XPMmap const & other) const {
297 return other.key == name_;
304 XPMmap sorted_xpm_map[] = {
305 { "Bumpeq", "bumpeq2" },
308 { "Delta", "delta2" },
309 { "Downarrow", "downarrow2" },
310 { "Gamma", "gamma2" },
311 { "Lambda", "lambda2" },
312 { "Leftarrow", "leftarrow2" },
313 { "Leftrightarrow", "leftrightarrow2" },
314 { "Longleftarrow", "longleftarrow2" },
315 { "Longleftrightarrow", "longleftrightarrow2" },
316 { "Longrightarrow", "longrightarrow2" },
317 { "Omega", "omega2" },
321 { "Rightarrow", "rightarrow2" },
322 { "Sigma", "sigma2" },
323 { "Subset", "subset2" },
324 { "Supset", "supset2" },
325 { "Theta", "theta2" },
326 { "Uparrow", "uparrow2" },
327 { "Updownarrow", "updownarrow2" },
328 { "Upsilon", "upsilon2" },
329 { "Vdash", "vdash3" },
331 { "nLeftarrow", "nleftarrow2" },
332 { "nLeftrightarrow", "nleftrightarrow2" },
333 { "nRightarrow", "nrightarrow2" },
334 { "nVDash", "nvdash3" },
335 { "nvDash", "nvdash2" },
336 { "textrm_Å", "textrm_A" },
337 { "textrm_Ø", "textrm_0" },
338 { "vDash", "vdash2" }
341 size_t const nr_sorted_xpm_map = sizeof(sorted_xpm_map) / sizeof(XPMmap);
346 string const find_xpm(string const & name)
348 XPMmap const * const begin = sorted_xpm_map;
349 XPMmap const * const end = begin + nr_sorted_xpm_map;
350 BOOST_ASSERT(sorted(begin, end));
352 XPMmap const * const it =
353 std::find_if(begin, end, CompareKey(name));
357 xpm_name = it->value;
359 xpm_name = subst(name, "_", "underscore");
360 xpm_name = subst(xpm_name, ' ', '_');
362 // This way we can have "math-delim { }" on the toolbar.
363 xpm_name = subst(xpm_name, "(", "lparen");
364 xpm_name = subst(xpm_name, ")", "rparen");
365 xpm_name = subst(xpm_name, "[", "lbracket");
366 xpm_name = subst(xpm_name, "]", "rbracket");
367 xpm_name = subst(xpm_name, "{", "lbrace");
368 xpm_name = subst(xpm_name, "}", "rbrace");
369 xpm_name = subst(xpm_name, "|", "bars");
372 lyxerr[Debug::GUI] << "find_xpm(" << name << ")\n"
373 << "Looking for math XPM called \""
374 << xpm_name << '"' << std::endl;
376 return LibFileSearch("images/math/", xpm_name, "xpm");
379 } // namespace frontend