This is a spinoff of another question I posted here.
\documentclass[8pt]{book}
\usepackage{etoolbox}
\usepackage{hyperref}
\newcommand{\mychapter}[1]{\chapter{#1} \hypertarget{chapter::\theHchapter}{}}
\newcommand{\refChapter}{\hyperlink{chapter::\theHchapter}{\thechapter}}
\newcommand{\addTimeline}[2]{%
\ifcsname timeLine#1\endcsname
\csappto{timeLine#1}{\unexpanded{\\& #2 & } \thechapter}%
\else
\csdef{timeLine#1}{\unexpanded{\\\textbf{#1} & #2 & } \thechapter}%
\fi
}
\newcount\timelineCounter
\newcommand{\printTimeline}[2]{%
\def\timelineData{}%
\timelineCounter=#1\relax
\loop \ifnum \timelineCounter<#2
\edef\timelineData{\expandonce{\timelineData}\csuse{timeLine\the\timelineCounter}}%
\advance \timelineCounter 1
\repeat
\begin{tabular}{c p{7cm} c}
\timelineData
\end{tabular}
}
\begin{document}
\mychapter{First}
\addTimeline{4}{Event1}
\addTimeline{19}{Event2}
\addTimeline{2}{Event3}
\mychapter{Second}
\addTimeline{29}{Event4}
\addTimeline{15}{Event5}
\addTimeline{19}{Event6}
\mychapter{Timeline}
\printTimeline{1}{30}
\end{document}
I expected it to print two empty chapters followed by a Chapter 3, called Timeline with
2 Event3 1
4 Event1 1
15 Event5 2
19 Event2 1
Event6 2
29 Event4 2
but instead in the third column I get all "3". In the ideal scenario I'd use \refChapter
command that I created, instead of the \thechapter
, but the former doesn't compile. I am a bit clueless as how to expand this kind of expression. Any guidance would be appreciated.