]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathString.cpp
Substack support for XHTML.
[lyx.git] / src / mathed / InsetMathString.cpp
index 5dcd595d858a0d97e018df7389a4246bd9eb922e..98b641a72655d922a37acce871b696727d5e8aab 100644 (file)
 #include <config.h>
 
 #include "InsetMathString.h"
+#include "MathFactory.h"
 #include "MathStream.h"
 #include "MathSupport.h"
 
 #include "Encoding.h"
 
+#include "support/debug.h"
 #include "support/gettext.h"
+#include "support/lassert.h"
 #include "support/lstrings.h"
 #include "support/textutils.h"
 
+using lyx::support::escape;
+
 
 namespace lyx {
 
@@ -86,25 +91,17 @@ void InsetMathString::octave(OctaveStream & os) const
 }
 
 
-void InsetMathString::mathmlize(MathStream & os) const
+void InsetMathString::mathmlize(MathStream & /*os*/) const
 {
-/*
-       if (code_ == LM_TC_VAR)
-               os << "<mi> " << str_ << " </mi>";
-       else if (code_ == LM_TC_CONST)
-               os << "<mn> " << str_ << " </mn>";
-       else if (code_ == LM_TC_RM || code_ == LM_TC_TEXTRM)
-               os << "<mtext> " << str_ <<  " </mtext>";
-       else
-*/
-               os << str_;
+       // useless, no doubt, but we should not be here
+       LASSERT(false, /* */);
 }
 
 
 void InsetMathString::write(WriteStream & os) const
 {
-       if (!os.latex()) {
-               os << str_;
+       if (!os.latex() || os.lockedMode()) {
+               os << (os.asciiOnly() ? escape(str_) : str_);
                return;
        }
 
@@ -159,14 +156,24 @@ void InsetMathString::write(WriteStream & os) const
                            && isAlphaASCII(command[command.size() - 1]))
                                os.pendingSpace(true);
                } catch (EncodingException & e) {
-                       if (os.dryrun()) {
-                               // FIXME: this is OK for View->Source
-                               // but math preview will likely fail.
+                       switch (os.output()) {
+                       case WriteStream::wsDryrun: {
                                os << "<" << _("LyX Warning: ")
                                   << _("uncodable character") << " '";
                                os << docstring(1, e.failed_char);
                                os << "'>";
-                       } else {
+                               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);
                        }