We're working on a technical document where we define messages in different chapter/section all over the document. All messages have the same structure and are displayed in a table. We thought that it would be nice to have a list with all these messages at the end of the document.
So I started working on a solution, that all table entries get stored in a separate file, which will be included at the end of the document.
This is my working solution:
\documentclass{article}
\RequirePackage{fontspec}
\usepackage{longtable, colortbl,environ}
\NewEnviron{tbl}
{%
\begin{longtable}{|p{2cm}|p{2cm}|p{2cm}|p{2cm}|}%
\hline\rowcolor[gray]{.8}%
Column 1 & Column 2 & Column 3 & Column 4\\\hline%
\endhead%
\BODY%
\end{longtable}%
}
\newwrite\mytabularwrite
\newcommand{\writetotablefile}[1]{\immediate\write\mytabularwrite{\unexpanded{#1}}}
\newcommand{\myrow}[4]{\writetotablefile{\unexpanded{#1\\\hline}}%
#1\\\hline%
}
\AtBeginDocument{\immediate\openout\mytabularwrite=\jobname-table.tex}
\AtEndDocument{}
\begin{document}
\section{Table 1}
\begin{tbl}
\myrow{1äöü€}{2}{3}{4}
\end{tbl}
\section{Table 2}
\begin{tbl}
\myrow{5}{6}{7}{8}
\end{tbl}
\section{Complete Table}
\begin{tbl}
% ATTENTION: Starting with that point here: don't use \myrow anymore! Temp. file is already closed.
\immediate\closeout\mytabularwrite
\input{\jobname-table}
\end{tbl}
\end{document}
The problem, I had to solve, was that (La)TeX cannot write text in append mode to a file. I found workarounds like: reading the tempfile, add my new data, store tempfile, repeat... But I think that is not efficient.
I now open the tempfile with the begin of the document and close it before including the tempfile for the final table.
Ok, I have a working solution, where's the problem? There currently is no problem. But I would like to ask, if there is a better way solving that problem.
Bye & thx, aronadaal


list of ...would be easier, I think! – Jul 02 '16 at 11:34list ofwith a structured information like the message, that consists of 4 parts? – aronadaal Jul 02 '16 at 11:37