Fix bug #3325: Labels with special characters in equations do not work

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33325 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Enrico Forestieri 2010-02-04 19:08:17 +00:00
parent 63cb2b52aa
commit 271d53fdd0
7 changed files with 32 additions and 5 deletions

View File

@ -491,6 +491,8 @@ public:
virtual mode_type currentMode() const { return UNDECIDED_MODE; } virtual mode_type currentMode() const { return UNDECIDED_MODE; }
/// returns whether changing mode during latex export is forbidden /// returns whether changing mode during latex export is forbidden
virtual bool lockedMode() const { return false; } 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 /// returns whether this inset is allowed in other insets of given mode
virtual bool allowedIn(mode_type) const { return true; } virtual bool allowedIn(mode_type) const { return true; }
/** /**

View File

@ -65,11 +65,15 @@ void CommandInset::draw(PainterInfo & pi, int x, int y) const
void CommandInset::write(WriteStream & os) const void CommandInset::write(WriteStream & os) const
{ {
ModeSpecifier specifier(os, currentMode(), lockedMode());
MathEnsurer ensurer(os, needs_math_mode_); MathEnsurer ensurer(os, needs_math_mode_);
os << '\\' << name_.c_str(); bool const ascii = os.asciiOnly();
os.asciiOnly(asciiOnly());
os << '\\' << name_;
if (cell(1).size()) if (cell(1).size())
os << '[' << cell(1) << ']'; os << '[' << cell(1) << ']';
os << '{' << cell(0) << '}'; os << '{' << cell(0) << '}';
os.asciiOnly(ascii);
} }

View File

@ -1069,7 +1069,8 @@ docstring InsetMathHull::eolString(row_type row, bool fragile) const
docstring res; docstring res;
if (numberedType()) { if (numberedType()) {
if (label_[row] && !nonum_[row]) if (label_[row] && !nonum_[row])
res += "\\label{" + label_[row]->getParam("name") + '}'; res += "\\label{" +
escape(label_[row]->getParam("name")) + '}';
if (nonum_[row] && (type_ != hullMultline)) if (nonum_[row] && (type_ != hullMultline))
res += "\\nonumber "; res += "\\nonumber ";
} }

View File

@ -33,6 +33,12 @@ public:
/// ///
void infoize(odocstream & os) const; 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; docstring const screenLabel() const;
/// ///
void validate(LaTeXFeatures & features) const; void validate(LaTeXFeatures & features) const;

View File

@ -23,6 +23,8 @@
#include "support/lstrings.h" #include "support/lstrings.h"
#include "support/textutils.h" #include "support/textutils.h"
using lyx::support::escape;
namespace lyx { namespace lyx {
@ -99,7 +101,7 @@ void InsetMathString::mathmlize(MathStream & /*os*/) const
void InsetMathString::write(WriteStream & os) const void InsetMathString::write(WriteStream & os) const
{ {
if (!os.latex() || os.lockedMode()) { if (!os.latex() || os.lockedMode()) {
os << str_; os << (os.asciiOnly() ? escape(str_) : str_);
return; return;
} }

View File

@ -113,14 +113,14 @@ WriteStream::WriteStream(odocstream & os, bool fragile, bool latex, OutputType o
Encoding const * encoding) Encoding const * encoding)
: os_(os), fragile_(fragile), firstitem_(false), latex_(latex), : os_(os), fragile_(fragile), firstitem_(false), latex_(latex),
output_(output), pendingspace_(false), pendingbrace_(false), 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) WriteStream::WriteStream(odocstream & os)
: os_(os), fragile_(false), firstitem_(false), latex_(false), : os_(os), fragile_(false), firstitem_(false), latex_(false),
output_(wsDefault), pendingspace_(false), pendingbrace_(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) WriteStream & operator<<(WriteStream & ws, MathAtom const & at)
{ {
at->write(ws); at->write(ws);

View File

@ -75,6 +75,10 @@ public:
void lockedMode(bool locked); void lockedMode(bool locked);
/// tell whether we are allowed to switch mode when producing latex code /// tell whether we are allowed to switch mode when producing latex code
bool lockedMode() const { return locked_; } 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 /// LaTeX encoding
Encoding const * encoding() const { return encoding_; } Encoding const * encoding() const { return encoding_; }
private: private:
@ -96,6 +100,8 @@ private:
bool textmode_; bool textmode_;
/// are we allowed to switch mode when producing latex code? /// are we allowed to switch mode when producing latex code?
bool locked_; bool locked_;
/// should we use only ascii chars when producing latex code?
bool ascii_;
/// ///
int line_; int line_;
/// ///