COPASI API  4.16.103
Public Member Functions | Static Public Member Functions | List of all members
CMathMLToTeX Class Reference

#include <CMathMLToTeX.h>

Public Member Functions

 CMathMLToTeX ()
 
 ~CMathMLToTeX ()
 

Static Public Member Functions

static void convert (QString &text)
 convert to TeX More...
 
static void mNode (QString &text)
 normal equation node More...
 
static void mtableNode (QString &text)
 converting <mtable> ... </mtable> More...
 
static void replaceLogicOperators (QString &text)
 replace logic operators (eg. <=, <, >=, >, and, or) More...
 
static void replaceMathOperators (QString &text)
 replace mathematical operators (eg. inf, log) More...
 
static void replaceOtherOperators (QString &text)
 replace other operators (eg. .) More...
 
static void replaceTrigoOperators (QString &text)
 replace trigonometrical operators (eg. inf, log) More...
 

Detailed Description

Definition at line 21 of file CMathMLToTeX.h.

Constructor & Destructor Documentation

CMathMLToTeX::CMathMLToTeX ( )
inline

Definition at line 24 of file CMathMLToTeX.h.

24 {};
CMathMLToTeX::~CMathMLToTeX ( )
inline

Definition at line 25 of file CMathMLToTeX.h.

25 {};

Member Function Documentation

void CMathMLToTeX::convert ( QString &  text)
static

convert to TeX

Definition at line 148 of file CMathMLToTeX.cpp.

References mNode(), mtableNode(), replaceLogicOperators(), replaceMathOperators(), replaceOtherOperators(), and replaceTrigoOperators().

Referenced by CQExpressionMmlStackedWidget::saveTeX(), and CQDifferentialEquations::saveTeX().

149 {
150  replaceOtherOperators(text);
151  replaceLogicOperators(text);
152  replaceMathOperators(text);
153  replaceTrigoOperators(text);
154 
155  if (text.contains("mtable"))
156  mtableNode(text);
157  else
158  {
159  if (text.count("<mtable>") > 1)
160  {
161  text = "The MathML contains <mtable> more than one. Needs more handling.";
162  return;
163  }
164 
165  mNode(text);
166  }
167 }
static void replaceTrigoOperators(QString &text)
replace trigonometrical operators (eg. inf, log)
static void mNode(QString &text)
normal equation node
static void replaceOtherOperators(QString &text)
replace other operators (eg. .)
static void mtableNode(QString &text)
converting <mtable> ... </mtable>
static void replaceMathOperators(QString &text)
replace mathematical operators (eg. inf, log)
static void replaceLogicOperators(QString &text)
replace logic operators (eg. <=, <, >=, >, and, or)
void CMathMLToTeX::mNode ( QString &  text)
static

normal equation node

Definition at line 170 of file CMathMLToTeX.cpp.

References CStructureParser::getTeX().

Referenced by convert().

171 {
172  CStructureParser xmlParser(0);
173  QXmlSimpleReader xmlReader;
174 
175  xmlReader.setContentHandler(&xmlParser);
176 
177  QXmlInputSource xmlSource;
178  xmlSource.setData(text);
179 
180  xmlReader.parse(xmlSource);
181 
182  text = xmlParser.getTeX();
183 }
void CMathMLToTeX::mtableNode ( QString &  text)
static

converting <mtable> ... </mtable>

Definition at line 186 of file CMathMLToTeX.cpp.

References CStructureParser::getTeX().

Referenced by convert().

187 {
188  int sumCols = 0;
189 
190  if (text.contains("<mtr>"))
191  {
192  int posA = text.indexOf("<mtr>");
193  int posB = text.indexOf("</mtr>");
194  QString mtrText = text.mid(posA, posB - posA + 6);
195 
196  sumCols = mtrText.count("<mtd");
197  }
198 
199  CStructureParser xmlParser(sumCols);
200  QXmlSimpleReader xmlReader;
201 
202  xmlReader.setContentHandler(&xmlParser);
203 
204  QXmlInputSource xmlSource;
205  xmlSource.setData(text);
206 
207  xmlReader.parse(xmlSource);
208 
209  text = xmlParser.getTeX();
210 }
void CMathMLToTeX::replaceLogicOperators ( QString &  text)
static

replace logic operators (eg. <=, <, >=, >, and, or)

Definition at line 29 of file CMathMLToTeX.cpp.

Referenced by convert().

30 {
31  text.replace("&gt;=", "\\ge");
32  text.replace("&gt;", ">");
33  text.replace("&lt;=", "\\le");
34  text.replace("&lt;", "\\lt");
35  text.replace("&NotEqual;", "\\ne");
36  text.replace("and", "\\wedge");
37 
38  text.replace(" or ", "\\vee");
39 }
void CMathMLToTeX::replaceMathOperators ( QString &  text)
static

replace mathematical operators (eg. inf, log)

Definition at line 42 of file CMathMLToTeX.cpp.

Referenced by convert().

43 {
44  text.replace("log", "\\log");
45  text.replace("ln", "\\ln");
46  text.replace("&infin;", "\\infty");
47  text.replace("&pi;", "\\pi");
48  text.replace("%", "\\%");
49 }
void CMathMLToTeX::replaceOtherOperators ( QString &  text)
static

replace other operators (eg. .)

Definition at line 23 of file CMathMLToTeX.cpp.

Referenced by convert().

24 {
25  text.replace("&CenterDot;", "\\cdot");
26 }
void CMathMLToTeX::replaceTrigoOperators ( QString &  text)
static

replace trigonometrical operators (eg. inf, log)

Definition at line 52 of file CMathMLToTeX.cpp.

Referenced by convert().

53 {
54  // sin, sinh, asin, arcsinh
55 
56  text.replace("arcsinh", "arsoh");
57  text.replace("arcsin", "arcso");
58  text.replace("sinh", "sooh");
59 
60  if (text.length() == 3) // exactly 'sin' word
61  text.replace("sin", "\\sin");
62 
63  text.replace("sooh", "sinh");
64  text.replace("sinh", "\\sinh");
65 
66  text.replace("arcso", "arcsin");
67  text.replace("arcsin", "\\arcsin");
68 
69  text.replace("arsoh", "arcsinh");
70 
71  // cos, cosh, acos, arccosh
72 
73  text.replace("arccosh", "arcoh");
74  text.replace("arccos", "arcce");
75  text.replace("cosh", "cooh");
76 
77  if (text.length() == 3) // exactly 'cos' word
78  text.replace("cos", "\\cos");
79 
80  text.replace("cooh", "cosh");
81  text.replace("cosh", "\\cosh");
82 
83  text.replace("arcce", "arccos");
84  text.replace("arccos", "\\arccos");
85 
86  text.replace("arcoh", "arccosh");
87 
88  // tan, tanh, atan, arctanh
89 
90  text.replace("arctanh", "artoh");
91  text.replace("arctan", "arcto");
92  text.replace("tanh", "tooh");
93 
94  if (text.length() == 3) // exactly 'tan' word
95  text.replace("tan", "\\tan");
96 
97  text.replace("tooh", "tanh");
98  text.replace("tanh", "\\tanh");
99 
100  text.replace("arcto", "arctan");
101  text.replace("arctan", "\\arctan");
102 
103  text.replace("artoh", "arctanh");
104 
105  // sec, sech, arcsec, arcsech
106 
107  text.replace("arcsech", "arsoh");
108  text.replace("arcsec", "arcso");
109  text.replace("sech", "sooh");
110 
111  if (text.length() == 3) // exactly 'sec' word
112  text.replace("sec", "\\sec");
113 
114  text.replace("sooh", "sech");
115  text.replace("arcso", "arcsec");
116  text.replace("arsoh", "arcsech");
117 
118  // csc, csch, arccsc, arccsch
119 
120  text.replace("arccsch", "arcoh");
121  text.replace("arccsc", "arcce");
122  text.replace("csch", "cooh");
123 
124  if (text.length() == 3) // exactly 'csc' word
125  text.replace("csc", "\\csc");
126 
127  text.replace("cooh", "csch");
128  text.replace("arcce", "arccsc");
129  text.replace("arcoh", "arccsch");
130 
131  // cot, coth, arccot, arccoth
132 
133  text.replace("arccoth", "arctoh");
134  text.replace("arccot", "arcto");
135  text.replace("coth", "tooh");
136 
137  if (text.length() == 3) // exactly 'cot' word
138  text.replace("cot", "\\cot");
139 
140  text.replace("tooh", "coth");
141  text.replace("coth", "\\coth");
142 
143  text.replace("arcto", "arccot");
144  text.replace("arctoh", "arccoth");
145 }

The documentation for this class was generated from the following files: