COPASI API  4.16.103
Public Member Functions | Private Attributes | List of all members
CStructureParser Class Reference

#include <CStructureParser.h>

Inheritance diagram for CStructureParser:
Inheritance graph
[legend]
Collaboration diagram for CStructureParser:
Collaboration graph
[legend]

Public Member Functions

bool characters (const QString &)
 
 CStructureParser (int)
 
bool endElement (const QString &, const QString &, const QString &)
 
QString getTeX ()
 
bool ignorableWhitespace (const QString &)
 
bool skippedEntity (const QString &)
 
bool startDocument ()
 
bool startElement (const QString &, const QString &, const QString &, const QXmlAttributes &)
 

Private Attributes

QString indent
 
int indexColumns
 
QLinkedList< QString > mListOfUncompletedTags
 
bool needToWriteColumnAllignment
 
int sumColumns
 
QString tagName
 
QString tex
 
QString texHead
 
QString texTail
 

Detailed Description

Definition at line 21 of file CStructureParser.h.

Constructor & Destructor Documentation

CStructureParser::CStructureParser ( int  n)

NOTE: We use index 1 and 2 to refer to the first and to the second part, resp., of some elements. These elements are mfrac, msub, and msup.

Definition at line 26 of file CStructureParser.cpp.

26  :
27  indent(),
28  texHead(),
29  tex(),
30  texTail(),
31  tagName(),
33  sumColumns(n),
34  indexColumns(0),
36 {}
bool needToWriteColumnAllignment
QLinkedList< QString > mListOfUncompletedTags

Member Function Documentation

bool CStructureParser::characters ( const QString &  str)

Definition at line 261 of file CStructureParser.cpp.

References tagName, tex, TO_UTF8, and TRUE.

262 {
263  QRegExp rx("\\w");
264  QString strAux = str.trimmed();
265  int pos = rx.indexIn(strAux);
266 
267  std::cout << TO_UTF8(strAux) << std::endl;
268 
269  if (pos != -1)
270  {
271  // handling word character within <mrow> ... </mrow>
272  if (tagName == "mrow")
273  {
274  if (strAux.length() > 1)
275  tex += "{\\text{" + strAux + "}}";
276  else // exactly only one character
277  tex += "{" + strAux + "}";
278  }
279 
280  // handling word character within <mi> ... </mi>
281  if (tagName == "mi")
282  {
283  if (strAux.contains("\\")) // for, eg., \sin, \cos
284  tex += strAux;
285  else if (strAux.length() > 1)
286  {
287  if (strAux == "sech" || strAux == "csch" || strAux == "arcsec" || strAux == "arccsc"
288  || strAux == "arccot" || strAux == "arcsinh" || strAux == "arccosh" || strAux == "arctanh"
289  || strAux == "arcsech" || strAux == "arccsch" || strAux == "arccoth")
290  tex += "{\\mathrm{" + strAux + " \\: }}";
291  else
292  {
293  strAux.replace("_", "\\_");
294  strAux.replace(" ", "\\;");
295  tex += "{\\mathrm{" + strAux + "}}";
296  }
297  }
298  else // exactly only one character
299  tex += "{" + strAux + "}";
300  }
301 
302  // handling word character within <mo> ... </mo>
303  if (tagName == "mo")
304  {
305  if (strAux.contains("\\")) // for, eg.,\cdot, \ge, \le, \ne
306  {
307  if (strAux == "\\log")
308  tex += " \\, " + strAux;
309  else if (strAux == "\\lt")
310  tex += " \\, < \\, ";
311  else
312  tex += " \\, " + strAux + " \\, ";
313  }
314  else if (strAux.contains("xor"))
315  tex += "\\; \\mathrm{" + strAux + "} \\; ";
316  else if (strAux == "e")
317  tex += strAux;
318  else
319  tex += "\\mathrm{" + strAux + "}";
320  }
321 
322  // handling word character within <mn> ... </mn>
323  if (tagName == "mn")
324  tex += "{" + strAux + "}";
325  }
326  // handling non-word character
327  else if (strAux == "=" || strAux == "!" || strAux == "|")
328  tex += strAux;
329  else if (strAux == "-" || strAux == "+" || strAux == ">" || strAux.contains("%"))
330  tex += " \\, " + strAux + " \\, ";
331 
332  return TRUE;
333 }
#define TRUE
Definition: CGA.h:25
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
bool CStructureParser::endElement ( const QString &  ,
const QString &  ,
const QString &  qName 
)

Definition at line 335 of file CStructureParser.cpp.

References indent, indexColumns, mListOfUncompletedTags, sumColumns, tex, texTail, and TRUE.

336 {
337  QLinkedList< QString >::iterator itL;
338 
339  indent.remove((uint)0, 4);
340 
341  if (qName == "mtable")
342  texTail = "\\end{array}";
343 
344  if (qName == "mfrac")
345  {
346  if (mListOfUncompletedTags.size() > 0 &&
347  mListOfUncompletedTags.last().contains("mfrac")) // must be not empty
348  mListOfUncompletedTags.pop_back();
349 
350  // </mfrac> direct after </mfrac>
351  if (mListOfUncompletedTags.size() > 0 &&
352  mListOfUncompletedTags.last().contains("mfrac")) // must be not empty
353  tex += " }";
354  }
355 
356  if (qName == "mtr")
357  tex += "\\\\ \n && \\\\ \n";
358 
359  if (qName == "mtd")
360  {
361  if (indexColumns > 0 && indexColumns < sumColumns - 1)
362  tex += "& \\; ";
363 
364  indexColumns++;
365  }
366 
367  if (qName == "mrow")
368  {
369  if (mListOfUncompletedTags.size() > 0 &&
370  mListOfUncompletedTags.last() == "mrow") // must not be empty
371  mListOfUncompletedTags.pop_back();
372 
373  tex += " } ";
374  }
375 
376  if (qName == "mfenced")
377  {
378  if (mListOfUncompletedTags.size() > 0 &&
379  mListOfUncompletedTags.last() == "mfenced") // must be not empty
380  mListOfUncompletedTags.pop_back();
381 
382  tex += "\\right)";
383 
384  QString &last = mListOfUncompletedTags.last(); // must be not empty
385 
386  // </msub> direct after </mfenced>
387  if (mListOfUncompletedTags.size() > 0 &&
388  last.contains("msub"))
389  {
390  QStringList strList = last.split("_");
391  QString &lastUncompletedTags = strList.first();
392  QString &idxStr = strList.last();
393  int idx = idxStr.toInt();
394  idx++;
395 
396  // update with incrementally index
397  last = lastUncompletedTags + "_" + QString::number(idx);
398 
399  if (lastUncompletedTags.contains("msub") && idx == 2)
400  tex += "_";
401  }
402 
403  // </msup> direct after </mfenced>
404  if (mListOfUncompletedTags.size() > 0 &&
405  last.contains("msup"))
406  {
407  QStringList strList = last.split("_");
408  QString &lastUncompletedTags = strList.first();
409  QString &idxStr = strList.last();
410  int idx = idxStr.toInt();
411  idx++;
412 
413  // update with incrementally index
414  last = lastUncompletedTags + "_" + QString::number(idx);
415 
416  if (mListOfUncompletedTags.size() > 0 &&
417  lastUncompletedTags.contains("msup") && idx == 2)
418  tex += "^";
419  }
420  }
421 
422  if (qName == "msub")
423  {
424  if (mListOfUncompletedTags.size() > 0 &&
425  mListOfUncompletedTags.last().contains("msub")) // must be not empty
426  mListOfUncompletedTags.pop_back();
427 
428  // </mfrac> direct after </msub>
429  if (mListOfUncompletedTags.size() > 0 &&
430  mListOfUncompletedTags.last().contains("mfrac")) // must ne not empty
431  tex += " }";
432  }
433 
434  if (qName == "msup")
435  {
436  if (mListOfUncompletedTags.size() > 0 &&
437  mListOfUncompletedTags.last().contains("msup")) // must be not empty
438  mListOfUncompletedTags.pop_back();
439 
440  // </mfrac> direct after </msup>
441  if (mListOfUncompletedTags.size() > 0 &&
442  mListOfUncompletedTags.last().contains("mfrac")) // must be not empty
443  tex += " }";
444  }
445 
446  return TRUE;
447 }
#define TRUE
Definition: CGA.h:25
QLinkedList< QString > mListOfUncompletedTags
QString CStructureParser::getTeX ( )

Definition at line 459 of file CStructureParser.cpp.

References tex, texHead, and texTail.

Referenced by CMathMLToTeX::mNode(), and CMathMLToTeX::mtableNode().

460 {
461  QString texIntro;
462 
463  texIntro = "%%% Attention: \n";
464  texIntro += "%%% We provide only the LaTeX code of the Differential Equations. \n";
465  texIntro += "%%% You need to include it in your TeX document. \n";
466  texIntro += "%%% Some manual adjustments may be needed for too wide equations. \n\n";
467 
468  if (!texHead.isNull())
469  return texIntro + "$$\n" + texHead + "\n" + tex + texTail + "\n$$";
470  else
471  return texIntro + "$$\n" + tex + "\n$$";
472 }
bool CStructureParser::ignorableWhitespace ( const QString &  )

Definition at line 449 of file CStructureParser.cpp.

References TRUE.

450 {
451  return TRUE;
452 }
#define TRUE
Definition: CGA.h:25
bool CStructureParser::skippedEntity ( const QString &  )

Definition at line 454 of file CStructureParser.cpp.

References TRUE.

455 {
456  return TRUE;
457 }
#define TRUE
Definition: CGA.h:25
bool CStructureParser::startDocument ( )

Definition at line 38 of file CStructureParser.cpp.

References indent, indexColumns, needToWriteColumnAllignment, sumColumns, tex, and TRUE.

39 {
40  indent = "";
41  tex = "";
42 
43  indexColumns = -1;
44 
45  if (!sumColumns)
47  else
49 
50  return TRUE;
51 }
bool needToWriteColumnAllignment
#define TRUE
Definition: CGA.h:25
bool CStructureParser::startElement ( const QString &  ,
const QString &  ,
const QString &  qName,
const QXmlAttributes &  attr 
)

Definition at line 53 of file CStructureParser.cpp.

References indent, indexColumns, mListOfUncompletedTags, needToWriteColumnAllignment, sumColumns, tagName, tex, texHead, and TRUE.

56 {
57  tagName = qName;
58 
59  QLinkedList< QString >::iterator itL;
60 
61  if (qName == "mtable")
62  texHead = "\\begin{array}";
63 
64  if (qName == "mtr")
65  indexColumns = 0;
66 
67  if (qName == "mtd")
68  {
69  if (indexColumns > 0 && indexColumns < sumColumns - 1)
70  tex += " \\; &";
71 
73  texHead += "{";
74 
76  {
77  if (attr.count())
78  {
79  if (attr.value("columnalign") == "left")
80  texHead += "l";
81  else if (attr.value("columnalign") == "center")
82  texHead += "c";
83  else if (attr.value("columnalign") == "right")
84  texHead += "r";
85  }
86  else
87  texHead += "c";
88  }
89 
90  if (indexColumns == sumColumns - 1)
91  {
93  texHead += "}";
94 
96  }
97  }
98 
99  if (qName == "mfrac") // find a mfrac element
100  {
101  // increment index, if any
102  if (!mListOfUncompletedTags.isEmpty())
103  {
104  QString &last = mListOfUncompletedTags.last(); // must be not empty
105 
106  // <mfrac> direct after <mfrac>
107  if (last.contains("mfrac"))
108  {
109  QStringList strList = last.split("_");
110  QString &lastUncompletedTags = strList.first();
111  QString &idxStr = strList.last();
112  int idx = idxStr.toInt();
113  idx++;
114 
115  // update with incrementally index
116  last = lastUncompletedTags + "_" + QString::number(idx);
117 
118  tex += "{";
119  }
120  }
121 
122  mListOfUncompletedTags.push_back("mfrac_0");
123  tex += "\\frac";
124  }
125 
126  if (qName == "mfenced")
127  {
128  mListOfUncompletedTags.push_back("mfenced");
129  tex += "\\left(";
130  }
131 
132  if (qName == "msub")
133  {
134  if (mListOfUncompletedTags.size() > 0)
135  {
136  QString &last = mListOfUncompletedTags.last(); // must be not empty
137 
138  // <msub> direct after <mfrac>
139  if (last.contains("mfrac"))
140  {
141  QStringList strList = last.split("_");
142  QString &lastUncompletedTags = strList.first();
143  QString &idxStr = strList.last();
144  int idx = idxStr.toInt();
145  idx++;
146 
147  // update with incrementally index
148  last = lastUncompletedTags + "_" + QString::number(idx);
149 
150  tex += "{";
151  }
152 
153  // <msub> direct after <mfenced>
154  if (last.contains("mfenced") && (!tex.endsWith("(") && !tex.endsWith("(")))
155  {
156  tex += ", \\, ";
157  }
158  }
159 
160  mListOfUncompletedTags.push_back("msub_0");
161  }
162 
163  if (qName == "msup")
164  {
165  if (mListOfUncompletedTags.size() > 0)
166  {
167  QString &last = mListOfUncompletedTags.last(); // must be not empty
168 
169  // <msup> direct after <mfrac>
170  if (last.contains("mfrac"))
171  {
172  QStringList strList = last.split("_");
173  QString &lastUncompletedTags = strList.first();
174  QString &idxStr = strList.last();
175  int idx = idxStr.toInt();
176  idx++;
177 
178  // update with incrementally index
179  last = lastUncompletedTags + "_" + QString::number(idx);
180 
181  tex += "{";
182  }
183 
184  // <msup> direct after <mfenced>
185  if (last.contains("mfenced") && (!tex.endsWith("(") && !tex.endsWith("(")))
186  {
187  tex += ", \\, ";
188  }
189  }
190 
191  mListOfUncompletedTags.push_back("msup_0");
192  }
193 
194  if (qName == "mrow")
195  {
196  // increment index, if any
197  if (!mListOfUncompletedTags.isEmpty())
198  {
199  QString &last = mListOfUncompletedTags.last(); // can be empty
200 
201  if (last.contains("mfrac") || last.contains("msub") || last.contains("msup"))
202  {
203  QStringList strList = last.split("_");
204  QString &lastUncompletedTags = strList.first();
205  QString &idxStr = strList.last();
206  int idx = idxStr.toInt();
207  idx++;
208 
209  // update with incrementally index
210  last = lastUncompletedTags + "_" + QString::number(idx);
211 
212  if (lastUncompletedTags.contains("msub") && idx == 2)
213  tex += "_";
214 
215  if (lastUncompletedTags.contains("msup") && idx == 2)
216  tex += "^";
217  }
218  }
219 
220  mListOfUncompletedTags.push_back("mrow");
221  tex += " {";
222  }
223 
224  if (qName == "mi" || qName == "mo" || qName == "mn")
225  {
226  // increment index, if any
227  if (!mListOfUncompletedTags.isEmpty())
228  {
229  QString &last = mListOfUncompletedTags.last(); // can be empty
230 
231  if (last.contains("mfrac") || last.contains("msub") || last.contains("msup"))
232  {
233  QStringList strList = last.split("_");
234  QString &lastUncompletedTags = strList.first();
235  QString &idxStr = strList.last();
236  int idx = idxStr.toInt();
237  idx++;
238 
239  // update with incrementally index
240  last = lastUncompletedTags + "_" + QString::number(idx);
241 
242  if (lastUncompletedTags.contains("msub") && idx == 2)
243  tex += "_";
244 
245  if (lastUncompletedTags.contains("msup") && idx == 2)
246  tex += "^";
247  }
248 
249  if (last.contains("mfenced") && (!tex.endsWith("(") && !tex.endsWith("(")))
250  {
251  tex += ", \\, ";
252  }
253  }
254  }
255 
256  indent += " ";
257 
258  return TRUE;
259 }
bool needToWriteColumnAllignment
#define TRUE
Definition: CGA.h:25
QLinkedList< QString > mListOfUncompletedTags

Member Data Documentation

QString CStructureParser::indent
private

Definition at line 39 of file CStructureParser.h.

Referenced by endElement(), startDocument(), and startElement().

int CStructureParser::indexColumns
private

Definition at line 50 of file CStructureParser.h.

Referenced by endElement(), startDocument(), and startElement().

QLinkedList<QString> CStructureParser::mListOfUncompletedTags
private

Definition at line 52 of file CStructureParser.h.

Referenced by endElement(), and startElement().

bool CStructureParser::needToWriteColumnAllignment
private

Definition at line 48 of file CStructureParser.h.

Referenced by startDocument(), and startElement().

int CStructureParser::sumColumns
private

Definition at line 49 of file CStructureParser.h.

Referenced by endElement(), startDocument(), and startElement().

QString CStructureParser::tagName
private

Definition at line 45 of file CStructureParser.h.

Referenced by characters(), and startElement().

QString CStructureParser::tex
private

Definition at line 42 of file CStructureParser.h.

Referenced by characters(), endElement(), getTeX(), startDocument(), and startElement().

QString CStructureParser::texHead
private

Definition at line 42 of file CStructureParser.h.

Referenced by getTeX(), and startElement().

QString CStructureParser::texTail
private

Definition at line 42 of file CStructureParser.h.

Referenced by endElement(), and getTeX().


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