4

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.

Matthew Son
  • 1,109
  • 8
  • 27

1 Answers1

6

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


shafee
  • 15,566
  • 3
  • 19
  • 47