# Changelog from file

I'm trying to get a very nice changelog table in my template and I'm trying to do that using the table of contents way (so writing to a file and reading from that afterwards). This works well, however it doesn't allow me (as far as I can see) to write these lines into a REAL table (so not a toc, but like a tabu or tabularx).

Anyone here who can help me with this?

Here is what I tried:

\documentclass{article}
\usepackage{hyperref}
\usepackage{verbatim}
\usepackage{tabu}
\makeatletter
\newcommand{\l@changelogline[2]}{
#2\\
}
\makeatother

\newcommand{\changelog}{
%\csname @starttoc\endcsname{cl}%
\begin{tabu} spread \textwidth {l l l X[l]}
\csname @starttoc\endcsname{cl}%
\end{tabu}
}
\addcontentsline{cl}{changelogline}{V0.1 & 21-02-2018 & Foitn & Initial version}
\addcontentsline{cl}{changelogline}{V0.2 & 22-02-2018 & Foitn & Some kind of change}
\begin{document}
asdf
\bigskip
\changelog
\end{document}


Right now it's giving me this error:

Missing } inserted. ...18 & Foitn & Initial version}{1}{Doc-Start}
Missing \endgroup inserted. ...18 & Foitn & Initial version}{1}{Doc-Start}

• The problem is, that \@starttoc starts with a \begingroup which wouldn't be ended in the cell of tabu. – Skillmon likes topanswers.xyz Feb 23 '18 at 10:58

That's the code I used to create the file. It doesn't write to the *.aux file, but directly to \jobname.cl.

\documentclass{article}
\usepackage{hyperref}
\usepackage{verbatim}
\usepackage{tabu}
\makeatletter
\newwrite\@changelog
\newcommand*\changelog@filename{\jobname.cl}
\newcommand*\changelog
{%
\IfFileExists{./\changelog@filename}
{%
\begin{tabu} spread \textwidth {l l l X[l]}%
\input{\changelog@filename}
\end{tabu}%
}{}%
}
\newcommand*\changelog@contents{}
{%
\xdef\changelog@contents
{%
\unexpanded\expandafter{\changelog@contents
#1 & #2 & #3 & #4\string\\
}%
}%
}
\AtEndDocument
{%
\immediate\openout\@changelog=\changelog@filename
\immediate\write\@changelog{\changelog@contents}%
\immediate\closeout\@changelog
}
\makeatother
\begin{document}
asdf
\bigskip
\changelog
\end{document}


Working way of using \addtocontents and the like:

\documentclass{article}
\usepackage{hyperref}
\usepackage{verbatim}
\usepackage{tabu}
\makeatletter
\newwrite\@changelog
\newcommand*\changelog@extension{cl}
\newcommand*\changelog@filename{}
\edef\changelog@filename{\jobname.\changelog@extension}
\newcommand*\changelog
{%
\IfFileExists{./\changelog@filename}
{%
\begin{tabu} spread \textwidth {l l l X[l]}%
\input{\changelog@filename}
\end{tabu}%
}{}%
\bgroup
\renewcommand*\changelogline[4]{}%
\@starttoc{\changelog@extension}%
\egroup
}
\newcommand*\changelog@contents{}
\newcommand*\changelogline[4]{#1 & #2 & #3 & #4\\}
{%
{\protect\changelogline{#1}{#2}{#3}{#4}}%
}
%\show\@starttoc
\makeatother
\begin{document}
asdf
\bigskip
\changelog
\end{document}

• Looks very good! Thank you for the effort! Though, the addtocontents doesn't seem to work. After a little googling I found that this command only works for toc, lot & lof. I'll keep searching to write to a different file – Foitn Feb 23 '18 at 10:55
• the file is not created on my pc :( – Foitn Feb 23 '18 at 11:12
• @Foitn Guess that's my fault, I did create it with a different code beforehand and didn't delete it in between. – Skillmon likes topanswers.xyz Feb 23 '18 at 11:14
• wow, this works like a charm, thank you so much! – Foitn Feb 23 '18 at 12:04