]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/MathExtern.cpp
Run codespell on src/mathed
[lyx.git] / src / mathed / MathExtern.cpp
index da43bd4e3508043ee7bc6a70801efc90598d470b..311b32389533edb494223d0c3ef8a01f3737b8ba 100644 (file)
@@ -115,7 +115,7 @@ bool extractScript(MathData & ar,
 // try to extract an "argument" to some function.
 // returns position behind the argument
 MathData::iterator extractArgument(MathData & ar,
-       MathData::iterator pos, MathData::iterator last, 
+       MathData::iterator pos, MathData::iterator last,
        ExternalMath kind, bool function = false)
 {
        // nothing to get here
@@ -211,7 +211,7 @@ void extractMatrices(MathData & ar)
                        continue;
                if (!arr.front()->asGridInset())
                        continue;
-               ar[i] = MathAtom(new InsetMathMatrix(*(arr.front()->asGridInset()), 
+               ar[i] = MathAtom(new InsetMathMatrix(*(arr.front()->asGridInset()),
                                 inset->left_, inset->right_));
        }
 
@@ -342,7 +342,7 @@ void replaceNested(
 
 
 //
-// split scripts into seperate super- and subscript insets. sub goes in
+// split scripts into separate super- and subscript insets. sub goes in
 // front of super...
 //
 
@@ -602,7 +602,7 @@ void extractFunctions(MathData & ar, ExternalMath kind)
                auto p = make_unique<InsetMathExFunc>(buf, name);
 
                // jt points to the "argument". Get hold of this.
-               MathData::iterator st = 
+               MathData::iterator st =
                                extractArgument(p->cell(0), jt, ar.end(), kind, true);
 
                // replace the function name by a real function inset
@@ -683,7 +683,7 @@ void extractIntegrals(MathData & ar, ExternalMath kind)
                if (!testIntegral(*it))
                        continue;
 
-               // core ist part from behind the scripts to the 'd'
+               // core is part from behind the scripts to the 'd'
                auto p = make_unique<InsetMathExInt>(buf, from_ascii("int"));
 
                // handle scripts if available
@@ -775,17 +775,17 @@ void extractSums(MathData & ar)
                InsetMathScript const * sub = ar[i]->asScriptInset();
                if (sub && sub->hasDown()) {
                        // try to figure out the summation index from the subscript
-                       MathData const & ar = sub->down();
+                       MathData const & md = sub->down();
                        MathData::const_iterator xt =
-                               find_if(ar.begin(), ar.end(), &testEqualSign);
-                       if (xt != ar.end()) {
+                               find_if(md.begin(), md.end(), &testEqualSign);
+                       if (xt != md.end()) {
                                // we found a '=', use everything in front of that as index,
                                // and everything behind as lower index
-                               p->cell(1) = MathData(buf, ar.begin(), xt);
-                               p->cell(2) = MathData(buf, xt + 1, ar.end());
+                               p->cell(1) = MathData(buf, md.begin(), xt);
+                               p->cell(2) = MathData(buf, xt + 1, md.end());
                        } else {
                                // use everything as summation index, don't use scripts.
-                               p->cell(1) = ar;
+                               p->cell(1) = md;
                        }
                }
 
@@ -896,11 +896,11 @@ void extractDiff(MathData & ar)
                                int mult = 1;
                                if (extractNumber(script->up(), mult)) {
                                        //lyxerr << "mult: " << mult << endl;
-                                       if (mult > 1000) {
-                                               lyxerr << "Cannot differentiate more than 1000 times !" << endl;
+                                       if (mult < 0 || mult > 1000) {
+                                               lyxerr << "Cannot differentiate less than 0 or more than 1000 times !" << endl;
                                                continue;
                                        }
-                                       for (int i = 0; i < mult; ++i)
+                                       for (int ii = 0; ii < mult; ++ii)
                                                diff->addDer(MathData(buf, dt + 1, st));
                                }
                        } else {
@@ -1391,9 +1391,9 @@ namespace {
                return res;
        }
 
-}
+} // namespace
 
-} // anon namespace
+} // namespace
 
 void write(MathData const & dat, WriteStream & wi)
 {
@@ -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()) {
@@ -1556,19 +1586,19 @@ void mathematica(MathData const & dat, MathematicaStream & os)
 }
 
 
-void mathmlize(MathData const & dat, MathStream & os)
+void mathmlize(MathData const & dat, MathStream & ms)
 {
        MathData ar = dat;
        extractStructure(ar, MATHML);
        if (ar.empty())
-               os << "<mrow/>";
+               ms << "<" << from_ascii(ms.namespacedTag("mrow")) << "/>";
        else if (ar.size() == 1)
-               os << ar.front();
+               ms << ar.front();
        else {
-               os << MTag("mrow");
+               ms << MTag("mrow");
                for (MathData::const_iterator it = ar.begin(); it != ar.end(); ++it)
-                       (*it)->mathmlize(os);
-               os << ETag("mrow");
+                       (*it)->mathmlize(ms);
+               ms << ETag("mrow");
        }
 }