GeneralCrossing Reference

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
darkilious
Posts: 1
Joined: Fri Jun 24, 2022 12:24 pm

Crossing Reference

Post by darkilious »

I try to establish a crossing link to check if all variables used are defined somewhere in the document. The goal is to identify impact when a variable is modify, and when a variable isn't defined. The final objectiv is to have more quality in a software specification.

For that, I store all variables in two arrays (one for used, one for definition) and at the end I evaluate if each variable in in the used array are present in the defined array. The crossing link, distribution and security about not defined variables work well. The problem is on the link in the "Matrix" table, all link to the same.

You can find the code below :

Code: Select all

\documentclass{article}

\usepackage{xinttools}
\usepackage{hyperref}
\hypersetup{colorlinks=true}

\newcounter{Cpt}
\newcommand{\VARRRI}{}
\newcommand{\VARRRO}{}


\makeatletter
\newcommand{\DefVariable}[1]{  \textbf{#1}  \phantomsection  \def\@currentlabel{#1}  \label{[var@#1]}  \g@addto@macro\VARRRI{{var@#1}} \global\@namedef{var@#1@ismetby}{} }

\newcommand{\meetsreqY}[1]{\@ifundefined{r@[var@#1]}{THIS VARIABLE ISN T DEFINED #1 !!}{{} \expandafter\g@addto@macro\csname var@#1@ismetby\expandafter\endcsname \expandafter {\expandafter{\@currentspece}}}}

\newcommand{\specswithreqY}[1] {\xintListWithSep{, }{\xintApply { \nameref}{\csname #1@ismetby\endcsname }}}

\newcommand{\specY}[1]{\label{va@#1}\xdef\@currentspece{va@#1}}

\newcommand{\UseVariable}[1]{\stepcounter{Cpt}\specY{\theCpt}\ref{[var@#1]}  \g@addto@macro\VARRRO{{#1} } }
\makeatother


\begin{document}

\section{section1}
\DefVariable{MeasureVoltage1} : Hardware input

\section{section2} 
\DefVariable{FaultOvervoltage} : \UseVariable{MeasureVoltage1} sup to 50

\section{section5}
\DefVariable{TotalVoltage} : \UseVariable{MeasureVoltage1} add with \UseVariable{MeasureVoltage2}

\section{section3}
\DefVariable{MeasureVoltage2} : I define this variable

\section{section4} 
\DefVariable{FaultOvervoltage} : \UseVariable{MeasureCurrent} sup to 50

\clearpage
\section{Tracability MAtrix}

\xintFor* #1 in \VARRRO\do {\meetsreqY{#1}}

\begin{table}[htbp]
\begin{tabular}{|l|l|}
\hline
section where variable is defined & section where variable is used    \\ 
\hline
\xintFor* #1 in \VARRRI\do {  \ref{[#1]}&\specswithreqY{#1}\\\hline }

\end{tabular}
\end{table}

\end{document}
Thanks in advance for your support.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX books
Post Reply