From 4e88da70763e42ef573fbc32ac0cb6b2098ec9a0 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Tue, 16 Jul 2002 09:57:40 +0000 Subject: [PATCH] do not suppress too many extra braces in math parser git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH-1_2_X@4645 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/math_braceinset.h | 2 ++ src/mathed/math_inset.C | 18 ++++++++++++++++++ src/mathed/math_inset.h | 7 +++++-- src/mathed/math_parser.C | 20 ++++++-------------- src/mathed/math_sizeinset.h | 2 ++ status.12x | 8 +++++--- 6 files changed, 38 insertions(+), 19 deletions(-) diff --git a/src/mathed/math_braceinset.h b/src/mathed/math_braceinset.h index adebc05bb0..ce6856bef1 100644 --- a/src/mathed/math_braceinset.h +++ b/src/mathed/math_braceinset.h @@ -21,6 +21,8 @@ public: MathInset * clone() const; /// MathBraceInset * asBraceInset() { return this; } + /// identifies things that add {...} when written + bool extraBraces() const { return true; } /// void draw(Painter &, int x, int y) const; /// diff --git a/src/mathed/math_inset.C b/src/mathed/math_inset.C index 41b40a4474..e85aec7e2a 100644 --- a/src/mathed/math_inset.C +++ b/src/mathed/math_inset.C @@ -26,6 +26,7 @@ #include "math_scriptinset.h" #include "math_mathmlstream.h" #include "debug.h" +#include "math_parser.h" using std::ostream; @@ -235,3 +236,20 @@ void MathInset::mathmlize(MathMLStream & os) const NormalStream ns(os.os()); normalize(ns); } + + +string asString(MathArray const & ar) +{ + std::ostringstream os; + WriteStream ws(os); + ws << ar; + return os.str(); +} + + +MathArray asArray(string const & str) +{ + MathArray ar; + mathed_parse_cell(ar, str); + return ar; +} diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index 3bdff2dbbf..b81e90b2a0 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -220,8 +220,8 @@ public: virtual MathTextCodes code() const { return LM_TC_MIN; } /// identifies things that can get \limits or \nolimits virtual bool takesLimits() const { return false; } - /// identifies complicated things that need braces if used as arg - virtual bool needsBraces() const { return true; } + /// identifies things that add {...} when written + virtual bool extraBraces() const { return false; } /// virtual void edit(BufferView *, int, int, unsigned int) {} @@ -256,4 +256,7 @@ public: std::ostream & operator<<(std::ostream &, MathInset const &); +string asString(MathArray const & ar); +MathArray asArray(string const & str); + #endif diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index 7d3092bba9..e08aeb300f 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -932,10 +932,6 @@ void Parser::parse_into(MathArray & array, unsigned flags, MathTextCodes code) { parse_into1(array, flags, code); // remove 'unnecessary' braces: - if (array.size() == 1 && array.back()->asBraceInset()) { - lyxerr << "extra braces removed\n"; - array = array.back()->asBraceInset()->cell(0); - } } @@ -1012,15 +1008,9 @@ void Parser::parse_into1(MathArray & array, unsigned flags, MathTextCodes code) else if (t.cat() == catBegin) { MathArray ar; parse_into(ar, FLAG_BRACE_LAST); -#ifndef WITH_WARNINGS -#warning this might be wrong in general! -#endif - // ignore braces around simple items - if ((ar.size() == 1 && !ar.front()->needsBraces() - || (ar.size() == 2 && !ar.front()->needsBraces() - && ar.back()->asScriptInset())) - || (ar.size() == 0 && array.size() == 0)) - { + // do not create a BraceInset if they were written by LyX + // this helps to keep the annoyance of "a choose b" to a minimum + if (ar.size() == 1 && ar.front()->extraBraces()) { array.push_back(ar); } else { array.push_back(MathAtom(new MathBraceInset)); @@ -1177,7 +1167,9 @@ void Parser::parse_into1(MathArray & array, unsigned flags, MathTextCodes code) */ else if (t.cs() == "label") { - curr_label_ = getArg('{', '}'); + MathArray ar; + parse_into(ar, FLAG_ITEM, code); + curr_label_ = asString(ar); } else if (t.cs() == "choose" || t.cs() == "over" || t.cs() == "atop") { diff --git a/src/mathed/math_sizeinset.h b/src/mathed/math_sizeinset.h index 048ffd498a..0114e19971 100644 --- a/src/mathed/math_sizeinset.h +++ b/src/mathed/math_sizeinset.h @@ -21,6 +21,8 @@ public: explicit MathSizeInset(latexkeys const * l); /// MathInset * clone() const; + /// identifies things that add {...} when written + bool extraBraces() const { return true; } /// void metrics(MathMetricsInfo const & st) const; /// diff --git a/status.12x b/status.12x index ce37639dcd..26a038ad77 100644 --- a/status.12x +++ b/status.12x @@ -20,6 +20,9 @@ What's new ** Updates +- it is now possible to build LyX with xforms 1.0rc4 (and probably 1.0 + when this gets released) + - new option `keep aspect ratio' in graphics dialog - update finnish, danish, french and russian localizations @@ -101,6 +104,8 @@ What's new - when a document is registered though version control, make sure it has been saved +- fix bug where the math parser would drop some pairs of braces + - only use the amsmath package when it is needed - fix the spacing around fraction insets in math editor @@ -124,9 +129,6 @@ What's new - make latex import script (reLyX) honor the LYX_DIR_12x envirnment variable, like the rest of LyX -- rework the configuration script wrt xforms 1.0. This version is now - supported. - - honor --with-extra-XXX when searching for AikSaurus library - fix search for pspell library