]> git.lyx.org Git - features.git/commitdiff
Fix bug #3325: Labels with special characters in equations do not work
authorEnrico Forestieri <forenr@lyx.org>
Thu, 4 Feb 2010 19:08:17 +0000 (19:08 +0000)
committerEnrico Forestieri <forenr@lyx.org>
Thu, 4 Feb 2010 19:08:17 +0000 (19:08 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33325 a592a061-630c-0410-9148-cb99ea01b6c8

src/insets/Inset.h
src/mathed/CommandInset.cpp
src/mathed/InsetMathHull.cpp
src/mathed/InsetMathRef.h
src/mathed/InsetMathString.cpp
src/mathed/MathStream.cpp
src/mathed/MathStream.h

index 3958f965b2cd6b7cf4d05f40d1aaf706bc53a0e7..eb547f6c958f4a4eb2fe22fe32aef312f5e7f9ff 100644 (file)
@@ -491,6 +491,8 @@ public:
        virtual mode_type currentMode() const { return UNDECIDED_MODE; }
        /// returns whether changing mode during latex export is forbidden
        virtual bool lockedMode() const { return false; }
+       /// returns whether only ascii chars are allowed during latex export
+       virtual bool asciiOnly() const { return false; }
        /// returns whether this inset is allowed in other insets of given mode
        virtual bool allowedIn(mode_type) const { return true; }
        /**
index be67c3d52e63d0316361b711ff0b11a1d3bbb532..c5448a21fc688ab89ad915a30385f5521a1d938e 100644 (file)
@@ -65,11 +65,15 @@ void CommandInset::draw(PainterInfo & pi, int x, int y) const
 
 void CommandInset::write(WriteStream & os) const
 {
+       ModeSpecifier specifier(os, currentMode(), lockedMode());
        MathEnsurer ensurer(os, needs_math_mode_);
-       os << '\\' << name_.c_str();
+       bool const ascii = os.asciiOnly();
+       os.asciiOnly(asciiOnly());
+       os << '\\' << name_;
        if (cell(1).size())
                os << '[' << cell(1) << ']';
        os << '{' << cell(0) << '}';
+       os.asciiOnly(ascii);
 }
 
 
index eaaa94757d5a6dc27c74fee36d2f0280c13aed52..003c3e0aaef8e2f8d743041a49bbf79394ee501e 100644 (file)
@@ -1069,7 +1069,8 @@ docstring InsetMathHull::eolString(row_type row, bool fragile) const
        docstring res;
        if (numberedType()) {
                if (label_[row] && !nonum_[row])
-                       res += "\\label{" + label_[row]->getParam("name") + '}';
+                       res += "\\label{" +
+                           escape(label_[row]->getParam("name")) + '}';
                if (nonum_[row] && (type_ != hullMultline))
                        res += "\\nonumber ";
        }
index a93d91059483b1c2488c243d4772ed3bea2a6e22..8fa5a499a8ba68468eee7fa5a353b9d8e0018bb9 100644 (file)
@@ -33,6 +33,12 @@ public:
        ///
        void infoize(odocstream & os) const;
        ///
+       mode_type currentMode() const { return TEXT_MODE; }
+       ///
+       bool lockedMode() const { return true; }
+       ///
+       bool asciiOnly() const { return true; }
+       ///
        docstring const screenLabel() const;
        ///
        void validate(LaTeXFeatures & features) const;
index ac951a1838203e0137a2cdc32c4ea3a37bda24b0..d5b0d78864e9754c721c5b50956e9c147b998860 100644 (file)
@@ -23,6 +23,8 @@
 #include "support/lstrings.h"
 #include "support/textutils.h"
 
+using lyx::support::escape;
+
 
 namespace lyx {
 
@@ -99,7 +101,7 @@ void InsetMathString::mathmlize(MathStream & /*os*/) const
 void InsetMathString::write(WriteStream & os) const
 {
        if (!os.latex() || os.lockedMode()) {
-               os << str_;
+               os << (os.asciiOnly() ? escape(str_) : str_);
                return;
        }
 
index 9c8ebeb2a25db513e935fdabb7ae612f1d21cac0..2d2be812548389c7b218181018f50967dfce0637 100644 (file)
@@ -113,14 +113,14 @@ WriteStream::WriteStream(odocstream & os, bool fragile, bool latex, OutputType o
                        Encoding const * encoding)
        : os_(os), fragile_(fragile), firstitem_(false), latex_(latex),
          output_(output), pendingspace_(false), pendingbrace_(false),
-         textmode_(false), locked_(0), line_(0), encoding_(encoding)
+         textmode_(false), locked_(0), ascii_(0), line_(0), encoding_(encoding)
 {}
 
 
 WriteStream::WriteStream(odocstream & os)
        : os_(os), fragile_(false), firstitem_(false), latex_(false),
          output_(wsDefault), pendingspace_(false), pendingbrace_(false),
-         textmode_(false), locked_(0), line_(0), encoding_(0)
+         textmode_(false), locked_(0), ascii_(0), line_(0), encoding_(0)
 {}
 
 
@@ -163,6 +163,12 @@ void WriteStream::lockedMode(bool locked)
 }
 
 
+void WriteStream::asciiOnly(bool ascii)
+{
+       ascii_ = ascii;
+}
+
+
 WriteStream & operator<<(WriteStream & ws, MathAtom const & at)
 {
        at->write(ws);
index 78b77b780a8f74250563a007e5cd8cd63a343c42..5eb2f8de2fb1206b89794938a7572702142680bb 100644 (file)
@@ -75,6 +75,10 @@ public:
        void lockedMode(bool locked);
        /// tell whether we are allowed to switch mode when producing latex code
        bool lockedMode() const { return locked_; }
+       /// tell whether to use only ascii chars when producing latex code
+       void asciiOnly(bool ascii);
+       /// tell whether to use only ascii chars when producing latex code
+       bool asciiOnly() const { return ascii_; }
        /// LaTeX encoding
        Encoding const * encoding() const { return encoding_; }
 private:
@@ -96,6 +100,8 @@ private:
        bool textmode_;
        /// are we allowed to switch mode when producing latex code?
        bool locked_;
+       /// should we use only ascii chars when producing latex code?
+       bool ascii_;
        ///
        int line_;
        ///