]> git.lyx.org Git - lyx.git/blobdiff - src/Encoding.cpp
Cmake build:
[lyx.git] / src / Encoding.cpp
index d9fe69110dec9063b871b1150af16f2ac02a370c..298fc6a0ae5e4e56c452c708980212a3e3526269 100644 (file)
@@ -22,6 +22,7 @@
 #include "LyXRC.h"
 
 #include "support/debug.h"
+#include "support/gettext.h"
 #include "support/FileName.h"
 #include "support/lstrings.h"
 #include "support/textutils.h"
@@ -399,6 +400,44 @@ pair<docstring, bool> Encoding::latexChar(char_type c) const
 }
 
 
+pair<docstring, docstring> Encoding::latexString(docstring const input, bool dryrun) const
+{
+       docstring result;
+       docstring uncodable;
+       bool terminate = false;
+       for (size_t n = 0; n < input.size(); ++n) {
+               try {
+                       char_type const c = input[n];
+                       pair<docstring, bool> latex_char = latexChar(c);
+                       docstring const latex = latex_char.first;
+                       if (terminate && !prefixIs(latex, '\\')
+                           && !prefixIs(latex, '{')
+                           && !prefixIs(latex, '}')) {
+                                       // Prevent eating of a following
+                                       // space or command corruption by
+                                       // following characters
+                                       if (latex == " ")
+                                               result += "{}";
+                                       else
+                                               result += " ";
+                               }
+                       result += latex;
+                       terminate = latex_char.second;
+               } catch (EncodingException & /* e */) {
+                       LYXERR0("Uncodable character in latexString!");
+                       if (dryrun) {
+                               result += "<" + _("LyX Warning: ")
+                                          + _("uncodable character") + " '";
+                               result += docstring(1, input[n]);
+                               result += "'>";
+                       } else
+                               uncodable += input[n];
+               }
+       }
+       return make_pair(result, uncodable);
+}
+
+
 vector<char_type> Encoding::symbolsList() const
 {
        // assure the used encoding is properly initialized
@@ -658,8 +697,12 @@ void Encodings::validate(char_type c, LaTeXFeatures & features, bool for_mathed)
                bool const use_text = (for_mathed && isTextCmd(c)) ||
                                      (!for_mathed && !it->second.textcommand.empty());
                bool const plain_utf8 = (features.runparams().encoding->name() == "utf8-plain");
+               bool const unicode_math = (features.isRequired("unicode-math")
+                       && features.isAvailable("unicode-math"));
                // with utf8-plain, we only load packages when in mathed (see #7766)
-               if (math_mode || (use_math && !plain_utf8)) {
+               // and if we do not use unicode-math
+               if ((math_mode && !unicode_math)
+                    || (use_math && !plain_utf8)) {
                        if (!it->second.mathpreamble.empty()) {
                                if (it->second.mathfeature()) {
                                        string feats = it->second.mathpreamble;
@@ -809,8 +852,7 @@ Encoding const * Encodings::fromLaTeXName(string const & n) const
 
 
 Encodings::Encodings()
-{
-}
+{}
 
 
 void Encodings::read(FileName const & encfile, FileName const & symbolsfile)