mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
make i18npreamble work with polyglossia.
We might want to rename the babelpreamble tokens to something more general. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36773 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
3370b1d2fa
commit
089927dd6f
@ -1881,8 +1881,34 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features,
|
||||
lyxpreamble += from_utf8(features.getBabelPostsettings());
|
||||
}
|
||||
|
||||
// FIXME Polyglossia?
|
||||
docstring const i18npreamble = features.getTClassI18nPreamble(use_babel);
|
||||
// xunicode needs to be loaded at least after amsmath, amssymb,
|
||||
// esint and the other packages that provide special glyphs
|
||||
if (features.runparams().flavor == OutputParams::XETEX)
|
||||
lyxpreamble += "\\usepackage{xunicode}\n";
|
||||
|
||||
// Polyglossia must be loaded last
|
||||
if (use_polyglossia) {
|
||||
// call the package
|
||||
lyxpreamble += "\\usepackage{polyglossia}\n";
|
||||
// set the main language
|
||||
lyxpreamble += "\\setdefaultlanguage";
|
||||
if (!language->polyglossiaOpts().empty())
|
||||
lyxpreamble += "[" + from_ascii(language->polyglossiaOpts()) + "]";
|
||||
lyxpreamble += "{" + from_ascii(language->polyglossia()) + "}\n";
|
||||
// now setup the other languages
|
||||
std::map<std::string, std::string> const polylangs =
|
||||
features.getPolyglossiaLanguages();
|
||||
for (std::map<std::string, std::string>::const_iterator mit = polylangs.begin();
|
||||
mit != polylangs.end() ; ++mit) {
|
||||
lyxpreamble += "\\setotherlanguage";
|
||||
if (!mit->second.empty())
|
||||
lyxpreamble += "[" + from_ascii(mit->second) + "]";
|
||||
lyxpreamble += "{" + from_ascii(mit->first) + "}\n";
|
||||
}
|
||||
}
|
||||
|
||||
docstring const i18npreamble =
|
||||
features.getTClassI18nPreamble(use_babel, use_polyglossia);
|
||||
if (!i18npreamble.empty())
|
||||
lyxpreamble += i18npreamble + '\n';
|
||||
|
||||
@ -1892,35 +1918,6 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features,
|
||||
|
||||
os << lyxpreamble;
|
||||
|
||||
// xunicode needs to be loaded at least after amsmath, amssymb,
|
||||
// esint and the other packages that provide special glyphs
|
||||
if (features.runparams().flavor == OutputParams::XETEX) {
|
||||
os << "\\usepackage{xunicode}\n";
|
||||
texrow.newline();
|
||||
}
|
||||
// Polyglossia must be loaded last
|
||||
if (use_polyglossia) {
|
||||
// call the package
|
||||
os << "\\usepackage{polyglossia}\n";
|
||||
texrow.newline();
|
||||
// set the main language
|
||||
os << "\\setdefaultlanguage";
|
||||
if (!language->polyglossiaOpts().empty())
|
||||
os << "[" << from_ascii(language->polyglossiaOpts()) << "]";
|
||||
os << "{" + from_ascii(language->polyglossia()) + "}\n";
|
||||
texrow.newline();
|
||||
// now setup the other languages
|
||||
std::map<std::string, std::string> const polylangs =
|
||||
features.getPolyglossiaLanguages();
|
||||
for (std::map<std::string, std::string>::const_iterator mit = polylangs.begin();
|
||||
mit != polylangs.end() ; ++mit) {
|
||||
os << "\\setotherlanguage";
|
||||
if (!mit->second.empty())
|
||||
os << "[" << from_ascii(mit->second) << "]";
|
||||
os << "{" << from_ascii(mit->first) << "}\n";
|
||||
texrow.newline();
|
||||
}
|
||||
}
|
||||
return use_babel;
|
||||
}
|
||||
|
||||
|
@ -1126,7 +1126,7 @@ docstring const getFloatI18nPreamble(docstring const & type, docstring const & n
|
||||
}
|
||||
|
||||
|
||||
docstring const LaTeXFeatures::getTClassI18nPreamble(bool use_babel) const
|
||||
docstring const LaTeXFeatures::getTClassI18nPreamble(bool use_babel, bool use_polyglossia) const
|
||||
{
|
||||
DocumentClass const & tclass = params_.documentClass();
|
||||
// collect preamble snippets in a set to prevent multiple identical
|
||||
@ -1139,15 +1139,17 @@ docstring const LaTeXFeatures::getTClassI18nPreamble(bool use_babel) const
|
||||
list<docstring>::const_iterator end = usedLayouts_.end();
|
||||
for (; cit != end; ++cit) {
|
||||
// language dependent commands (once per document)
|
||||
snippets.insert(tclass[*cit].langpreamble(buffer().language()));
|
||||
snippets.insert(tclass[*cit].langpreamble(buffer().language(),
|
||||
use_polyglossia));
|
||||
// commands for language changing (for multilanguage documents)
|
||||
if (use_babel && !UsedLanguages_.empty()) {
|
||||
snippets.insert(tclass[*cit].babelpreamble(buffer().language()));
|
||||
if ((use_babel || use_polyglossia) && !UsedLanguages_.empty()) {
|
||||
snippets.insert(tclass[*cit].babelpreamble(buffer().language(),
|
||||
use_polyglossia));
|
||||
for (lang_it lit = lbeg; lit != lend; ++lit)
|
||||
snippets.insert(tclass[*cit].babelpreamble(*lit));
|
||||
snippets.insert(tclass[*cit].babelpreamble(*lit, use_polyglossia));
|
||||
}
|
||||
}
|
||||
if (use_babel && !UsedLanguages_.empty()) {
|
||||
if ((use_babel || use_polyglossia) && !UsedLanguages_.empty()) {
|
||||
FloatList const & floats = params_.documentClass().floats();
|
||||
UsedFloats::const_iterator fit = usedFloats_.begin();
|
||||
UsedFloats::const_iterator fend = usedFloats_.end();
|
||||
@ -1157,15 +1159,25 @@ docstring const LaTeXFeatures::getTClassI18nPreamble(bool use_babel) const
|
||||
docstring const flname = from_utf8(fl.name());
|
||||
docstring name = translateIfPossible(flname,
|
||||
buffer().language()->code());
|
||||
snippets.insert(getFloatI18nPreamble(
|
||||
type, name,
|
||||
from_ascii(buffer().language()->babel())));
|
||||
if (use_polyglossia)
|
||||
snippets.insert(getFloatI18nPreamble(
|
||||
type, name,
|
||||
from_ascii(buffer().language()->polyglossia())));
|
||||
else
|
||||
snippets.insert(getFloatI18nPreamble(
|
||||
type, name,
|
||||
from_ascii(buffer().language()->babel())));
|
||||
for (lang_it lit = lbeg; lit != lend; ++lit) {
|
||||
name = translateIfPossible(flname,
|
||||
(*lit)->code());
|
||||
snippets.insert(getFloatI18nPreamble(
|
||||
type, name,
|
||||
from_ascii((*lit)->babel())));
|
||||
if (use_polyglossia)
|
||||
snippets.insert(getFloatI18nPreamble(
|
||||
type, name,
|
||||
from_ascii((*lit)->polyglossia())));
|
||||
else
|
||||
snippets.insert(getFloatI18nPreamble(
|
||||
type, name,
|
||||
from_ascii((*lit)->babel())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ public:
|
||||
/// The definitions needed by the document's textclass
|
||||
docstring const getTClassPreamble() const;
|
||||
/// The language dependent definitions needed by the document's textclass
|
||||
docstring const getTClassI18nPreamble(bool use_babel) const;
|
||||
docstring const getTClassI18nPreamble(bool use_babel, bool use_polyglossia) const;
|
||||
///
|
||||
docstring const getTClassHTMLStyles() const;
|
||||
///
|
||||
|
@ -877,12 +877,14 @@ void Layout::readSpacing(Lexer & lex)
|
||||
|
||||
namespace {
|
||||
|
||||
docstring const i18npreamble(Language const * lang, docstring const & templ)
|
||||
docstring const i18npreamble(Language const * lang, docstring const & templ, bool const polyglossia)
|
||||
{
|
||||
if (templ.empty())
|
||||
return templ;
|
||||
|
||||
string preamble = subst(to_utf8(templ), "$$lang", lang->babel());
|
||||
string preamble = polyglossia ?
|
||||
subst(to_utf8(templ), "$$lang", lang->polyglossia()) :
|
||||
subst(to_utf8(templ), "$$lang", lang->babel());
|
||||
|
||||
#ifdef TEX2LYX
|
||||
// tex2lyx does not have getMessages()
|
||||
@ -912,15 +914,15 @@ docstring const i18npreamble(Language const * lang, docstring const & templ)
|
||||
}
|
||||
|
||||
|
||||
docstring const Layout::langpreamble(Language const * lang) const
|
||||
docstring const Layout::langpreamble(Language const * lang, bool const polyglossia) const
|
||||
{
|
||||
return i18npreamble(lang, langpreamble_);
|
||||
return i18npreamble(lang, langpreamble_, polyglossia);
|
||||
}
|
||||
|
||||
|
||||
docstring const Layout::babelpreamble(Language const * lang) const
|
||||
docstring const Layout::babelpreamble(Language const * lang, bool const polyglossia) const
|
||||
{
|
||||
return i18npreamble(lang, babelpreamble_);
|
||||
return i18npreamble(lang, babelpreamble_, polyglossia);
|
||||
}
|
||||
|
||||
|
||||
|
@ -95,10 +95,10 @@ public:
|
||||
docstring const & preamble() const { return preamble_; }
|
||||
/// Get language dependent macro definitions needed for this layout
|
||||
/// for language \p lang
|
||||
docstring const langpreamble(Language const * lang) const;
|
||||
docstring const langpreamble(Language const * lang, bool const polyglossia) const;
|
||||
/// Get language and babel dependent macro definitions needed for
|
||||
/// this layout for language \p lang
|
||||
docstring const babelpreamble(Language const * lang) const;
|
||||
docstring const babelpreamble(Language const * lang, bool const polyglossia) const;
|
||||
///
|
||||
std::set<std::string> const & requires() const { return requires_; }
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user