origin.replace(0, sysdirprefix.length() - 1,
package().system_support().absFileName());
}
+ } else if (token == "\\begin_metadata") {
+ readDocumentMetadata(lex);
} else if (token == "\\begin_preamble") {
readPreamble(lex);
} else if (token == "\\begin_local_layout") {
baseClass()->name()), "layout"))
<< '\n';
+ // then document metadata
+ if (!document_metadata.empty()) {
+ // remove '\n' from the end of document_metadata
+ docstring const tmpmd = rtrim(document_metadata, "\n");
+ os << "\\begin_metadata\n"
+ << to_utf8(tmpmd)
+ << "\n\\end_metadata\n";
+ }
+
// then the preamble
if (!preamble.empty()) {
// remove '\n' from the end of preamble
bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
FileName const & filepath) const
{
+ // DocumentMetadata must come before anything else
+ if (features.isAvailable("LaTeX-2022/06/01")
+ && !containsOnly(document_metadata, " \n\t")) {
+ // Check if the user preamble contains uncodable glyphs
+ odocstringstream doc_metadata;
+ docstring uncodable_glyphs;
+ Encoding const * const enc = features.runparams().encoding;
+ if (enc) {
+ for (char_type c : document_metadata) {
+ if (!enc->encodable(c)) {
+ docstring const glyph(1, c);
+ LYXERR0("Uncodable character '"
+ << glyph
+ << "' in document metadata!");
+ uncodable_glyphs += glyph;
+ if (features.runparams().dryrun) {
+ doc_metadata << "<" << _("LyX Warning: ")
+ << _("uncodable character") << " '";
+ doc_metadata.put(c);
+ doc_metadata << "'>";
+ }
+ } else
+ doc_metadata.put(c);
+ }
+ } else
+ doc_metadata << document_metadata;
+
+ // On BUFFER_VIEW|UPDATE, warn user if we found uncodable glyphs
+ if (!features.runparams().dryrun && !uncodable_glyphs.empty()) {
+ frontend::Alert::warning(
+ _("Uncodable character in document metadata"),
+ support::bformat(
+ _("The metadata of your document contains glyphs "
+ "that are unknown in the current document encoding "
+ "(namely %1$s).\nThese glyphs are omitted "
+ " from the output, which may result in "
+ "incomplete output."
+ "\n\nPlease select an appropriate "
+ "document encoding\n"
+ "(such as utf8) or change the "
+ "preamble code accordingly."),
+ uncodable_glyphs));
+ }
+ if (!doc_metadata.str().empty()) {
+ os << "\\DocumentMetadata{\n"
+ << doc_metadata.str()
+ << "}\n";
+ }
+ }
+
// http://www.tug.org/texmf-dist/doc/latex/base/fixltx2e.pdf
// !! To use the Fix-cm package, load it before \documentclass, and use the command
// \RequirePackage to do so, rather than the normal \usepackage
// if we use fontspec or newtxmath, we have to load the AMS packages here
string const ams = features.loadAMSPackages();
- bool const ot1 = (main_font_encoding() == "default" || main_font_encoding() == "OT1");
+ string const main_font_enc = features.runparams().main_fontenc;
+ bool const ot1 = (main_font_enc == "default" || main_font_enc == "OT1");
bool const use_newtxmath =
theLaTeXFonts().getLaTeXFont(from_ascii(fontsMath())).getUsedPackage(
ot1, false, false) == "newtxmath";
// set font encoding
// non-TeX fonts use font encoding TU (set by fontspec)
if (!useNonTeXFonts && !features.isProvided("fontenc")
- && main_font_encoding() != "default") {
+ && main_font_enc != "default") {
// get main font encodings
vector<string> fontencs = font_encodings();
// get font encodings of secondary languages
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")).
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";
}
if (!tmppreamble.str.empty())
atlyxpreamble << "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
"LyX specific LaTeX commands.\n"
- << move(tmppreamble)
+ << std::move(tmppreamble)
<< '\n';
}
// the text class specific preamble
}
+void BufferParams::readDocumentMetadata(Lexer & lex)
+{
+ if (lex.getString() != "\\begin_metadata")
+ lyxerr << "Error (BufferParams::readDocumentMetadata):"
+ "consistency check failed." << endl;
+
+ document_metadata = lex.getLongString(from_ascii("\\end_metadata"));
+}
+
+
void BufferParams::readLocalLayout(Lexer & lex, bool forced)
{
string const expected = forced ? "\\begin_forced_local_layout" :
string const BufferParams::main_font_encoding() const
{
- if (font_encodings().empty()) {
+ vector<string> const fencs = font_encodings();
+ if (fencs.empty()) {
if (ascii_lowercase(language->fontenc(*this)) == "none")
return "none";
return "default";
}
- return font_encodings().back();
+ return fencs.back();
}
if (!doc_fontenc.empty())
// If we have a custom setting, we use only that!
return getVectorFromString(doc_fontenc);
- if (!language->fontenc(*this).empty()
+ string const lfe = language->fontenc(*this);
+ if (!lfe.empty()
&& ascii_lowercase(language->fontenc(*this)) != "none") {
- vector<string> fencs = getVectorFromString(language->fontenc(*this));
+ vector<string> fencs = getVectorFromString(lfe);
for (auto & fe : fencs) {
if (find(fontencs.begin(), fontencs.end(), fe) == fontencs.end())
fontencs.push_back(fe);
if (features.isRequired("japanese")
|| features.isProvided("inputenc"))
break;
- os << "\\usepackage[" << from_ascii(encoding().latexName());
- if (features.runparams().flavor == Flavor::LuaTeX
+ string const doc_encoding = encoding().latexName();
+ // 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.isAvailable("ucs-2022/08/07")
+ && !features.isProvided("ucs"))
+ os << "\\usepackage{ucs}\n";
+ os << "\\usepackage[" << from_ascii(doc_encoding);
+ if (features.runparams().flavor == Flavor::LuaTeX
|| features.runparams().flavor == Flavor::DviLuaTeX)
os << "]{luainputenc}\n";
else
}
// Tex Fonts
- bool const ot1 = (main_font_encoding() == "default" || main_font_encoding() == "OT1");
+ bool const ot1 = (features.runparams().main_fontenc == "default"
+ || features.runparams().main_fontenc == "OT1");
bool const dryrun = features.runparams().dryrun;
bool const complete = (fontsSans() == "default" && fontsTypewriter() == "default");
bool const nomath = (fontsMath() != "auto");
{
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);
}
+BufferParams const & defaultBufferParams()
+{
+ static BufferParams default_params;
+ return default_params;
+}
+
} // namespace lyx