可能是 gdef 扩展问题,但如何解决?

可能是 gdef 扩展问题,但如何解决?

尝试整合这个问题的答案邮政将它放入我的真实代码中,我面临错误

\timedelta@i 的参数有一个额外的 }

调用建议的方法时。到目前为止,我还没能修复它。你能帮忙吗?谢谢。

我当前的代码

\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}

答案1

我无法完全验证这一点,因为我的机器上没有运行 FontAwesome,但你必须扩展for\routeFrom的参数。否则,你提供的数据结构与你的模式不匹配。下面的代码应该有效(如果我删除相关命令,它也会有效):\timedelta\routeStep\timedelta@ifontawesome

\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}

答案2

使用我提出的代码另一个答案

\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}

在此处输入图片描述

相关内容