# Probably a gdef-expansion problem, but how to solve?

Trying to integrate the answer of this post it into my real code, I face the error

Argument of \timedelta@i has an extra }

when calling the proposed method. Upto now, I've not been able to fix it. Can you help? Thx.

My current code

\documentclass{article}
\usepackage{multirow}
\usepackage{fontawesome}

% Routes Details
\newcommand{\routeInitial}[3]{%{icon}{Description}{startTime}
& #1 & #2\\
\multirow{1}{*}[1.5ex]{#3}%
\gdef\routeFrom{#3}%
}

\newcommand{\routeStep}[3]{%{icon}{Description}{toTime}
\timedelta{\routeFrom}{#3}\relax & #1 & #2\\%
\multirow{1}{*}[1.5ex]{#3}%
\gdef\routeFrom{#3}%
}

\newcommand{\routeFinal}[2]{%{icon}{Description}
& #1 & #2\\%
}

% Duration
\makeatletter
\newcommand{\timedelta}[2]{\romannumeral0\timedelta@i#1:#2:}%
\def\timedelta@i #1:#2:#3:#4:%
{\expandafter\timedelta@ii\the\numexpr#3*60+#4-#1*60-#2.}%
\def\timedelta@ii#1{\expandafter\timedelta@iii\the\numexpr
\if-#11440\fi #1}%
\def\timedelta@iii#1.{\expandafter\timedelta@iv\the\numexpr
(#1 + 30)/60 -1.#1.}%
\def\timedelta@iv #1.#2.{\expandafter\timedelta@v\the\numexpr
100+#2-60*#1\expandafter.\the\numexpr100+#1.}
\def\timedelta@v 1#1.1#2.{ #2:#1}
\makeatother

\begin{document}

\timedelta{16:03}{17:46}\\% This is working !

\begin{tabular}{lcl}
\routeInitial{\faicon{home}}{}{16:03}%
\routeStep{\faicon{car}}{}{17:46}% This is not working ! Argument of \timedelta@i has an extra }
\routeStep{\faicon{beer}}{}{17:58}
\routeStep{\faicon{car}}{}{18:23}
\routeStep{\faicon{cutlery}}{Royal Wok}{20:20}
\routeStep{\faicon{car}}{}{22:44}
\routeStep{\faicon{female}}{}{22:50}
\routeStep{\faicon{car}}{}{01:27}
\routeFinal{\faicon{hotel}}{Seligweiler}
\end{tabular}

\end{document}

• I have updated my original answer to your original post to makethe \timedelta automatically expand its two arguments. I should have done that initially, this would have avoided you quite a few troubles, sorry. – user4686 Nov 8 '17 at 22:12

I can't verify this completely, because FontAwesome isn't running on my machine, but you have to expand \routeFrom in the argument of \timedelta for \routeStep. Otherwise the structure of the data you give to \timedelta@i doesn't match your pattern. The following should work (and does if I remove the fontawesome related commands):

\documentclass{article}
\usepackage{multirow}
\usepackage{fontawesome}

% Routes Details
\newcommand{\routeInitial}[3]{%{icon}{Description}{startTime}
& #1 & #2\\
\multirow{1}{*}[1.5ex]{#3}%
\gdef\routeFrom{#3}%
}

\newcommand{\routeStep}[3]{%{icon}{Description}{toTime}
\expandafter\timedelta\expandafter{\routeFrom}{#3}\relax & #1 & #2\\%
\multirow{1}{*}[1.5ex]{#3}%
\gdef\routeFrom{#3}%
}

\newcommand{\routeFinal}[2]{%{icon}{Description}
& #1 & #2\\%
}

% Duration
\makeatletter
\newcommand{\timedelta}[2]{\romannumeral0\timedelta@i#1:#2:}%
\def\timedelta@i #1:#2:#3:#4:%
{\expandafter\timedelta@ii\the\numexpr#3*60+#4-#1*60-#2.}%
\def\timedelta@ii#1{\expandafter\timedelta@iii\the\numexpr
\if-#11440\fi #1}%
\def\timedelta@iii#1.{\expandafter\timedelta@iv\the\numexpr
(#1 + 30)/60 -1.#1.}%
\def\timedelta@iv #1.#2.{\expandafter\timedelta@v\the\numexpr
100+#2-60*#1\expandafter.\the\numexpr100+#1.}
\def\timedelta@v 1#1.1#2.{ #2:#1}
\makeatother

\begin{document}

\timedelta{16:03}{17:46}\\% This is working !

\begin{tabular}{lcl}
\routeInitial{\faicon{home}}{}{16:03}%
\routeStep{\faicon{car}}{}{17:46}% This is not working ! Argument of \timedelta@i has an extra }
\routeStep{\faicon{beer}}{}{17:58}
\routeStep{\faicon{car}}{}{18:23}
\routeStep{\faicon{cutlery}}{Royal Wok}{20:20}
\routeStep{\faicon{car}}{}{22:44}
\routeStep{\faicon{female}}{}{22:50}
\routeStep{\faicon{car}}{}{01:27}
\routeFinal{\faicon{hotel}}{Seligweiler}
\end{tabular}

\end{document}

• +1 and let's keep quiet else the LaTeX3 guys will comme haunt us and explain how simply they could have changed their macro to expand its arguments, simply by some "generate variant" xparse command... – user4686 Oct 28 '17 at 16:28
• @jfbu I could have done that in expl3, but I think the OP wanted to know where the error was, and not see 5 different approaches which wouldn't have this error :) – Skillmon Oct 28 '17 at 16:52
• What do I have to do to make it work with a gdef as 2nd argument? Let's say I have: \gdef\routeStop{01:27} But when I call the method: \expandafter\timedelta{16:03}\expandafter{\routeStop} I get the exception: Paragraph ended before \timedelta@i was complete. – Joseph Marie Nov 8 '17 at 13:27
• In general \gdef isn't expandable, so I'd guess that's the problem here, but I don't understand what you exactly called from your comment... – Skillmon Nov 8 '17 at 16:25
• I made a new post with a complete code sample here: tex.stackexchange.com/questions/400356/… – Joseph Marie Nov 8 '17 at 18:33

With the code I proposed in another answer

\documentclass{article}
\usepackage{xparse}
\usepackage{multirow}
\usepackage{fontawesome}

\ExplSyntaxOn

\NewExpandableDocumentCommand{\timedelta}{mm}
{
\joseph_timediff:ff { #1 } { #2 }
}

\cs_new:Nn \joseph_timediff:nn
{
\__joseph_timediff:ff
{ \__joseph_minutes:w #1 \q_stop }
{ \__joseph_minutes:w #2 \q_stop }
}
\cs_generate_variant:Nn \joseph_timediff:nn { ff }

\cs_new:Nn \__joseph_timediff:nn
{
\joseph_output:f
{
\int_eval:n { (#2) - (#1) \int_compare:nNnT { #2 } < { #1 } { + 1440 } }
}
}
\cs_generate_variant:Nn \__joseph_timediff:nn { ff }

\use:x
{
\cs_new:Npn \exp_not:N \__joseph_minutes:w ##1 \token_to_str:N : ##2 \exp_not:N \q_stop
}
{
#1 * 60 + #2
}

\cs_new:Nn \joseph_output:n
{
\int_compare:nNnT { \int_div_truncate:nn { #1 } { 60 } } < { 10 } { 0 }
\int_div_truncate:nn { #1 } { 60 }
:
\int_compare:nNnT { \int_mod:nn { #1 } { 60 } } < { 10 } { 0 }
\int_mod:nn { #1 } { 60 }
}
\cs_generate_variant:Nn \joseph_output:n { f }

\ExplSyntaxOff

% Routes Details
\newcommand{\routeInitial}[3]{%{icon}{Description}{startTime}
& #1 & #2\\
\multirow{1}{*}[1.5ex]{#3}%
\gdef\routeFrom{#3}%
}

\newcommand{\routeStep}[3]{%{icon}{Description}{toTime}
\timedelta{\routeFrom}{#3} & #1 & #2\\%
\multirow{1}{*}[1.5ex]{#3}%
\gdef\routeFrom{#3}%
}

\newcommand{\routeFinal}[2]{%{icon}{Description}
& #1 & #2\\%
}

\begin{document}

Test of \verb|\timedelta|: \timedelta{22:40}{22:50}

\bigskip

\begin{tabular}{lcl}
\routeInitial{\faicon{home}}{}{16:03}
\routeStep{\faicon{car}}{}{17:46}
\routeStep{\faicon{beer}}{}{17:58}
\routeStep{\faicon{car}}{}{18:23}
\routeStep{\faicon{cutlery}}{Royal Wok}{20:20}
\routeStep{\faicon{car}}{}{22:44}
\routeStep{\faicon{female}}{}{22:50}
\routeStep{\faicon{car}}{}{01:27}
\routeFinal{\faicon{hotel}}{Seligweiler}
\end{tabular}

\end{document}