0

I have a list a 4 items that I would like to link it the following results 1) 2) 3) and 4) as shown below.

My MWE

\documentclass{article}
\usepackage{enumitem}

\begin{document}

\begin{enumerate}
    \item This is item 1. %  this item is linked to --> 1) 
    \item This is item 2.  % this item is linked to --> 2) 
    \item This is item 3. % this item is linked to --> 3) 
    \item This is item 4. % this item is linked to --> 4) 
\end{enumerate}

% Results are shown below.

1) xyz \\ 2) abc \\ 3) mno \\ 4) rst 

\end{document}

By linking I mean, if I remove \item 1 from the list, result 1) xyz will also be removed. If I move \item 3 above \item 2 so will result 3) mno move in front of 2) abc so that at all times every \item is consistent with the results in terms of relative placement.

I have tried to use the footnote approach to solve this problem, but it was getting out of hand for me and my limited knowledge of LaTeX. I was wondering if there was a way I could 'tag' each item and result.

EDIT:

Maybe if I can reword it/simplify the issue.

Suppose I have two lists of n items.

% This is my primary list. I will modify this by moving an item up/down or removing it.

\begin{enumerate}
    \item This is item 1 in primary list. 
    \item This is item 2 in primary list.  
    \item This is item 3 in primary list. 
    \item This is item 4 in primary list. 
\end{enumerate}

% This is my secondary list.


\begin{enumerate}
    \item This is item 1 in secondary list. 
    \item This is item 2 in secondary list.  
    \item This is item 3 in secondary list. 
    \item This is item 4 in secondary list. 
\end{enumerate}

Now if I do the following:

a) shift item 3 from the primary list by up by one, item 3 from the secondary list will also move up by one. b) remove item 3 from the primary list, item 3 from the secondary list will also be removed.

2
  • I'm not quite clear on what you are asking for. Do you require regular citations (like \cite{item}) so that if you remove "item" the citation will disappear, or do you need some sort of secondary list or table with elements that mirror the enumerate items you have created?
    – Plergux
    Oct 31, 2020 at 9:38
  • Yes, I need a some sort of s secondary list/table that mirror the enumerate items. It's like if I give you an enumerate list with say 3 items and those 3 items come with a list/table with 3 results that corresponding to each item. I want to be able to move the enumerate list up/down/remove so that it will change the secondary list up/down/remove.
    – Alan Jones
    Oct 31, 2020 at 19:46

1 Answer 1

1

UPDATED ANSWER Can be done without much fuss in lualatex. There are two list to maintain: the name of the Test and the corresponding Result. I think the code is simple to understand.

\documentclass[12pt,a4paper]{article}   
\usepackage{luacode}
\usepackage{xparse}

\usepackage{filecontents}% remove in new LaTeX  installations

\begin{filecontents*}{"MechTestsi.lua"}
return {
    'Tensile test',
    'Compression test', 
    'Bending test',  
    'Torsion test',  
    'Creep rupture test',  
    'Brinell', 
    'Rockwell',  
    'Vickers',  
    'Impact test',  
    'Wohler fatigue test'
}
\end{filecontents*}

\begin{filecontents*}{"TestsResultsi.lua"}
return {
    'Te 84–107 Mpa pass',
    'Co 150 Mpam pass', 
    'Be 5000 pass',  
    'To 0.261 pass',  
    'Cr 186 no pass',  
    'Br 1.6 HBS 10/100  no pass', 
    'Ro HRC 55–66 pass',  
    'Vi 140HV30 pass',  
    'Im 3,3  pass',  
    'Wo 62712 no pass'
}
\end{filecontents*}

\begin{luacode*}
TestMade = {}
local MechTests = require("MechTestsi")
local TestsResults = require("TestsResultsi")

function T(...)
    local sff5=[[\item %s  ]]
    local i,j
    
    for j, v in ipairs{...} do
        tex.print(string.format(sff5,  MechTests[v]))
        TestMade[#TestMade+1] =v
    end 
end

function Rx()
    local k
    local sff5=[[\item %s]]
    for k =1, #TestMade do
        tex.print(string.format(sff5, TestsResults[TestMade[k]]))       
    end
end
\end{luacode*}

\NewDocumentCommand{\Tests}{O{1} O{nil} O{nil} O{nil} O{nil} O{nil}}{%
\directlua{T(#1,#2,#3,#4,#5,#6)}
}   

\NewDocumentCommand{\LinkedR}{}{\directlua{Rx()}}

\begin{document}

\section{Test completed}

% There are 10 Tests available and 10 correspnding Results
% enter them in the order you like up to 6 at the time or enlarge \Tests

\begin{enumerate}
    \Tests[10]  
    \Tests[4][3]
    \Tests[6][9][8][1][7]
    \Tests[2]
\end{enumerate} 

\section{Linked Table of results}

% The list of results follows the order of Tests as they where  made. Test #5 (Creep rupture test) was not performed.

\begin{enumerate}   
    \LinkedR
\end{enumerate}

\end{document}

output

6
  • I'm not sure if I understand your logic here. What if I had n items in a list with n results in a standard list. Do I change the code in the preamble? It looks like each item is hard coded?
    – Alan Jones
    Oct 31, 2020 at 19:44
  • @Alan Jones Please see the updated answer. Nov 1, 2020 at 23:46
  • its not working for me. Would it be easier, say if I had two \begin{enumerate} \item \item \item ... \end{enumerate} lists and then link them?
    – Alan Jones
    Nov 2, 2020 at 4:38
  • I have edited my original post, maybe it might make things easier for you to give me direction on how to solve it. I tried looking at the mcexam package but as always had 0 luck.
    – Alan Jones
    Nov 2, 2020 at 4:45
  • @Alan Jones I don't understand your new requirement. The above solution meets exactly conditions a) and b) for n elements. Why isn't it working for you? The lists ARE linked. The second is generated using the elements of the first, in the same quantity and arbitrary order. You are looking for a solution or for help on HOW to solve the question? Nov 2, 2020 at 11:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .