7

I like to print dates formatted in this way: 6 October 2018. Usually, I just type the date by hand. But I tried to set things up so that \today would format dates the way I like. I must have only tested it when the day number was two digits. I have this:

\documentclass{article}
\usepackage[english]{datetime2}
\DTMnewdatestyle{strunkdate}{%
  \renewcommand*{\DTMdisplaydate}[4]{##3 \DTMenglishmonthname{##2} ##1}
  \renewcommand*{\DTMDisplaydate}{\DTMdisplaydate}}
\AtBeginDocument{%
  \DTMsetdatestyle{strunkdate}}% after babel loaded, or babel stomps on this
\begin{document}
Today is \today.
\end{document}

Unfortunately, this prints 06 October 2018, with a leading zero to force a two-digit day. How do I get 6 October 2018, without the leading zero?

dedded
  • 2,236

1 Answers1

9

The package may have a specific command, but you can use the TeX \number command

\documentclass{article}
\usepackage[english]{datetime2}
\DTMnewdatestyle{strunkdate}{%
  \renewcommand*{\DTMdisplaydate}[4]{\number##3\ \DTMenglishmonthname{##2} ##1}
  \renewcommand*{\DTMDisplaydate}{\DTMdisplaydate}}
\AtBeginDocument{%
  \DTMsetdatestyle{strunkdate}}% after babel loaded, or babel stomps on this
\begin{document}
Today is \today.
\end{document}
David Carlisle
  • 757,742
  • 1
    That's actually the method recommended by the manual of datetime2, page 95. No caveat about the problem of following space, unfortunately. – egreg Oct 06 '18 at 19:48
  • 1
    @egreg didn't occur to me to look in a manual! – David Carlisle Oct 06 '18 at 19:56
  • In order to preserve full expandability to character tokens, \number\numexpr##3\relax\space\DTMenglishmonthname{##2} ##1 could be better. – egreg Oct 06 '18 at 20:04
  • @egreg I did wonder about that but expansion unlikely to be needed here I would guess and \ looks nicer in the code and doesn't require an essay on what it does:-) – David Carlisle Oct 06 '18 at 20:09
  • Works great! Is the expandability that you're worried about, @egreg, that of the characters in the day number itself? – dedded Oct 06 '18 at 21:08
  • @dedded If you want to use the date for other purposes, splitting it in parts, for instance, having control sequences in the middle can be of a hindrance. But probably it's not the case with your application. – egreg Oct 06 '18 at 21:26
  • Nothing like that. I can imagine passing it whole to another command. – dedded Oct 06 '18 at 22:07