Reputation: 1435
The custom date works in RMarkdown-pdf but I noticed Quarto doesn't.
How can I use custom date in Quarto YAML?
---
title: "Some pdf document"
author: "me"
date: "Spring 2022" <- I would like to use this
format: pdf
----
---
title: "Some pdf document"
author: "me"
date: "Last update : `r Sys.Date()`" <- Or, like this
format: pdf
----
Current Quarto-pdf generates %m/%d/%Y format date only.
Upvotes: 7
Views: 2319
Reputation: 11
This page specifies the commands for Quarto.
https://quarto.org/docs/reference/dates.html
You specify the date and its format separately in your yaml, e.g.:
date: today
date-format: "DD/MM/YYYY"
This would output 25/03/2024
Upvotes: 1
Reputation: 20017
You can provide last-modified
keyword (which refers to the last modified date and time of the file containing the date) to date and use date-format
to modify the date. Also you can put additional words in between square brackets which will be then escaped and kept as is.
---
title: "Some pdf document"
author: "me"
date: last-modified
date-format: "[Last Updated on] MMMM, YYYY"
format: pdf
---
Now, since there is no format-string for season name, it is possible make one using Pandoc Lua filter.
---
title: "Some pdf document"
author: "None"
date: last-modified
date-format: "[Last Updated on] %MMM%, YYYY"
format: pdf
filters:
- custom-date.lua
---
Note Here we have used %MMM%
, which will be replaced by season name.
custom-date.lua
local function replace_mon_with_season(date)
local season_table = {
Jan = "Winter", Feb = "Winter", Mar = "Spring",
Apr = "Spring", May = "Spring", Jun = "Summer",
Jul = "Summer", Aug = "Summer", Sep = "Autumn",
Oct = "Autumn", Nov = "Autumn", Dec = "Spring"
}
local date = pandoc.utils.stringify(date)
local mon = date:match("%%(%a+)%%")
local season = season_table[mon]
return date:gsub("%%" .. mon .. "%%", season)
end
function Meta(m)
m.date = replace_mon_with_season(m.date)
return m
end
Upvotes: 10