diff --git a/src/insets/Inset.h b/src/insets/Inset.h index 3958f965b2..eb547f6c95 100644 --- a/src/insets/Inset.h +++ b/src/insets/Inset.h @@ -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; } /** diff --git a/src/mathed/CommandInset.cpp b/src/mathed/CommandInset.cpp index be67c3d52e..c5448a21fc 100644 --- a/src/mathed/CommandInset.cpp +++ b/src/mathed/CommandInset.cpp @@ -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); } diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp index eaaa94757d..003c3e0aae 100644 --- a/src/mathed/InsetMathHull.cpp +++ b/src/mathed/InsetMathHull.cpp @@ -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 "; } diff --git a/src/mathed/InsetMathRef.h b/src/mathed/InsetMathRef.h index a93d910594..8fa5a499a8 100644 --- a/src/mathed/InsetMathRef.h +++ b/src/mathed/InsetMathRef.h @@ -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; diff --git a/src/mathed/InsetMathString.cpp b/src/mathed/InsetMathString.cpp index ac951a1838..d5b0d78864 100644 --- a/src/mathed/InsetMathString.cpp +++ b/src/mathed/InsetMathString.cpp @@ -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; } diff --git a/src/mathed/MathStream.cpp b/src/mathed/MathStream.cpp index 9c8ebeb2a2..2d2be81254 100644 --- a/src/mathed/MathStream.cpp +++ b/src/mathed/MathStream.cpp @@ -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); diff --git a/src/mathed/MathStream.h b/src/mathed/MathStream.h index 78b77b780a..5eb2f8de2f 100644 --- a/src/mathed/MathStream.h +++ b/src/mathed/MathStream.h @@ -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_; ///