# A problem with using the \ganttbar macros inside another one

I'm trying to write a macros for converting day time to a format, which the pgfgrantt package can understand. Here it is:

\newcommand{\htime}[2][0]{
\StrBefore{#2}{:}[\hours]
\StrBehind{#2}{:}[\minutes]
\pgfmathparse{\hours+\minutes/60+#1}
\pgfmathresult
}

\newcommand{\gantthbar}[3]{
\def\from{\htime[1]{#2}}
\def\to{\htime{#3}}
\ganttbar{#1}{\from}{\to}
}

% \gantthbar{test}{11:15}{12:00} -> \ganttbar{test}{12.25}{12.0}


Compilation failed with an error, I can't resolve:

! Use of \\ganttbar doesn't match its definition.
\kernel@ifnextchar ...rved@d =#1\def \reserved@a {
#2}\def \reserved@b {#3}\f...
l.37   \gantthbar{test}{11:15}{12:00}

?


This one compiles without errors:

\newcommand{\gantthbar}[3]{
\def\from{\htime[1]{#2}}
\def\to{\htime{#3}}
\ganttbar{#1 \from \to}{12.25}{12.0}
}


\documentclass[a4paper, 12pt]{report}

\usepackage{xstring}
\usepackage{pgfgantt}

\newcommand{\gantthbar}[3]{
\StrBefore{#2}{:}[\hoursfrom]
\StrBehind{#2}{:}[\minutesfrom]
\StrBefore{#3}{:}[\hoursto]
\StrBehind{#3}{:}[\minutesto]
\pgfmathsetmacro\from{\hoursfrom + \minutesfrom / 60 + 1}
\pgfmathsetmacro\to{\hoursto + \minutesto / 60}
\ganttbar{#1}{\from}{\to}
}

\begin{document}
\begin{ganttchart}[vgrid]{24}
\gantthbar{test}{11:15}{12:00}
\end{ganttchart}
\end{document}

• Welcome to TeX-SX! Have a look at our starter page for a quick intro if you wish to familiarize yourself with our format. – Claudio Fiandrino Jul 29 '13 at 14:48
• Please provide a minimal working example (MWE). Guessing from what you have there: Neither \from nor \to are fully expandable (they contain xstring macros and \pgfmathparse). Another approach is needed, e.g. let \htime assign a variable like \pgfmathsetmacro\myFrom{…} or use \pgfmathresult directly in the parameters to \ganttbar. – Qrrbrbirlbel Jul 29 '13 at 15:04
• That being said, pgfgantt only understands integer values for the time slots (slots being the important word here). You might be interested in my answer to Gantt chart with title list in minutes and hours which could be customized in the same way so that you can use the h:mm format for the input, too. – Qrrbrbirlbel Jul 29 '13 at 15:24