]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/MathExtern.cpp
Preserve \inputencoding value when switching to non-TeX fonts.
[lyx.git] / src / mathed / MathExtern.cpp
index 323ea138d19078cfbf80e4c651af679a589beb6c..504fab717bee958d43df5b7802ee5277e86ef03c 100644 (file)
@@ -1421,13 +1421,45 @@ void write(MathData const & dat, WriteStream & wi)
 
 void writeString(docstring const & s, WriteStream & os)
 {
-       if (!os.latex() || os.lockedMode()) {
+       if (!os.latex()) {
                os << (os.asciiOnly() ? escape(s) : s);
                return;
        }
 
-       docstring::const_iterator cit = s.begin();
-       docstring::const_iterator end = s.end();
+       if (os.lockedMode()) {
+               bool space;
+               docstring cmd;
+               for (char_type c : s) {
+                       try {
+                               Encodings::latexMathChar(c, true, os.encoding(), cmd, space);
+                               os << cmd;
+                               os.pendingSpace(space);
+                       } catch (EncodingException const & e) {
+                               switch (os.output()) {
+                               case WriteStream::wsDryrun: {
+                                       os << "<" << _("LyX Warning: ")
+                                          << _("uncodable character") << " '";
+                                       os << docstring(1, e.failed_char);
+                                       os << "'>";
+                                       break;
+                               }
+                               case WriteStream::wsPreview: {
+                                       // indicate the encoding error by a boxed '?'
+                                       os << "{\\fboxsep=1pt\\fbox{?}}";
+                                       LYXERR0("Uncodable character" << " '"
+                                               << docstring(1, e.failed_char)
+                                               << "'");
+                                       break;
+                               }
+                               case WriteStream::wsDefault:
+                               default:
+                                       // throw again
+                                       throw(e);
+                               }
+                       }
+               }
+               return;
+       }
 
        // We may already be inside an \ensuremath command.
        bool in_forced_mode = os.pendingBrace();
@@ -1435,9 +1467,8 @@ void writeString(docstring const & s, WriteStream & os)
        // We will take care of matching braces.
        os.pendingBrace(false);
 
-       while (cit != end) {
+       for (char_type const c : s) {
                bool mathmode = in_forced_mode ? os.textMode() : !os.textMode();
-               char_type const c = *cit;
                docstring command(1, c);
                try {
                        bool termination = false;
@@ -1500,7 +1531,6 @@ void writeString(docstring const & s, WriteStream & os)
                                throw(e);
                        }
                }
-               ++cit;
        }
 
        if (in_forced_mode && os.textMode()) {