X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FBufferParams.cpp;h=a6ccd4ed546ff25ce2a632ce5731bac52dce7543;hb=b198a36a363bb6a084407d476942d68ef5fb5e86;hp=b1846beaa3a24a87aeef673a92aef08791f7ee2b;hpb=44d1756783262ae0af39991e18ec9bcb847fb439;p=lyx.git diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index b1846beaa3..a6ccd4ed54 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -370,6 +370,9 @@ BufferParams::Impl::Impl() authorlist.record(Author(from_utf8(lyxrc.user_name), from_utf8(lyxrc.user_email), from_utf8(lyxrc.user_initials))); + // set comparison author + authorlist.record(Author(from_utf8("Document Comparison"), + docstring(), docstring())); } @@ -633,45 +636,29 @@ bool BufferParams::spellignored(WordLangTuple const & wl) const Bullet & BufferParams::temp_bullet(lyx::size_type const index) { - if (index < 4) - return pimpl_->temp_bullets[index]; - // Fallback bullet if we are too deeply nested - docstring const fb = from_ascii("?") + convert(index + 1); - Bullet const & res = Bullet(fb); - return const_cast(res); + LASSERT(index < 4, return pimpl_->temp_bullets[0]); + return pimpl_->temp_bullets[index]; } Bullet const & BufferParams::temp_bullet(lyx::size_type const index) const { - if (index < 4) - return pimpl_->temp_bullets[index]; - // Fallback bullet if we are too deeply nested - docstring const fb = from_ascii("?") + convert(index + 1); - Bullet const & res = Bullet(fb); - return res; + LASSERT(index < 4, return pimpl_->temp_bullets[0]); + return pimpl_->temp_bullets[index]; } Bullet & BufferParams::user_defined_bullet(lyx::size_type const index) { - if (index < 4) - return pimpl_->user_defined_bullets[index]; - // Fallback bullet if we are too deeply nested - docstring const fb = from_ascii("?") + convert(index + 1); - Bullet const & res = Bullet(fb); - return const_cast(res); + LASSERT(index < 4, return pimpl_->temp_bullets[0]); + return pimpl_->user_defined_bullets[index]; } Bullet const & BufferParams::user_defined_bullet(lyx::size_type const index) const { - if (index < 4) - return pimpl_->user_defined_bullets[index]; - // Fallback bullet if we are too deeply nested - docstring const fb = from_ascii("?") + convert(index + 1); - Bullet const & res = Bullet(fb); - return res; + LASSERT(index < 4, return pimpl_->temp_bullets[0]); + return pimpl_->user_defined_bullets[index]; } @@ -1716,7 +1703,7 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features, FileName const & filepath) const { // DocumentMetadata must come before anything else - if (features.isAvailable("LaTeX-2022/06/01") + if (features.isAvailableAtLeastFrom("LaTeX", 2022, 6) && !containsOnly(document_metadata, " \n\t")) { // Check if the user preamble contains uncodable glyphs odocstringstream doc_metadata; @@ -1755,7 +1742,7 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features, "\n\nPlease select an appropriate " "document encoding\n" "(such as utf8) or change the " - "preamble code accordingly."), + "metadata accordingly."), uncodable_glyphs)); } if (!doc_metadata.str().empty()) { @@ -1934,8 +1921,18 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features, if (useNonTeXFonts) { // Babel (as of 2017/11/03) loads fontspec itself + // However, it does so only if a non-default font is requested via \babelfont + // Thus load fontspec if this is not the case and we need fontspec features + bool const babel_needfontspec = + !features.isAvailableAtLeastFrom("babel", 2017, 11, 3) + || (fontsRoman() == "default" + && fontsSans() == "default" + && fontsTypewriter() == "default" + // these need fontspec features + && (features.isRequired("textquotesinglep") + || features.isRequired("textquotedblp"))); if (!features.isProvided("fontspec") - && !(features.useBabel() && features.isAvailable("babel-2017/11/03"))) + && (!features.useBabel() || babel_needfontspec)) os << "\\usepackage{fontspec}\n"; if (features.mustProvide("unicode-math") && features.isAvailable("unicode-math")) @@ -1995,6 +1992,8 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features, if (!features.runparams().includeall && !included_children_.empty()) { os << "\\includeonly{"; bool first = true; + // we do not use "auto const &" here, because incfile is modified later + // coverity[auto_causes_copy] for (auto incfile : included_children_) { FileName inc = makeAbsPath(incfile, filepath.absFileName()); string mangled = DocFileName(changeExtension(inc.absFileName(), ".tex")). @@ -2207,7 +2206,7 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features, os << from_utf8(output_sync_macro) +"\n"; else if (features.runparams().flavor == Flavor::LaTeX) os << "\\usepackage[active]{srcltx}\n"; - else if (features.runparams().flavor == Flavor::PdfLaTeX) + else os << "\\synctex=-1\n"; } @@ -2291,7 +2290,7 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features, if (!tmppreamble.str.empty()) atlyxpreamble << "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% " "LyX specific LaTeX commands.\n" - << move(tmppreamble) + << std::move(tmppreamble) << '\n'; } // the text class specific preamble @@ -3399,56 +3398,51 @@ void BufferParams::writeEncodingPreamble(otexstream & os, if (useNonTeXFonts) return; + string const doc_encoding = encoding().latexName(); + Encoding::Package const package = encoding().package(); + // (dvi)lualatex uses luainputenc rather than inputenc + string const inputenc_package = + (features.runparams().flavor == Flavor::LuaTeX + || features.runparams().flavor == Flavor::DviLuaTeX) + ? "luainputenc" : "inputenc"; + if (inputenc == "auto-legacy") { - string const doc_encoding = - language->encoding()->latexName(); - Encoding::Package const package = - language->encoding()->package(); - - // Create list of inputenc options: - set encoding_set; - // luainputenc fails with more than one encoding - if (features.runparams().flavor != Flavor::LuaTeX - && features.runparams().flavor != Flavor::DviLuaTeX) - // list all input encodings used in the document - encoding_set = features.getEncodingSet(doc_encoding); - - // The "japanese" babel-language requires the pLaTeX engine + // The "japanese" babel language requires the pLaTeX engine // which conflicts with "inputenc". // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg129680.html - if ((!encoding_set.empty() || package == Encoding::inputenc) - && !features.isRequired("japanese") + if (!features.isRequired("japanese") && !features.isProvided("inputenc")) { - os << "\\usepackage["; - set::const_iterator it = encoding_set.begin(); - set::const_iterator const end = encoding_set.end(); - if (it != end) { - os << from_ascii(*it); - ++it; - } - for (; it != end; ++it) - os << ',' << from_ascii(*it); if (package == Encoding::inputenc) { - if (!encoding_set.empty()) - os << ','; - os << from_ascii(doc_encoding); + // Main language requires (lua)inputenc + os << "\\usepackage[" << doc_encoding << "]{" + << inputenc_package << "}\n"; + } else { + // We might have an additional language that requires inputenc + set encoding_set = features.getEncodingSet(doc_encoding); + bool inputenc = false; + for (auto const & enc : encoding_set) { + if (encodings.fromLaTeXName(enc) + && encodings.fromLaTeXName(enc)->package() == Encoding::inputenc) { + inputenc = true; + break; + } + } + if (inputenc) + // load (lua)inputenc without options + // (the encoding is loaded later) + os << "\\usepackage{" << inputenc_package << "}\n"; } - if (features.runparams().flavor == Flavor::LuaTeX - || features.runparams().flavor == Flavor::DviLuaTeX) - os << "]{luainputenc}\n"; - else - os << "]{inputenc}\n"; } } else if (inputenc != "auto-legacy-plain") { - switch (encoding().package()) { + switch (package) { case Encoding::none: case Encoding::CJK: case Encoding::japanese: if (encoding().iconvName() != "UTF-8" - && !features.runparams().isFullUnicode()) - // don't default to [utf8]{inputenc} with TeXLive >= 18 - os << "\\ifdefined\\UseRawInputEncoding\n" - << " \\UseRawInputEncoding\\fi\n"; + && !features.runparams().isFullUnicode() + && features.isAvailableAtLeastFrom("LaTeX", 2018, 4)) + // don't default to [utf8]{inputenc} with LaTeX >= 2018/04 + os << "\\UseRawInputEncoding\n"; break; case Encoding::inputenc: // do not load inputenc if japanese is used @@ -3456,20 +3450,26 @@ void BufferParams::writeEncodingPreamble(otexstream & os, if (features.isRequired("japanese") || features.isProvided("inputenc")) break; - os << "\\usepackage[" << from_ascii(encoding().latexName()); - if (features.runparams().flavor == Flavor::LuaTeX - || features.runparams().flavor == Flavor::DviLuaTeX) - os << "]{luainputenc}\n"; - else - os << "]{inputenc}\n"; + // The 2022 release of ucs.sty uses the default utf8 + // inputenc encoding with 'utf8x' inputenc if the ucs + // package is not loaded before inputenc. + // This breaks existing documents that use utf8x + // and also makes utf8x redundant. + // Thus we load ucs.sty in order to keep functionality + // that would otherwise be silently dropped. + if (doc_encoding == "utf8x" + && features.isAvailableAtLeastFrom("ucs", 2022, 8, 7) + && !features.isProvided("ucs")) + os << "\\usepackage{ucs}\n"; + os << "\\usepackage[" << doc_encoding << "]{" + << inputenc_package << "}\n"; break; } } - if (inputenc == "auto-legacy-plain" || features.isRequired("japanese")) { - // don't default to [utf8]{inputenc} with TeXLive >= 18 - os << "\\ifdefined\\UseRawInputEncoding\n"; - os << " \\UseRawInputEncoding\\fi\n"; - } + if ((inputenc == "auto-legacy-plain" || features.isRequired("japanese")) + && features.isAvailableAtLeastFrom("LaTeX", 2018, 4)) + // don't default to [utf8]{inputenc} with LaTeX >= 2018/04 + os << "\\UseRawInputEncoding\n"; } @@ -3517,7 +3517,7 @@ string const BufferParams::loadFonts(LaTeXFeatures & features) const // As of 2017/11/03, Babel has its own higher-level // interface on top of fontspec that is to be used. bool const babelfonts = features.useBabel() - && features.isAvailable("babel-2017/11/03"); + && features.isAvailableAtLeastFrom("babel", 2017, 11, 3); string const texmapping = (features.runparams().flavor == Flavor::XeTeX) ? "Mapping=tex-text" : "Ligatures=TeX"; @@ -3821,6 +3821,7 @@ void BufferParams::copyForAdvFR(const BufferParams & bp) { string const & lang = bp.language->lang(); setLanguage(lang); + quotes_style = bp.quotes_style; layout_modules_ = bp.layout_modules_; string const & doc_class = bp.documentClass().name(); setBaseClass(doc_class); @@ -3841,5 +3842,11 @@ string const BufferParams::bibFileEncoding(string const & file) const } +BufferParams const & defaultBufferParams() +{ + static BufferParams default_params; + return default_params; +} + } // namespace lyx