Support arbitrary content for document title

For PDF, they will be immediately turned into plain text. However, it's still useful because templates can now accept content titles (with math or such things) instead of forcing strings because of set document. Moreover, it will be useful with "get rules" in the future.
This commit is contained in:
Laurenz 2023-11-20 18:31:23 +01:00
parent b5956ca3f1
commit c1bc529986
2 changed files with 9 additions and 6 deletions

View File

@ -13,7 +13,7 @@ use crate::prelude::*;
/// rule must appear before any of the document's contents. /// rule must appear before any of the document's contents.
/// ///
/// ```example /// ```example
/// #set document(title: "Hello") /// #set document(title: [Hello])
/// ///
/// This has no visible output, but /// This has no visible output, but
/// embeds metadata into the PDF! /// embeds metadata into the PDF!
@ -25,7 +25,10 @@ use crate::prelude::*;
pub struct DocumentElem { pub struct DocumentElem {
/// The document's title. This is often rendered as the title of the /// The document's title. This is often rendered as the title of the
/// PDF viewer window. /// PDF viewer window.
pub title: Option<EcoString>, ///
/// While this can be arbitrary content, PDF viewers only support plain text
/// titles, so the conversion might be lossy.
pub title: Option<Content>,
/// The document's authors. /// The document's authors.
pub author: Author, pub author: Author,
@ -90,7 +93,7 @@ impl LayoutRoot for DocumentElem {
Ok(Document { Ok(Document {
pages, pages,
title: self.title(styles), title: self.title(styles).map(|content| content.plain_text()),
author: self.author(styles).0, author: self.author(styles).0,
keywords: self.keywords(styles).0, keywords: self.keywords(styles).0,
date: self.date(styles), date: self.date(styles),

View File

@ -2,7 +2,7 @@
--- ---
// This is okay. // This is okay.
#set document(title: "Hello") #set document(title: [Hello])
What's up? What's up?
--- ---
@ -24,7 +24,7 @@ What's up?
Hello Hello
// Error: 2-30 document set rules must appear before any content // Error: 2-30 document set rules must appear before any content
#set document(title: "Hello") #set document(title: [Hello])
--- ---
// Error: 10-12 can only be used in set rules // Error: 10-12 can only be used in set rules
@ -33,7 +33,7 @@ Hello
--- ---
#box[ #box[
// Error: 4-32 document set rules are not allowed inside of containers // Error: 4-32 document set rules are not allowed inside of containers
#set document(title: "Hello") #set document(title: [Hello])
] ]
--- ---