I want to fill in an already printed form. The form has boxes to write down current date. How can I expand current date so that it look like 1 4 0 2 2 0 2 2 with a space between the digits
2 Answers
Here, I use the datetime package to get the proper order and format of date digits...I then use a tokencycle to insert a space after each digit.
\documentclass{article}
\usepackage{datetime,calc,tokcycle}
\Characterdirective{\addcytoks{#1\ }}
\newcommand{\customtoday}{\expandedtokcyclexpress
{\twodigit{\the\day}\twodigit{\the\month}\the\year}\the\cytoks\unskip}
\begin{document}
Custom date is \customtoday.
\end{document}
- 237,551
If you want the digits to fit in some predetermined boxes, you want to enclose each one in a box of the appropriate width, so I offer an optional argument to visually fix the needed width.
\documentclass{article}
\ExplSyntaxOn
\NewDocumentCommand{\spacedcurrentdate}{O{1em}}
{
\exp_args:Ne \tl_map_inline:nn
{
\int_compare:nT { \c_sys_day_int < 10 } { 0 }
\int_use:N \c_sys_day_int
\int_compare:nT { \c_sys_month_int < 10 } { 0 }
\int_use:N \c_sys_month_int
\int_use:N \c_sys_year_int
}
{ \makebox[#1]{##1} }
}
\ExplSyntaxOff
\begin{document}
X\spacedcurrentdate X
X\spacedcurrentdate[1.2em]X
\end{document}
- 1,121,712

