]> git.lyx.org Git - lyx.git/blobdiff - src/LaTeXFeatures.cpp
Fix #10778 (issue with CJK and language nesting)
[lyx.git] / src / LaTeXFeatures.cpp
index 562e0e2a00bc2bf6c693d472c9d03596154b40f9..a3aa242e62577068cbe39beab885b327a76bf762 100644 (file)
@@ -134,6 +134,24 @@ static docstring const paragraphleftindent_def = from_ascii(
        "}\n"
        "{\\end{list}}\n");
 
+static docstring const floatingfootnote_def = from_ascii(
+       "%% Special footnote code from the package 'stblftnt.sty'\n"
+       "%% Author: Robin Fairbairns -- Last revised Dec 13 1996\n"
+       "\\let\\SF@@footnote\\footnote\n"
+       "\\def\\footnote{\\ifx\\protect\\@typeset@protect\n"
+       "    \\expandafter\\SF@@footnote\n"
+       "  \\else\n"
+       "    \\expandafter\\SF@gobble@opt\n"
+       "  \\fi\n"
+       "}\n"
+       "\\expandafter\\def\\csname SF@gobble@opt \\endcsname{\\@ifnextchar[%]\n"
+       "  \\SF@gobble@twobracket\n"
+       "  \\@gobble\n"
+       "}\n"
+       "\\edef\\SF@gobble@opt{\\noexpand\\protect\n"
+       "  \\expandafter\\noexpand\\csname SF@gobble@opt \\endcsname}\n"
+       "\\def\\SF@gobble@twobracket[#1]#2{}\n");
+
 static docstring const binom_def = from_ascii(
        "%% Binom macro for standard LaTeX users\n"
        "\\newcommand{\\binom}[2]{{#1 \\choose #2}}\n");
@@ -173,12 +191,25 @@ static docstring const changetracking_dvipost_def = from_ascii(
 static docstring const changetracking_xcolor_ulem_def = from_ascii(
        "%% Change tracking with ulem\n"
        "\\DeclareRobustCommand{\\lyxadded}[3]{{\\color{lyxadded}{}#3}}\n"
-       "\\DeclareRobustCommand{\\lyxdeleted}[3]{{\\color{lyxdeleted}\\sout{#3}}}\n");
+       "\\DeclareRobustCommand{\\lyxdeleted}[3]{{\\color{lyxdeleted}\\lyxsout{#3}}}\n"
+       "\\DeclareRobustCommand{\\lyxsout}[1]{\\ifx\\\\#1\\else\\sout{#1}\\fi}\n");
 
 static docstring const changetracking_xcolor_ulem_hyperref_def = from_ascii(
        "%% Change tracking with ulem\n"
        "\\DeclareRobustCommand{\\lyxadded}[3]{{\\texorpdfstring{\\color{lyxadded}{}}{}#3}}\n"
-       "\\DeclareRobustCommand{\\lyxdeleted}[3]{{\\texorpdfstring{\\color{lyxdeleted}\\sout{#3}}{}}}\n");
+       "\\DeclareRobustCommand{\\lyxdeleted}[3]{{\\texorpdfstring{\\color{lyxdeleted}\\lyxsout{#3}}{}}}\n"
+       "\\DeclareRobustCommand{\\lyxsout}[1]{\\ifx\\\\#1\\else\\sout{#1}\\fi}\n");
+
+static docstring const changetracking_tikz_math_sout_def = from_ascii(
+       "%% Strike out display math with tikz\n"
+       "\\usepackage{tikz}\n"
+       "\\usetikzlibrary{calc}\n"
+       "\\newcommand{\\lyxmathsout}[1]{%\n"
+       "  \\tikz[baseline=(math.base)]{\n"
+       "    \\node[inner sep=0pt,outer sep=0pt](math){#1};\n"
+       "    \\draw($(math.south west)+(2em,.5em)$)--($(math.north east)-(2em,.5em)$);\n"
+       "  }\n"
+       "}\n");
 
 static docstring const changetracking_none_def = from_ascii(
        "\\newcommand{\\lyxadded}[3]{#3}\n"
@@ -211,6 +242,13 @@ static docstring const papersizepdf_def = from_ascii(
        "\\pdfpageheight\\paperheight\n"
        "\\pdfpagewidth\\paperwidth\n");
 
+static docstring const papersizepdflua_def = from_ascii(
+       "% Backwards compatibility for LuaTeX < 0.90\n"
+       "\\@ifundefined{pageheight}{\\let\\pageheight\\pdfpageheight}{}\n"
+       "\\@ifundefined{pagewidth}{\\let\\pagewidth\\pdfpagewidth}{}\n"
+       "\\pageheight\\paperheight\n"
+       "\\pagewidth\\paperwidth\n");
+
 static docstring const cedilla_def = from_ascii(
        "\\newcommand{\\docedilla}[2]{\\underaccent{#1\\mathchar'30}{#2}}\n"
        "\\newcommand{\\cedilla}[1]{\\mathpalette\\docedilla{#1}}\n");
@@ -363,7 +401,8 @@ static docstring const lyxstrikeout_style = from_ascii(
 
 LaTeXFeatures::LaTeXFeatures(Buffer const & b, BufferParams const & p,
                             OutputParams const & r)
-       : buffer_(&b), params_(p), runparams_(r), in_float_(false)
+       : buffer_(&b), params_(p), runparams_(r), in_float_(false),
+         in_deleted_inset_(false)
 {}
 
 
@@ -382,14 +421,14 @@ LaTeXFeatures::LangPackage LaTeXFeatures::langPackage() const
        if (local_lp == "none")
                return LANG_PACK_NONE;
 
-       /* If "auto" is selected, we load polyglossia if required,
+       /* If "auto" is selected, we load polyglossia with non-TeX fonts,
         * else we select babel.
         * If babel is selected (either directly or via the "auto"
         * mechanism), we really do only require it if we have
         * a language that needs it.
         */
        bool const polyglossia_required =
-               isRequired("polyglossia")
+               params_.useNonTeXFonts
                && isAvailable("polyglossia")
                && !isProvided("babel")
                && this->hasOnlyPolyglossiaLanguages();
@@ -516,24 +555,24 @@ bool LaTeXFeatures::isProvided(string const & name) const
 
        bool const ot1 = (params_.font_encoding() == "default"
                || params_.font_encoding() == "OT1");
-       bool const complete = (params_.fonts_sans == "default")
-               && (params_.fonts_typewriter == "default");
-       bool const nomath = (params_.fonts_math == "default");
+       bool const complete = (params_.fontsSans() == "default"
+               && params_.fontsTypewriter() == "default");
+       bool const nomath = (params_.fontsMath() == "default");
        return params_.documentClass().provides(name)
                || theLaTeXFonts().getLaTeXFont(
-                       from_ascii(params_.fonts_roman)).provides(name, ot1,
+                       from_ascii(params_.fontsRoman())).provides(name, ot1,
                                                                  complete,
                                                                  nomath)
                || theLaTeXFonts().getLaTeXFont(
-                       from_ascii(params_.fonts_sans)).provides(name, ot1,
+                       from_ascii(params_.fontsSans())).provides(name, ot1,
                                                                 complete,
                                                                 nomath)
                || theLaTeXFonts().getLaTeXFont(
-                       from_ascii(params_.fonts_typewriter)).provides(name, ot1,
+                       from_ascii(params_.fontsTypewriter())).provides(name, ot1,
                                                                       complete,
                                                                       nomath)
                || theLaTeXFonts().getLaTeXFont(
-                       from_ascii(params_.fonts_math)).provides(name, ot1,
+                       from_ascii(params_.fontsMath())).provides(name, ot1,
                                                                       complete,
                                                                       nomath);
        // TODO: "textbaltic" provided, if the font-encoding is "L7x"
@@ -561,11 +600,12 @@ bool LaTeXFeatures::isAvailable(string const & name)
 }
 
 
-void LaTeXFeatures::addPreambleSnippet(string const & preamble)
+void LaTeXFeatures::addPreambleSnippet(string const & preamble,
+               bool allowdupes)
 {
        SnippetList::const_iterator begin = preamble_snippets_.begin();
        SnippetList::const_iterator end   = preamble_snippets_.end();
-       if (find(begin, end, preamble) == end)
+       if (allowdupes || find(begin, end, preamble) == end)
                preamble_snippets_.push_back(preamble);
 }
 
@@ -657,6 +697,42 @@ bool LaTeXFeatures::hasPolyglossiaExclusiveLanguages() const
 }
 
 
+vector<string> LaTeXFeatures::getPolyglossiaExclusiveLanguages() const
+{
+       vector<string> result;
+       // first the main language
+       if (params_.language->isPolyglossiaExclusive())
+               result.push_back(params_.language->display());
+       // now the secondary languages
+       LanguageList::const_iterator const begin = UsedLanguages_.begin();
+       for (LanguageList::const_iterator cit = begin;
+            cit != UsedLanguages_.end();
+            ++cit) {
+               if ((*cit)->isPolyglossiaExclusive())
+                       result.push_back((*cit)->display());
+       }
+       return result;
+}
+
+
+vector<string> LaTeXFeatures::getBabelExclusiveLanguages() const
+{
+       vector<string> result;
+       // first the main language
+       if (params_.language->isBabelExclusive())
+               result.push_back(params_.language->display());
+       // now the secondary languages
+       LanguageList::const_iterator const begin = UsedLanguages_.begin();
+       for (LanguageList::const_iterator cit = begin;
+            cit != UsedLanguages_.end();
+            ++cit) {
+               if ((*cit)->isBabelExclusive())
+                       result.push_back((*cit)->display());
+       }
+       return result;
+}
+
+
 string LaTeXFeatures::getBabelLanguages() const
 {
        ostringstream languages;
@@ -678,15 +754,16 @@ string LaTeXFeatures::getBabelLanguages() const
 }
 
 
-std::map<std::string, std::string> LaTeXFeatures::getPolyglossiaLanguages() const
+set<string> LaTeXFeatures::getPolyglossiaLanguages() const
 {
-       std::map<std::string, std::string> languages;
+       set<string> languages;
 
        LanguageList::const_iterator const begin = UsedLanguages_.begin();
        for (LanguageList::const_iterator cit = begin;
             cit != UsedLanguages_.end();
             ++cit) {
-               languages[(*cit)->polyglossia()] = (*cit)->polyglossiaOpts();
+               // We do not need the variants here
+               languages.insert((*cit)->polyglossia());
        }
        return languages;
 }
@@ -711,8 +788,9 @@ set<string> LaTeXFeatures::getEncodingSet(string const & doc_encoding) const
 
 void LaTeXFeatures::getFontEncodings(vector<string> & encodings) const
 {
-       // these must be loaded if glyphs of this script
-       // are used (notwithstanding the language)
+       // these must be loaded if glyphs of this script are used
+       // unless a language providing them is used in the document
+       // FIXME: currently the option is written twice in this case
        if (mustProvide("textgreek"))
                encodings.insert(encodings.begin(), "LGR");
        if (mustProvide("textcyr"))
@@ -796,7 +874,8 @@ char const * simplefeatures[] = {
        "pdfcomment",
        "fixme",
        "todonotes",
-       "forest"
+       "forest",
+       "varwidth"
 };
 
 char const * bibliofeatures[] = {
@@ -933,7 +1012,7 @@ string const LaTeXFeatures::getPackages() const
        string const amsPackages = loadAMSPackages();
        bool const ot1 = (params_.font_encoding() == "default" || params_.font_encoding() == "OT1");
        bool const use_newtxmath =
-               theLaTeXFonts().getLaTeXFont(from_ascii(params_.fonts_math)).getUsedPackage(
+               theLaTeXFonts().getLaTeXFont(from_ascii(params_.fontsMath())).getUsedPackage(
                        ot1, false, false) == "newtxmath";
 
        if (!params_.useNonTeXFonts && !use_newtxmath && !amsPackages.empty())
@@ -1148,8 +1227,11 @@ docstring const LaTeXFeatures::getMacros() const
        }
 
        if (mustProvide("papersize")) {
-               if (runparams_.flavor == OutputParams::LATEX)
+               if (runparams_.flavor == OutputParams::LATEX
+                   || runparams_.flavor == OutputParams::DVILUATEX)
                        macros << papersizedvi_def << '\n';
+               else if  (runparams_.flavor == OutputParams::LUATEX)
+                       macros << papersizepdflua_def << '\n';
                else
                        macros << papersizepdf_def << '\n';
        }
@@ -1254,6 +1336,8 @@ docstring const LaTeXFeatures::getMacros() const
        // other
        if (mustProvide("ParagraphLeftIndent"))
                macros << paragraphleftindent_def;
+       if (mustProvide("NeedLyXFootnoteCode"))
+               macros << floatingfootnote_def;
 
        // some problems with tex->html converters
        if (mustProvide("NeedTabularnewline"))
@@ -1297,6 +1381,9 @@ docstring const LaTeXFeatures::getMacros() const
                        macros << changetracking_xcolor_ulem_def;
        }
 
+       if (mustProvide("ct-tikz-math-sout"))
+                       macros << changetracking_tikz_math_sout_def;
+
        if (mustProvide("ct-none"))
                macros << changetracking_none_def;
 
@@ -1397,7 +1484,10 @@ docstring const LaTeXFeatures::getTClassPreamble() const
        list<docstring>::const_iterator cit = usedLayouts_.begin();
        list<docstring>::const_iterator end = usedLayouts_.end();
        for (; cit != end; ++cit)
-               tcpreamble << tclass[*cit].preamble();
+               // For InPreamble layouts, we output the preamble stuff earlier
+               // (before the layouts). See Paragraph::Private::validate.
+               if (!tclass[*cit].inpreamble)
+                       tcpreamble << tclass[*cit].preamble();
 
        cit = usedInsetLayouts_.begin();
        end = usedInsetLayouts_.end();