I have a time value in the format HH:MM (i.e 03:00).

I need to compute the TotalMinutes of this time (expected result 180).

My current code is






but unfortunatelly, it gives me error:

Runaway argument?

\tOne \\end {document}

! File ended while scanning use of \timeHHMMToTotalMinutes@h.

How to I solve this? What did I misunderstood about argument parsing?

  • 1
    You have to expand \tOne before calling \timeHHMMToTotalMinutes. \expandafter\timeHHMMToTotalMinutes\expandafter{\tOne} would work. Adding an \expandafter to the command definition also works: \newcommand{\timeHHMMToTotalMinutes}[1]% {\expandafter\timeHHMMToTotalMinutes@h#1}% – Phelype Oleinik Jun 12 '18 at 11:33

According to your definition, the input


gets transformed into


Since the auxiliary macro expects to see


TeX will look for a colon until getting to a \par token or the end of the file. The reason is that TeX does no macro expansion when collecting arguments to macros.

Thus you need to expand \tOne before TeX expands \timeHHMMToTotalMinutes@h and starts looking for its arguments.

Anyhow, there is another fix to do. If you define


then your call will become first


and then

\timeHHMMToTotalMinutes@h 03:00

The collected arguments will be 03 for #1 and 0 for #2. The second 0 will remain in the input stream and you'll get


which provides the correct result, but by chance. Something like


will surprise you. Better delimiting also the second argument and terminating \numexpr with \relax.








This prints 18023. You code, with just \expandafter added would print 203.

  • Do we have to handle the expansion for a "more than one" argument command in a different way? With the following code, I still get the same error: \newcommand{\timeStamp}[2]{%{#1-Date (YYYY.MM.DD)}{#2-Time (HH:MM)} \expandafter\timeStamp@t#1 #2\@nil%}% \def\timeStamp@t#1.#2.#3 #4:#5\@nil{% \the\numexpr#5+#4*60+(#3-1)*60*24+(#2-1)*60*24*31+(#1-2017)*60*24*31*365\relax% }%...\def\tOne{03:00}%\def\dOne{2017.08.01}%\timeStamp{\dOne}{\tOne}\\% – Joseph Marie Jun 18 '18 at 10:01
  • @JosephMarie It's very difficult to read the code in comments; please ask a followup question. – egreg Jun 18 '18 at 10:03
  • Indeed! Here is my new question: tex.stackexchange.com/questions/436868/… – Joseph Marie Jun 18 '18 at 10:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.