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