From ab4bd6b77ebb6163b57254653dd5ab6c27006e94 Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Sat, 21 Apr 2018 15:00:42 +0200 Subject: [PATCH] Define \textgreek only if needed Babel provides a definition if a Greek language is loaded. Also, clarify some FIXMEs --- src/LaTeXFeatures.cpp | 45 +++++++++++++++++++++++++++++++------------ src/LaTeXFeatures.h | 3 ++- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp index dddfc2e666..204c3ec4cc 100644 --- a/src/LaTeXFeatures.cpp +++ b/src/LaTeXFeatures.cpp @@ -609,6 +609,28 @@ bool LaTeXFeatures::isRequired(string const & name) const bool LaTeXFeatures::isProvided(string const & name) const { + // \textgreek is provided by babel globally if a Greek language/variety + // is used in the document + if (useBabel() && name == "textgreek" + && params_.main_font_encoding() != "default") { + // get main font encodings + vector fontencs = params_.font_encodings(); + // get font encodings of secondary languages + getFontEncodings(fontencs, true); + for (auto & fe : fontencs) { + if (!Encodings::needsScriptWrapper(name, fe)) + return true; + } + } + // FIXME: Analoguously, babel provides a command \textcyrillic, but + // for some reason, we roll our own \textcyr definition + // We should use \textcyrillic instead and only define it + // if we do not use a respective language that features it (i.e., + // add "textcyrillic" to the test above. + // FIXME: the "textbaltic" definitions are only needed if the context + // font-encoding where the respective char is is not l7x. + // We cannot check this here as we have no context information. + if (params_.useNonTeXFonts) return params_.documentClass().provides(name); @@ -634,9 +656,6 @@ bool LaTeXFeatures::isProvided(string const & name) const from_ascii(params_.fontsMath())).provides(name, ot1, complete, nomath); - // TODO: "textbaltic" provided, if the font-encoding is "L7x" - // "textgreek" provided, if a language with font-encoding LGR is used in the document - // "textcyr" provided, if a language with font-encoding T2A is used in the document } @@ -880,16 +899,18 @@ set LaTeXFeatures::getEncodingSet(string const & doc_encoding) const } -void LaTeXFeatures::getFontEncodings(vector & encs) const +void LaTeXFeatures::getFontEncodings(vector & encs, bool const onlylangs) const { - // these must be loaded if glyphs of this script are used - // unless a language providing them is used in the document - if (mustProvide("textgreek") - && find(encs.begin(), encs.end(), "LGR") == encs.end()) - encs.insert(encs.begin(), "LGR"); - if (mustProvide("textcyr") - && find(encs.begin(), encs.end(), "T2A") == encs.end()) - encs.insert(encs.begin(), "T2A"); + if (!onlylangs) { + // these must be loaded if glyphs of this script are used + // unless a language providing them is used in the document + if (mustProvide("textgreek") + && find(encs.begin(), encs.end(), "LGR") == encs.end()) + encs.insert(encs.begin(), "LGR"); + if (mustProvide("textcyr") + && find(encs.begin(), encs.end(), "T2A") == encs.end()) + encs.insert(encs.begin(), "T2A"); + } for (auto const & lang : UsedLanguages_) if (!lang->fontenc().empty() diff --git a/src/LaTeXFeatures.h b/src/LaTeXFeatures.h index 72451ad8ee..29d0b369fd 100644 --- a/src/LaTeXFeatures.h +++ b/src/LaTeXFeatures.h @@ -136,7 +136,8 @@ public: /// std::set getEncodingSet(std::string const & doc_encoding) const; /// - void getFontEncodings(std::vector & encodings) const; + void getFontEncodings(std::vector & encodings, + bool const onlylangs = false) const; /// void useLayout(docstring const & lyt); ///