]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathExFunc.cpp
173436eb612a7b031f1b2f862cab3cac734d297f
[lyx.git] / src / mathed / InsetMathExFunc.cpp
1 /**
2  * \file InsetMathExFunc.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "InsetMathExFunc.h"
14
15 #include "MathData.h"
16 #include "MathExtern.h"
17 #include "MathStream.h"
18 #include "MathSupport.h"
19 #include "MetricsInfo.h"
20
21 #include "support/docstream.h"
22
23 using namespace std;
24
25 namespace lyx {
26
27
28 InsetMathExFunc::InsetMathExFunc(Buffer * buf, docstring const & name)
29         : InsetMathNest(buf, 1), name_(name)
30 {}
31
32
33 InsetMathExFunc::InsetMathExFunc(Buffer * buf, docstring const & name, MathData const & ar)
34         : InsetMathNest(buf, 1), name_(name)
35 {
36         cell(0) = ar;
37 }
38
39
40 Inset * InsetMathExFunc::clone() const
41 {
42         return new InsetMathExFunc(*this);
43 }
44
45
46 void InsetMathExFunc::metrics(MetricsInfo & mi, Dimension & dim) const
47 {
48         mathed_string_dim(mi.base.font, name_, dim);
49 }
50
51
52 void InsetMathExFunc::draw(PainterInfo & pi, int x, int y) const
53 {
54         drawStrBlack(pi, x, y, name_);
55 }
56
57
58 docstring InsetMathExFunc::name() const
59 {
60         return name_;
61 }
62
63
64 void InsetMathExFunc::maple(MapleStream & os) const
65 {
66         if (name_ == "det")
67                 os << "linalg[det](" << cell(0) << ')';
68         else
69                 os << name_ << '(' << cell(0) << ')';
70 }
71
72
73 void InsetMathExFunc::maxima(MaximaStream & os) const
74 {
75         if (name_ == "det")
76                 os << "determinant(" << cell(0) << ')';
77         else
78                 os << name_ << '(' << cell(0) << ')';
79 }
80
81
82 static string asMathematicaName(string const & name)
83 {
84         if (name == "sin")    return "Sin";
85         if (name == "sinh")   return "Sinh";
86         if (name == "arcsin") return "ArcSin";
87         if (name == "asin")   return "ArcSin";
88         if (name == "cos")    return "Cos";
89         if (name == "cosh")   return "Cosh";
90         if (name == "arccos") return "ArcCos";
91         if (name == "acos")   return "ArcCos";
92         if (name == "tan")    return "Tan";
93         if (name == "tanh")   return "Tanh";
94         if (name == "arctan") return "ArcTan";
95         if (name == "atan")   return "ArcTan";
96         if (name == "cot")    return "Cot";
97         if (name == "coth")   return "Coth";
98         if (name == "csc")    return "Csc";
99         if (name == "sec")    return "Sec";
100         if (name == "exp")    return "Exp";
101         if (name == "log")    return "Log";
102         if (name == "ln" )    return "Log";
103         if (name == "arg" )   return "Arg";
104         if (name == "det" )   return "Det";
105         if (name == "gcd" )   return "GCD";
106         if (name == "max" )   return "Max";
107         if (name == "min" )   return "Min";
108         if (name == "erf" )   return "Erf";
109         if (name == "erfc" )  return "Erfc";
110         return name;
111 }
112
113
114 static docstring asMathematicaName(docstring const & name)
115 {
116         return from_utf8(asMathematicaName(to_utf8(name)));
117 }
118
119
120 void InsetMathExFunc::mathematica(MathematicaStream & os) const
121 {
122         os << asMathematicaName(name_) << '[' << cell(0) << ']';
123 }
124
125
126 docstring InsetMathExFunc::mathmlize(MathStream & os) const
127 {
128         os << "<mi>" << name_ << "</mi><mo>&af;</mo>";
129         return lyx::mathmlize(cell(0), os);
130 }
131
132
133 void InsetMathExFunc::octave(OctaveStream & os) const
134 {
135         os << name_ << '(' << cell(0) << ')';
136 }
137
138
139 } // namespace lyx