2 * \file BufferEncodings.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
7 * \author Jean-Marc Lasgouttes
11 * Full author contact details are available in file CREDITS.
16 #include "BufferEncodings.h"
19 #include "InsetIterator.h"
20 #include "LaTeXFeatures.h"
22 #include "support/lstrings.h"
25 using namespace lyx::support;
29 void BufferEncodings::initUnicodeMath(Buffer const & buffer, bool for_master)
38 Inset & inset = buffer.inset();
39 InsetIterator it = inset_iterator_begin(inset);
40 InsetIterator const end = inset_iterator_end(inset);
41 for (; it != end; ++it)
42 it->initUnicodeMath();
48 for (Buffer * buf : buffer.getDescendants())
49 initUnicodeMath(*buf, false);
53 void BufferEncodings::validate(char_type c, LaTeXFeatures & features, bool for_mathed)
55 CharInfo const & ci = Encodings::unicodeCharInfo(c);
56 if (ci.isUnicodeSymbol()) {
57 // In mathed, c could be used both in textmode and mathmode
58 docstring const textcommand = ci.textcommand();
59 bool const math_mode = for_mathed && isMathCmd(c);
60 bool const use_math = math_mode ||
61 (!for_mathed && textcommand.empty());
62 bool const use_text = (for_mathed && isTextCmd(c)) ||
63 (!for_mathed && !textcommand.empty());
64 bool const plain_utf8 = (features.runparams().encoding->name() == "utf8-plain");
65 bool const unicode_math = (features.isRequired("unicode-math")
66 && features.isAvailable("unicode-math"));
67 // with utf8-plain, we only load packages when in mathed (see #7766)
68 // and if we do not use unicode-math
69 if ((math_mode && !unicode_math)
70 || (use_math && !plain_utf8)) {
71 string const mathpreamble = ci.mathpreamble();
72 if (!mathpreamble.empty()) {
73 if (ci.mathfeature()) {
74 string feats = mathpreamble;
75 while (!feats.empty()) {
77 feats = split(feats, feat, ',');
78 features.require(feat);
81 features.addPreambleSnippet(from_utf8(mathpreamble));
84 // with utf8-plain, we do not load packages (see #7766)
85 if (use_text && !plain_utf8) {
86 string const textpreamble = ci.textpreamble();
87 if (!textpreamble.empty()) {
88 if (ci.textfeature()) {
89 string feats = textpreamble;
90 while (!feats.empty()) {
92 feats = split(feats, feat, ',');
93 // context-dependent features are handled
94 // in Paragraph::Private::validate()
95 if (!contains(feat, '='))
96 features.require(feat);
99 features.addPreambleSnippet(from_utf8(textpreamble));
103 if (for_mathed && isMathSym(c)) {
104 features.require("amstext");
105 features.require("lyxmathsym");