commit 71f0dd3a7ff4c25e1339ed493605e88b25f2779a
Author: Juergen Spitzmueller <[email protected]>
Date: Sat Apr 21 15:47:39 2018 +0200
Add Provides tag to languages
This allows to specify macros that are provided by specific (Babel)
languages (such as \textgreek)
---
lib/languages | 4 ++++
src/LaTeXFeatures.cpp | 27 ++++++++++++++-------------
src/LaTeXFeatures.h | 8 ++++++--
src/Language.cpp | 7 ++++++-
src/Language.h | 4 ++++
5 files changed, 34 insertions(+), 16 deletions(-)
diff --git a/lib/languages b/lib/languages
index 4c3b49b..909043d 100644
--- a/lib/languages
+++ b/lib/languages
@@ -26,6 +26,7 @@
# <extra latex code inserted after babel>
# EndPostBabelPreamble
# Requires <requirement>
+# Provides <feature>
# End
#
#
@@ -167,6 +168,7 @@ Language ancientgreek
InternalEncoding true
FontEncoding LGR
LangCode grc_GR
+ Provides textgreek
End
# FIXME: dummy babel language for arabic_arabtex to be able
@@ -618,6 +620,7 @@ Language greek
InternalEncoding true
FontEncoding LGR
LangCode el_GR
+ Provides textgreek
End
Language polutonikogreek
@@ -630,6 +633,7 @@ Language polutonikogreek
InternalEncoding true
FontEncoding LGR
LangCode el_GR
+ Provides textgreek
End
Language hebrew
diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp
index 204c3ec..3627cc6 100644
--- a/src/LaTeXFeatures.cpp
+++ b/src/LaTeXFeatures.cpp
@@ -544,6 +544,12 @@ void LaTeXFeatures::require(set<string> const & names)
}
+void LaTeXFeatures::provide(string const & name)
+{
+ provides_.insert(name);
+}
+
+
void LaTeXFeatures::useLayout(docstring const & layoutname)
{
useLayout(layoutname, 0);
@@ -609,19 +615,11 @@ 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<string> fontencs = params_.font_encodings();
- // get font encodings of secondary languages
- getFontEncodings(fontencs, true);
- for (auto & fe : fontencs) {
- if (!Encodings::needsScriptWrapper(name, fe))
- return true;
- }
- }
+ // \textgreek is provided by babel globally if a Greek
+ // language/variety is used in the document
+ if (provides_.find(name) != provides_.end())
+ 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
@@ -756,6 +754,9 @@ void LaTeXFeatures::useLanguage(Language const * lang)
UsedLanguages_.insert(lang);
if (!lang->requires().empty())
require(lang->requires());
+ // currently only supported for Babel
+ if (!lang->provides().empty() && useBabel())
+ provide(lang->provides());
// CJK languages do not have a babel name.
// They use the CJK package
if (lang->encoding()->package() == Encoding::CJK)
diff --git a/src/LaTeXFeatures.h b/src/LaTeXFeatures.h
index 29d0b36..32a6242 100644
--- a/src/LaTeXFeatures.h
+++ b/src/LaTeXFeatures.h
@@ -103,6 +103,8 @@ public:
void require(std::string const & name);
/// Add a set of feature names requirements
void require(std::set<std::string> const & names);
+ /// Add a feature name provision
+ void provide(std::string const & name);
/// Is the (required) package available?
static bool isAvailable(std::string const & name);
/// Has the package been required?
@@ -186,10 +188,12 @@ private:
std::list<docstring> usedLayouts_;
///
std::list<docstring> usedInsetLayouts_;
- /// The features that are needed by the document
- typedef std::set<std::string> Features;
///
+ typedef std::set<std::string> Features;
+ /// The features that are needed by the document
Features features_;
+ /// Features that are provided
+ Features provides_;
/// Static preamble bits, from external templates, or anywhere else
typedef std::list<TexString> SnippetList;
///
diff --git a/src/Language.cpp b/src/Language.cpp
index 31212cb..3061df3 100644
--- a/src/Language.cpp
+++ b/src/Language.cpp
@@ -87,9 +87,10 @@ bool Language::readLanguage(Lexer & lex)
LA_POLYGLOSSIANAME,
LA_POLYGLOSSIAOPTS,
LA_POSTBABELPREAMBLE,
- LA_QUOTESTYLE,
LA_PREBABELPREAMBLE,
+ LA_PROVIDES,
LA_REQUIRES,
+ LA_QUOTESTYLE,
LA_RTL
};
@@ -109,6 +110,7 @@ bool Language::readLanguage(Lexer & lex)
{ "polyglossiaopts", LA_POLYGLOSSIAOPTS },
{ "postbabelpreamble", LA_POSTBABELPREAMBLE },
{ "prebabelpreamble", LA_PREBABELPREAMBLE },
+ { "provides", LA_PROVIDES },
{ "quotestyle", LA_QUOTESTYLE },
{ "requires", LA_REQUIRES },
{ "rtl", LA_RTL }
@@ -184,6 +186,9 @@ bool Language::readLanguage(Lexer & lex)
case LA_REQUIRES:
lex >> requires_;
break;
+ case LA_PROVIDES:
+ lex >> provides_;
+ break;
case LA_RTL:
lex >> rightToLeft_;
break;
diff --git a/src/Language.h b/src/Language.h
index 594a324..ddcc328 100644
--- a/src/Language.h
+++ b/src/Language.h
@@ -50,6 +50,8 @@ public:
std::string const quoteStyle() const { return quote_style_; }
/// requirement (package, function)
std::string const requires() const { return requires_; }
+ /// provides feature
+ std::string const provides() const { return provides_; }
/// translatable GUI name
std::string const display() const { return display_; }
/// is this a RTL language?
@@ -109,6 +111,8 @@ private:
///
trivstring requires_;
///
+ trivstring provides_;
+ ///
trivstring display_;
///
bool rightToLeft_;