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