The branch, 2.0.x, has been updated.

- Log -----------------------------------------------------------------

commit 90d8f3adcbdf4509c7b862d34b71302c21ea56c4
Author: Uwe Stöhr <uwesto...@lyx.org>
Date:   Sat Jun 30 02:18:18 2012 +0200

    polyglossia tex2lyx support also for branch

diff --git a/src/tex2lyx/Preamble.cpp b/src/tex2lyx/Preamble.cpp
index 8d2a111..6c3e284 100644
--- a/src/tex2lyx/Preamble.cpp
+++ b/src/tex2lyx/Preamble.cpp
@@ -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", "bahasa",
 "bahasam", "brazilian", "canadian", "chinese-simplified", "english",
@@ -166,8 +201,9 @@ const char * const known_if_3arg_commands[] = 
{"@ifundefined", "IfFileExists",
 0};
 
 /// packages that work only in xetex
+/// polyglossia is handled separately
 const char * const known_xetex_packages[] = {"arabxetex", "fixlatvian",
-"fontbook", "fontwrap", "mathspec", "philokalia", "polyglossia", "unisugar",
+"fontbook", "fontwrap", "mathspec", "philokalia", "unisugar",
 "xeCJK", "xecolor", "xecyr", "xeindex", "xepersian", "xunicode", 0};
 
 // codes used to remove packages that are loaded automatically by LyX.
@@ -407,6 +443,7 @@ Preamble::Preamble() : one_language(true), 
title_layout_found(false)
        h_font_sf_scale           = "100";
        h_font_tt_scale           = "100";
        h_graphics                = "default";
+       h_default_output_format   = "default";
        h_html_be_strict          = "false";
        h_html_css_as_file        = "0";
        h_html_math_output        = "0";
@@ -585,6 +622,7 @@ void Preamble::handle_package(Parser &p, string const & 
name,
        if (is_known(name, known_xetex_packages)) {
                xetex = true;
                h_use_non_tex_fonts = "true";
+               registerAutomaticallyLoadedPackage("fontspec");
                if (h_inputencoding == "auto")
                        p.setEncoding("utf8");
        }
@@ -675,11 +713,23 @@ 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";
        }
 
+       else if (name == "polyglossia") {
+               h_language_package = "default";
+               h_default_output_format = "pdf4";
+               h_use_non_tex_fonts = "true";
+               xetex = true;
+               registerAutomaticallyLoadedPackage("xunicode");
+               if (h_inputencoding == "auto")
+                       p.setEncoding("utf8");
+       }
+
        else if (name == "fontenc") {
                h_fontencoding = getStringFromVector(options, ",");
                /* We could do the following for better round trip support,
@@ -734,10 +784,10 @@ void Preamble::handle_package(Parser &p, string const & 
name,
 
        else if (name == "array" || name == "booktabs" || name == "calc" ||
                     name == "color" || name == "hhline" || name == "ifthen" ||
-                    name == "float" || name == "longtable" || name == 
"makeidx" ||
-                    name == "multirow" || name == "nomencl" || name == 
"setspace" ||
-                    name == "splitidx" || name == "subscript" || name == 
"ulem" ||
-                    name == "url") {
+                    name == "float" || name == "fontspec" || name == 
"longtable" ||
+                        name == "makeidx" || name == "multirow" || name == 
"nomencl" ||
+                        name == "setspace" || name == "splitidx" || name == 
"subscript" ||
+                        name == "ulem" || name == "url" || name == "xunicode") 
{
                if (name == "splitidx")
                        h_use_indices = "true";
                if (!in_lyx_preamble)
@@ -824,9 +874,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
@@ -913,7 +960,8 @@ bool Preamble::writeLyXHeader(ostream & os, bool subdoc)
           << "\\font_osf " << h_font_osf << "\n"
           << "\\font_sf_scale " << h_font_sf_scale << "\n"
           << "\\font_tt_scale " << h_font_tt_scale << "\n"
-          << "\\graphics " << h_graphics << "\n";
+          << "\\graphics " << h_graphics << "\n"
+          << "\\default_output_format " << h_default_output_format << "\n";
        if (!h_float_placement.empty())
                os << "\\float_placement " << h_float_placement << "\n";
        os << "\\paperfontsize " << h_paperfontsize << "\n"
@@ -1064,6 +1112,70 @@ void Preamble::parse(Parser & p, string const & 
forceclass,
                else if (t.cs() == "pagestyle")
                        h_paperpagestyle = p.verbatim_item();
 
+               else if (t.cs() == "setdefaultlanguage") {
+                       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);
+                               string::size_type k = langopts.find('=', 
pos_var);
+                               if (pos_var != string::npos){
+                                       string variant;
+                                       if (i == string::npos)
+                                               variant = langopts.substr(k + 
1, langopts.length() - k - 2);
+                                       else
+                                               variant = langopts.substr(k + 
1, i - k - 1);
+                                       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") {
+                       // 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();
+               }
+
+               else if (t.cs() == "setmainfont") {
+                       // we don't care about the option
+                       p.hasOpt() ? p.getOpt() : string();
+                       h_font_roman = p.getArg('{', '}');
+               }
+
+               else if (t.cs() == "setsansfont" || t.cs() == "setmonofont") {
+                       // LyX currently only supports the scale option
+                       string scale;
+                       if (p.hasOpt()) {
+                               string fontopts = p.getArg('[', ']');
+                               // check if the option contains a scaling, if 
yes, extract it
+                               string::size_type pos = fontopts.find("Scale");
+                               if (pos != string::npos) {
+                                       string::size_type i = 
fontopts.find(',', pos);
+                                       if (i == string::npos)
+                                               scale = 
scale_as_percentage(fontopts.substr(pos + 1));
+                                       else
+                                               scale = 
scale_as_percentage(fontopts.substr(pos, i - pos));
+                               }
+                       }
+                       if (t.cs() == "setsansfont") {
+                               if (!scale.empty())
+                                       h_font_sf_scale = scale;
+                               h_font_sans = p.getArg('{', '}');
+                       } else {
+                               if (!scale.empty())
+                                       h_font_tt_scale = scale;
+                               h_font_typewriter = p.getArg('{', '}');
+                       }
+               }
+
                else if (t.cs() == "date") {
                        string argument = p.getArg('{', '}');
                        if (argument.empty())
@@ -1479,6 +1591,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);
diff --git a/src/tex2lyx/Preamble.h b/src/tex2lyx/Preamble.h
index c116250..9b15a3f 100644
--- a/src/tex2lyx/Preamble.h
+++ b/src/tex2lyx/Preamble.h
@@ -103,6 +103,7 @@ private:
        std::string h_font_sf_scale;
        std::string h_font_tt_scale;
        std::string h_graphics;
+       std::string h_default_output_format;
        std::string h_html_be_strict;
        std::string h_html_css_as_file;
        std::string h_html_math_output;
diff --git a/src/tex2lyx/test/XeTeX-polyglossia.tex 
b/src/tex2lyx/test/XeTeX-polyglossia.tex
index a17af3d..95c4c82 100644
--- a/src/tex2lyx/test/XeTeX-polyglossia.tex
+++ b/src/tex2lyx/test/XeTeX-polyglossia.tex
@@ -1,20 +1,20 @@
 \documentclass{article}
 \usepackage{fontspec}
-\setmainfont{Aharoni}
-\setsansfont[Mapping=tex-text]{AngsanaUPC}
-\setmonofont{Arial Black}
+\setmainfont[Mapping=tex-text]{Linux Libertine O}
+\setsansfont[Mapping=tex-text,Scale=0.75]{Linux Biolinum O}
+\setmonofont{Linux Biolinum O}
 \usepackage{xunicode}
 \usepackage{polyglossia}
 \setdefaultlanguage[variant=british, ordinalmonthday = false]{english}
 \setotherlanguage{albanian}
 \setotherlanguage[variant=polytonic]{greek}
-\setotherlanguage{german}
+\setotherlanguage{syriac}
 \begin{document}
 
 \part{df}
 
 1 English \textgreek[variant=ancient]{ancient Greek} English
-\textgreek[numerals=arabic, variant=ancient]{ancient Greek with Arabic 
numerals} English
+\textgreek[numerals=arabic, variant=ancient]{ancient G\textsf{reek} with 
Arabic numerals} English
 
 \begin{albanian}%
 
@@ -23,13 +23,13 @@
 2 Albanian \textgreek{Greek} Albanian \textsc{smallcaps}
 
 \end{albanian}%
-\begin{german}%
+\begin{hebrew}%
 
 \part{df}
 
-3 German
+3 Hebrew
 
-\end{german}%
+\end{hebrew}%
 
 %empty language paragraph
 \begin{albanian}%
diff --git a/src/tex2lyx/tex2lyx.h b/src/tex2lyx/tex2lyx.h
index 730013c..4aa5db3 100644
--- a/src/tex2lyx/tex2lyx.h
+++ b/src/tex2lyx/tex2lyx.h
@@ -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);
 
diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp
index 3200845..2543b47 100644
--- a/src/tex2lyx/text.cpp
+++ b/src/tex2lyx/text.cpp
@@ -1189,6 +1189,23 @@ void parse_environment(Parser & p, ostream & os, bool 
outer,
                }
        }
 
+       else if (is_known(name, polyglossia_languages)) {
+               // We must begin a new paragraph if not already done
+               if (! parent_context.atParagraphStart()) {
+                       parent_context.check_end_layout(os);
+                       parent_context.new_paragraph(os);
+               }
+               // save the language in the context so that it is
+               // handled by parse_text
+               parent_context.font.language = polyglossia2lyx(name);
+               parse_text(p, os, FLAG_END, outer, parent_context);
+               // Just in case the environment is empty
+               parent_context.extra_stuff.erase();
+               // We must begin a new paragraph to reset the language
+               parent_context.new_paragraph(os);
+               p.skip_spaces();
+       }
+
        else if (unstarred_name == "tabular" || name == "longtable") {
                eat_whitespace(p, os, parent_context, false);
                string width = "0pt";
@@ -3330,7 +3347,6 @@ void parse_text(Parser & p, ostream & os, unsigned flags, 
bool outer,
                        context.check_layout(os);
                        // save the language for the case that a
                        // \foreignlanguage is used
-
                        context.font.language = babel2lyx(p.verbatim_item());
                        os << "\n\\lang " << context.font.language << "\n";
                }
@@ -3341,6 +3357,36 @@ void parse_text(Parser & p, ostream & os, unsigned 
flags, bool outer,
                                              context, "\\lang",
                                              context.font.language, lang);
                }
+               
+               else if (prefixIs(t.cs(), "text") 
+                        && is_known(t.cs().substr(4), polyglossia_languages)) {
+                       // scheme is \textLANGUAGE{text} where LANGUAGE is in 
polyglossia_languages[]
+                       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(',');
+                               string::size_type k = langopts.find('=', 
pos_var);
+                               if (pos_var != string::npos && i == 
string::npos) {
+                                       string variant;
+                                       variant = langopts.substr(k + 1, 
langopts.length() - k - 2);
+                                       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 {
+                               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
diff --git a/status.20x b/status.20x
index b2d19c8..4ce7367 100644
--- a/status.20x
+++ b/status.20x
@@ -34,6 +34,7 @@ What's new
 
 * TEX2LYX IMPROVEMENTS
 
+- The polyglossia/XeTeX language commands are now supported (bug 8212).
 
 
 * USER INTERFACE

-----------------------------------------------------------------------

Summary of changes:
 src/tex2lyx/Preamble.cpp               |  139 +++++++++++++++++++++++++++++--
 src/tex2lyx/Preamble.h                 |    1 +
 src/tex2lyx/test/XeTeX-polyglossia.tex |   16 ++--
 src/tex2lyx/tex2lyx.h                  |    2 +
 src/tex2lyx/text.cpp                   |   48 +++++++++++-
 status.20x                             |    1 +
 6 files changed, 189 insertions(+), 18 deletions(-)


hooks/post-receive
-- 
The LyX Source Repository

Reply via email to