I'd like to make a container in LaTeX in which I can store and append LaTeX-code for later use.

I have found many solutions to what I'm basically try to do (here for instance), but if they work, they stop working when you try to use it inside an enumerate environment.

To make sure the solution works in my case, I've made an example that uses all relevant features the container must be capable of. In this example \addtotraceabilitymatrixcontent should append #1 &#2\\ to the \traceabilitymatrixcontent container.


    % something that safely appends {#1 &#2 \\} 
    % to \traceabilitymatrixcontent while keeping
    % the references intact.

        Requirement & Validation \\

    \item \label{req:#1} \addtotraceabilitymatrixcontent{\ref{req:#1}}{#2}



        \reqitem{1}{\ref{val:1}} Requirement one
        \reqitem{2}{\ref{val:2}, \ref{val:3}} Requirement two
        \reqitem{3}{\ref{val:2}, \ref{val:3}} Requirement three

        \item \label{val:1} Test to validate requirement one
        \item \label{val:2} Test to validate requirement two and three partially
        \item \label{val:3} Test to validate requirement two and three partially

I've found what I was looking for in the etoolbox package. I still don't know exactly what I'm doing but defining \addtotraceabilitymatrixcontent as follows did the trick:

    \gappto{\traceabilitymatrixcontent}{#1 & #2\\}
  • You're appending information to the replacement text of \traceabilitymatrixcontent. It's indeed the right thing to do; the command \gappto differs from \appto in that its action is global and it's necessary because environments form a group.
    – egreg
    May 30 '13 at 13:24

I might have something in the right direction. I had to figure this out to write a best practices document where I had to very clearly identify the best practices, be able to reference them, and list them.

The solution I have uses memoir, and defines a new environment which is numbered. I am pretty sure I got some of the code from the memoir manual and somewhere on here.

This code generates a series of main items with sub items, where a short description of the main item is stored for use in a table of items.

Noting that this is probably incomprehensible, here is a MWE...



%% Custom list
% define the list of MyList's
\newcommand{\listMyListname}{List of My Items}
% define a counter
% define the command that creates an MyList, which is indexed every time we call it
    \refstepcounter{MyListno} \protect\item #2 %
% set up the list
% borrow formatting
% define the environment in which we will embed the MyList
    \begin{list}{\underline{\textbf{MyList \theMyList:}}~}{}%
% Reference an MyList
\newcommand{\refMyList}[1]{\hyperref[#1]{MyList \ref{#1}}}    
\renewcommand{\theSubList}{\theMyList\  \alph{SubList})}    
\newcommand{\MySubList}[1]{\refstepcounter{SubList} \item #1}    




    \MyList{Item the first}{Thou shalt do x.\label{MyList:Dox}}
    \MySubList{In the first sub case:
\item sub item 1.1
\item sub item 1.2
    \MySubList{In the second sub case:
        \item sub item 2.1.
        \item sub item 2.2.
    \MySubList{In the third sub case: 
        \item sub item 3.1.
        \item sub item 3.2.
        \item sub item 3.3.

In \refMyList{MyList:Dox}, I said something.


You then end up with something that looks like this: enter image description here

You'll see there are the list items, a table of short descriptions of the list items, and ways to reference the list items. I suspect you could use a similar approach, possibly removing the sub items?

  • Unfortunately not really what I'm going for. The problem is not really to cross reference to a list. The problem is to use a certain macro from out a list.
    – tiM
    May 24 '13 at 10:55
  • @tiM: you might want to rework your question and give a mock-up of what you were looking for? May 24 '13 at 15:09
  • I just rewrote the question, thanks for the advice
    – tiM
    May 27 '13 at 14:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.