]> git.lyx.org Git - features.git/blobdiff - src/BufferParams.cpp
Load hyperref with a suitable driver
[features.git] / src / BufferParams.cpp
index 52fd35bc20943b43db6b93ba2335a5904355ab63..f0be844870c8f079659574683f242380a36e2f13 100644 (file)
@@ -323,7 +323,7 @@ bool inSystemDir(FileName const & document_dir, string & system_dir)
        return false;
 }
 
-} // anon namespace
+} // namespace
 
 
 class BufferParams::Impl
@@ -385,7 +385,7 @@ BufferParams::BufferParams()
        makeDocumentClass();
        paragraph_separation = ParagraphIndentSeparation;
        is_math_indent = false;
-       math_number = DEFAULT;
+       math_numbering_side = DEFAULT;
        quotes_style = InsetQuotesParams::EnglishQuotes;
        dynamic_quotes = false;
        fontsize = "default";
@@ -394,7 +394,7 @@ BufferParams::BufferParams()
        papersize = PAPER_DEFAULT;
        orientation = ORIENTATION_PORTRAIT;
        use_geometry = false;
-       biblio_style = "plain";
+       biblio_style = string();
        use_bibtopic = false;
        multibib = string();
        use_indices = false;
@@ -459,8 +459,10 @@ BufferParams::BufferParams()
        html_css_as_file = false;
        display_pixel_ratio = 1.0;
 
+       shell_escape = false;
        output_sync = false;
        use_refstyle = true;
+       use_minted = false;
 
        // map current author
        author_map_[pimpl_->authorlist.get(0).bufferId()] = 0;
@@ -669,8 +671,8 @@ void BufferParams::setDefSkip(VSpace const & vs)
 
 BufferParams::MathNumber BufferParams::getMathNumber() const
 {
-       if (math_number != DEFAULT)
-               return math_number;
+       if (math_numbering_side != DEFAULT)
+               return math_numbering_side;
        // FIXME: do not hardcode language here
        else if (language->lang() == "arabic_arabi"
                 || documentClass().provides("leqno"))
@@ -865,16 +867,20 @@ string BufferParams::readToken(Lexer & lex, string const & token,
                lex >> is_math_indent;
        } else if (token == "\\math_indentation") {
                lex.next();
-               pimpl_->mathindent = Length(lex.getString());
-       } else if (token == "\\math_number_before") {
+               string mathindent = lex.getString();
+               if (mathindent == "default")
+                       pimpl_->mathindent = Length();
+               else
+                       pimpl_->mathindent = Length(mathindent);
+       } else if (token == "\\math_numbering_side") {
                string tmp;
                lex >> tmp;
-               if (tmp == "true")
-                       math_number = LEFT;
-               else if (tmp == "false")
-                       math_number = RIGHT;
+               if (tmp == "left")
+                       math_numbering_side = LEFT;
+               else if (tmp == "right")
+                       math_numbering_side = RIGHT;
                else
-                       math_number = DEFAULT;
+                       math_numbering_side = DEFAULT;
        } else if (token == "\\quotes_style") {
                string qstyle;
                lex >> qstyle;
@@ -1095,6 +1101,8 @@ string BufferParams::readToken(Lexer & lex, string const & token,
                lex >> output_sync_macro;
        } else if (token == "\\use_refstyle") {
                lex >> use_refstyle;
+       } else if (token == "\\use_minted") {
+               lex >> use_minted;
        } else {
                lyxerr << "BufferParams::readToken(): Unknown token: " <<
                        token << endl;
@@ -1112,7 +1120,7 @@ namespace {
                        return "\"" + str + "\"";
                return str;
        }
-}
+} // namespace
 
 
 void BufferParams::writeFile(ostream & os, Buffer const * buf) const
@@ -1302,6 +1310,7 @@ void BufferParams::writeFile(ostream & os, Buffer const * buf) const
           << "\n\\suppress_date " << convert<string>(suppress_date)
           << "\n\\justification " << convert<string>(justification)
           << "\n\\use_refstyle " << use_refstyle
+          << "\n\\use_minted " << use_minted
           << '\n';
        if (isbackgroundcolor == true)
                os << "\\backgroundcolor " << lyx::X11hexname(backgroundcolor) << '\n';
@@ -1373,15 +1382,16 @@ void BufferParams::writeFile(ostream & os, Buffer const * buf) const
        else
                os << "\n\\defskip " << getDefSkip().asLyXCommand();
        os << "\n\\is_math_indent " << is_math_indent;
-       if (is_math_indent && !getMathIndent().empty())
-               os << "\n\\math_indentation " << getMathIndent().asString();
-       os << "\n\\math_number_before ";
-       switch(math_number) {
+       if (is_math_indent)
+               os << "\n\\math_indentation "
+                  << (getMathIndent().empty() ? "default" : getMathIndent().asString());
+       os << "\n\\math_numbering_side ";
+       switch(math_numbering_side) {
        case LEFT:
-               os << "true";
+               os << "left";
                break;
        case RIGHT:
-               os << "false";
+               os << "right";
                break;
        case DEFAULT:
                os << "default";
@@ -1544,7 +1554,7 @@ void BufferParams::validate(LaTeXFeatures & features) const
 
        if (useNonTeXFonts && fontsMath() != "auto")
                features.require("unicode-math");
-       
+
        if (use_microtype)
                features.require("microtype");
 
@@ -1670,7 +1680,7 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
        if (is_math_indent)
                clsoptions << "fleqn,";
 
-       switch(math_number) {
+       switch(math_numbering_side) {
        case LEFT:
                clsoptions << "leqno,";
                break;
@@ -2040,13 +2050,12 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
        // http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg144349.html
        os << from_ascii(features.getColorOptions());
 
-       // If we use hyperref, jurabib, japanese, varioref or vietnamese,
+       // If we use hyperref, jurabib, japanese or varioref,
        // we have to call babel before
        if (use_babel
            && (features.isRequired("jurabib")
                || features.isRequired("hyperref")
                || features.isRequired("varioref")
-               || features.isRequired("vietnamese")
                || features.isRequired("japanese"))) {
                        os << features.getBabelPresettings();
                        // FIXME UNICODE
@@ -2085,8 +2094,8 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
                OutputParams tmp_params = features.runparams();
                pdfoptions().writeLaTeX(tmp_params, os,
                                        features.isProvided("hyperref"));
-               // correctly break URLs with hyperref and dvi output
-               if (features.runparams().flavor == OutputParams::LATEX
+               // correctly break URLs with hyperref and dvi/ps output
+               if (features.runparams().hyperref_driver == "dvips"
                    && features.isAvailable("breakurl"))
                        os << "\\usepackage{breakurl}\n";
        } else if (features.isRequired("nameref"))
@@ -2242,8 +2251,7 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
        // called after babel, though.
        if (use_babel && !features.isRequired("jurabib")
            && !features.isRequired("hyperref")
-               && !features.isRequired("varioref")
-           && !features.isRequired("vietnamese")
+           && !features.isRequired("varioref")
            && !features.isRequired("japanese")) {
                os << features.getBabelPresettings();
                // FIXME UNICODE
@@ -2253,10 +2261,19 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
        }
        if (features.isRequired("bicaption"))
                os << "\\usepackage{bicaption}\n";
-       if (!listings_params.empty() || features.mustProvide("listings"))
-               os << "\\usepackage{listings}\n";
+       if (!listings_params.empty()
+           || features.mustProvide("listings")
+           || features.mustProvide("minted")) {
+               if (features.mustProvide("listings"))
+                       os << "\\usepackage{listings}\n";
+               else
+                       os << "\\usepackage{minted}\n";
+       }
        if (!listings_params.empty()) {
-               os << "\\lstset{";
+               if (features.mustProvide("listings"))
+                       os << "\\lstset{";
+               else
+                       os << "\\setminted{";
                // do not test validity because listings_params is
                // supposed to be valid
                string par =
@@ -2269,7 +2286,8 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
        // (the rest is obsoleted by the new TU encoding).
        // It needs to be loaded at least after amsmath, amssymb,
        // esint and the other packages that provide special glyphs
-       if (features.mustProvide("tipa") && useNonTeXFonts) {
+       if (features.mustProvide("tipa") && useNonTeXFonts
+           && !features.isProvided("xunicode")) {
                // The package officially only supports XeTeX, but also works
                // with LuaTeX. Thus we work around its XeTeX test.
                if (features.runparams().flavor != OutputParams::XETEX) {
@@ -2304,7 +2322,11 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
        }
 
        // ... but before biblatex (see #7065)
-       if (features.mustProvide("biblatex")) {
+       if (features.mustProvide("biblatex")
+           && !features.isProvided("biblatex-natbib")
+           && !features.isProvided("natbib-internal")
+           && !features.isProvided("natbib")
+           && !features.isProvided("jurabib")) {
                string delim = "";
                string opts;
                os << "\\usepackage";
@@ -2353,7 +2375,8 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
        }
 
        docstring const i18npreamble =
-               features.getTClassI18nPreamble(use_babel, use_polyglossia);
+               features.getTClassI18nPreamble(use_babel, use_polyglossia,
+                                              use_minted);
        if (!i18npreamble.empty())
                os << i18npreamble + '\n';
 
@@ -2559,7 +2582,7 @@ FormatList const & BufferParams::exportableFormats(bool only_viewable) const
 {
        FormatList & cached = only_viewable ?
                        pimpl_->viewableFormatList : pimpl_->exportableFormatList;
-       bool & valid = only_viewable ? 
+       bool & valid = only_viewable ?
                        pimpl_->isViewCacheValid : pimpl_->isExportCacheValid;
        if (valid)
                return cached;
@@ -2574,7 +2597,7 @@ FormatList const & BufferParams::exportableFormats(bool only_viewable) const
                theConverters().getReachable(backs[0], only_viewable, true, excludes);
        for (vector<string>::const_iterator it = backs.begin() + 1;
             it != backs.end(); ++it) {
-               FormatList r = theConverters().getReachable(*it, only_viewable, 
+               FormatList r = theConverters().getReachable(*it, only_viewable,
                                false, excludes);
                result.insert(result.end(), r.begin(), r.end());
        }
@@ -2603,8 +2626,16 @@ vector<string> BufferParams::backends() const
                        v.push_back("luatex");
                        v.push_back("dviluatex");
                }
-       } else
-               v.push_back(buffmt);
+       } else {
+               string rbuffmt = buffmt;
+               // If we use an OutputFormat in Japanese docs,
+               // we need special format in order to get the path
+               // via pLaTeX (#8823)
+               if (documentClass().hasOutputFormat()
+                   && encoding().package() == Encoding::japanese)
+                       rbuffmt += "-ja";
+               v.push_back(rbuffmt);
+       }
 
        v.push_back("xhtml");
        v.push_back("text");
@@ -2647,9 +2678,8 @@ OutputParams::FLAVOR BufferParams::getOutputFlavor(string const & format) const
                if (find(backs.begin(), backs.end(), dformat) == backs.end()) {
                        // Get shortest path to format
                        Graph::EdgePath path;
-                       for (vector<string>::const_iterator it = backs.begin();
-                           it != backs.end(); ++it) {
-                               Graph::EdgePath p = theConverters().getPath(*it, dformat);
+                       for (auto const & bvar : backs) {
+                               Graph::EdgePath p = theConverters().getPath(bvar, dformat);
                                if (!p.empty() && (path.empty() || p.size() < path.size())) {
                                        path = p;
                                }
@@ -2669,14 +2699,15 @@ string BufferParams::getDefaultOutputFormat() const
        if (!default_output_format.empty()
            && default_output_format != "default")
                return default_output_format;
-       if (isDocBook()
-           || encoding().package() == Encoding::japanese) {
+       if (isDocBook()) {
                FormatList const & formats = exportableFormats(true);
                if (formats.empty())
                        return string();
                // return the first we find
                return formats.front()->name();
        }
+       if (encoding().package() == Encoding::japanese)
+               return lyxrc.default_platex_view_format;
        if (useNonTeXFonts)
                return lyxrc.default_otf_view_format;
        return lyxrc.default_view_format;
@@ -3163,21 +3194,21 @@ void BufferParams::writeEncodingPreamble(otexstream & os,
                        language->encoding()->package();
 
                // Create list of inputenc options:
-               set<string> encodings;
+               set<string> encoding_set;
                // luainputenc fails with more than one encoding
                if (!features.runparams().isFullUnicode()) // if we reach this point, this means LuaTeX with TeX fonts
                        // list all input encodings used in the document
-                       encodings = features.getEncodingSet(doc_encoding);
+                       encoding_set = features.getEncodingSet(doc_encoding);
 
                // If the "japanese" package (i.e. pLaTeX) is used,
                // inputenc must be omitted.
                // see http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg129680.html
-               if ((!encodings.empty() || package == Encoding::inputenc)
+               if ((!encoding_set.empty() || package == Encoding::inputenc)
                    && !features.isRequired("japanese")
                    && !features.isProvided("inputenc")) {
                        os << "\\usepackage[";
-                       set<string>::const_iterator it = encodings.begin();
-                       set<string>::const_iterator const end = encodings.end();
+                       set<string>::const_iterator it = encoding_set.begin();
+                       set<string>::const_iterator const end = encoding_set.end();
                        if (it != end) {
                                os << from_ascii(*it);
                                ++it;
@@ -3185,7 +3216,7 @@ void BufferParams::writeEncodingPreamble(otexstream & os,
                        for (; it != end; ++it)
                                os << ',' << from_ascii(*it);
                        if (package == Encoding::inputenc) {
-                               if (!encodings.empty())
+                               if (!encoding_set.empty())
                                        os << ',';
                                os << from_ascii(doc_encoding);
                        }
@@ -3349,7 +3380,7 @@ string const BufferParams::loadFonts(LaTeXFeatures & features) const
 Encoding const & BufferParams::encoding() const
 {
        // Main encoding for LaTeX output.
-       // 
+       //
        // Exception: XeTeX with 8-bit TeX fonts requires ASCII (see #9740).
        // As the "flavor" is only known once export started, this
        // cannot be handled here. Instead, runparams.encoding is set
@@ -3394,6 +3425,9 @@ bool BufferParams::addCiteEngine(vector<string> const & engine)
 
 string const & BufferParams::defaultBiblioStyle() const
 {
+       if (!biblio_style.empty())
+               return biblio_style;
+
        map<string, string> const & bs = documentClass().defaultBiblioStyle();
        auto cit = bs.find(theCiteEnginesList.getTypeAsString(citeEngineType()));
        if (cit != bs.end())