# Output depending on crossreferences

I want to write a specification. It has a section listing all features. Another section lists tests. Each test must reference the feature it tests.

Now by TeX-magic, I want untested features be colored red. I also want features to get a list of tests, which test it. Ideally clickable references to jump back and forth in pdfs and numbered.

More concretely, a hypothetical specification:

\begin{document}
\feature{Features have a List of Tests}{at-feature-list}
The first part is the title, the second a label, like for \\label
\feature{Untested Features are red}{123}
\feature{Tests link to Features they test}{crossref}

\ftest{A list of Features}{at-feature-list,123}
Create an example listing...
\end{document}


It should output like

F1. Features have a List of Tests

Tested by: T1

The first part is the title, the second a label, like for \label

F2. Untested Features are red

Tested by: T1

F3. Tests link to Features they test (colored red!)

Tested by: -

T1. A list of Features

Testing: F1, F2


As far as I know, there is no package for this. Implementing \feature and \ftest probably implementing something similar to \label and \ref.

• this can be done using rdfref package, I thing. It doesn't have documentation, unfortunately. but you can see what it can do in this answer, or another one – michal.h21 Dec 2 '16 at 19:40

Thanks to michal.h21 and his rdfref package I was able to build something, which is nearly there.

The relevant part of the document looks like this:

\section*{Funktionen}

\functionality{Foo}{fnc:foo}
\functionality{Bar}{fnc:bar}

\section*{Tests}

\test{First Start}{tst:first}
\tests{fnc:bar}

\test{Trial}{tst:trial}
\tests{fnc:bar}


The output is:

Funktionen
F1 Foo   Tested by:
F2 Bar   Tested by: T1 T2

Tests

T1 First Start   Testing: F2
T2 Trial   Testing: F2


The TeX macros to get there are:

\newcommand\tests[1]{

{ \GetProperty{#1}{pfl:tstid} }}
{ \GetProperty{#1}{pfl:fncid} }}

\newcounter{functionality}
\newcounter{test}

\newcommand\functionality[2]{
\stepcounter{functionality}
\par\textbf{F\arabic{functionality} #1}\rdflabel{#2}
\IfProperty{#2}{pfl:is-fulfilled}{%
}{{\color{red}{NOT TESTED}}}
\par}

\newcommand\test[2]{
\stepcounter{test}
\par\textbf{T\arabic{test} #1}\rdflabel{#2}

The \AddProperty calls are relative to the previous \rdflabel and store triples like (tst:trial,pfl:tests,fnc:bar).
Then \Bind{?t}{pfl:tests}{#2}{ \testlink{\GetVal{?t}} } outputs the list of links. The query (?t,pfl:tests,fnc:bar) looks for all triples, where the second and third element matches. It outputs a \testlink for each found triple with ?t bound to the first triple element.
There is also the (id,pfl:is-tested,yeah) triples. They are used for the \IfProperty checks. If there is no such triple for an id, then a red warning NOT TESTED is printed, instead of the backlinks.