Custom date for Quarto YAML header pdf document
Asked Answered
G

2

7

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.

Galvano answered 1/2, 2023 at 19:5 Comment(0)
M
9

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
---

screenshot of pdf output


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

pdf output screenshot


Mongol answered 1/2, 2023 at 19:14 Comment(1)
It prints "February, 2023". How can I print "Spring 2023" or "Last update: February, 2023"?Galvano
F
1

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

Freida answered 25/3 at 10:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.