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