-
-void MathParInset::Write(ostream & os, bool fragile)
-{
- if (array.empty())
- return;
-
- int brace = 0;
- latexkeys const * l;
- MathedIter data(&array);
- // hack
- MathedRowContainer::iterator crow = getRowSt().begin();
- data.Reset();
-
- if (!Permit(LMPF_FIXED_SIZE)) {
- l = lm_get_key_by_id(size(), LM_TK_STY);
- if (l)
- os << '\\' << l->name << ' ';
- }
- while (data.OK()) {
- byte cx = data.GetChar();
- if (cx >= ' ') {
- string str = data.GetString();
-
- if (data.fcode() >= LM_TC_RM && data.fcode() <= LM_TC_TEXTRM) {
- os << '\\' << math_font_name[data.fcode()-LM_TC_RM] << '{';
- }
- for (string::const_iterator s = str.begin();
- s != str.end(); ++s) {
- byte c = *s;
- if (MathIsSymbol(data.fcode())) {
- l = lm_get_key_by_id(c, (data.fcode() == LM_TC_BSYM) ?
- LM_TK_BIGSYM : LM_TK_SYM);
- if (l) {
- os << '\\' << l->name << ' ';
- } else {
-#ifdef WITH_WARNINGS
-#warning this does not compile on gcc 2.97
-#endif
- //lyxerr << "Illegal symbol code[" << c
- // << " " << str.end() - s << " " << data.fcode() << "]";
- }
- } else {
- // Is there a standard logical XOR?
- if ((data.fcode() == LM_TC_TEX && c != '{' && c != '}') ||
- (data.fcode() == LM_TC_SPECIAL))
- os << '\\';
- else {
- if (c == '{')
- ++brace;
- if (c == '}')
- --brace;
- }
- if (c == '}' && data.fcode() == LM_TC_TEX && brace < 0)
- lyxerr <<"Math warning: Unexpected closing brace."
- << endl;
- else
- os << char(c);
- }
- }
- if (data.fcode()>= LM_TC_RM && data.fcode()<= LM_TC_TEXTRM)
- os << '}';
- } else {
- if (MathIsInset(cx)) {
- MathedInset * p = data.GetInset();
- if (cx == LM_TC_UP)
- os << "^{";
- if (cx == LM_TC_DOWN)
- os << "_{";
- p->Write(os, fragile);
- if (cx == LM_TC_UP || cx == LM_TC_DOWN)
- os << '}';
- data.Next();
- } else {
- switch (cx) {
- case LM_TC_TAB:
- {
- os << " & ";
- data.Next();
- break;
- }
- case LM_TC_CR:
- {
- if (crow) {
- if (!crow->isNumbered()) {
- os << "\\nonumber ";
- }
- if (!crow->getLabel().empty()) {
- os << "\\label{"
- << crow->getLabel()
- << "} ";
- }
- ++crow;
- }
- if (fragile)
- os << "\\protect";
- os << "\\\\\n";
- ++number_of_newlines;
- data.Next();
- break;
- }
- default:
- lyxerr << "WMath Error: unrecognized code[" << cx << "]";
- return;
- }
- }
- }
- }
-
- if (crow) {
- if (!crow->isNumbered()) {
- os << "\\nonumber ";
- }
- if (!crow->getLabel().empty()) {
- os << "\\label{"
- << crow->getLabel()
- << "} ";
- }
- }
-
- if (brace > 0)
- os << string(brace, '}');
-}
-
-
-void MathParInset::WriteNormal(ostream & os)
-{
- if (array.empty()) {
- os << "[par] ";
- return;
- }
-
- os << "[par ";
-
- int brace = 0;
- latexkeys const * l;
- MathedIter data(&array);
- // hack
- MathedRowContainer::iterator crow = getRowSt().begin();
- data.Reset();
-
- if (!Permit(LMPF_FIXED_SIZE)) {
- l = lm_get_key_by_id(size(), LM_TK_STY);
- if (l)
- os << l->name << ' ';
- }
- while (data.OK()) {
- byte cx = data.GetChar();
- if (cx >= ' ') {
- string str = data.GetString();
-
- if (data.fcode() >= LM_TC_RM && data.fcode() <= LM_TC_TEXTRM) {
- os << "[font " << math_font_name[data.fcode()-LM_TC_RM] << " [";
- }
- for (string::const_iterator s = str.begin();
- s != str.end(); ++s) {
- byte c = *s;
- if (MathIsSymbol(data.fcode())) {
- l = lm_get_key_by_id(c, (data.fcode() == LM_TC_BSYM) ?
- LM_TK_BIGSYM : LM_TK_SYM);
- if (l) {
- os << " [" << l->name << "] ";
- } else {
-#ifdef WITH_WARNINGS
-#warning this does not compile on gcc 2.97
-#endif
- //lyxerr << "Illegal symbol code[" << c
- // << " " << str.end() - s << " " << data.fcode() << "]";
- }
- } else {
- // Is there a standard logical XOR?
- if ((data.fcode() == LM_TC_TEX && c != '{' && c != '}') ||
- (data.fcode() == LM_TC_SPECIAL))
- os << "[";
- else {
- if (c == '{')
- ++brace;
- if (c == '}')
- --brace;
- }
- if (c == '}' && data.fcode() == LM_TC_TEX && brace < 0)
- lyxerr <<"Math warning: Unexpected closing brace."
- << endl;
- else
- os << char(c);
- }
- }
- if (data.fcode()>= LM_TC_RM && data.fcode()<= LM_TC_TEXTRM)
- os << "] ";
- } else {
- if (MathIsInset(cx)) {
- MathedInset * p = data.GetInset();
- if (cx == LM_TC_UP)
- os << "[superscript ";
- if (cx == LM_TC_DOWN)
- os << "[subscript ";
- p->WriteNormal(os);
- if (cx == LM_TC_UP || cx == LM_TC_DOWN)
- os << "] ";
- data.Next();
- } else {
- switch (cx) {
- case LM_TC_TAB:
- {
- os << "] [";
- data.Next();
- break;
- }
- case LM_TC_CR:
- {
- os << "] ] ";
- data.Next();
- break;
- }
- default:
- lyxerr << "WMath Error: unrecognized code[" << cx << "]";
- return;
- }
- }
- }
- }
-
- if (brace > 0)
- os << string(brace, '}');
-
- os << "] ";
-}
-
-
-void MathParInset::clear()
-{
- array.clear();
-}
-
-bool MathParInset::Inside(int x, int y)
-{
- return (x >= xo() && x <= xo() + width
- && y <= yo() + descent && y >= yo() - ascent);
-}
-
-
-void MathParInset::GetXY(int & x, int & y) const
-{
- x = xo();
- y = yo();
-}
-
-
-void MathParInset::UserSetSize(short sz)
-{
- if (sz >= 0) {
- size(sz);
- flag = flag & ~LMPF_FIXED_SIZE;
- }
-}
-
-
-void MathParInset::SetStyle(short sz)
-{
- if (Permit(LMPF_FIXED_SIZE)) {
- if (Permit(LMPF_SCRIPT))
- sz = (sz < LM_ST_SCRIPT) ? LM_ST_SCRIPT: LM_ST_SCRIPTSCRIPT;
- if (Permit(LMPF_SMALLER) && sz < LM_ST_SCRIPTSCRIPT)
- ++sz;
- MathedInset::SetStyle(sz);
- }
-}
-
-
-bool MathParInset::Permit(short f) const
-{
- return bool(f & flag);
-}
-
-
-MathedArray & MathParInset::GetData()
-{
- return array;
-}
-
-void MathParInset::push_back(MathedInset * inset, int t)