- tex2lyx: support for the polyglossia language variants

- XeTeX-polyglossia.tex: simplifications, added some more testcases
This commit is contained in:
Uwe Stöhr 2012-06-23 04:28:52 +02:00
parent 121b32bcbc
commit 828f7171e8
4 changed files with 111 additions and 47 deletions

View File

@ -92,6 +92,41 @@ const char * const known_coded_languages[] = {"french", "afrikaans", "albanian",
"uppersorbian", "uppersorbian", "english", "english", "vietnamese", "welsh",
0};
/**
* known polyglossia language names (including variants)
*/
const char * const polyglossia_languages[] = {
"albanian", "croatian", "hebrew", "norsk", "swedish", "amharic", "czech", "hindi",
"nynorsk", "syriac", "arabic", "danish", "icelandic", "occitan", "tamil",
"armenian", "divehi", "interlingua", "polish", "telugu", "asturian", "dutch",
"irish", "portuges", "thai", "bahasai", "english", "italian", "romanian", "turkish",
"bahasam", "esperanto", "lao", "russian", "turkmen", "basque", "estonian", "latin",
"samin", "ukrainian", "bengali", "farsi", "latvian", "sanskrit", "urdu", "brazil",
"brazilian", "finnish", "lithuanian", "scottish", "usorbian", "breton", "french",
"lsorbian", "serbian", "vietnamese", "bulgarian", "galician", "magyar", "slovak",
"welsh", "catalan", "german", "malayalam", "slovenian", "coptic", "greek",
"marathi", "spanish",
"american", "ancient", "australian", "british", "monotonic", "newzealand",
"polytonic", 0};
/**
* the same as polyglossia_languages with .lyx names
* please keep this in sync with polyglossia_languages line by line!
*/
const char * const coded_polyglossia_languages[] = {
"albanian", "croatian", "hebrew", "norsk", "swedish", "amharic", "czech", "hindi",
"nynorsk", "syriac", "arabic_arabi", "danish", "icelandic", "occitan", "tamil",
"armenian", "divehi", "interlingua", "polish", "telugu", "asturian", "dutch",
"irish", "portuges", "thai", "bahasa", "english", "italian", "romanian", "turkish",
"bahasam", "esperanto", "lao", "russian", "turkmen", "basque", "estonian", "latin",
"samin", "ukrainian", "bengali", "farsi", "latvian", "sanskrit", "urdu", "brazilian",
"brazilian", "finnish", "lithuanian", "scottish", "uppersorbian", "breton", "french",
"lowersorbian", "serbian", "vietnamese", "bulgarian", "galician", "magyar", "slovak",
"welsh", "catalan", "ngerman", "malayalam", "slovene", "coptic", "greek",
"marathi", "spanish",
"american", "ancientgreek", "australian", "british", "greek", "newzealand",
"polutonikogreek", 0};
/// languages with english quotes (.lyx names)
const char * const known_english_quotes_languages[] = {"american", "australian",
"bahasa", "bahasam", "brazilian", "canadian", "chinese-simplified", "english",
@ -686,6 +721,8 @@ void Preamble::handle_package(Parser &p, string const & name,
// reasons for it.
h_preamble << "\\usepackage[" << opts << "]{babel}\n";
delete_opt(options, known_languages);
// finally translate the babel name to a LyX name
h_language = babel2lyx(h_language);
}
else
h_preamble << "\\usepackage{babel}\n";
@ -824,9 +861,6 @@ void Preamble::handle_if(Parser & p, bool in_lyx_preamble)
bool Preamble::writeLyXHeader(ostream & os, bool subdoc)
{
// translate from babel to LyX names
h_language = babel2lyx(h_language);
// set the quote language
// LyX only knows the following quotes languages:
// english, swedish, german, polish, french and danish
@ -1073,14 +1107,31 @@ void Preamble::parse(Parser & p, string const & forceclass,
h_paperpagestyle = p.verbatim_item();
else if (t.cs() == "setdefaultlanguage") {
// FIXME: we don't yet care about the option because LyX doesn't
// support this yet, see bug #8214
p.hasOpt() ? p.getOpt() : string();
xetex = true;
// We don't yet care about non-language variant options
// because LyX doesn't support this yet, see bug #8214
if (p.hasOpt()) {
string langopts = p.getOpt();
// check if the option contains a variant, if yes, extract it
string::size_type pos_var = langopts.find("variant");
string::size_type i = langopts.find(',', pos_var);
if (pos_var != string::npos){
string variant;
if (i == string::npos)
variant = langopts.substr(pos_var + 8, langopts.length() - pos_var - 9);
else
variant = langopts.substr(pos_var + 8, i - pos_var - 8);
h_language = variant;
}
p.verbatim_item();
} else
h_language = p.verbatim_item();
//finally translate the poyglossia name to a LyX name
h_language = polyglossia2lyx(h_language);
}
else if (t.cs() == "setotherlanguage") {
// FIXME: we don't yet care about the option because LyX doesn't
// We don't yet care about the option because LyX doesn't
// support this yet, see bug #8214
p.hasOpt() ? p.getOpt() : string();
p.verbatim_item();
@ -1525,6 +1576,15 @@ string babel2lyx(string const & language)
}
string polyglossia2lyx(string const & language)
{
char const * const * where = is_known(language, polyglossia_languages);
if (where)
return coded_polyglossia_languages[where - polyglossia_languages];
return language;
}
string rgbcolor2code(string const & name)
{
char const * const * where = is_known(name, known_basic_colors);

View File

@ -1,20 +1,20 @@
\documentclass[albanian]{article}
\documentclass{article}
\usepackage{fontspec}
\setmainfont[Mapping=tex-text]{Aharoni}
\setmainfont{Aharoni}
\setsansfont[Mapping=tex-text]{AngsanaUPC}
\setmonofont{Arial Black}
\usepackage{xunicode}
\usepackage{polyglossia}
\setdefaultlanguage{coptic}
\setdefaultlanguage[variant=british, ordinalmonthday = false]{english}
\setotherlanguage{albanian}
\setotherlanguage{divehi}
\setotherlanguage[variant=monotonic]{greek}
\setotherlanguage[variant=polytonic]{greek}
\setotherlanguage{syriac}
\begin{document}
\part{df}
1 Coptic \textgreek[variant=ancient]{ancient Greek} Coptic
1 English \textgreek[variant=ancient]{ancient Greek} English
\textgreek[numerals=arabic, variant=ancient]{ancient Greek with Arabic numerals} English
\begin{albanian}%
@ -23,26 +23,13 @@
2 Albanian \textgreek{Greek} Albanian \textsc{smallcaps}
\end{albanian}%
\begin{divehi}%
\part{df}
3
\end{divehi}%
\begin{syriac}%
\part{df}
4
3 Syriac
\end{syriac}%
\begin{divehi}%
\part{df}
5
\end{divehi}%
%empty language paragraph
\begin{albanian}%

View File

@ -45,6 +45,8 @@ public:
/// Translate babel language name to LyX language name
extern std::string babel2lyx(std::string const & language);
/// Translate polyglossia language name to LyX language name
extern std::string polyglossia2lyx(std::string const & language);
/// Translate basic color name or RGB color in LaTeX syntax to LyX color code
extern std::string rgbcolor2code(std::string const & name);

View File

@ -118,7 +118,7 @@ char const * const known_coded_ref_commands[] = { "ref", "pageref", "vref",
"vpageref", "formatted", "eqref", 0 };
/**
* known polyglossia language names (inluding synomyms)
* known polyglossia language names (including variants)
*/
const char * const polyglossia_languages[] = {
"albanian", "croatian", "hebrew", "norsk", "swedish", "amharic", "czech", "hindi",
@ -130,7 +130,9 @@ const char * const polyglossia_languages[] = {
"brazilian", "finnish", "lithuanian", "scottish", "usorbian", "breton", "french",
"lsorbian", "serbian", "vietnamese", "bulgarian", "galician", "magyar", "slovak",
"welsh", "catalan", "german", "malayalam", "slovenian", "coptic", "greek",
"marathi", "spanish", 0};
"marathi", "spanish"
"american", "ancient", "australian", "british", "monotonic", "newzealand",
"polytonic", 0};
/**
* the same as polyglossia_languages with .lyx names
@ -146,15 +148,9 @@ const char * const coded_polyglossia_languages[] = {
"brazilian", "finnish", "lithuanian", "scottish", "uppersorbian", "breton", "french",
"lowersorbian", "serbian", "vietnamese", "bulgarian", "galician", "magyar", "slovak",
"welsh", "catalan", "ngerman", "malayalam", "slovene", "coptic", "greek",
"marathi", "spanish", 0};
string polyglossia2lyx(string const & language)
{
char const * const * where = is_known(language, polyglossia_languages);
if (where)
return coded_polyglossia_languages[where - polyglossia_languages];
return language;
}
"marathi", "spanish"
"american", "ancientgreek", "australian", "british", "greek", "newzealand",
"polutonikogreek", 0};
/*!
* natbib commands.
@ -3470,16 +3466,35 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
else if (is_known(t.cs().substr(4, string::npos), polyglossia_languages)) {
// scheme is \textLANGUAGE{text} where LANGUAGE is in polyglossia_languages[]
string const lang = polyglossia2lyx(t.cs().substr(4, string::npos));
// FIXME: we have to output the whole command if it has an option
// because lyX doesn't support this yet, see bug #8214
if (p.hasOpt())
handle_ert(os, t.asInput() + p.getOpt(), context);
else
string lang;
// We have to output the whole command if it has an option
// because LyX doesn't support this yet, see bug #8214,
// only if there is a single option specifying a variant, we can handle it.
if (p.hasOpt()) {
string langopts = p.getOpt();
// check if the option contains a variant, if yes, extract it
string::size_type pos_var = langopts.find("variant");
string::size_type i = langopts.find(',');
if (pos_var != string::npos){
string variant;
if (i == string::npos) {
variant = langopts.substr(pos_var + 8, langopts.length() - pos_var - 9);
lang = polyglossia2lyx(variant);
parse_text_attributes(p, os, FLAG_ITEM, outer,
context, "\\lang",
context.font.language, lang);
}
else
handle_ert(os, t.asInput() + langopts, context);
} else
handle_ert(os, t.asInput() + langopts, context);
} else {
lang = polyglossia2lyx(t.cs().substr(4, string::npos));
parse_text_attributes(p, os, FLAG_ITEM, outer,
context, "\\lang",
context.font.language, lang);
}
}
else if (t.cs() == "inputencoding") {
// nothing to write here