+ // 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";
+ }
+ }
+