]> git.lyx.org Git - lyx.git/blobdiff - src/LaTeXFeatures.cpp
Fix #10778 (issue with CJK and language nesting)
[lyx.git] / src / LaTeXFeatures.cpp
index a69fd5971df16cd526488e71a5c160e80777b9fe..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)
 {}
 
 
@@ -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;
 }
@@ -1150,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';
        }
@@ -1256,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"))
@@ -1299,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;
 
@@ -1399,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();