2

I need to convert a date from one format to another. This is a very simple problem that has already been solved in the topic Latex convert Date string format from mm/dd/yyyyy to dd/MM/yyyy. However, there is a peculiarity in my case. The date is determined through \def\date#1{\def\thedate{#1}} and in this case the error Paragraph ended before \todots was complete occurs:

\documentclass{article}

\def\date#1{\def\thedate{#1}}
\def\datetodots#1{\todots#1\relax}
\def\todots#1-#2-#3\relax{#1.#2.#3}

\begin{document}

\date{3-10-2023}

\thedate

\datetodots{\thedate}

\end{document}

This is a minimal example, but it is part of a huge class in which the editor, in different commands defines different dates for processing the article and, via different variants of \def\date#1{\def\thedate{#1}} macro, defines several dates that need to be displayed and save to a file in different formats. Is it possible to solve the problem without using xstring and LaTeX3? I will be grateful to the community for help and tips.

1 Answer 1

5

You want to expand the argument before calling \todots.

\documentclass{article}

\def\date#1{\def\thedate{#1}}
\def\datetodots#1{\expandafter\todots\expanded{#1}\relax}
\def\todots#1-#2-#3\relax{#1.#2.#3}

\begin{document}

\date{3-10-2023}

\thedate

\datetodots{\thedate}

\datetodots{3-10-2023}

\end{document}

enter image description here

1
  • Exactly! Thank you!
    – Crosfield
    Oct 2 at 21:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .