]> git.lyx.org Git - features.git/commitdiff
Use a helper method in order to avoid code repetition.
authorEnrico Forestieri <forenr@lyx.org>
Mon, 16 Jun 2008 14:32:51 +0000 (14:32 +0000)
committerEnrico Forestieri <forenr@lyx.org>
Mon, 16 Jun 2008 14:32:51 +0000 (14:32 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25273 a592a061-630c-0410-9148-cb99ea01b6c8

27 files changed:
src/mathed/CommandInset.cpp
src/mathed/InsetMath.cpp
src/mathed/InsetMath.h
src/mathed/InsetMathAMSArray.cpp
src/mathed/InsetMathArray.cpp
src/mathed/InsetMathBig.cpp
src/mathed/InsetMathBoldSymbol.cpp
src/mathed/InsetMathCases.cpp
src/mathed/InsetMathDecoration.cpp
src/mathed/InsetMathDelim.cpp
src/mathed/InsetMathEnv.cpp
src/mathed/InsetMathFrac.cpp
src/mathed/InsetMathOverset.cpp
src/mathed/InsetMathPhantom.cpp
src/mathed/InsetMathRoot.cpp
src/mathed/InsetMathScript.cpp
src/mathed/InsetMathSize.cpp
src/mathed/InsetMathSpace.cpp
src/mathed/InsetMathSplit.cpp
src/mathed/InsetMathSqrt.cpp
src/mathed/InsetMathStackrel.cpp
src/mathed/InsetMathSubstack.cpp
src/mathed/InsetMathSymbol.cpp
src/mathed/InsetMathUnderset.cpp
src/mathed/InsetMathXArrow.cpp
src/mathed/InsetMathXYArrow.cpp
src/mathed/InsetMathXYMatrix.cpp

index 9edf51b07ad067490be564b0bd0b0a6bc40a50f1..3ad90d1eb88f49109ce00674f53eb24d82c7a023 100644 (file)
@@ -65,12 +65,7 @@ void CommandInset::draw(PainterInfo & pi, int x, int y) const
 
 void CommandInset::write(WriteStream & os) const
 {
-       bool brace = os.pendingBrace();
-       os.pendingBrace(false);
-       if (os.latex() && os.textMode() && needs_math_mode_) {
-               os << "\\ensuremath{";
-               os.textMode(false);
-       }
+       bool brace = ensureMath(os, needs_math_mode_);
        os << '\\' << name_.c_str();
        if (cell(1).size())
                os << '[' << cell(1) << ']';
index dce8d598923f3d2be916bae4922a0b8b1a2aad20..0674d97382b58ffd19dc2f824518f12cd8369a05 100644 (file)
@@ -68,12 +68,7 @@ void InsetMath::drawT(TextPainter &, int, int) const
 
 void InsetMath::write(WriteStream & os) const
 {
-       bool brace = os.pendingBrace();
-       os.pendingBrace(false);
-       if (os.latex() && os.textMode()) {
-               os << "\\ensuremath{";
-               os.textMode(false);
-       }
+       bool brace = ensureMath(os);
        docstring const s = name();
        os << "\\" << s;
        // We need an extra ' ' unless this is a single-char-non-ASCII name
@@ -84,6 +79,19 @@ void InsetMath::write(WriteStream & os) const
 }
 
 
+bool InsetMath::ensureMath(WriteStream & os, bool needs_math_mode) const
+{
+       bool brace = os.pendingBrace();
+       os.pendingBrace(false);
+       if (os.latex() && os.textMode() && needs_math_mode) {
+               os << "\\ensuremath{";
+               os.textMode(false);
+               brace = true;
+       }
+       return brace;
+}
+
+
 int InsetMath::plaintext(odocstream &, OutputParams const &) const
 {
        // all math plain text output shall take place in InsetMathHull
index 2f91e9ede5e6f872d3b8fd753fc8b56205ebfed8..aae7d7474e4eba0e6dc89e766a068954e5a341cb 100644 (file)
@@ -181,6 +181,9 @@ public:
        /// write content as something readable by Octave
        virtual void octave(OctaveStream &) const;
 
+       /// ensure math mode when writing LaTeX
+       bool ensureMath(WriteStream & os, bool needs_math_mode = true) const;
+
        /// plain text output in ucs4 encoding
        int plaintext(odocstream &, OutputParams const &) const;
 
index fc839088c31e3156f06b34e2332e8b9fca8b3d76..16ddb91f3c6c450d464d036aa249918a7518d86e 100644 (file)
@@ -122,13 +122,7 @@ bool InsetMathAMSArray::getStatus(Cursor & cur, FuncRequest const & cmd,
 
 void InsetMathAMSArray::write(WriteStream & os) const
 {
-       bool brace = os.pendingBrace();
-       os.pendingBrace(false);
-       if (os.latex() && os.textMode()) {
-               os << "\\ensuremath{";
-               os.textMode(false);
-               brace = true;
-       }
+       bool brace = ensureMath(os);
        os << "\\begin{" << name_ << '}';
        InsetMathGrid::write(os);
        os << "\\end{" << name_ << '}';
index 0d9c7d5c879e049ad1d9f0757edbbaa25dab7a26..7b7d01dea9e5c0e75963c576dfac4aa695967dc6 100644 (file)
@@ -95,13 +95,7 @@ void InsetMathArray::draw(PainterInfo & pi, int x, int y) const
 
 void InsetMathArray::write(WriteStream & os) const
 {
-       bool brace = os.pendingBrace();
-       os.pendingBrace(false);
-       if (os.latex() && os.textMode()) {
-               os << "\\ensuremath{";
-               os.textMode(false);
-               brace = true;
-       }
+       bool brace = ensureMath(os);
 
        if (os.fragile())
                os << "\\protect";
index 6e54064aca4cfa2476c3a55d512d4a0dc6264e9e..d0d3b957d5f47b44edbe8b735ee6a956354e2d33 100644 (file)
@@ -89,13 +89,7 @@ void InsetMathBig::draw(PainterInfo & pi, int x, int y) const
 
 void InsetMathBig::write(WriteStream & os) const
 {
-       bool brace = os.pendingBrace();
-       os.pendingBrace(false);
-       if (os.latex() && os.textMode()) {
-               os << "\\ensuremath{";
-               os.textMode(false);
-               brace = true;
-       }
+       bool brace = ensureMath(os);
        os << '\\' << name_ << delim_;
        if (delim_[0] == '\\')
                os.pendingSpace(true);
index 3cca1180fb589ad636dbcb4c471c4d0ab6144ff8..d3633efc8c3dd15fa62b8ba47273ec4a3f249a3c 100644 (file)
@@ -76,13 +76,7 @@ void InsetMathBoldSymbol::validate(LaTeXFeatures & features) const
 
 void InsetMathBoldSymbol::write(WriteStream & os) const
 {
-       bool brace = os.pendingBrace();
-       os.pendingBrace(false);
-       if (os.latex() && os.textMode()) {
-               os << "\\ensuremath{";
-               os.textMode(false);
-               brace = true;
-       }
+       bool brace = ensureMath(os);
        switch (kind_) {
        case AMS_BOLD:
                os << "\\boldsymbol{" << cell(0) << "}";
index eb532484028913287550f71a2a2ef54cadbb4f2a..6f1444c3ad23808bb9728356007477998730c803 100644 (file)
@@ -107,12 +107,7 @@ bool InsetMathCases::getStatus(Cursor & cur, FuncRequest const & cmd,
 
 void InsetMathCases::write(WriteStream & os) const
 {
-       bool brace = os.pendingBrace();
-       if (os.latex() && os.textMode()) {
-               os << "\\ensuremath{";
-               os.textMode(false);
-               brace = true;
-       }
+       bool brace = ensureMath(os);
        if (os.fragile())
                os << "\\protect";
        os << "\\begin{cases}\n";
index d53efb0354765350ec4d4e09947f961ebd958d4e..17aaaf04d0d6a5e172825ca6af10caf9a8d47e14 100644 (file)
@@ -139,13 +139,7 @@ void InsetMathDecoration::draw(PainterInfo & pi, int x, int y) const
 
 void InsetMathDecoration::write(WriteStream & os) const
 {
-       bool brace = os.pendingBrace();
-       os.pendingBrace(false);
-       if (os.latex() && os.textMode()) {
-               os << "\\ensuremath{";
-               os.textMode(false);
-               brace = true;
-       }
+       bool brace = ensureMath(os);
        if (os.fragile() && protect())
                os << "\\protect";
        os << '\\' << key_->name << '{' << cell(0) << '}';
index 9cf6414e294257b03909933ecd287209d6fc10cd..c345a03d4d9e0fd123b0d00eac7f6ad94188304a 100644 (file)
@@ -59,17 +59,9 @@ Inset * InsetMathDelim::clone() const
 
 void InsetMathDelim::write(WriteStream & os) const
 {
-       bool brace = os.pendingBrace();
-       os.pendingBrace(false);
-       if (os.latex() && os.textMode()) {
-               os << "\\ensuremath{";
-               os.textMode(false);
-               brace = true;
-       }
-
+       bool brace = ensureMath(os);
        os << "\\left" << convertDelimToLatexName(left_) << cell(0)
           << "\\right" << convertDelimToLatexName(right_);
-
        os.pendingBrace(brace);
 }
 
index f04d87119f7d9f48bc5129452e2e92b39e228287..939b0765aadebe8976c8c149888dad24583c1fe1 100644 (file)
@@ -48,13 +48,7 @@ void InsetMathEnv::draw(PainterInfo & pi, int x, int y) const
 
 void InsetMathEnv::write(WriteStream & os) const
 {
-       bool brace = os.pendingBrace();
-       os.pendingBrace(false);
-       if (os.latex() && os.textMode()) {
-               os << "\\ensuremath{";
-               os.textMode(false);
-               brace = true;
-       }
+       bool brace = ensureMath(os);
        os << "\\begin{" << name_ << '}' << cell(0) << "\\end{" << name_ << '}';
        os.pendingBrace(brace);
 }
index 58e0c1b1803998774f7008e3cc1f3c14c9b979f2..456faa792ac26eb31342070480b69508288d8f78 100644 (file)
@@ -265,13 +265,7 @@ void InsetMathFrac::drawT(TextPainter & /*pain*/, int /*x*/, int /*y*/) const
 
 void InsetMathFrac::write(WriteStream & os) const
 {
-       bool brace = os.pendingBrace();
-       os.pendingBrace(false);
-       if (os.latex() && os.textMode()) {
-               os << "\\ensuremath{";
-               os.textMode(false);
-               brace = true;
-       }
+       bool brace = ensureMath(os);
 
        switch (kind_) {
        case ATOP:
@@ -545,13 +539,7 @@ bool InsetMathBinom::extraBraces() const
 
 void InsetMathBinom::write(WriteStream & os) const
 {
-       bool brace = os.pendingBrace();
-       os.pendingBrace(false);
-       if (os.latex() && os.textMode()) {
-               os << "\\ensuremath{";
-               os.textMode(false);
-               brace = true;
-       }
+       bool brace = ensureMath(os);
 
        switch (kind_) {
        case BINOM:
index 5d8edefef82ee45a64be6e585c7a38ae462ddf67..114ed0ebfc9f2f99e710d0faef240dc7fc620b69 100644 (file)
@@ -73,12 +73,7 @@ bool InsetMathOverset::idxLast(Cursor & cur) const
 
 void InsetMathOverset::write(WriteStream & os) const
 {
-       bool brace = os.pendingBrace();
-       os.pendingBrace(false);
-       if (os.latex() && os.textMode()) {
-               os << "\\ensuremath{";
-               os.textMode(false);
-       }
+       bool brace = ensureMath(os);
        os << "\\overset{" << cell(0) << "}{" << cell(1) << '}';
        os.pendingBrace(brace);
 }
index ba9b89a96a9bcd5cbedebe96c39c30eb9791cd7f..e4777e3953c793771c8d17cb17b2e3433335400f 100644 (file)
@@ -119,13 +119,7 @@ void InsetMathPhantom::draw(PainterInfo & pi, int x, int y) const
 
 void InsetMathPhantom::write(WriteStream & os) const
 {
-       bool brace = os.pendingBrace();
-       os.pendingBrace(false);
-       if (os.latex() && os.textMode()) {
-               os << "\\ensuremath{";
-               os.textMode(false);
-               brace = true;
-       }
+       bool brace = ensureMath(os);
        switch (kind_) {
        case phantom:
                os << "\\phantom{";
index 006c0716ae2deda2dae315b9f5d621d236a10c91..0102ebd08ddcda61dc4a36e7df5762c2de3ae6cc 100644 (file)
@@ -72,13 +72,7 @@ void InsetMathRoot::draw(PainterInfo & pi, int x, int y) const
 
 void InsetMathRoot::write(WriteStream & os) const
 {
-       bool brace = os.pendingBrace();
-       os.pendingBrace(false);
-       if (os.latex() && os.textMode()) {
-               os << "\\ensuremath{";
-               os.textMode(false);
-               brace = true;
-       }
+       bool brace = ensureMath(os);
        os << "\\sqrt[" << cell(0) << "]{" << cell(1) << '}';
        os.pendingBrace(brace);
 }
index 6bf53dd79900d4af5cd4a30c212e29013962b9ea..25830420ec3374a258f1853490820afe43a7d695 100644 (file)
@@ -525,13 +525,7 @@ bool InsetMathScript::idxUpDown(Cursor & cur, bool up) const
 
 void InsetMathScript::write(WriteStream & os) const
 {
-       bool brace = os.pendingBrace();
-       os.pendingBrace(false);
-       if (os.latex() && os.textMode()) {
-               os << "\\ensuremath{";
-               os.textMode(false);
-               brace = true;
-       }
+       bool brace = ensureMath(os);
 
        if (nuc().size()) {
                os << nuc();
index 898a39513957b899bcbc1228810e9836dec5e579..1ad777d9a622b2b4a5aa9a04c75095f8eb28f3c4 100644 (file)
@@ -52,13 +52,7 @@ void InsetMathSize::draw(PainterInfo & pi, int x, int y) const
 
 void InsetMathSize::write(WriteStream & os) const
 {
-       bool brace = os.pendingBrace();
-       os.pendingBrace(false);
-       if (os.latex() && os.textMode()) {
-               os << "\\ensuremath{";
-               os.textMode(false);
-               brace = true;
-       }
+       bool brace = ensureMath(os);
        os << "{\\" << key_->name << ' ' << cell(0) << '}';
        os.pendingBrace(brace);
 }
index 60950c30ad3e99657ebe0ac162b6e75dd3cbd3f1..4aa9ed58c1d025a70f8f1a5b8f9077ae4a47eb11 100644 (file)
@@ -147,13 +147,7 @@ void InsetMathSpace::normalize(NormalStream & os) const
 void InsetMathSpace::write(WriteStream & os) const
 {
        if (space_ >= 0 && space_ < nSpace) {
-               bool brace = os.pendingBrace();
-               os.pendingBrace(false);
-               if (os.latex() && os.textMode()) {
-                       os << "\\ensuremath{";
-                       os.textMode(false);
-                       brace = true;
-               }
+               bool brace = ensureMath(os);
                os << '\\' << latex_mathspace[space_];
                os.pendingSpace(true);
                os.pendingBrace(brace);
index 95fbc80f5fb85d9bb498aaf187dd72519751b49d..a574e172e826b9502ccaa06a8e8e0ee276a32746 100644 (file)
@@ -87,13 +87,7 @@ bool InsetMathSplit::getStatus(Cursor & cur, FuncRequest const & cmd,
 
 void InsetMathSplit::write(WriteStream & ws) const
 {
-       bool brace = ws.pendingBrace();
-       ws.pendingBrace(false);
-       if (ws.latex() && ws.textMode()) {
-               ws << "\\ensuremath{";
-               ws.textMode(false);
-               brace = true;
-       }
+       bool brace = ensureMath(ws);
        if (ws.fragile())
                ws << "\\protect";
        ws << "\\begin{" << name_ << '}';
index 11304a9bd1800ea18d96c35fe7fe8aedca2e1583..14f0600498ca7f3bacf31679896d6470a11b8cf1 100644 (file)
@@ -80,13 +80,7 @@ void InsetMathSqrt::drawT(TextPainter & /*pain*/, int /*x*/, int /*y*/) const
 
 void InsetMathSqrt::write(WriteStream & os) const
 {
-       bool brace = os.pendingBrace();
-       os.pendingBrace(false);
-       if (os.latex() && os.textMode()) {
-               os << "\\ensuremath{";
-               os.textMode(false);
-               brace = true;
-       }
+       bool brace = ensureMath(os);
        os << "\\sqrt{" << cell(0) << '}';
        os.pendingBrace(brace);
 }
index 410e21f1d8298902f3090d04172a8ccac0af2614..87e594e2b4cd1c51ffa1081870b278fd1b76dcf5 100644 (file)
@@ -58,13 +58,7 @@ void InsetMathStackrel::draw(PainterInfo & pi, int x, int y) const
 
 void InsetMathStackrel::write(WriteStream & os) const
 {
-       bool brace = os.pendingBrace();
-       os.pendingBrace(false);
-       if (os.latex() && os.textMode()) {
-               os << "\\ensuremath{";
-               os.textMode(false);
-               brace = true;
-       }
+       bool brace = ensureMath(os);
        os << "\\stackrel{" << cell(0) << "}{" << cell(1) << '}';
        os.pendingBrace(brace);
 }
index e5abe9818afac96b6c66e86fc91b05badf8730ac..1fa93585c7d0a0c3d1040ad66908bd2d93b0f88c 100644 (file)
@@ -89,13 +89,7 @@ void InsetMathSubstack::infoize(odocstream & os) const
 
 void InsetMathSubstack::write(WriteStream & os) const
 {
-       bool brace = os.pendingBrace();
-       os.pendingBrace(false);
-       if (os.latex() && os.textMode()) {
-               os << "\\ensuremath{";
-               os.textMode(false);
-               brace = true;
-       }
+       bool brace = ensureMath(os);
        os << "\\substack{";
        InsetMathGrid::write(os);
        os << "}\n";
index 28119d2a9ba6f05ef992e5ae02b38b4290bac2c7..7fff4a3e72031a18971e6f65bc3f1fd763289455 100644 (file)
@@ -206,13 +206,7 @@ void InsetMathSymbol::octave(OctaveStream & os) const
 
 void InsetMathSymbol::write(WriteStream & os) const
 {
-       bool brace = os.pendingBrace();
-       os.pendingBrace(false);
-       if (os.latex() && os.textMode()) {
-               os << "\\ensuremath{";
-               os.textMode(false);
-               brace = true;
-       }
+       bool brace = ensureMath(os);
        os << '\\' << name();
        os.pendingBrace(brace);
 
index ae5ab36228de8ab3b4d5b3b2637a39752a4c7f09..eb0f63b2eb83962320b13b27bcc0c2c7574cc57b 100644 (file)
@@ -84,13 +84,7 @@ bool InsetMathUnderset::idxUpDown(Cursor & cur, bool up) const
 
 void InsetMathUnderset::write(WriteStream & os) const
 {
-       bool brace = os.pendingBrace();
-       os.pendingBrace(false);
-       if (os.latex() && os.textMode()) {
-               os << "\\ensuremath{";
-               os.textMode(false);
-               brace = true;
-       }
+       bool brace = ensureMath(os);
        os << "\\underset{" << cell(0) << "}{" << cell(1) << '}';
        os.pendingBrace(brace);
 }
index 78d5390a3f9d48d13b3db264fbb2d080eae0319b..ac4cea005cdb6ed99e810d4707e0907e915c8f17 100644 (file)
@@ -62,19 +62,11 @@ void InsetMathXArrow::draw(PainterInfo & pi, int x, int y) const
 
 void InsetMathXArrow::write(WriteStream & os) const
 {
-       bool brace = os.pendingBrace();
-       os.pendingBrace(false);
-       if (os.latex() && os.textMode()) {
-               os << "\\ensuremath{";
-               os.textMode(false);
-               brace = true;
-       }
-
+       bool brace = ensureMath(os);
        os << '\\' << name_;
        if (cell(1).size())
                os << '[' << cell(1) << ']';
        os << '{' << cell(0) << '}';
-
        os.pendingBrace(brace);
 }
 
index 866c3bb1d64bf32f9fe5b2df9155d9decede5afa..e9d933285733c109164de39877273551f4d93354 100644 (file)
@@ -140,13 +140,7 @@ void InsetMathXYArrow::draw(PainterInfo & pi, int x, int y) const
 
 void InsetMathXYArrow::write(WriteStream & os) const
 {
-       bool brace = os.pendingBrace();
-       os.pendingBrace(false);
-       if (os.latex() && os.textMode()) {
-               os << "\\ensuremath{";
-               os.textMode(false);
-               brace = true;
-       }
+       bool brace = ensureMath(os);
        os << "\\ar";
        if (cell(0).size())
                os << '[' << cell(0) << ']';
index 9be4e2efa6c67e3ad63bb8ec2f6976e3c6972632..4bd3b0e4e8ff69da5e228d9b404a76710be50179 100644 (file)
@@ -53,13 +53,7 @@ void InsetMathXYMatrix::metrics(MetricsInfo & mi, Dimension & dim) const
 
 void InsetMathXYMatrix::write(WriteStream & os) const
 {
-       bool brace = os.pendingBrace();
-       os.pendingBrace(false);
-       if (os.latex() && os.textMode()) {
-               os << "\\ensuremath{";
-               os.textMode(false);
-               brace = true;
-       }
+       bool brace = ensureMath(os);
        os << "\\xymatrix";
        switch (spacing_code_) {
        case 'R':