quarto-dev / quarto-cli

Open-source scientific and technical publishing system built on Pandoc.

Home Page:https://quarto.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`date` keywords and formatting does not work in PDF

cderv opened this issue · comments

---
date: today
date-format: long #"MMMM DD, YYYY" # "`r format(Sys.Date(), '%B %d, %Y')`"
---

Does not seem to work for format: pdf. How does dynamic date work in pdf output?

quarto version: quarto-0.9.228-macos.pkg (Pkg)

Originally posted by @eyayaw in #452 (reply in thread)

I can reproduce that with

---
title: test
author: "me"
date: today
date-format: long
format: pdf
---

# Hello

World 

image

@dragonstyle is this supposed to be supported in other format than HTML yet ?

It does not seem so as the magic happens in

if (dateRaw) {
const formatted = formattedDate(
dateRaw,
format.metadata[kDateFormat] as string || "long",
);
if (formatted) {
dateEl.innerText = formatted;
}
const dateContainer = metadataEl(
doc,
localizedString(format, kTitleBlockPublished),
[dateEl],
);
metadataContainerEl.appendChild(dateContainer);
}

so only for HTML

For other formats it seems were are only doing

// Resolve the date if there are any special
// date specifiers
if (isSpecialDate(allMetadata[kDate])) {
allMetadata[kDate] = parseSpecialDate(
input,
allMetadata[kDate] as string,
);
}

which does not take into accound date-format

but this does not explain why today is shown in the PDF output instead of the resolved date 🤔

Thank you for taking the initiative, Christophe (@cderv).

This is definitely not working as it should - I will take a look! Thanks for reporting it and digging in!

I also just stumbled across this. Not sure if helpful, but I've noted that date keywords (kind of) work for PDF output inside a quarto project. Only kind of, because the date-format has no effect. Have created a minimum working example here.

Thanks @pat-alt, it means the project structure is directly related. This is not the first case where something works differently on Project vs single file.

@dragonstyle If you want me to have a deeper look, I can do it.

I should have a fix in for this tomorrow AM! I'll post here when its ready...

Jus building a release that should have the changes the make this work seamlessly across any format...