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"
27 using support::compare;
28 using support::libFileSearch;
33 ControlMath::ControlMath(Dialog & dialog)
34 : Dialog::Controller(dialog)
38 void ControlMath::dispatchFunc(kb_action action, string const & arg) const
40 kernel().dispatch(FuncRequest(action, arg));
44 void ControlMath::dispatchInsert(string const & name) const
46 dispatchFunc(LFUN_MATH_INSERT, '\\' + name);
50 void ControlMath::dispatchSubscript() const
52 dispatchFunc(LFUN_MATH_INSERT, "_");
56 void ControlMath::dispatchSuperscript() const
58 dispatchFunc(LFUN_MATH_INSERT, "^");
62 void ControlMath::dispatchCubeRoot() const
64 dispatchFunc(LFUN_MATH_INSERT, "\\root");
65 dispatchFunc(LFUN_SELF_INSERT, "3");
66 dispatchFunc(LFUN_CHAR_FORWARD);
70 void ControlMath::dispatchMatrix(string const & str) const
72 dispatchFunc(LFUN_MATH_MATRIX, str);
76 void ControlMath::dispatchDelim(string const & str) const
78 dispatchFunc(LFUN_MATH_DELIM, str);
82 void ControlMath::dispatchBigDelim(string const & str) const
84 dispatchFunc(LFUN_MATH_BIGDELIM, str);
88 void ControlMath::dispatchToggleDisplay() const
90 dispatchFunc(LFUN_MATH_DISPLAY);
94 void ControlMath::showDialog(string const & name) const
96 dispatchFunc(LFUN_DIALOG_SHOW, name);
100 char const * function_names[] = {
101 "arccos", "arcsin", "arctan", "arg", "bmod",
102 "cos", "cosh", "cot", "coth", "csc", "deg",
103 "det", "dim", "exp", "gcd", "hom", "inf", "ker",
104 "lg", "lim", "liminf", "limsup", "ln", "log",
105 "max", "min", "sec", "sin", "sinh", "sup",
106 "tan", "tanh", "Pr", ""
109 int const nr_function_names = sizeof(function_names) / sizeof(char const *) - 1;
111 char const * latex_dots[] = {
112 "ldots", "cdots", "vdots", "ddots", ""
115 int const nr_latex_dots = sizeof(latex_dots) / sizeof(char const *) - 1;
117 char const * latex_deco[] = {
118 "widehat", "widetilde", "overbrace", "overleftarrow", "overrightarrow",
119 "overline", "underbrace", "underline", "underleftarrow", "underrightarrow",
120 "underleftrightarrow", "overleftrightarrow",
121 "hat", "acute", "bar", "dot",
122 "check", "grave", "vec", "ddot",
123 "breve", "tilde", "overset", "underset", ""
126 int const nr_latex_deco = sizeof(latex_deco) / sizeof(char const *) - 1;
128 char const * latex_arrow[] = {
129 "downarrow", "leftarrow", "Downarrow", "Leftarrow",
130 "hookleftarrow", "rightarrow", "uparrow", "Rightarrow", "Uparrow",
131 "hookrightarrow", "updownarrow", "Leftrightarrow", "leftharpoonup",
132 "rightharpoonup", "rightleftharpoons", "leftrightarrow", "Updownarrow",
133 "leftharpoondown", "rightharpoondown", "mapsto",
134 "Longleftarrow", "Longrightarrow", "Longleftrightarrow",
135 "longleftrightarrow", "longleftarrow", "longrightarrow", "longmapsto",
136 "nwarrow", "nearrow", "swarrow", "searrow", "",
139 int const nr_latex_arrow = sizeof(latex_arrow) / sizeof(char const *);
141 char const * latex_bop[] = {
142 "pm", "cap", "diamond", "oplus",
143 "mp", "cup", "bigtriangleup", "ominus",
144 "times", "uplus", "bigtriangledown", "otimes",
145 "div", "sqcap", "triangleright", "oslash",
146 "cdot", "sqcup", "triangleleft", "odot",
147 "star", "vee", "amalg", "bigcirc",
148 "setminus", "wedge", "dagger", "circ",
149 "bullet", "wr", "ddagger", ""
152 int const nr_latex_bop = sizeof(latex_bop) / sizeof(char const *);
154 char const * latex_brel[] = {
155 "leq", "geq", "equiv", "models",
156 "prec", "succ", "sim", "perp",
157 "preceq", "succeq", "simeq", "mid",
158 "ll", "gg", "asymp", "parallel",
159 "subset", "supset", "approx", "smile",
160 "subseteq", "supseteq", "cong", "frown",
161 "sqsubseteq", "sqsupseteq", "doteq", "neq",
162 "in", "ni", "propto", "notin",
163 "vdash", "dashv", "bowtie", ""
166 int const nr_latex_brel = sizeof(latex_brel) / sizeof(char const *);
168 char const * latex_greek[] = {
169 "Gamma", "Delta", "Theta", "Lambda", "Xi", "Pi",
170 "Sigma", "Upsilon", "Phi", "Psi", "Omega",
171 "alpha", "beta", "gamma", "delta", "epsilon", "varepsilon", "zeta",
172 "eta", "theta", "vartheta", "iota", "kappa", "lambda", "mu",
173 "nu", "xi", "pi", "varpi", "rho", "sigma", "varsigma",
174 "tau", "upsilon", "phi", "varphi", "chi", "psi", "omega", ""
177 int const nr_latex_greek = sizeof(latex_greek) / sizeof(char const *);
179 char const * latex_misc[] = {
180 "nabla", "partial", "infty", "prime", "ell",
181 "emptyset", "exists", "forall", "imath", "jmath",
182 "Re", "Im", "aleph", "wp", "hbar",
183 "angle", "top", "bot", "Vert", "neg",
184 "flat", "natural", "sharp", "surd", "triangle",
185 "diamondsuit", "heartsuit", "clubsuit", "spadesuit",
186 "textrm \\AA", "textrm \\O", "mathcircumflex", "_",
188 "mathbb N", "mathbb Z", "mathbb Q",
189 "mathbb R", "mathbb C", "mathbb H",
190 "mathcal F", "mathcal L",
191 "mathcal H", "mathcal O",
192 "phantom", "vphantom", "hphantom", ""
195 int const nr_latex_misc = sizeof(latex_misc) / sizeof(char const *);
197 char const * latex_varsz[] = {
198 "sum", "int", "intop", "oint", "ointop",
199 "prod", "coprod", "bigsqcup",
200 "bigotimes", "bigodot", "bigoplus",
201 "bigcap", "bigcup", "biguplus",
202 "bigvee", "bigwedge", ""
205 int const nr_latex_varsz = sizeof(latex_varsz) / sizeof(char const *);
207 char const * latex_ams_misc[] = {
208 "digamma", "varkappa", "beth", "daleth", "gimel",
209 "ulcorner", "urcorner", "llcorner", "lrcorner",
210 "hbar", "hslash", "vartriangle",
211 "triangledown", "square", "lozenge",
212 "circledS", "angle", "measuredangle",
213 "nexists", "mho", "Finv",
214 "Game", "Bbbk", "backprime",
215 "varnothing", "blacktriangle", "blacktriangledown",
216 "blacksquare", "blacklozenge", "bigstar",
217 "sphericalangle", "complement", "eth",
218 "diagup", "diagdown", ""
221 int const nr_latex_ams_misc = sizeof(latex_ams_misc) / sizeof(char const *);
223 char const * latex_ams_arrows[] = {
224 "dashrightarrow", "dashleftarrow", "leftleftarrows",
225 "leftrightarrows", "Lleftarrow", "twoheadleftarrow",
226 "leftarrowtail", "looparrowleft", "leftrightharpoons",
227 "curvearrowleft", "circlearrowleft", "Lsh",
228 "upuparrows", "upharpoonleft", "downharpoonleft",
229 "multimap", "leftrightsquigarrow", "rightrightarrows",
230 "rightleftarrows", "rightrightarrows", "rightleftarrows",
231 "twoheadrightarrow", "rightarrowtail", "looparrowright",
232 "rightleftharpoons", "curvearrowright", "circlearrowright",
233 "Rsh", "downdownarrows", "upharpoonright",
234 "downharpoonright", "rightsquigarrow",
235 "nleftarrow", "nrightarrow", "nLeftarrow",
236 "nRightarrow", "nleftrightarrow", "nLeftrightarrow", ""
239 int const nr_latex_ams_arrows = sizeof(latex_ams_arrows) / sizeof(char const *);
241 char const * latex_ams_rel[] = {
242 "leqq", "leqslant", "eqslantless", "eqslantgtr", "gtrsim", "gtrapprox",
243 "lesssim", "lessapprox", "approxeq", "gtrdot", "ggg", "gtrless",
244 "lessdot", "lll", "lessgtr", "gtreqless", "gtreqqless", "eqcirc",
245 "lesseqgtr", "lesseqqgtr", "doteqdot", "circeq", "triangleq", "thicksim",
246 "risingdotseq", "fallingdotseq", "backsim", "thickapprox", "supseteqq", "Supset",
247 "backsimeq", "subseteqq", "Subset", "sqsupset", "succcurlyeq", "curlyeqsucc",
248 "sqsubset", "preccurlyeq", "curlyeqprec", "succsim", "succapprox", "vartriangleright",
249 "precsim", "precapprox", "vartriangleleft", "trianglerighteq", "Vdash", "shortmid",
250 "trianglelefteq", "vDash", "Vvdash", "shortparallel", "between", "pitchfork",
251 "smallsmile", "smallfrown", "bumpeq", "varpropto", "blacktriangleleft", "therefore",
252 "Bumpeq", "geqq", "geqslant", "backepsilon", "blacktriangleright", "because", ""
255 int const nr_latex_ams_rel = sizeof(latex_ams_rel) / sizeof(char const *);
257 char const * latex_ams_nrel[] = {
258 "nless", "nleq", "nleqslant", "ngeqslant", "ngeqq", "gneq",
259 "nleqq", "lneq", "lneqq", "gneqq", "gvertneqq", "gnsim",
260 "lvertneqq", "lnsim", "lnapprox", "gnapprox", "nsucc", "nsucceq",
261 "nprec", "npreceq", "precnsim","succnsim", "succnapprox", "ncong",
262 "precnapprox", "nsim", "nshortmid", "nshortparallel", "nparallel", "nvDash",
264 "nmid", "nvdash", "nvDash", "nVDash", "ntriangleright", "ntrianglerighteq",
265 "ntriangleleft", "ntrianglelefteq", "nsubseteq", "nsupseteq", "nsupseteqq", "supsetneq",
266 "subsetneq", "varsubsetneq", "subsetneqq", "varsupsetneq", "supsetneqq", "varsupsetneqq",
267 "varsubsetneqq", "ngtr", "ngeq", "", "", ""
270 int const nr_latex_ams_nrel = sizeof(latex_ams_nrel) / sizeof(char const *);
273 char const * latex_ams_ops[] = {
274 "dotplus", "smallsetminus", "Cap",
275 "Cup", "barwedge", "veebar",
276 "doublebarwedge", "boxminus", "boxtimes",
277 "boxdot", "boxplus", "divideontimes",
278 "ltimes", "rtimes", "leftthreetimes",
279 "rightthreetimes", "curlywedge", "curlyvee",
280 "circleddash", "circledast", "circledcirc",
281 "centerdot", "intercal", ""
284 int const nr_latex_ams_ops = sizeof(latex_ams_ops) / sizeof(char const *);
295 bool operator<(XPMmap const & lhs, XPMmap const & rhs)
297 return compare(lhs.key, rhs.key) < 0;
301 class CompareKey : public std::unary_function<XPMmap, bool> {
303 CompareKey(string const & name) : name_(name) {}
304 bool operator()(XPMmap const & other) const {
305 return other.key == name_;
312 XPMmap sorted_xpm_map[] = {
313 { "Bumpeq", "bumpeq2" },
316 { "Delta", "delta2" },
317 { "Downarrow", "downarrow2" },
318 { "Gamma", "gamma2" },
319 { "Lambda", "lambda2" },
320 { "Leftarrow", "leftarrow2" },
321 { "Leftrightarrow", "leftrightarrow2" },
322 { "Longleftarrow", "longleftarrow2" },
323 { "Longleftrightarrow", "longleftrightarrow2" },
324 { "Longrightarrow", "longrightarrow2" },
325 { "Omega", "omega2" },
329 { "Rightarrow", "rightarrow2" },
330 { "Sigma", "sigma2" },
331 { "Subset", "subset2" },
332 { "Supset", "supset2" },
333 { "Theta", "theta2" },
334 { "Uparrow", "uparrow2" },
335 { "Updownarrow", "updownarrow2" },
336 { "Upsilon", "upsilon2" },
337 { "Vdash", "vdash3" },
339 { "nLeftarrow", "nleftarrow2" },
340 { "nLeftrightarrow", "nleftrightarrow2" },
341 { "nRightarrow", "nrightarrow2" },
342 { "nVDash", "nvdash3" },
343 { "nvDash", "nvdash2" },
344 { "textrm \\AA", "textrm_AA"},
345 { "textrm \\O", "textrm_Oe"},
346 { "vDash", "vdash2" }
349 size_t const nr_sorted_xpm_map = sizeof(sorted_xpm_map) / sizeof(XPMmap);
354 string const find_xpm(string const & name)
356 XPMmap const * const begin = sorted_xpm_map;
357 XPMmap const * const end = begin + nr_sorted_xpm_map;
358 BOOST_ASSERT(sorted(begin, end));
360 XPMmap const * const it =
361 std::find_if(begin, end, CompareKey(name));
365 xpm_name = it->value;
367 xpm_name = subst(name, "_", "underscore");
368 xpm_name = subst(xpm_name, ' ', '_');
370 // This way we can have "math-delim { }" on the toolbar.
371 xpm_name = subst(xpm_name, "(", "lparen");
372 xpm_name = subst(xpm_name, ")", "rparen");
373 xpm_name = subst(xpm_name, "[", "lbracket");
374 xpm_name = subst(xpm_name, "]", "rbracket");
375 xpm_name = subst(xpm_name, "{", "lbrace");
376 xpm_name = subst(xpm_name, "}", "rbrace");
377 xpm_name = subst(xpm_name, "|", "bars");
380 lyxerr[Debug::GUI] << "find_xpm(" << name << ")\n"
381 << "Looking for math XPM called \""
382 << xpm_name << '"' << std::endl;
384 return libFileSearch("images/math/", xpm_name, "xpm");
387 } // namespace frontend