2003-08-19 13:00:56 +00:00
|
|
|
|
/**
|
2007-04-25 03:01:35 +00:00
|
|
|
|
* \file MathParser.cpp
|
2003-08-19 13:00:56 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
1999-09-27 18:44:28 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2002-03-21 17:42:56 +00:00
|
|
|
|
/*
|
2001-10-29 15:45:24 +00:00
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
|
If someone desperately needs partial "structures" (such as a few
|
|
|
|
|
cells of an array inset or similar) (s)he could uses the
|
|
|
|
|
following hack as starting point to write some macros:
|
2001-10-29 15:45:24 +00:00
|
|
|
|
|
|
|
|
|
\newif\ifcomment
|
|
|
|
|
\commentfalse
|
|
|
|
|
\ifcomment
|
|
|
|
|
\def\makeamptab{\catcode`\&=4\relax}
|
|
|
|
|
\def\makeampletter{\catcode`\&=11\relax}
|
|
|
|
|
\def\b{\makeampletter\expandafter\makeamptab\bi}
|
|
|
|
|
\long\def\bi#1\e{}
|
|
|
|
|
\else
|
|
|
|
|
\def\b{}\def\e{}
|
|
|
|
|
\fi
|
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
\[\begin{array}{ccc}
|
2003-02-13 16:53:15 +00:00
|
|
|
|
1
|
|
|
|
|
&
|
|
|
|
|
|
2001-10-29 15:45:24 +00:00
|
|
|
|
\end{array}\]
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include <config.h>
|
2000-09-26 13:54:57 +00:00
|
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "MathParser.h"
|
2006-09-17 10:00:15 +00:00
|
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "InsetMathArray.h"
|
|
|
|
|
#include "InsetMathBig.h"
|
|
|
|
|
#include "InsetMathBrace.h"
|
|
|
|
|
#include "InsetMathChar.h"
|
|
|
|
|
#include "InsetMathColor.h"
|
|
|
|
|
#include "InsetMathComment.h"
|
|
|
|
|
#include "InsetMathDelim.h"
|
|
|
|
|
#include "InsetMathEnv.h"
|
|
|
|
|
#include "InsetMathKern.h"
|
2007-04-25 16:11:45 +00:00
|
|
|
|
#include "MathMacro.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "InsetMathPar.h"
|
2006-09-17 10:00:15 +00:00
|
|
|
|
#include "InsetMathRef.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "InsetMathRoot.h"
|
|
|
|
|
#include "InsetMathScript.h"
|
2006-10-02 20:01:30 +00:00
|
|
|
|
#include "InsetMathSplit.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "InsetMathSqrt.h"
|
|
|
|
|
#include "InsetMathTabular.h"
|
2006-09-17 10:00:15 +00:00
|
|
|
|
#include "MathMacroTemplate.h"
|
|
|
|
|
#include "MathFactory.h"
|
|
|
|
|
#include "MathMacroArgument.h"
|
|
|
|
|
#include "MathSupport.h"
|
2002-06-24 15:51:35 +00:00
|
|
|
|
|
2007-04-26 11:30:54 +00:00
|
|
|
|
#include "Lexer.h"
|
2001-11-08 12:55:58 +00:00
|
|
|
|
#include "debug.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2005-01-27 21:05:44 +00:00
|
|
|
|
#include "support/convert.h"
|
2004-07-24 10:55:30 +00:00
|
|
|
|
|
2005-01-27 21:05:44 +00:00
|
|
|
|
#include <sstream>
|
2004-11-07 13:27:20 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
2003-09-08 00:33:41 +00:00
|
|
|
|
using std::endl;
|
|
|
|
|
using std::fill;
|
2001-12-18 03:16:46 +00:00
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2003-09-08 00:33:41 +00:00
|
|
|
|
using std::ios;
|
2000-04-04 00:19:15 +00:00
|
|
|
|
using std::istream;
|
2001-08-17 11:08:55 +00:00
|
|
|
|
using std::ostream;
|
2002-02-16 15:59:55 +00:00
|
|
|
|
using std::vector;
|
2000-03-28 02:18:55 +00:00
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
|
|
2002-02-15 14:07:09 +00:00
|
|
|
|
//#define FILEDEBUG
|
|
|
|
|
|
2000-11-02 04:48:34 +00:00
|
|
|
|
|
2001-08-10 07:52:04 +00:00
|
|
|
|
namespace {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
InsetMath::mode_type asMode(InsetMath::mode_type oldmode, docstring const & str)
|
2002-08-08 14:22:44 +00:00
|
|
|
|
{
|
2003-08-02 11:30:30 +00:00
|
|
|
|
//lyxerr << "handling mode: '" << str << "'" << endl;
|
2002-08-08 14:22:44 +00:00
|
|
|
|
if (str == "mathmode")
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return InsetMath::MATH_MODE;
|
2002-08-08 14:22:44 +00:00
|
|
|
|
if (str == "textmode" || str == "forcetext")
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return InsetMath::TEXT_MODE;
|
2002-10-15 08:41:35 +00:00
|
|
|
|
return oldmode;
|
2002-08-08 14:22:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
bool stared(docstring const & s)
|
2001-08-17 09:48:24 +00:00
|
|
|
|
{
|
2006-10-22 10:15:23 +00:00
|
|
|
|
size_t const n = s.size();
|
2001-08-17 09:48:24 +00:00
|
|
|
|
return n && s[n - 1] == '*';
|
|
|
|
|
}
|
|
|
|
|
|
2001-08-10 09:30:02 +00:00
|
|
|
|
|
2004-12-28 15:43:29 +00:00
|
|
|
|
/*!
|
|
|
|
|
* Add the row \p cellrow to \p grid.
|
|
|
|
|
* \returns wether the row could be added. Adding a row can fail for
|
|
|
|
|
* environments like "equation" that have a fixed number of rows.
|
|
|
|
|
*/
|
2006-09-16 18:11:38 +00:00
|
|
|
|
bool addRow(InsetMathGrid & grid, InsetMathGrid::row_type & cellrow,
|
2007-03-19 16:08:17 +00:00
|
|
|
|
docstring const & vskip, bool allow_pagebreak = true)
|
2004-12-28 15:43:29 +00:00
|
|
|
|
{
|
|
|
|
|
++cellrow;
|
|
|
|
|
if (cellrow == grid.nrows()) {
|
|
|
|
|
//lyxerr << "adding row " << cellrow << endl;
|
|
|
|
|
grid.addRow(cellrow - 1);
|
|
|
|
|
if (cellrow == grid.nrows()) {
|
|
|
|
|
// We can't add a row to this grid, so let's
|
|
|
|
|
// append the content of this cell to the previous
|
|
|
|
|
// one.
|
|
|
|
|
// This does not happen in well formed .lyx files,
|
|
|
|
|
// but LyX versions 1.3.x and older could create
|
2005-01-07 13:32:26 +00:00
|
|
|
|
// such files and tex2lyx can still do that.
|
2004-12-28 15:43:29 +00:00
|
|
|
|
--cellrow;
|
|
|
|
|
lyxerr << "ignoring extra row";
|
|
|
|
|
if (!vskip.empty())
|
2006-10-22 10:15:23 +00:00
|
|
|
|
lyxerr << " with extra space " << to_utf8(vskip);
|
2007-03-19 16:08:17 +00:00
|
|
|
|
if (!allow_pagebreak)
|
|
|
|
|
lyxerr << " with no page break allowed";
|
2004-12-28 15:43:29 +00:00
|
|
|
|
lyxerr << '.' << endl;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-04-28 12:58:49 +00:00
|
|
|
|
grid.vcrskip(Length(to_utf8(vskip)), cellrow - 1);
|
2007-03-19 16:08:17 +00:00
|
|
|
|
grid.rowinfo(cellrow - 1).allow_pagebreak_ = allow_pagebreak;
|
2004-12-28 15:43:29 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* Add the column \p cellcol to \p grid.
|
|
|
|
|
* \returns wether the column could be added. Adding a column can fail for
|
|
|
|
|
* environments like "eqnarray" that have a fixed number of columns.
|
|
|
|
|
*/
|
2006-09-16 18:11:38 +00:00
|
|
|
|
bool addCol(InsetMathGrid & grid, InsetMathGrid::col_type & cellcol)
|
2004-12-28 15:43:29 +00:00
|
|
|
|
{
|
|
|
|
|
++cellcol;
|
|
|
|
|
if (cellcol == grid.ncols()) {
|
|
|
|
|
//lyxerr << "adding column " << cellcol << endl;
|
|
|
|
|
grid.addCol(cellcol - 1);
|
|
|
|
|
if (cellcol == grid.ncols()) {
|
|
|
|
|
// We can't add a column to this grid, so let's
|
|
|
|
|
// append the content of this cell to the previous
|
|
|
|
|
// one.
|
|
|
|
|
// This does not happen in well formed .lyx files,
|
|
|
|
|
// but LyX versions 1.3.x and older could create
|
2005-01-07 13:32:26 +00:00
|
|
|
|
// such files and tex2lyx can still do that.
|
2004-12-28 15:43:29 +00:00
|
|
|
|
--cellcol;
|
|
|
|
|
lyxerr << "ignoring extra column." << endl;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-02-14 14:25:18 +00:00
|
|
|
|
/*!
|
|
|
|
|
* Check wether the last row is empty and remove it if yes.
|
|
|
|
|
* Otherwise the following code
|
|
|
|
|
* \verbatim
|
|
|
|
|
\begin{array}{|c|c|}
|
|
|
|
|
\hline
|
|
|
|
|
1 & 2 \\ \hline
|
|
|
|
|
3 & 4 \\ \hline
|
|
|
|
|
\end{array}
|
|
|
|
|
* \endverbatim
|
|
|
|
|
* will result in a grid with 3 rows (+ the dummy row that is always present),
|
|
|
|
|
* because the last '\\' opens a new row.
|
|
|
|
|
*/
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void delEmptyLastRow(InsetMathGrid & grid)
|
2005-02-14 14:25:18 +00:00
|
|
|
|
{
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathGrid::row_type const row = grid.nrows() - 1;
|
|
|
|
|
for (InsetMathGrid::col_type col = 0; col < grid.ncols(); ++col) {
|
2005-02-14 14:25:18 +00:00
|
|
|
|
if (!grid.cell(grid.index(row, col)).empty())
|
|
|
|
|
return;
|
|
|
|
|
}
|
2005-11-08 15:12:05 +00:00
|
|
|
|
// Copy the row information of the empty row (which would contain the
|
|
|
|
|
// last hline in the example above) to the dummy row and delete the
|
|
|
|
|
// empty row.
|
|
|
|
|
grid.rowinfo(row + 1) = grid.rowinfo(row);
|
|
|
|
|
grid.delRow(row);
|
2005-02-14 14:25:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
// These are TeX's catcodes
|
|
|
|
|
enum CatCode {
|
2002-03-21 17:42:56 +00:00
|
|
|
|
catEscape, // 0 backslash
|
2001-08-17 09:48:24 +00:00
|
|
|
|
catBegin, // 1 {
|
|
|
|
|
catEnd, // 2 }
|
|
|
|
|
catMath, // 3 $
|
|
|
|
|
catAlign, // 4 &
|
|
|
|
|
catNewline, // 5 ^^M
|
|
|
|
|
catParameter, // 6 #
|
|
|
|
|
catSuper, // 7 ^
|
|
|
|
|
catSub, // 8 _
|
2002-03-21 17:42:56 +00:00
|
|
|
|
catIgnore, // 9
|
2001-08-17 09:48:24 +00:00
|
|
|
|
catSpace, // 10 space
|
|
|
|
|
catLetter, // 11 a-zA-Z
|
|
|
|
|
catOther, // 12 none of the above
|
|
|
|
|
catActive, // 13 ~
|
|
|
|
|
catComment, // 14 %
|
|
|
|
|
catInvalid // 15 <delete>
|
2001-06-25 00:06:33 +00:00
|
|
|
|
};
|
|
|
|
|
|
2006-11-04 11:03:14 +00:00
|
|
|
|
CatCode theCatcode[128];
|
2001-08-17 10:21:37 +00:00
|
|
|
|
|
|
|
|
|
|
2006-11-05 08:53:52 +00:00
|
|
|
|
inline CatCode catcode(char_type c)
|
2001-08-17 10:21:37 +00:00
|
|
|
|
{
|
2006-11-05 08:53:52 +00:00
|
|
|
|
/* The only characters that are not catOther lie in the pure ASCII
|
|
|
|
|
* range. Therefore theCatcode has only 128 entries.
|
|
|
|
|
* TeX itself deals with 8bit characters, so if needed this table
|
|
|
|
|
* could be enlarged to 256 entries.
|
|
|
|
|
* Any larger value does not make sense, since the fact that we use
|
|
|
|
|
* unicode internally does not change Knuth's TeX engine.
|
|
|
|
|
* Apart from that a table for the full 21bit UCS4 range would waste
|
|
|
|
|
* too much memory. */
|
2006-11-04 11:03:14 +00:00
|
|
|
|
if (c >= 128)
|
|
|
|
|
return catOther;
|
|
|
|
|
|
2001-08-17 10:21:37 +00:00
|
|
|
|
return theCatcode[c];
|
|
|
|
|
}
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
enum {
|
2005-01-10 08:38:28 +00:00
|
|
|
|
FLAG_ALIGN = 1 << 0, // next & or \\ ends the parsing process
|
|
|
|
|
FLAG_BRACE_LAST = 1 << 1, // next closing brace ends the parsing
|
2001-08-17 09:48:24 +00:00
|
|
|
|
FLAG_RIGHT = 1 << 2, // next \\right ends the parsing process
|
|
|
|
|
FLAG_END = 1 << 3, // next \\end ends the parsing process
|
2002-07-08 11:29:51 +00:00
|
|
|
|
FLAG_BRACK_LAST = 1 << 4, // next closing bracket ends the parsing
|
2002-06-18 15:44:30 +00:00
|
|
|
|
FLAG_TEXTMODE = 1 << 5, // we are in a box
|
2002-02-04 18:44:51 +00:00
|
|
|
|
FLAG_ITEM = 1 << 6, // read a (possibly braced token)
|
2002-06-18 15:44:30 +00:00
|
|
|
|
FLAG_LEAVE = 1 << 7, // leave the loop at the end
|
|
|
|
|
FLAG_SIMPLE = 1 << 8, // next $ leaves the loop
|
|
|
|
|
FLAG_EQUATION = 1 << 9, // next \] leaves the loop
|
2002-07-08 11:29:51 +00:00
|
|
|
|
FLAG_SIMPLE2 = 1 << 10, // next \) leaves the loop
|
2002-08-12 09:53:04 +00:00
|
|
|
|
FLAG_OPTION = 1 << 11, // read [...] style option
|
2004-08-13 15:06:46 +00:00
|
|
|
|
FLAG_BRACED = 1 << 12 // read {...} style argument
|
1999-09-27 18:44:28 +00:00
|
|
|
|
};
|
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
//
|
|
|
|
|
// Helper class for parsing
|
|
|
|
|
//
|
2001-02-26 12:53:35 +00:00
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
class Token {
|
|
|
|
|
public:
|
|
|
|
|
///
|
|
|
|
|
Token() : cs_(), char_(0), cat_(catIgnore) {}
|
|
|
|
|
///
|
2006-10-22 10:15:23 +00:00
|
|
|
|
Token(char_type c, CatCode cat) : cs_(), char_(c), cat_(cat) {}
|
2001-08-17 09:48:24 +00:00
|
|
|
|
///
|
2007-03-30 17:16:26 +00:00
|
|
|
|
explicit Token(docstring const & cs) : cs_(cs), char_(0), cat_(catIgnore) {}
|
2001-02-26 12:53:35 +00:00
|
|
|
|
|
2001-08-17 10:51:50 +00:00
|
|
|
|
///
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring const & cs() const { return cs_; }
|
2001-08-17 09:48:24 +00:00
|
|
|
|
///
|
|
|
|
|
CatCode cat() const { return cat_; }
|
|
|
|
|
///
|
2006-10-22 10:15:23 +00:00
|
|
|
|
char_type character() const { return char_; }
|
2001-08-17 09:48:24 +00:00
|
|
|
|
///
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring asString() const { return cs_.size() ? cs_ : docstring(1, char_); }
|
2006-04-20 09:55:45 +00:00
|
|
|
|
///
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring asInput() const { return cs_.size() ? '\\' + cs_ : docstring(1, char_); }
|
2001-08-13 14:02:37 +00:00
|
|
|
|
|
2002-03-21 17:42:56 +00:00
|
|
|
|
private:
|
2001-08-17 09:48:24 +00:00
|
|
|
|
///
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring cs_;
|
2001-08-17 09:48:24 +00:00
|
|
|
|
///
|
2006-10-22 10:15:23 +00:00
|
|
|
|
char_type char_;
|
2001-08-17 09:48:24 +00:00
|
|
|
|
///
|
|
|
|
|
CatCode cat_;
|
|
|
|
|
};
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2007-03-30 17:16:26 +00:00
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
ostream & operator<<(ostream & os, Token const & t)
|
|
|
|
|
{
|
2007-01-31 17:59:48 +00:00
|
|
|
|
if (t.cs().size()) {
|
|
|
|
|
docstring const & cs = t.cs();
|
|
|
|
|
// FIXME: For some strange reason, the stream operator instanciate
|
|
|
|
|
// a new Token before outputting the contents of t.cs().
|
2007-05-28 22:27:45 +00:00
|
|
|
|
// Because of this the line
|
2007-01-31 17:59:48 +00:00
|
|
|
|
// os << '\\' << cs;
|
|
|
|
|
// below becomes recursive.
|
|
|
|
|
// In order to avoid that we return early:
|
|
|
|
|
if (cs == "\\")
|
|
|
|
|
return os;
|
2007-03-30 17:16:26 +00:00
|
|
|
|
os << '\\' << to_utf8(cs);
|
2007-01-31 17:59:48 +00:00
|
|
|
|
}
|
2003-03-04 09:06:13 +00:00
|
|
|
|
else if (t.cat() == catLetter)
|
|
|
|
|
os << t.character();
|
2001-08-17 09:48:24 +00:00
|
|
|
|
else
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << '[' << t.character() << ',' << t.cat() << ']';
|
2001-08-17 09:48:24 +00:00
|
|
|
|
return os;
|
|
|
|
|
}
|
2001-08-10 09:30:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Parser {
|
|
|
|
|
public:
|
2002-08-08 14:22:44 +00:00
|
|
|
|
///
|
2006-09-16 18:11:38 +00:00
|
|
|
|
typedef InsetMath::mode_type mode_type;
|
2002-08-08 14:22:44 +00:00
|
|
|
|
|
2001-08-10 09:30:02 +00:00
|
|
|
|
///
|
2007-04-26 11:30:54 +00:00
|
|
|
|
Parser(Lexer & lex);
|
2006-12-19 14:24:25 +00:00
|
|
|
|
/// Only use this for reading from .lyx file format, for the reason
|
|
|
|
|
/// see Parser::tokenize(std::istream &).
|
2001-08-17 09:48:24 +00:00
|
|
|
|
Parser(istream & is);
|
2006-12-19 14:24:25 +00:00
|
|
|
|
///
|
|
|
|
|
Parser(docstring const & str);
|
2001-08-10 09:30:02 +00:00
|
|
|
|
|
|
|
|
|
///
|
2002-07-12 14:24:47 +00:00
|
|
|
|
bool parse(MathAtom & at);
|
2001-08-10 09:30:02 +00:00
|
|
|
|
///
|
2007-04-26 16:05:57 +00:00
|
|
|
|
void parse(MathData & array, unsigned flags, mode_type mode);
|
2001-08-10 09:30:02 +00:00
|
|
|
|
///
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void parse1(InsetMathGrid & grid, unsigned flags, mode_type mode,
|
2002-08-14 16:11:55 +00:00
|
|
|
|
bool numbered);
|
|
|
|
|
///
|
2007-04-26 16:05:57 +00:00
|
|
|
|
MathData parse(unsigned flags, mode_type mode);
|
2002-08-12 09:53:04 +00:00
|
|
|
|
///
|
2001-08-10 09:30:02 +00:00
|
|
|
|
int lineno() const { return lineno_; }
|
2001-08-13 14:46:06 +00:00
|
|
|
|
///
|
2001-08-17 09:48:24 +00:00
|
|
|
|
void putback();
|
2001-08-10 09:30:02 +00:00
|
|
|
|
|
|
|
|
|
private:
|
2002-02-07 09:47:21 +00:00
|
|
|
|
///
|
2002-08-08 14:22:44 +00:00
|
|
|
|
void parse2(MathAtom & at, unsigned flags, mode_type mode, bool numbered);
|
2002-05-30 07:09:54 +00:00
|
|
|
|
/// get arg delimited by 'left' and 'right'
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring getArg(char_type left, char_type right);
|
2001-08-10 09:30:02 +00:00
|
|
|
|
///
|
2006-10-22 10:15:23 +00:00
|
|
|
|
char_type getChar();
|
2001-08-10 09:30:02 +00:00
|
|
|
|
///
|
|
|
|
|
void error(string const & msg);
|
2006-10-22 10:15:23 +00:00
|
|
|
|
void error(docstring const & msg) { error(to_utf8(msg)); }
|
2002-02-11 08:19:02 +00:00
|
|
|
|
/// dump contents to screen
|
|
|
|
|
void dump() const;
|
2006-12-19 14:24:25 +00:00
|
|
|
|
/// Only use this for reading from .lyx file format (see
|
|
|
|
|
/// implementation for reason)
|
2001-08-17 09:48:24 +00:00
|
|
|
|
void tokenize(istream & is);
|
2001-08-10 09:30:02 +00:00
|
|
|
|
///
|
2006-10-22 10:15:23 +00:00
|
|
|
|
void tokenize(docstring const & s);
|
2001-08-17 09:48:24 +00:00
|
|
|
|
///
|
2006-10-22 12:07:01 +00:00
|
|
|
|
void skipSpaceTokens(idocstream & is, char_type c);
|
2002-02-12 09:11:50 +00:00
|
|
|
|
///
|
2001-08-17 09:48:24 +00:00
|
|
|
|
void push_back(Token const & t);
|
|
|
|
|
///
|
|
|
|
|
void pop_back();
|
2001-08-10 09:30:02 +00:00
|
|
|
|
///
|
2001-08-17 09:48:24 +00:00
|
|
|
|
Token const & prevToken() const;
|
2001-08-10 09:30:02 +00:00
|
|
|
|
///
|
2001-08-17 09:48:24 +00:00
|
|
|
|
Token const & nextToken() const;
|
2001-08-10 09:30:02 +00:00
|
|
|
|
///
|
2001-08-17 09:48:24 +00:00
|
|
|
|
Token const & getToken();
|
2001-11-28 13:09:40 +00:00
|
|
|
|
/// skips spaces if any
|
|
|
|
|
void skipSpaces();
|
2001-08-17 09:48:24 +00:00
|
|
|
|
///
|
2006-10-22 10:15:23 +00:00
|
|
|
|
void lex(docstring const & s);
|
2001-08-17 09:48:24 +00:00
|
|
|
|
///
|
|
|
|
|
bool good() const;
|
2002-09-30 06:48:53 +00:00
|
|
|
|
///
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring parse_verbatim_item();
|
2002-09-30 06:48:53 +00:00
|
|
|
|
///
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring parse_verbatim_option();
|
2001-08-10 09:30:02 +00:00
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
///
|
|
|
|
|
int lineno_;
|
|
|
|
|
///
|
2002-02-16 15:59:55 +00:00
|
|
|
|
vector<Token> tokens_;
|
2001-08-17 09:48:24 +00:00
|
|
|
|
///
|
|
|
|
|
unsigned pos_;
|
2005-02-14 14:25:18 +00:00
|
|
|
|
/// Stack of active environments
|
2006-10-22 10:15:23 +00:00
|
|
|
|
vector<docstring> environments_;
|
2001-08-10 09:30:02 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 11:30:54 +00:00
|
|
|
|
Parser::Parser(Lexer & lexer)
|
2002-06-03 07:31:08 +00:00
|
|
|
|
: lineno_(lexer.getLineNo()), pos_(0)
|
2001-08-13 14:46:06 +00:00
|
|
|
|
{
|
2001-08-17 09:48:24 +00:00
|
|
|
|
tokenize(lexer.getStream());
|
2001-08-18 12:02:40 +00:00
|
|
|
|
lexer.eatLine();
|
2001-08-13 14:46:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
Parser::Parser(istream & is)
|
2002-06-03 07:31:08 +00:00
|
|
|
|
: lineno_(0), pos_(0)
|
2001-08-10 09:30:02 +00:00
|
|
|
|
{
|
2001-08-17 09:48:24 +00:00
|
|
|
|
tokenize(is);
|
2001-08-10 09:30:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-12-19 14:24:25 +00:00
|
|
|
|
Parser::Parser(docstring const & str)
|
|
|
|
|
: lineno_(0), pos_(0)
|
|
|
|
|
{
|
|
|
|
|
tokenize(str);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
void Parser::push_back(Token const & t)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-08-17 09:48:24 +00:00
|
|
|
|
tokens_.push_back(t);
|
|
|
|
|
}
|
2001-07-13 07:55:55 +00:00
|
|
|
|
|
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
void Parser::pop_back()
|
|
|
|
|
{
|
|
|
|
|
tokens_.pop_back();
|
|
|
|
|
}
|
2001-07-13 07:55:55 +00:00
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
|
|
|
|
|
Token const & Parser::prevToken() const
|
|
|
|
|
{
|
|
|
|
|
static const Token dummy;
|
|
|
|
|
return pos_ > 0 ? tokens_[pos_ - 1] : dummy;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-11-15 11:06:41 +00:00
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
Token const & Parser::nextToken() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-08-17 09:48:24 +00:00
|
|
|
|
static const Token dummy;
|
|
|
|
|
return good() ? tokens_[pos_] : dummy;
|
|
|
|
|
}
|
2001-08-13 14:46:06 +00:00
|
|
|
|
|
2001-08-14 07:46:11 +00:00
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
Token const & Parser::getToken()
|
|
|
|
|
{
|
|
|
|
|
static const Token dummy;
|
2003-08-02 11:30:30 +00:00
|
|
|
|
//lyxerr << "looking at token " << tokens_[pos_] << " pos: " << pos_ << endl;
|
2001-08-17 09:48:24 +00:00
|
|
|
|
return good() ? tokens_[pos_++] : dummy;
|
|
|
|
|
}
|
2001-08-14 07:46:11 +00:00
|
|
|
|
|
2001-08-13 14:46:06 +00:00
|
|
|
|
|
2001-11-28 13:09:40 +00:00
|
|
|
|
void Parser::skipSpaces()
|
|
|
|
|
{
|
2002-08-02 07:50:01 +00:00
|
|
|
|
while (nextToken().cat() == catSpace || nextToken().cat() == catNewline)
|
2001-11-28 13:09:40 +00:00
|
|
|
|
getToken();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
void Parser::putback()
|
|
|
|
|
{
|
|
|
|
|
--pos_;
|
|
|
|
|
}
|
2001-08-13 14:46:06 +00:00
|
|
|
|
|
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
bool Parser::good() const
|
|
|
|
|
{
|
|
|
|
|
return pos_ < tokens_.size();
|
|
|
|
|
}
|
2001-08-13 14:46:06 +00:00
|
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
char_type Parser::getChar()
|
2001-08-17 09:48:24 +00:00
|
|
|
|
{
|
2002-06-24 15:37:14 +00:00
|
|
|
|
if (!good())
|
|
|
|
|
error("The input stream is not well...");
|
2001-08-17 09:48:24 +00:00
|
|
|
|
return tokens_[pos_++].character();
|
|
|
|
|
}
|
|
|
|
|
|
2001-08-13 14:46:06 +00:00
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring Parser::getArg(char_type left, char_type right)
|
2001-08-17 09:48:24 +00:00
|
|
|
|
{
|
2002-02-11 08:19:02 +00:00
|
|
|
|
skipSpaces();
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring result;
|
|
|
|
|
char_type c = getChar();
|
2001-08-13 14:46:06 +00:00
|
|
|
|
|
2002-03-27 16:13:52 +00:00
|
|
|
|
if (c != left)
|
2001-08-17 09:48:24 +00:00
|
|
|
|
putback();
|
2002-03-21 17:42:56 +00:00
|
|
|
|
else
|
2002-03-27 16:13:52 +00:00
|
|
|
|
while ((c = getChar()) != right && good())
|
2001-08-17 09:48:24 +00:00
|
|
|
|
result += c;
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-22 12:07:01 +00:00
|
|
|
|
void Parser::skipSpaceTokens(idocstream & is, char_type c)
|
2002-07-31 17:26:14 +00:00
|
|
|
|
{
|
|
|
|
|
// skip trailing spaces
|
|
|
|
|
while (catcode(c) == catSpace || catcode(c) == catNewline)
|
|
|
|
|
if (!is.get(c))
|
|
|
|
|
break;
|
2003-08-02 11:30:30 +00:00
|
|
|
|
//lyxerr << "putting back: " << c << endl;
|
2002-07-31 17:26:14 +00:00
|
|
|
|
is.putback(c);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
void Parser::tokenize(istream & is)
|
|
|
|
|
{
|
|
|
|
|
// eat everything up to the next \end_inset or end of stream
|
|
|
|
|
// and store it in s for further tokenization
|
2006-12-19 14:24:25 +00:00
|
|
|
|
string s;
|
2001-08-17 09:48:24 +00:00
|
|
|
|
char c;
|
|
|
|
|
while (is.get(c)) {
|
|
|
|
|
s += c;
|
|
|
|
|
if (s.size() >= 10 && s.substr(s.size() - 10) == "\\end_inset") {
|
|
|
|
|
s = s.substr(0, s.size() - 10);
|
|
|
|
|
break;
|
2001-08-13 14:46:06 +00:00
|
|
|
|
}
|
2001-08-17 09:48:24 +00:00
|
|
|
|
}
|
2002-12-18 10:57:45 +00:00
|
|
|
|
// Remove the space after \end_inset
|
|
|
|
|
if (is.get(c) && c != ' ')
|
|
|
|
|
is.unget();
|
2001-08-13 14:46:06 +00:00
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
// tokenize buffer
|
2006-10-22 12:07:01 +00:00
|
|
|
|
tokenize(from_utf8(s));
|
2001-08-17 09:48:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
void Parser::tokenize(docstring const & buffer)
|
2001-08-17 09:48:24 +00:00
|
|
|
|
{
|
2006-10-22 12:07:01 +00:00
|
|
|
|
idocstringstream is(buffer, ios::in | ios::binary);
|
2001-08-17 09:48:24 +00:00
|
|
|
|
|
2006-10-22 12:07:01 +00:00
|
|
|
|
char_type c;
|
2001-08-17 09:48:24 +00:00
|
|
|
|
while (is.get(c)) {
|
2003-08-02 11:30:30 +00:00
|
|
|
|
//lyxerr << "reading c: " << c << endl;
|
2001-08-17 09:48:24 +00:00
|
|
|
|
|
2001-08-17 10:21:37 +00:00
|
|
|
|
switch (catcode(c)) {
|
2001-08-17 09:48:24 +00:00
|
|
|
|
case catNewline: {
|
2002-03-21 17:42:56 +00:00
|
|
|
|
++lineno_;
|
2001-08-17 09:48:24 +00:00
|
|
|
|
is.get(c);
|
2001-08-17 10:21:37 +00:00
|
|
|
|
if (catcode(c) == catNewline)
|
2001-08-17 09:48:24 +00:00
|
|
|
|
; //push_back(Token("par"));
|
|
|
|
|
else {
|
2002-07-31 17:26:14 +00:00
|
|
|
|
push_back(Token('\n', catNewline));
|
2002-03-21 17:42:56 +00:00
|
|
|
|
is.putback(c);
|
2001-08-13 14:02:37 +00:00
|
|
|
|
}
|
2001-08-17 09:48:24 +00:00
|
|
|
|
break;
|
2001-02-26 12:53:35 +00:00
|
|
|
|
}
|
2001-08-17 09:48:24 +00:00
|
|
|
|
|
2002-08-14 15:13:07 +00:00
|
|
|
|
/*
|
2001-08-17 09:48:24 +00:00
|
|
|
|
case catComment: {
|
2001-08-17 10:21:37 +00:00
|
|
|
|
while (is.get(c) && catcode(c) != catNewline)
|
2001-08-17 09:48:24 +00:00
|
|
|
|
;
|
2002-03-21 17:42:56 +00:00
|
|
|
|
++lineno_;
|
2001-08-17 09:48:24 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2002-08-14 15:13:07 +00:00
|
|
|
|
*/
|
2001-08-17 09:48:24 +00:00
|
|
|
|
|
|
|
|
|
case catEscape: {
|
|
|
|
|
is.get(c);
|
2002-02-11 15:55:13 +00:00
|
|
|
|
if (!is) {
|
|
|
|
|
error("unexpected end of input");
|
|
|
|
|
} else {
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring s(1, c);
|
2002-02-11 15:55:13 +00:00
|
|
|
|
if (catcode(c) == catLetter) {
|
2002-02-12 09:11:50 +00:00
|
|
|
|
// collect letters
|
2002-02-11 15:55:13 +00:00
|
|
|
|
while (is.get(c) && catcode(c) == catLetter)
|
|
|
|
|
s += c;
|
2002-02-12 09:11:50 +00:00
|
|
|
|
skipSpaceTokens(is, c);
|
2002-03-21 17:42:56 +00:00
|
|
|
|
}
|
2002-02-11 15:55:13 +00:00
|
|
|
|
push_back(Token(s));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2002-02-12 09:11:50 +00:00
|
|
|
|
case catSuper:
|
|
|
|
|
case catSub: {
|
|
|
|
|
push_back(Token(c, catcode(c)));
|
|
|
|
|
is.get(c);
|
|
|
|
|
skipSpaceTokens(is, c);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2002-02-11 15:55:13 +00:00
|
|
|
|
case catIgnore: {
|
2003-08-02 11:30:30 +00:00
|
|
|
|
lyxerr << "ignoring a char: " << int(c) << endl;
|
2001-08-17 09:48:24 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
2001-08-17 10:21:37 +00:00
|
|
|
|
push_back(Token(c, catcode(c)));
|
2001-02-26 12:53:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2001-08-17 09:48:24 +00:00
|
|
|
|
|
2002-02-15 14:07:09 +00:00
|
|
|
|
#ifdef FILEDEBUG
|
|
|
|
|
dump();
|
|
|
|
|
#endif
|
2002-02-11 08:19:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Parser::dump() const
|
|
|
|
|
{
|
2001-08-17 15:47:02 +00:00
|
|
|
|
lyxerr << "\nTokens: ";
|
2002-03-27 16:13:52 +00:00
|
|
|
|
for (unsigned i = 0; i < tokens_.size(); ++i) {
|
|
|
|
|
if (i == pos_)
|
|
|
|
|
lyxerr << " <#> ";
|
2001-08-17 15:47:02 +00:00
|
|
|
|
lyxerr << tokens_[i];
|
2002-03-27 16:13:52 +00:00
|
|
|
|
}
|
2003-08-02 11:30:30 +00:00
|
|
|
|
lyxerr << " pos: " << pos_ << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-03-21 17:42:56 +00:00
|
|
|
|
void Parser::error(string const & msg)
|
2001-07-26 06:46:50 +00:00
|
|
|
|
{
|
2001-08-10 09:30:02 +00:00
|
|
|
|
lyxerr << "Line ~" << lineno_ << ": Math parse error: " << msg << endl;
|
2002-02-11 08:19:02 +00:00
|
|
|
|
dump();
|
2001-09-12 09:17:46 +00:00
|
|
|
|
//exit(1);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-07-12 07:18:29 +00:00
|
|
|
|
|
2002-07-12 14:24:47 +00:00
|
|
|
|
bool Parser::parse(MathAtom & at)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
2002-06-28 12:33:21 +00:00
|
|
|
|
skipSpaces();
|
2007-04-26 16:05:57 +00:00
|
|
|
|
MathData ar;
|
2006-09-16 18:11:38 +00:00
|
|
|
|
parse(ar, false, InsetMath::UNDECIDED_MODE);
|
2006-09-03 16:14:51 +00:00
|
|
|
|
if (ar.size() != 1 || ar.front()->getType() == hullNone) {
|
2002-07-08 06:39:40 +00:00
|
|
|
|
lyxerr << "unusual contents found: " << ar << endl;
|
2006-09-16 18:11:38 +00:00
|
|
|
|
at = MathAtom(new InsetMathPar(ar));
|
2002-08-23 11:24:55 +00:00
|
|
|
|
//if (at->nargs() > 0)
|
|
|
|
|
// at.nucleus()->cell(0) = ar;
|
|
|
|
|
//else
|
|
|
|
|
// lyxerr << "unusual contents found: " << ar << endl;
|
2001-10-15 14:19:16 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2002-06-24 15:37:14 +00:00
|
|
|
|
at = ar[0];
|
|
|
|
|
return true;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring Parser::parse_verbatim_option()
|
2002-09-30 06:48:53 +00:00
|
|
|
|
{
|
2003-03-04 08:14:14 +00:00
|
|
|
|
skipSpaces();
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring res;
|
2002-09-30 06:48:53 +00:00
|
|
|
|
if (nextToken().character() == '[') {
|
|
|
|
|
Token t = getToken();
|
|
|
|
|
for (Token t = getToken(); t.character() != ']' && good(); t = getToken()) {
|
|
|
|
|
if (t.cat() == catBegin) {
|
|
|
|
|
putback();
|
|
|
|
|
res += '{' + parse_verbatim_item() + '}';
|
2002-11-24 15:20:31 +00:00
|
|
|
|
} else
|
2002-09-30 06:48:53 +00:00
|
|
|
|
res += t.asString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring Parser::parse_verbatim_item()
|
2002-09-30 06:48:53 +00:00
|
|
|
|
{
|
2003-03-04 08:14:14 +00:00
|
|
|
|
skipSpaces();
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring res;
|
2002-09-30 06:48:53 +00:00
|
|
|
|
if (nextToken().cat() == catBegin) {
|
|
|
|
|
Token t = getToken();
|
|
|
|
|
for (Token t = getToken(); t.cat() != catEnd && good(); t = getToken()) {
|
|
|
|
|
if (t.cat() == catBegin) {
|
|
|
|
|
putback();
|
|
|
|
|
res += '{' + parse_verbatim_item() + '}';
|
|
|
|
|
}
|
2002-11-24 15:20:31 +00:00
|
|
|
|
else
|
2002-09-30 06:48:53 +00:00
|
|
|
|
res += t.asString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 16:05:57 +00:00
|
|
|
|
MathData Parser::parse(unsigned flags, mode_type mode)
|
2002-08-12 09:53:04 +00:00
|
|
|
|
{
|
2007-04-26 16:05:57 +00:00
|
|
|
|
MathData ar;
|
2002-08-12 09:53:04 +00:00
|
|
|
|
parse(ar, flags, mode);
|
|
|
|
|
return ar;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 16:05:57 +00:00
|
|
|
|
void Parser::parse(MathData & array, unsigned flags, mode_type mode)
|
2002-02-07 09:47:21 +00:00
|
|
|
|
{
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathGrid grid(1, 1);
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse1(grid, flags, mode, false);
|
2002-06-03 07:31:08 +00:00
|
|
|
|
array = grid.cell(0);
|
2002-02-07 09:47:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-04 08:14:14 +00:00
|
|
|
|
void Parser::parse2(MathAtom & at, const unsigned flags, const mode_type mode,
|
|
|
|
|
const bool numbered)
|
2002-06-03 07:31:08 +00:00
|
|
|
|
{
|
2002-08-09 07:01:17 +00:00
|
|
|
|
parse1(*(at.nucleus()->asGridInset()), flags, mode, numbered);
|
2002-06-03 07:31:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void Parser::parse1(InsetMathGrid & grid, unsigned flags,
|
2003-03-04 08:14:14 +00:00
|
|
|
|
const mode_type mode, const bool numbered)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
2002-08-28 17:59:32 +00:00
|
|
|
|
int limits = 0;
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathGrid::row_type cellrow = 0;
|
|
|
|
|
InsetMathGrid::col_type cellcol = 0;
|
2007-04-26 16:05:57 +00:00
|
|
|
|
MathData * cell = &grid.cell(grid.index(cellrow, cellcol));
|
2002-06-03 07:31:08 +00:00
|
|
|
|
|
|
|
|
|
if (grid.asHullInset())
|
|
|
|
|
grid.asHullInset()->numbered(cellrow, numbered);
|
|
|
|
|
|
|
|
|
|
//dump();
|
2003-08-02 11:30:30 +00:00
|
|
|
|
//lyxerr << " flags: " << flags << endl;
|
|
|
|
|
//lyxerr << " mode: " << mode << endl;
|
2002-06-03 07:31:08 +00:00
|
|
|
|
//lyxerr << "grid: " << grid << endl;
|
2001-07-27 12:32:29 +00:00
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
while (good()) {
|
|
|
|
|
Token const & t = getToken();
|
2002-03-21 17:42:56 +00:00
|
|
|
|
|
2002-02-15 14:07:09 +00:00
|
|
|
|
#ifdef FILEDEBUG
|
2003-08-02 11:30:30 +00:00
|
|
|
|
lyxerr << "t: " << t << " flags: " << flags << endl;
|
|
|
|
|
lyxerr << "mode: " << mode << endl;
|
2002-08-14 15:13:07 +00:00
|
|
|
|
cell->dump();
|
2003-08-02 11:30:30 +00:00
|
|
|
|
lyxerr << endl;
|
2002-02-15 14:07:09 +00:00
|
|
|
|
#endif
|
2001-04-24 16:13:38 +00:00
|
|
|
|
|
2001-07-13 07:55:55 +00:00
|
|
|
|
if (flags & FLAG_ITEM) {
|
2002-03-07 17:34:51 +00:00
|
|
|
|
|
2004-08-12 21:29:21 +00:00
|
|
|
|
if (t.cat() == catBegin) {
|
2001-08-10 15:49:15 +00:00
|
|
|
|
// skip the brace and collect everything to the next matching
|
2001-07-13 07:55:55 +00:00
|
|
|
|
// closing brace
|
2003-04-24 10:47:05 +00:00
|
|
|
|
parse1(grid, FLAG_BRACE_LAST, mode, numbered);
|
|
|
|
|
return;
|
2001-02-26 12:53:35 +00:00
|
|
|
|
}
|
2002-03-07 17:34:51 +00:00
|
|
|
|
|
|
|
|
|
// handle only this single token, leave the loop if done
|
2003-04-24 10:47:05 +00:00
|
|
|
|
flags = FLAG_LEAVE;
|
2001-02-26 12:53:35 +00:00
|
|
|
|
}
|
2001-04-25 15:43:57 +00:00
|
|
|
|
|
2002-07-08 11:29:51 +00:00
|
|
|
|
|
2002-08-12 09:53:04 +00:00
|
|
|
|
if (flags & FLAG_BRACED) {
|
|
|
|
|
if (t.cat() == catSpace)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (t.cat() != catBegin) {
|
|
|
|
|
error("opening brace expected");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// skip the brace and collect everything to the next matching
|
|
|
|
|
// closing brace
|
|
|
|
|
flags = FLAG_BRACE_LAST;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-07-08 11:29:51 +00:00
|
|
|
|
if (flags & FLAG_OPTION) {
|
|
|
|
|
if (t.cat() == catOther && t.character() == '[') {
|
2007-04-26 16:05:57 +00:00
|
|
|
|
MathData ar;
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse(ar, FLAG_BRACK_LAST, mode);
|
2002-08-05 06:39:33 +00:00
|
|
|
|
cell->append(ar);
|
|
|
|
|
} else {
|
|
|
|
|
// no option found, put back token and we are done
|
|
|
|
|
putback();
|
2002-07-08 11:29:51 +00:00
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
//
|
|
|
|
|
// cat codes
|
|
|
|
|
//
|
2001-12-18 12:21:33 +00:00
|
|
|
|
if (t.cat() == catMath) {
|
2006-09-16 18:11:38 +00:00
|
|
|
|
if (mode != InsetMath::MATH_MODE) {
|
2002-06-04 09:45:41 +00:00
|
|
|
|
// we are inside some text mode thingy, so opening new math is allowed
|
2002-06-24 15:37:14 +00:00
|
|
|
|
Token const & n = getToken();
|
|
|
|
|
if (n.cat() == catMath) {
|
|
|
|
|
// TeX's $$...$$ syntax for displayed math
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(MathAtom(new InsetMathHull(hullEquation)));
|
|
|
|
|
parse2(cell->back(), FLAG_SIMPLE, InsetMath::MATH_MODE, false);
|
2002-06-24 15:37:14 +00:00
|
|
|
|
getToken(); // skip the second '$' token
|
|
|
|
|
} else {
|
|
|
|
|
// simple $...$ stuff
|
|
|
|
|
putback();
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(MathAtom(new InsetMathHull(hullSimple)));
|
|
|
|
|
parse2(cell->back(), FLAG_SIMPLE, InsetMath::MATH_MODE, false);
|
2002-06-24 15:37:14 +00:00
|
|
|
|
}
|
2002-06-04 09:45:41 +00:00
|
|
|
|
}
|
2002-06-24 15:37:14 +00:00
|
|
|
|
|
2002-06-05 07:54:26 +00:00
|
|
|
|
else if (flags & FLAG_SIMPLE) {
|
2002-06-03 07:31:08 +00:00
|
|
|
|
// this is the end of the formula
|
|
|
|
|
return;
|
|
|
|
|
}
|
2002-06-24 15:37:14 +00:00
|
|
|
|
|
2002-06-05 07:54:26 +00:00
|
|
|
|
else {
|
2003-08-02 11:30:30 +00:00
|
|
|
|
error("something strange in the parser");
|
2002-06-05 07:54:26 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2001-12-18 12:21:33 +00:00
|
|
|
|
}
|
2001-08-13 14:46:06 +00:00
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
else if (t.cat() == catLetter)
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(MathAtom(new InsetMathChar(t.character())));
|
2001-08-13 14:02:37 +00:00
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
else if (t.cat() == catSpace && mode != InsetMath::MATH_MODE) {
|
2002-08-22 10:04:11 +00:00
|
|
|
|
if (cell->empty() || cell->back()->getChar() != ' ')
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(MathAtom(new InsetMathChar(t.character())));
|
2002-08-22 10:04:11 +00:00
|
|
|
|
}
|
2001-02-26 12:53:35 +00:00
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
else if (t.cat() == catNewline && mode != InsetMath::MATH_MODE) {
|
2003-04-14 06:17:19 +00:00
|
|
|
|
if (cell->empty() || cell->back()->getChar() != ' ')
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(MathAtom(new InsetMathChar(' ')));
|
2003-04-14 06:17:19 +00:00
|
|
|
|
}
|
2002-07-31 17:26:14 +00:00
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
else if (t.cat() == catParameter) {
|
|
|
|
|
Token const & n = getToken();
|
2002-06-03 07:31:08 +00:00
|
|
|
|
cell->push_back(MathAtom(new MathMacroArgument(n.character()-'0')));
|
2001-08-03 09:54:48 +00:00
|
|
|
|
}
|
2001-02-26 12:53:35 +00:00
|
|
|
|
|
2002-08-06 09:15:46 +00:00
|
|
|
|
else if (t.cat() == catActive)
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(MathAtom(new InsetMathChar(t.character())));
|
2002-08-06 09:15:46 +00:00
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
else if (t.cat() == catBegin) {
|
2007-04-26 16:05:57 +00:00
|
|
|
|
MathData ar;
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse(ar, FLAG_BRACE_LAST, mode);
|
2002-07-10 07:15:36 +00:00
|
|
|
|
// do not create a BraceInset if they were written by LyX
|
2002-07-04 11:00:51 +00:00
|
|
|
|
// this helps to keep the annoyance of "a choose b" to a minimum
|
2002-07-11 07:56:14 +00:00
|
|
|
|
if (ar.size() == 1 && ar[0]->extraBraces())
|
2002-07-30 13:56:02 +00:00
|
|
|
|
cell->append(ar);
|
2002-07-11 07:56:14 +00:00
|
|
|
|
else
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(MathAtom(new InsetMathBrace(ar)));
|
2001-08-17 09:48:24 +00:00
|
|
|
|
}
|
2001-02-26 12:53:35 +00:00
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
else if (t.cat() == catEnd) {
|
2001-08-29 16:23:54 +00:00
|
|
|
|
if (flags & FLAG_BRACE_LAST)
|
|
|
|
|
return;
|
2002-06-27 11:31:32 +00:00
|
|
|
|
error("found '}' unexpectedly");
|
2003-09-09 17:25:35 +00:00
|
|
|
|
//BOOST_ASSERT(false);
|
2002-06-03 07:31:08 +00:00
|
|
|
|
//add(cell, '}', LM_TC_TEX);
|
2001-08-17 09:48:24 +00:00
|
|
|
|
}
|
2002-03-21 17:42:56 +00:00
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
else if (t.cat() == catAlign) {
|
2004-12-28 15:43:29 +00:00
|
|
|
|
//lyxerr << " column now " << (cellcol + 1)
|
|
|
|
|
// << " max: " << grid.ncols() << endl;
|
2005-01-10 08:38:28 +00:00
|
|
|
|
if (flags & FLAG_ALIGN)
|
|
|
|
|
return;
|
2004-12-28 15:43:29 +00:00
|
|
|
|
if (addCol(grid, cellcol))
|
2005-01-10 08:38:28 +00:00
|
|
|
|
cell = &grid.cell(grid.index(cellrow, cellcol));
|
2001-08-17 09:48:24 +00:00
|
|
|
|
}
|
2002-03-21 17:42:56 +00:00
|
|
|
|
|
2001-09-11 10:58:17 +00:00
|
|
|
|
else if (t.cat() == catSuper || t.cat() == catSub) {
|
2002-09-30 06:48:53 +00:00
|
|
|
|
bool up = (t.cat() == catSuper);
|
|
|
|
|
// we need no new script inset if the last thing was a scriptinset,
|
|
|
|
|
// which has that script already not the same script already
|
|
|
|
|
if (!cell->size())
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(MathAtom(new InsetMathScript(up)));
|
2002-09-30 06:48:53 +00:00
|
|
|
|
else if (cell->back()->asScriptInset() &&
|
|
|
|
|
!cell->back()->asScriptInset()->has(up))
|
|
|
|
|
cell->back().nucleus()->asScriptInset()->ensure(up);
|
|
|
|
|
else if (cell->back()->asScriptInset())
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(MathAtom(new InsetMathScript(up)));
|
2002-09-30 06:48:53 +00:00
|
|
|
|
else
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->back() = MathAtom(new InsetMathScript(cell->back(), up));
|
|
|
|
|
InsetMathScript * p = cell->back().nucleus()->asScriptInset();
|
2002-09-30 06:48:53 +00:00
|
|
|
|
// special handling of {}-bases
|
2006-11-11 15:26:31 +00:00
|
|
|
|
// Here we could remove the brace inset for things
|
|
|
|
|
// like {a'}^2 and add the braces back in
|
|
|
|
|
// InsetMathScript::write().
|
|
|
|
|
// We do not do it, since it is not possible to detect
|
|
|
|
|
// reliably whether the braces are needed because the
|
|
|
|
|
// nucleus contains more than one symbol, or whether
|
|
|
|
|
// they are needed for unknown commands like \xx{a}_0
|
|
|
|
|
// or \yy{a}{b}_0. This was done in revision 14819
|
|
|
|
|
// in an unreliable way. See this thread
|
|
|
|
|
// http://www.mail-archive.com/lyx-devel%40lists.lyx.org/msg104917.html
|
|
|
|
|
// for more details.
|
2004-04-07 12:10:19 +00:00
|
|
|
|
parse(p->cell(p->idxOfScript(up)), FLAG_ITEM, mode);
|
2002-09-30 06:48:53 +00:00
|
|
|
|
if (limits) {
|
|
|
|
|
p->limits(limits);
|
|
|
|
|
limits = 0;
|
2002-08-08 14:22:44 +00:00
|
|
|
|
}
|
2001-09-11 10:58:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-08-05 06:39:33 +00:00
|
|
|
|
else if (t.character() == ']' && (flags & FLAG_BRACK_LAST)) {
|
2003-08-02 11:30:30 +00:00
|
|
|
|
//lyxerr << "finished reading option" << endl;
|
2001-08-17 09:48:24 +00:00
|
|
|
|
return;
|
2002-08-05 06:39:33 +00:00
|
|
|
|
}
|
2001-08-17 09:48:24 +00:00
|
|
|
|
|
|
|
|
|
else if (t.cat() == catOther)
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(MathAtom(new InsetMathChar(t.character())));
|
2002-03-21 17:42:56 +00:00
|
|
|
|
|
2002-08-14 15:13:07 +00:00
|
|
|
|
else if (t.cat() == catComment) {
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring s;
|
2002-08-14 15:13:07 +00:00
|
|
|
|
while (good()) {
|
|
|
|
|
Token const & t = getToken();
|
|
|
|
|
if (t.cat() == catNewline)
|
|
|
|
|
break;
|
|
|
|
|
s += t.asString();
|
|
|
|
|
}
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(MathAtom(new InsetMathComment(s)));
|
2002-08-14 15:13:07 +00:00
|
|
|
|
skipSpaces();
|
|
|
|
|
}
|
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
//
|
2001-10-31 12:26:42 +00:00
|
|
|
|
// control sequences
|
2002-03-21 17:42:56 +00:00
|
|
|
|
//
|
2002-07-12 14:24:47 +00:00
|
|
|
|
|
2002-08-01 15:53:46 +00:00
|
|
|
|
else if (t.cs() == "lyxlock") {
|
|
|
|
|
if (cell->size())
|
2002-08-09 07:01:17 +00:00
|
|
|
|
cell->back().nucleus()->lock(true);
|
2002-08-01 15:53:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-07-04 15:55:18 +00:00
|
|
|
|
else if (t.cs() == "def" ||
|
|
|
|
|
t.cs() == "newcommand" ||
|
|
|
|
|
t.cs() == "renewcommand")
|
|
|
|
|
{
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring const type = t.cs();
|
|
|
|
|
docstring name;
|
2002-07-12 14:24:47 +00:00
|
|
|
|
int nargs = 0;
|
|
|
|
|
if (t.cs() == "def") {
|
|
|
|
|
// get name
|
|
|
|
|
name = getToken().cs();
|
|
|
|
|
|
|
|
|
|
// read parameter
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring pars;
|
2002-07-12 14:24:47 +00:00
|
|
|
|
while (good() && nextToken().cat() != catBegin) {
|
|
|
|
|
pars += getToken().cs();
|
|
|
|
|
++nargs;
|
|
|
|
|
}
|
|
|
|
|
nargs /= 2;
|
2003-08-02 11:30:30 +00:00
|
|
|
|
//lyxerr << "read \\def parameter list '" << pars << "'" << endl;
|
2002-07-12 14:24:47 +00:00
|
|
|
|
|
2003-07-04 15:55:18 +00:00
|
|
|
|
} else { // t.cs() == "newcommand" || t.cs() == "renewcommand"
|
2002-07-12 14:24:47 +00:00
|
|
|
|
|
|
|
|
|
if (getToken().cat() != catBegin) {
|
2003-08-02 11:30:30 +00:00
|
|
|
|
error("'{' in \\newcommand expected (1) ");
|
2002-07-12 14:24:47 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
name = getToken().cs();
|
|
|
|
|
|
|
|
|
|
if (getToken().cat() != catEnd) {
|
2003-08-02 11:30:30 +00:00
|
|
|
|
error("'}' in \\newcommand expected");
|
2002-07-12 14:24:47 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-19 14:24:25 +00:00
|
|
|
|
docstring const arg = getArg('[', ']');
|
2002-07-12 14:24:47 +00:00
|
|
|
|
if (!arg.empty())
|
2005-01-27 21:05:44 +00:00
|
|
|
|
nargs = convert<int>(arg);
|
2002-07-12 14:24:47 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-26 16:05:57 +00:00
|
|
|
|
MathData ar1;
|
2006-09-16 18:11:38 +00:00
|
|
|
|
parse(ar1, FLAG_ITEM, InsetMath::UNDECIDED_MODE);
|
2002-07-12 14:24:47 +00:00
|
|
|
|
|
|
|
|
|
// we cannot handle recursive stuff at all
|
2007-04-26 16:05:57 +00:00
|
|
|
|
//MathData test;
|
2006-09-16 18:11:38 +00:00
|
|
|
|
//test.push_back(createInsetMath(name));
|
2002-07-12 14:24:47 +00:00
|
|
|
|
//if (ar1.contains(test)) {
|
2003-08-02 11:30:30 +00:00
|
|
|
|
// error("we cannot handle recursive macros at all.");
|
2002-07-12 14:24:47 +00:00
|
|
|
|
// return;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
// is a version for display attached?
|
|
|
|
|
skipSpaces();
|
2007-04-26 16:05:57 +00:00
|
|
|
|
MathData ar2;
|
2003-04-24 10:47:05 +00:00
|
|
|
|
if (nextToken().cat() == catBegin)
|
2006-09-16 18:11:38 +00:00
|
|
|
|
parse(ar2, FLAG_ITEM, InsetMath::MATH_MODE);
|
2002-07-12 14:24:47 +00:00
|
|
|
|
|
2003-07-04 15:55:18 +00:00
|
|
|
|
cell->push_back(MathAtom(new MathMacroTemplate(name, nargs, type,
|
|
|
|
|
ar1, ar2)));
|
2002-07-12 14:24:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-06-24 15:37:14 +00:00
|
|
|
|
else if (t.cs() == "(") {
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(MathAtom(new InsetMathHull(hullSimple)));
|
|
|
|
|
parse2(cell->back(), FLAG_SIMPLE2, InsetMath::MATH_MODE, false);
|
2002-06-24 15:37:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (t.cs() == "[") {
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(MathAtom(new InsetMathHull(hullEquation)));
|
|
|
|
|
parse2(cell->back(), FLAG_EQUATION, InsetMath::MATH_MODE, false);
|
2002-06-24 15:37:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-10-31 12:26:42 +00:00
|
|
|
|
else if (t.cs() == "protect")
|
2002-06-24 15:37:14 +00:00
|
|
|
|
// ignore \\protect, will hopefully be re-added during output
|
2001-08-17 09:48:24 +00:00
|
|
|
|
;
|
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
|
else if (t.cs() == "end") {
|
|
|
|
|
if (flags & FLAG_END) {
|
|
|
|
|
// eat environment name
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring const name = getArg('{', '}');
|
2005-02-14 14:25:18 +00:00
|
|
|
|
if (environments_.empty())
|
|
|
|
|
error("'found \\end{" + name +
|
|
|
|
|
"}' without matching '\\begin{" +
|
|
|
|
|
name + "}'");
|
|
|
|
|
else if (name != environments_.back())
|
|
|
|
|
error("'\\end{" + name +
|
|
|
|
|
"}' does not match '\\begin{" +
|
|
|
|
|
environments_.back() + "}'");
|
|
|
|
|
else {
|
|
|
|
|
environments_.pop_back();
|
2005-10-14 10:50:23 +00:00
|
|
|
|
// Delete empty last row in matrix
|
|
|
|
|
// like insets.
|
2006-09-16 18:11:38 +00:00
|
|
|
|
// If you abuse InsetMathGrid for
|
2005-10-14 10:50:23 +00:00
|
|
|
|
// non-matrix like structures you
|
|
|
|
|
// probably need to refine this test.
|
|
|
|
|
// Right now we only have to test for
|
|
|
|
|
// single line hull insets.
|
|
|
|
|
if (grid.nrows() > 1)
|
2005-02-14 14:25:18 +00:00
|
|
|
|
delEmptyLastRow(grid);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
error("found 'end' unexpectedly");
|
2002-06-18 15:44:30 +00:00
|
|
|
|
}
|
2001-08-17 09:48:24 +00:00
|
|
|
|
|
2002-06-27 11:31:32 +00:00
|
|
|
|
else if (t.cs() == ")") {
|
|
|
|
|
if (flags & FLAG_SIMPLE2)
|
|
|
|
|
return;
|
|
|
|
|
error("found '\\)' unexpectedly");
|
|
|
|
|
}
|
2001-08-17 09:48:24 +00:00
|
|
|
|
|
2002-06-27 11:31:32 +00:00
|
|
|
|
else if (t.cs() == "]") {
|
|
|
|
|
if (flags & FLAG_EQUATION)
|
|
|
|
|
return;
|
|
|
|
|
error("found '\\]' unexpectedly");
|
|
|
|
|
}
|
2001-08-17 09:48:24 +00:00
|
|
|
|
|
|
|
|
|
else if (t.cs() == "\\") {
|
2005-01-10 08:38:28 +00:00
|
|
|
|
if (flags & FLAG_ALIGN)
|
|
|
|
|
return;
|
2007-03-19 16:08:17 +00:00
|
|
|
|
bool added;
|
|
|
|
|
if (nextToken().asInput() == "*") {
|
|
|
|
|
getToken();
|
|
|
|
|
added = addRow(grid, cellrow, docstring(), false);
|
|
|
|
|
} else
|
|
|
|
|
added = addRow(grid, cellrow, getArg('[', ']'));
|
|
|
|
|
if (added) {
|
2004-12-28 15:43:29 +00:00
|
|
|
|
cellcol = 0;
|
|
|
|
|
if (grid.asHullInset())
|
|
|
|
|
grid.asHullInset()->numbered(
|
|
|
|
|
cellrow, numbered);
|
|
|
|
|
cell = &grid.cell(grid.index(cellrow,
|
2006-04-05 23:56:29 +00:00
|
|
|
|
cellcol));
|
2004-12-28 15:43:29 +00:00
|
|
|
|
}
|
2001-08-10 10:39:56 +00:00
|
|
|
|
}
|
2002-03-21 17:42:56 +00:00
|
|
|
|
|
2002-08-15 18:04:01 +00:00
|
|
|
|
#if 0
|
2002-06-18 15:44:30 +00:00
|
|
|
|
else if (t.cs() == "multicolumn") {
|
|
|
|
|
// extract column count and insert dummy cells
|
2007-04-26 16:05:57 +00:00
|
|
|
|
MathData count;
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse(count, FLAG_ITEM, mode);
|
2002-06-18 15:44:30 +00:00
|
|
|
|
int cols = 1;
|
|
|
|
|
if (!extractNumber(count, cols)) {
|
2003-08-02 11:30:30 +00:00
|
|
|
|
lyxerr << " can't extract number of cells from " << count << endl;
|
2002-06-18 15:44:30 +00:00
|
|
|
|
}
|
|
|
|
|
// resize the table if necessary
|
|
|
|
|
for (int i = 0; i < cols; ++i) {
|
2004-12-28 15:43:29 +00:00
|
|
|
|
if (addCol(grid, cellcol)) {
|
|
|
|
|
cell = &grid.cell(grid.index(
|
|
|
|
|
cellrow, cellcol));
|
|
|
|
|
// mark this as dummy
|
|
|
|
|
grid.cellinfo(grid.index(
|
|
|
|
|
cellrow, cellcol)).dummy_ = true;
|
2002-06-18 15:44:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2004-12-28 15:43:29 +00:00
|
|
|
|
// the last cell is the real thing, not a dummy
|
2002-06-18 15:44:30 +00:00
|
|
|
|
grid.cellinfo(grid.index(cellrow, cellcol)).dummy_ = false;
|
|
|
|
|
|
|
|
|
|
// read special alignment
|
2007-04-26 16:05:57 +00:00
|
|
|
|
MathData align;
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse(align, FLAG_ITEM, mode);
|
2002-06-18 15:44:30 +00:00
|
|
|
|
//grid.cellinfo(grid.index(cellrow, cellcol)).align_ = extractString(align);
|
|
|
|
|
|
|
|
|
|
// parse the remaining contents into the "real" cell
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse(*cell, FLAG_ITEM, mode);
|
2002-06-18 15:44:30 +00:00
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
|
else if (t.cs() == "limits")
|
|
|
|
|
limits = 1;
|
2002-03-21 17:42:56 +00:00
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
|
else if (t.cs() == "nolimits")
|
|
|
|
|
limits = -1;
|
2002-03-21 17:42:56 +00:00
|
|
|
|
|
2002-06-03 07:31:08 +00:00
|
|
|
|
else if (t.cs() == "nonumber") {
|
|
|
|
|
if (grid.asHullInset())
|
|
|
|
|
grid.asHullInset()->numbered(cellrow, false);
|
|
|
|
|
}
|
2001-07-26 16:56:23 +00:00
|
|
|
|
|
2002-06-03 07:31:08 +00:00
|
|
|
|
else if (t.cs() == "number") {
|
|
|
|
|
if (grid.asHullInset())
|
|
|
|
|
grid.asHullInset()->numbered(cellrow, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (t.cs() == "hline") {
|
2002-11-08 08:44:52 +00:00
|
|
|
|
grid.rowinfo(cellrow).lines_ ++;
|
2002-06-03 07:31:08 +00:00
|
|
|
|
}
|
2001-02-26 12:53:35 +00:00
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
else if (t.cs() == "sqrt") {
|
2007-04-26 16:05:57 +00:00
|
|
|
|
MathData ar;
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse(ar, FLAG_OPTION, mode);
|
2002-07-08 11:29:51 +00:00
|
|
|
|
if (ar.size()) {
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(MathAtom(new InsetMathRoot));
|
2002-08-09 07:01:17 +00:00
|
|
|
|
cell->back().nucleus()->cell(0) = ar;
|
|
|
|
|
parse(cell->back().nucleus()->cell(1), FLAG_ITEM, mode);
|
2001-02-26 12:53:35 +00:00
|
|
|
|
} else {
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(MathAtom(new InsetMathSqrt));
|
2002-08-09 07:01:17 +00:00
|
|
|
|
parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode);
|
2001-02-26 12:53:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-21 17:42:56 +00:00
|
|
|
|
|
2003-02-05 11:44:14 +00:00
|
|
|
|
else if (t.cs() == "xrightarrow" || t.cs() == "xleftarrow") {
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(createInsetMath(t.cs()));
|
2003-02-05 11:44:14 +00:00
|
|
|
|
parse(cell->back().nucleus()->cell(1), FLAG_OPTION, mode);
|
|
|
|
|
parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode);
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-17 16:25:00 +00:00
|
|
|
|
else if (t.cs() == "ref" || t.cs() == "prettyref" ||
|
2003-02-25 15:48:47 +00:00
|
|
|
|
t.cs() == "pageref" || t.cs() == "vpageref" || t.cs() == "vref") {
|
2007-04-28 20:49:56 +00:00
|
|
|
|
cell->push_back(MathAtom(new InsetMathRef(t.cs())));
|
2002-08-09 07:01:17 +00:00
|
|
|
|
parse(cell->back().nucleus()->cell(1), FLAG_OPTION, mode);
|
|
|
|
|
parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode);
|
2002-06-24 15:37:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
else if (t.cs() == "left") {
|
2003-03-04 08:14:14 +00:00
|
|
|
|
skipSpaces();
|
2005-03-02 14:26:12 +00:00
|
|
|
|
Token const & tl = getToken();
|
2006-09-16 18:11:38 +00:00
|
|
|
|
// \| and \Vert are equivalent, and InsetMathDelim
|
2005-03-02 14:26:12 +00:00
|
|
|
|
// can't handle \|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
// FIXME: fix this in InsetMathDelim itself!
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring const l = tl.cs() == "|" ? from_ascii("Vert") : tl.asString();
|
2007-04-26 16:05:57 +00:00
|
|
|
|
MathData ar;
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse(ar, FLAG_RIGHT, mode);
|
2007-03-30 17:16:26 +00:00
|
|
|
|
if (!good())
|
|
|
|
|
break;
|
2003-03-04 08:14:14 +00:00
|
|
|
|
skipSpaces();
|
2005-03-02 14:26:12 +00:00
|
|
|
|
Token const & tr = getToken();
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring const r = tr.cs() == "|" ? from_ascii("Vert") : tr.asString();
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(MathAtom(new InsetMathDelim(l, r, ar)));
|
2001-02-26 12:53:35 +00:00
|
|
|
|
}
|
2002-03-21 17:42:56 +00:00
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
else if (t.cs() == "right") {
|
2002-06-24 15:37:14 +00:00
|
|
|
|
if (flags & FLAG_RIGHT)
|
|
|
|
|
return;
|
2003-08-02 11:30:30 +00:00
|
|
|
|
//lyxerr << "got so far: '" << cell << "'" << endl;
|
2002-06-24 15:37:14 +00:00
|
|
|
|
error("Unmatched right delimiter");
|
2001-08-17 09:48:24 +00:00
|
|
|
|
return;
|
2001-08-10 15:32:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
else if (t.cs() == "begin") {
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring const name = getArg('{', '}');
|
2005-02-14 14:25:18 +00:00
|
|
|
|
environments_.push_back(name);
|
2002-08-12 09:53:04 +00:00
|
|
|
|
|
2002-02-14 14:52:23 +00:00
|
|
|
|
if (name == "array" || name == "subarray") {
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring const valign = parse_verbatim_option() + 'c';
|
|
|
|
|
docstring const halign = parse_verbatim_item();
|
|
|
|
|
cell->push_back(MathAtom(new InsetMathArray(name, (char)valign[0], halign)));
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse2(cell->back(), FLAG_END, mode, false);
|
2002-06-24 15:37:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-03-04 08:14:14 +00:00
|
|
|
|
else if (name == "tabular") {
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring const valign = parse_verbatim_option() + 'c';
|
|
|
|
|
docstring const halign = parse_verbatim_item();
|
|
|
|
|
cell->push_back(MathAtom(new InsetMathTabular(name, (char)valign[0], halign)));
|
2006-09-16 18:11:38 +00:00
|
|
|
|
parse2(cell->back(), FLAG_END, InsetMath::TEXT_MODE, false);
|
2003-03-03 16:15:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-10-02 20:01:30 +00:00
|
|
|
|
else if (name == "split" || name == "cases") {
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(createInsetMath(name));
|
2005-10-14 10:50:23 +00:00
|
|
|
|
parse2(cell->back(), FLAG_END, mode, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (name == "alignedat") {
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring const valign = parse_verbatim_option() + 'c';
|
2005-10-14 10:50:23 +00:00
|
|
|
|
// ignore this for a while
|
|
|
|
|
getArg('{', '}');
|
2006-10-22 10:15:23 +00:00
|
|
|
|
cell->push_back(MathAtom(new InsetMathSplit(name, (char)valign[0])));
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse2(cell->back(), FLAG_END, mode, false);
|
2002-06-24 15:37:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (name == "math") {
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(MathAtom(new InsetMathHull(hullSimple)));
|
|
|
|
|
parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, true);
|
2002-06-24 15:37:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (name == "equation" || name == "equation*"
|
|
|
|
|
|| name == "displaymath") {
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(MathAtom(new InsetMathHull(hullEquation)));
|
|
|
|
|
parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, (name == "equation"));
|
2002-06-24 15:37:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (name == "eqnarray" || name == "eqnarray*") {
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(MathAtom(new InsetMathHull(hullEqnArray)));
|
|
|
|
|
parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, !stared(name));
|
2002-06-24 15:37:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (name == "align" || name == "align*") {
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(MathAtom(new InsetMathHull(hullAlign)));
|
|
|
|
|
parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, !stared(name));
|
2002-06-24 15:37:14 +00:00
|
|
|
|
}
|
2002-10-14 12:56:21 +00:00
|
|
|
|
|
|
|
|
|
else if (name == "flalign" || name == "flalign*") {
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(MathAtom(new InsetMathHull(hullFlAlign)));
|
|
|
|
|
parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, !stared(name));
|
2002-10-14 12:56:21 +00:00
|
|
|
|
}
|
2002-06-24 15:37:14 +00:00
|
|
|
|
|
|
|
|
|
else if (name == "alignat" || name == "alignat*") {
|
|
|
|
|
// ignore this for a while
|
|
|
|
|
getArg('{', '}');
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(MathAtom(new InsetMathHull(hullAlignAt)));
|
|
|
|
|
parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, !stared(name));
|
2002-06-24 15:37:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (name == "xalignat" || name == "xalignat*") {
|
|
|
|
|
// ignore this for a while
|
|
|
|
|
getArg('{', '}');
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(MathAtom(new InsetMathHull(hullXAlignAt)));
|
|
|
|
|
parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, !stared(name));
|
2002-06-24 15:37:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (name == "xxalignat") {
|
|
|
|
|
// ignore this for a while
|
|
|
|
|
getArg('{', '}');
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(MathAtom(new InsetMathHull(hullXXAlignAt)));
|
|
|
|
|
parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, !stared(name));
|
2002-06-24 15:37:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (name == "multline" || name == "multline*") {
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(MathAtom(new InsetMathHull(hullMultline)));
|
|
|
|
|
parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, !stared(name));
|
2002-06-24 15:37:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (name == "gather" || name == "gather*") {
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(MathAtom(new InsetMathHull(hullGather)));
|
|
|
|
|
parse2(cell->back(), FLAG_END, InsetMath::MATH_MODE, !stared(name));
|
2002-06-24 15:37:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-07-09 09:46:31 +00:00
|
|
|
|
else if (latexkeys const * l = in_word_set(name)) {
|
|
|
|
|
if (l->inset == "matrix") {
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(createInsetMath(name));
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse2(cell->back(), FLAG_END, mode, false);
|
2006-10-03 19:45:43 +00:00
|
|
|
|
} else if (l->inset == "split") {
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring const valign = parse_verbatim_option() + 'c';
|
|
|
|
|
cell->push_back(MathAtom(new InsetMathSplit(name, (char)valign[0])));
|
2006-10-03 19:45:43 +00:00
|
|
|
|
parse2(cell->back(), FLAG_END, mode, false);
|
|
|
|
|
} else {
|
|
|
|
|
dump();
|
2007-03-30 17:16:26 +00:00
|
|
|
|
lyxerr << "found math environment `" << to_utf8(name)
|
2006-10-03 19:45:43 +00:00
|
|
|
|
<< "' in symbols file with unsupported inset `"
|
2007-03-30 17:16:26 +00:00
|
|
|
|
<< to_utf8(l->inset) << "'." << endl;
|
2006-10-03 19:45:43 +00:00
|
|
|
|
// create generic environment inset
|
|
|
|
|
cell->push_back(MathAtom(new InsetMathEnv(name)));
|
|
|
|
|
parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode);
|
2002-06-24 15:37:14 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-07-09 09:46:31 +00:00
|
|
|
|
|
|
|
|
|
else {
|
2003-03-04 09:06:13 +00:00
|
|
|
|
dump();
|
2007-03-30 17:16:26 +00:00
|
|
|
|
lyxerr << "found unknown math environment '" << to_utf8(name)
|
|
|
|
|
<< "'" << endl;
|
2002-07-09 09:46:31 +00:00
|
|
|
|
// create generic environment inset
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(MathAtom(new InsetMathEnv(name)));
|
2003-03-04 09:06:13 +00:00
|
|
|
|
parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode);
|
2002-07-09 09:46:31 +00:00
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
2002-03-21 17:42:56 +00:00
|
|
|
|
|
2001-08-21 14:20:50 +00:00
|
|
|
|
else if (t.cs() == "kern") {
|
2007-08-10 11:47:12 +00:00
|
|
|
|
// FIXME: A hack...
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring s;
|
2002-11-24 15:20:31 +00:00
|
|
|
|
while (true) {
|
2001-08-21 14:20:50 +00:00
|
|
|
|
Token const & t = getToken();
|
|
|
|
|
if (!good()) {
|
2002-03-21 17:42:56 +00:00
|
|
|
|
putback();
|
2001-08-21 14:20:50 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
s += t.character();
|
2006-10-22 10:15:23 +00:00
|
|
|
|
if (isValidLength(to_utf8(s)))
|
2001-08-21 14:20:50 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(MathAtom(new InsetMathKern(s)));
|
2002-03-27 10:51:46 +00:00
|
|
|
|
}
|
2002-03-25 12:11:25 +00:00
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
else if (t.cs() == "label") {
|
2005-10-14 10:50:23 +00:00
|
|
|
|
// FIXME: This is swallowed in inline formulas
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring label = parse_verbatim_item();
|
2007-04-26 16:05:57 +00:00
|
|
|
|
MathData ar;
|
2006-10-22 10:15:23 +00:00
|
|
|
|
asArray(label, ar);
|
2002-07-10 15:23:36 +00:00
|
|
|
|
if (grid.asHullInset()) {
|
2002-09-30 06:48:53 +00:00
|
|
|
|
grid.asHullInset()->label(cellrow, label);
|
2002-07-11 07:56:14 +00:00
|
|
|
|
} else {
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(createInsetMath(t.cs()));
|
|
|
|
|
cell->push_back(MathAtom(new InsetMathBrace(ar)));
|
2002-07-10 15:23:36 +00:00
|
|
|
|
}
|
2001-08-17 09:48:24 +00:00
|
|
|
|
}
|
2001-08-13 14:02:37 +00:00
|
|
|
|
|
2001-08-17 17:50:00 +00:00
|
|
|
|
else if (t.cs() == "choose" || t.cs() == "over" || t.cs() == "atop") {
|
2006-09-16 18:11:38 +00:00
|
|
|
|
MathAtom at = createInsetMath(t.cs());
|
2002-08-09 07:01:17 +00:00
|
|
|
|
at.nucleus()->cell(0) = *cell;
|
2002-07-30 13:56:02 +00:00
|
|
|
|
cell->clear();
|
2002-08-09 07:01:17 +00:00
|
|
|
|
parse(at.nucleus()->cell(1), flags, mode);
|
|
|
|
|
cell->push_back(at);
|
2001-10-31 12:04:45 +00:00
|
|
|
|
return;
|
2001-08-13 14:02:37 +00:00
|
|
|
|
}
|
2001-10-19 11:25:48 +00:00
|
|
|
|
|
2003-10-27 17:22:27 +00:00
|
|
|
|
else if (t.cs() == "color") {
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring const color = parse_verbatim_item();
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(MathAtom(new InsetMathColor(true, color)));
|
2005-06-17 14:35:19 +00:00
|
|
|
|
parse(cell->back().nucleus()->cell(0), flags, mode);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (t.cs() == "textcolor") {
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring const color = parse_verbatim_item();
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(MathAtom(new InsetMathColor(false, color)));
|
|
|
|
|
parse(cell->back().nucleus()->cell(0), FLAG_ITEM, InsetMath::TEXT_MODE);
|
2005-06-17 14:35:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (t.cs() == "normalcolor") {
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(createInsetMath(t.cs()));
|
2005-06-17 14:35:19 +00:00
|
|
|
|
parse(cell->back().nucleus()->cell(0), flags, mode);
|
2003-10-27 17:22:27 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2002-02-14 14:52:23 +00:00
|
|
|
|
else if (t.cs() == "substack") {
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(createInsetMath(t.cs()));
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse2(cell->back(), FLAG_ITEM, mode, false);
|
2002-02-14 14:52:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-02-22 12:26:06 +00:00
|
|
|
|
else if (t.cs() == "xymatrix") {
|
2006-10-31 19:10:30 +00:00
|
|
|
|
odocstringstream os;
|
|
|
|
|
while (good() && nextToken().cat() != catBegin)
|
|
|
|
|
os << getToken().asInput();
|
|
|
|
|
cell->push_back(createInsetMath(t.cs() + os.str()));
|
2006-02-22 12:26:06 +00:00
|
|
|
|
parse2(cell->back(), FLAG_ITEM, mode, false);
|
|
|
|
|
}
|
|
|
|
|
|
2003-05-07 07:46:04 +00:00
|
|
|
|
else if (t.cs() == "framebox" || t.cs() == "makebox") {
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(createInsetMath(t.cs()));
|
|
|
|
|
parse(cell->back().nucleus()->cell(0), FLAG_OPTION, InsetMath::TEXT_MODE);
|
|
|
|
|
parse(cell->back().nucleus()->cell(1), FLAG_OPTION, InsetMath::TEXT_MODE);
|
|
|
|
|
parse(cell->back().nucleus()->cell(2), FLAG_ITEM, InsetMath::TEXT_MODE);
|
2002-08-29 10:48:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-03-16 15:05:47 +00:00
|
|
|
|
else if (t.cs() == "tag") {
|
|
|
|
|
if (nextToken().character() == '*') {
|
|
|
|
|
getToken();
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(createInsetMath(t.cs() + '*'));
|
2006-03-16 15:05:47 +00:00
|
|
|
|
} else
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(createInsetMath(t.cs()));
|
|
|
|
|
parse(cell->back().nucleus()->cell(0), FLAG_ITEM, InsetMath::TEXT_MODE);
|
2006-03-16 15:05:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-01-09 15:21:56 +00:00
|
|
|
|
#if 0
|
2002-08-28 08:30:27 +00:00
|
|
|
|
else if (t.cs() == "infer") {
|
2007-04-26 16:05:57 +00:00
|
|
|
|
MathData ar;
|
2002-08-28 08:30:27 +00:00
|
|
|
|
parse(ar, FLAG_OPTION, mode);
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(createInsetMath(t.cs()));
|
2002-08-28 08:30:27 +00:00
|
|
|
|
parse2(cell->back(), FLAG_ITEM, mode, false);
|
|
|
|
|
}
|
|
|
|
|
|
2002-02-11 08:19:02 +00:00
|
|
|
|
// Disabled
|
|
|
|
|
else if (1 && t.cs() == "ar") {
|
2006-09-16 18:11:38 +00:00
|
|
|
|
auto_ptr<InsetMathXYArrow> p(new InsetMathXYArrow);
|
2002-02-11 08:19:02 +00:00
|
|
|
|
// try to read target
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse(p->cell(0), FLAG_OTPTION, mode);
|
2002-02-11 08:19:02 +00:00
|
|
|
|
// try to read label
|
|
|
|
|
if (nextToken().cat() == catSuper || nextToken().cat() == catSub) {
|
|
|
|
|
p->up_ = nextToken().cat() == catSuper;
|
|
|
|
|
getToken();
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse(p->cell(1), FLAG_ITEM, mode);
|
2003-08-02 11:30:30 +00:00
|
|
|
|
//lyxerr << "read label: " << p->cell(1) << endl;
|
2002-02-11 08:19:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-11-03 17:47:28 +00:00
|
|
|
|
cell->push_back(MathAtom(p.release()));
|
2003-08-02 11:30:30 +00:00
|
|
|
|
//lyxerr << "read cell: " << cell << endl;
|
2002-02-08 08:03:38 +00:00
|
|
|
|
}
|
2002-02-15 14:07:09 +00:00
|
|
|
|
#endif
|
2002-02-08 08:03:38 +00:00
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
else if (t.cs().size()) {
|
|
|
|
|
latexkeys const * l = in_word_set(t.cs());
|
|
|
|
|
if (l) {
|
2006-04-20 09:55:45 +00:00
|
|
|
|
if (l->inset == "big") {
|
|
|
|
|
skipSpaces();
|
2006-10-22 10:15:23 +00:00
|
|
|
|
docstring const delim = getToken().asInput();
|
2006-09-16 18:11:38 +00:00
|
|
|
|
if (InsetMathBig::isBigInsetDelim(delim))
|
2006-04-20 09:55:45 +00:00
|
|
|
|
cell->push_back(MathAtom(
|
2006-09-16 18:11:38 +00:00
|
|
|
|
new InsetMathBig(t.cs(), delim)));
|
2006-04-20 09:55:45 +00:00
|
|
|
|
else {
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(createInsetMath(t.cs()));
|
2006-10-20 10:43:53 +00:00
|
|
|
|
putback();
|
2006-04-20 09:55:45 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (l->inset == "font") {
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(createInsetMath(t.cs()));
|
2005-01-10 08:38:28 +00:00
|
|
|
|
parse(cell->back().nucleus()->cell(0),
|
|
|
|
|
FLAG_ITEM, asMode(mode, l->extra));
|
2001-08-17 09:48:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-05-30 07:09:54 +00:00
|
|
|
|
else if (l->inset == "oldfont") {
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(createInsetMath(t.cs()));
|
2005-01-10 08:38:28 +00:00
|
|
|
|
parse(cell->back().nucleus()->cell(0),
|
|
|
|
|
flags | FLAG_ALIGN, asMode(mode, l->extra));
|
|
|
|
|
if (prevToken().cat() != catAlign &&
|
|
|
|
|
prevToken().cs() != "\\")
|
|
|
|
|
return;
|
|
|
|
|
putback();
|
2001-10-24 17:14:05 +00:00
|
|
|
|
}
|
2001-08-17 09:48:24 +00:00
|
|
|
|
|
2002-05-30 07:09:54 +00:00
|
|
|
|
else if (l->inset == "style") {
|
2006-09-16 18:11:38 +00:00
|
|
|
|
cell->push_back(createInsetMath(t.cs()));
|
2005-01-10 08:38:28 +00:00
|
|
|
|
parse(cell->back().nucleus()->cell(0),
|
|
|
|
|
flags | FLAG_ALIGN, mode);
|
|
|
|
|
if (prevToken().cat() != catAlign &&
|
|
|
|
|
prevToken().cs() != "\\")
|
|
|
|
|
return;
|
|
|
|
|
putback();
|
2002-01-03 12:02:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
else {
|
2006-09-16 18:11:38 +00:00
|
|
|
|
MathAtom at = createInsetMath(t.cs());
|
|
|
|
|
for (InsetMath::idx_type i = 0; i < at->nargs(); ++i)
|
2005-01-10 08:38:28 +00:00
|
|
|
|
parse(at.nucleus()->cell(i),
|
|
|
|
|
FLAG_ITEM, asMode(mode, l->extra));
|
2002-08-09 07:01:17 +00:00
|
|
|
|
cell->push_back(at);
|
2001-08-17 09:48:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else {
|
2006-09-16 18:11:38 +00:00
|
|
|
|
MathAtom at = createInsetMath(t.cs());
|
|
|
|
|
InsetMath::mode_type m = mode;
|
|
|
|
|
//if (m == InsetMath::UNDECIDED_MODE)
|
2003-08-02 11:30:30 +00:00
|
|
|
|
//lyxerr << "default creation: m1: " << m << endl;
|
2006-09-16 18:11:38 +00:00
|
|
|
|
if (at->currentMode() != InsetMath::UNDECIDED_MODE)
|
2002-08-09 07:01:17 +00:00
|
|
|
|
m = at->currentMode();
|
2003-08-02 11:30:30 +00:00
|
|
|
|
//lyxerr << "default creation: m2: " << m << endl;
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMath::idx_type start = 0;
|
2002-08-29 10:48:52 +00:00
|
|
|
|
// this fails on \bigg[...\bigg]
|
2007-04-26 16:05:57 +00:00
|
|
|
|
//MathData opt;
|
2006-09-16 18:11:38 +00:00
|
|
|
|
//parse(opt, FLAG_OPTION, InsetMath::VERBATIM_MODE);
|
2002-08-29 10:48:52 +00:00
|
|
|
|
//if (opt.size()) {
|
|
|
|
|
// start = 1;
|
|
|
|
|
// at.nucleus()->cell(0) = opt;
|
|
|
|
|
//}
|
2006-09-16 18:11:38 +00:00
|
|
|
|
for (InsetMath::idx_type i = start; i < at->nargs(); ++i) {
|
2002-08-09 07:01:17 +00:00
|
|
|
|
parse(at.nucleus()->cell(i), FLAG_ITEM, m);
|
2004-08-13 13:19:58 +00:00
|
|
|
|
skipSpaces();
|
2004-08-12 21:29:21 +00:00
|
|
|
|
}
|
2002-08-09 07:01:17 +00:00
|
|
|
|
cell->push_back(at);
|
2001-08-13 14:02:37 +00:00
|
|
|
|
}
|
2001-08-17 09:48:24 +00:00
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2001-07-13 07:55:55 +00:00
|
|
|
|
|
|
|
|
|
if (flags & FLAG_LEAVE) {
|
|
|
|
|
flags &= ~FLAG_LEAVE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2001-08-14 07:46:11 +00:00
|
|
|
|
}
|
2001-08-10 07:52:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
|
|
|
|
|
|
|
2001-08-10 09:30:02 +00:00
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
2001-07-12 07:18:29 +00:00
|
|
|
|
|
2007-04-26 16:05:57 +00:00
|
|
|
|
void mathed_parse_cell(MathData & ar, docstring const & str)
|
2001-07-26 16:14:23 +00:00
|
|
|
|
{
|
2006-12-19 14:24:25 +00:00
|
|
|
|
Parser(str).parse(ar, 0, InsetMath::MATH_MODE);
|
2001-10-18 13:21:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 16:05:57 +00:00
|
|
|
|
void mathed_parse_cell(MathData & ar, istream & is)
|
2001-10-18 13:21:21 +00:00
|
|
|
|
{
|
2006-09-16 18:11:38 +00:00
|
|
|
|
Parser(is).parse(ar, 0, InsetMath::MATH_MODE);
|
2001-07-20 10:57:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2006-12-19 14:24:25 +00:00
|
|
|
|
bool mathed_parse_normal(MathAtom & t, docstring const & str)
|
2001-08-03 09:54:48 +00:00
|
|
|
|
{
|
2006-12-19 14:24:25 +00:00
|
|
|
|
return Parser(str).parse(t);
|
2001-08-03 09:54:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-07-08 11:29:51 +00:00
|
|
|
|
|
2007-04-26 11:30:54 +00:00
|
|
|
|
bool mathed_parse_normal(MathAtom & t, Lexer & lex)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-07-12 14:24:47 +00:00
|
|
|
|
return Parser(lex).parse(t);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-08-14 16:11:55 +00:00
|
|
|
|
|
|
|
|
|
|
2006-12-19 14:24:25 +00:00
|
|
|
|
void mathed_parse_normal(InsetMathGrid & grid, docstring const & str)
|
2002-08-14 16:11:55 +00:00
|
|
|
|
{
|
2006-12-19 14:24:25 +00:00
|
|
|
|
Parser(str).parse1(grid, 0, InsetMath::MATH_MODE, false);
|
2002-08-14 16:11:55 +00:00
|
|
|
|
}
|
2004-04-13 06:27:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void initParser()
|
|
|
|
|
{
|
2006-11-04 11:03:14 +00:00
|
|
|
|
fill(theCatcode, theCatcode + 128, catOther);
|
2004-04-13 06:27:29 +00:00
|
|
|
|
fill(theCatcode + 'a', theCatcode + 'z' + 1, catLetter);
|
|
|
|
|
fill(theCatcode + 'A', theCatcode + 'Z' + 1, catLetter);
|
|
|
|
|
|
|
|
|
|
theCatcode[int('\\')] = catEscape;
|
|
|
|
|
theCatcode[int('{')] = catBegin;
|
|
|
|
|
theCatcode[int('}')] = catEnd;
|
|
|
|
|
theCatcode[int('$')] = catMath;
|
|
|
|
|
theCatcode[int('&')] = catAlign;
|
|
|
|
|
theCatcode[int('\n')] = catNewline;
|
|
|
|
|
theCatcode[int('#')] = catParameter;
|
|
|
|
|
theCatcode[int('^')] = catSuper;
|
|
|
|
|
theCatcode[int('_')] = catSub;
|
|
|
|
|
theCatcode[int(0x7f)] = catIgnore;
|
|
|
|
|
theCatcode[int(' ')] = catSpace;
|
|
|
|
|
theCatcode[int('\t')] = catSpace;
|
|
|
|
|
theCatcode[int('\r')] = catNewline;
|
|
|
|
|
theCatcode[int('~')] = catActive;
|
|
|
|
|
theCatcode[int('%')] = catComment;
|
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|