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"
21 using lyx::support::compare;
22 using lyx::support::LibFileSearch;
23 using lyx::support::subst;
28 ControlMath::ControlMath(Dialog & dialog)
29 : Dialog::Controller(dialog)
33 void ControlMath::dispatchFunc(kb_action action, string const & arg) const
35 kernel().dispatch(FuncRequest(action, arg));
39 void ControlMath::dispatchInsert(string const & name) const
41 dispatchFunc(LFUN_INSERT_MATH, '\\' + name);
45 void ControlMath::dispatchSubscript() const
47 dispatchFunc(LFUN_SUBSCRIPT);
51 void ControlMath::dispatchSuperscript() const
53 dispatchFunc(LFUN_SUPERSCRIPT);
57 void ControlMath::dispatchCubeRoot() const
59 dispatchFunc(LFUN_INSERT_MATH, "\\root");
60 dispatchFunc(LFUN_SELFINSERT, "3");
61 dispatchFunc(LFUN_RIGHT);
65 void ControlMath::dispatchMatrix(string const & str) const
67 dispatchFunc(LFUN_INSERT_MATRIX, str);
71 void ControlMath::dispatchDelim(string const & str) const
73 dispatchFunc(LFUN_MATH_DELIM, str);
77 void ControlMath::dispatchToggleDisplay() const
79 dispatchFunc(LFUN_MATH_DISPLAY);
83 void ControlMath::showDialog(string const & name) const
85 dispatchFunc(LFUN_DIALOG_SHOW, name);
89 char const * function_names[] = {
90 "arccos", "arcsin", "arctan", "arg", "bmod",
91 "cos", "cosh", "cot", "coth", "csc", "deg",
92 "det", "dim", "exp", "gcd", "hom", "inf", "ker",
93 "lg", "lim", "liminf", "limsup", "ln", "log",
94 "max", "min", "sec", "sin", "sinh", "sup",
95 "tan", "tanh", "Pr", ""
98 int const nr_function_names = sizeof(function_names) / sizeof(char const *) - 1;
100 char const * latex_dots[] = {
101 "ldots", "cdots", "vdots", "ddots", ""
104 int const nr_latex_dots = sizeof(latex_dots) / sizeof(char const *) - 1;
106 char const * latex_deco[] = {
107 "widehat", "widetilde", "overbrace", "overleftarrow", "overrightarrow",
108 "overline", "underbrace", "underline", "underleftarrow", "underrightarrow",
109 "underleftrightarrow", "overleftrightarrow",
110 "hat", "acute", "bar", "dot",
111 "check", "grave", "vec", "ddot",
115 int const nr_latex_deco = sizeof(latex_deco) / sizeof(char const *) - 1;
117 char const * latex_arrow[] = {
118 "downarrow", "leftarrow", "Downarrow", "Leftarrow",
119 "hookleftarrow", "rightarrow", "uparrow", "Rightarrow", "Uparrow",
120 "hookrightarrow", "updownarrow", "Leftrightarrow", "leftharpoonup",
121 "rightharpoonup", "rightleftharpoons", "leftrightarrow", "Updownarrow",
122 "leftharpoondown", "rightharpoondown", "mapsto",
123 "Longleftarrow", "Longrightarrow", "Longleftrightarrow",
124 "longleftrightarrow", "longleftarrow", "longrightarrow", "longmapsto",
125 "nwarrow", "nearrow", "swarrow", "searrow", "",
128 int const nr_latex_arrow = sizeof(latex_arrow) / sizeof(char const *);
130 char const * latex_bop[] = {
131 "pm", "cap", "diamond", "oplus",
132 "mp", "cup", "bigtriangleup", "ominus",
133 "times", "uplus", "bigtriangledown", "otimes",
134 "div", "sqcap", "triangleright", "oslash",
135 "cdot", "sqcup", "triangleleft", "odot",
136 "star", "vee", "amalg", "bigcirc",
137 "setminus", "wedge", "dagger", "circ",
138 "bullet", "wr", "ddagger", ""
141 int const nr_latex_bop = sizeof(latex_bop) / sizeof(char const *);
143 char const * latex_brel[] = {
144 "leq", "geq", "equiv", "models",
145 "prec", "succ", "sim", "perp",
146 "preceq", "succeq", "simeq", "mid",
147 "ll", "gg", "asymp", "parallel",
148 "subset", "supset", "approx", "smile",
149 "subseteq", "supseteq", "cong", "frown",
150 "sqsubseteq", "sqsupseteq", "doteq", "neq",
151 "in", "ni", "propto", "notin",
152 "vdash", "dashv", "bowtie", ""
155 int const nr_latex_brel = sizeof(latex_brel) / sizeof(char const *);
157 char const * latex_greek[] = {
158 "Gamma", "Delta", "Theta", "Lambda", "Xi", "Pi",
159 "Sigma", "Upsilon", "Phi", "Psi", "Omega",
160 "alpha", "beta", "gamma", "delta", "epsilon", "varepsilon", "zeta",
161 "eta", "theta", "vartheta", "iota", "kappa", "lambda", "mu",
162 "nu", "xi", "pi", "varpi", "rho", "sigma", "varsigma",
163 "tau", "upsilon", "phi", "varphi", "chi", "psi", "omega", ""
166 int const nr_latex_greek = sizeof(latex_greek) / sizeof(char const *);
168 char const * latex_misc[] = {
169 "nabla", "partial", "infty", "prime", "ell",
170 "emptyset", "exists", "forall", "imath", "jmath",
171 "Re", "Im", "aleph", "wp", "hbar",
172 "angle", "top", "bot", "Vert", "neg",
173 "flat", "natural", "sharp", "surd", "triangle",
174 "diamondsuit", "heartsuit", "clubsuit", "spadesuit",
175 "textrm Å", "textrm Ø", "mathcircumflex", "_",
177 "mathbb N", "mathbb Z", "mathbb Q",
178 "mathbb R", "mathbb C", "mathbb H",
179 "mathcal F", "mathcal L",
180 "mathcal H", "mathcal O", ""
183 int const nr_latex_misc = sizeof(latex_misc) / sizeof(char const *);
185 char const * latex_varsz[] = {
186 "sum", "int", "oint",
187 "prod", "coprod", "bigsqcup",
188 "bigotimes", "bigodot", "bigoplus",
189 "bigcap", "bigcup", "biguplus",
190 "bigvee", "bigwedge", ""
193 int const nr_latex_varsz = sizeof(latex_varsz) / sizeof(char const *);
195 char const * latex_ams_misc[] = {
196 "digamma", "varkappa", "beth", "daleth", "gimel",
197 "ulcorner", "urcorner", "llcorner", "lrcorner",
198 "hbar", "hslash", "vartriangle",
199 "triangledown", "square", "lozenge",
200 "circledS", "angle", "measuredangle",
201 "nexists", "mho", "Finv",
202 "Game", "Bbbk", "backprime",
203 "varnothing", "blacktriangle", "blacktriangledown",
204 "blacksquare", "blacklozenge", "bigstar",
205 "sphericalangle", "complement", "eth",
206 "diagup", "diagdown", ""
209 int const nr_latex_ams_misc = sizeof(latex_ams_misc) / sizeof(char const *);
211 char const * latex_ams_arrows[] = {
212 "dashrightarrow", "dashleftarrow", "leftleftarrows",
213 "leftrightarrows", "Lleftarrow", "twoheadleftarrow",
214 "leftarrowtail", "looparrowleft", "leftrightharpoons",
215 "curvearrowleft", "circlearrowleft", "Lsh",
216 "upuparrows", "upharpoonleft", "downharpoonleft",
217 "multimap", "leftrightsquigarrow", "rightrightarrows",
218 "rightleftarrows", "rightrightarrows", "rightleftarrows",
219 "twoheadrightarrow", "rightarrowtail", "looparrowright",
220 "rightleftharpoons", "curvearrowright", "circlearrowright",
221 "Rsh", "downdownarrows", "upharpoonright",
222 "downharpoonright", "rightsquigarrow",
223 "nleftarrow", "nrightarrow", "nLeftarrow",
224 "nRightarrow", "nleftrightarrow", "nLeftrightarrow", ""
227 int const nr_latex_ams_arrows = sizeof(latex_ams_arrows) / sizeof(char const *);
229 char const * latex_ams_rel[] = {
230 "leqq", "leqslant", "eqslantless", "eqslantgtr", "gtrsim", "gtrapprox",
231 "lesssim", "lessapprox", "approxeq", "gtrdot", "ggg", "gtrless",
232 "lessdot", "lll", "lessgtr", "gtreqless", "gtreqqless", "eqcirc",
233 "lesseqgtr", "lesseqqgtr", "doteqdot", "circeq", "triangleq", "thicksim",
234 "risingdotseq", "fallingdotseq", "backsim", "thickapprox", "supseteqq", "Supset",
235 "backsimeq", "subseteqq", "Subset", "sqsupset", "succcurlyeq", "curlyeqsucc",
236 "sqsubset", "preccurlyeq", "curlyeqprec", "succsim", "succapprox", "vartriangleright",
237 "precsim", "precapprox", "vartriangleleft", "trianglerighteq", "Vdash", "shortmid",
238 "trianglelefteq", "vDash", "Vvdash", "shortparallel", "between", "pitchfork",
239 "smallsmile", "smallfrown", "bumpeq", "varpropto", "blacktriangleleft", "therefore",
240 "Bumpeq", "geqq", "geqslant", "backepsilon", "blacktriangleright", "because", ""
243 int const nr_latex_ams_rel = sizeof(latex_ams_rel) / sizeof(char const *);
245 char const * latex_ams_nrel[] = {
246 "nless", "nleq", "nleqslant", "ngeqslant", "ngeqq", "gneq",
247 "nleqq", "lneq", "lneqq", "gneqq", "gvertneqq", "gnsim",
248 "lvertneqq", "lnsim", "lnapprox", "gnapprox", "nsucc", "nsucceq",
249 "nprec", "npreceq", "precnsim","succnsim", "succnapprox", "ncong",
250 "precnapprox", "nsim", "nshortmid", "nshortparallel", "nparallel", "nvDash",
252 "nmid", "nvdash", "nvDash", "nVDash", "ntriangleright", "ntrianglerighteq",
253 "ntriangleleft", "ntrianglelefteq", "nsubseteq", "nsupseteq", "nsupseteqq", "supsetneq",
254 "subsetneq", "varsubsetneq", "subsetneqq", "varsupsetneq", "supsetneqq", "varsupsetneqq",
255 "varsubsetneqq", "ngtr", "ngeq", "", "", ""
258 int const nr_latex_ams_nrel = sizeof(latex_ams_nrel) / sizeof(char const *);
261 char const * latex_ams_ops[] = {
262 "dotplus", "smallsetminus", "Cap",
263 "Cup", "barwedge", "veebar",
264 "doublebarwedge", "boxminus", "boxtimes",
265 "boxdot", "boxplus", "divideontimes",
266 "ltimes", "rtimes", "leftthreetimes",
267 "rightthreetimes", "curlywedge", "curlyvee",
268 "circleddash", "circledast", "circledcirc",
269 "centerdot", "intercal", ""
272 int const nr_latex_ams_ops = sizeof(latex_ams_ops) / sizeof(char const *);
283 bool operator<(XPMmap const & lhs, XPMmap const & rhs)
285 return compare(lhs.key, rhs.key) < 0;
290 CompareKey(string const & name) : name_(name) {}
291 bool operator()(XPMmap const & other) {
292 return compare(other.key, name_.c_str()) == 0;
299 XPMmap sorted_xpm_map[] = {
300 { "Bumpeq", "bumpeq2" },
303 { "Delta", "delta2" },
304 { "Downarrow", "downarrow2" },
305 { "Gamma", "gamma2" },
306 { "Lambda", "lambda2" },
307 { "Leftarrow", "leftarrow2" },
308 { "Leftrightarrow", "leftrightarrow2" },
309 { "Longleftarrow", "longleftarrow2" },
310 { "Longleftrightarrow", "longleftrightarrow2" },
311 { "Longrightarrow", "longrightarrow2" },
312 { "Omega", "omega2" },
316 { "Rightarrow", "rightarrow2" },
317 { "Sigma", "sigma2" },
318 { "Subset", "subset2" },
319 { "Supset", "supset2" },
320 { "Theta", "theta2" },
321 { "Uparrow", "uparrow2" },
322 { "Updownarrow", "updownarrow2" },
323 { "Upsilon", "upsilon2" },
324 { "Vdash", "vdash3" },
326 { "nLeftarrow", "nleftarrow2" },
327 { "nLeftrightarrow", "nleftrightarrow2" },
328 { "nRightarrow", "nrightarrow2" },
329 { "nVDash", "nvdash3" },
330 { "nvDash", "nvdash2" },
331 { "textrm_Å", "textrm_A" },
332 { "textrm_Ø", "textrm_0" },
333 { "vDash", "vdash2" }
336 size_t const nr_sorted_xpm_map = sizeof(sorted_xpm_map) / sizeof(XPMmap);
341 string const find_xpm(string const & name)
343 XPMmap const * const begin = sorted_xpm_map;
344 XPMmap const * const end = begin + nr_sorted_xpm_map;
345 BOOST_ASSERT(lyx::sorted(begin, end));
347 XPMmap const * const it =
348 std::find_if(begin, end, CompareKey(name));
352 xpm_name = it->value;
354 xpm_name = subst(name, "_", "underscore");
355 xpm_name = subst(xpm_name, ' ', '_');
357 // This way we can have "math-delim { }" on the toolbar.
358 xpm_name = subst(xpm_name, "(", "lparen");
359 xpm_name = subst(xpm_name, ")", "rparen");
360 xpm_name = subst(xpm_name, "[", "lbracket");
361 xpm_name = subst(xpm_name, "]", "rbracket");
362 xpm_name = subst(xpm_name, "{", "lbrace");
363 xpm_name = subst(xpm_name, "}", "rbrace");
364 xpm_name = subst(xpm_name, "|", "bars");
367 lyxerr[Debug::GUI] << "find_xpm(" << name << ")\n"
368 << "Looking for math XPM called \""
369 << xpm_name << '"' << std::endl;
371 return LibFileSearch("images/math/", xpm_name, "xpm");