# How can I redefine the description list to pass an arg to redefined items that contain TikZ nodes?

I am open to suggestions regarding my question's wording.

I would like to have all description lists support an optional argument that represents node name prefixes. This will be passed to the definition of items that is ultimately used to ensure the uniqueness of nodes names among global nodes (by global nodes I am referring to nodes using tikz's remember picture parameter).

I would like to essential implement the following code automatically.

# Pseudo-code

\documentclass{article}
\usepackage{fontspec}
\usepackage{xparse}
\usepackage{tikz}
\newcounter{itemcounter}
\NewDocumentCommand{\tmark}{ m }{\tikz [remember picture,overlay,baseline={([yshift=-.8ex]current bounding box.center)}] \node [draw] (#1) {};} % used in definition of \item

%Some fancy schmancy code to transform the following item:
%\item [item] Some text.
%into this:
%\item [\tmark{\nodeprefix\itemcount}item] Some text. %expands to [\tikz [remember picture, overlay] \node [draw] (lista1) {};]

\begin{document}
\begin{description}[nodeprefix=lista] % Not sure how to make a key or pass value of it to macro \nodeprefix
\item [Apple] This is a fruit.
\item [Broccoli] This is a vegetable.
\end{description}
\begin{description}[nodeprefix=listb] % Not sure how to make a key or pass value of it to macro \nodeprefix
\item [Silver] This is a solid.
\item [Water] This is a liquid.
\end{description}
\begin{description}[nodeprefix=listc] % Not sure how to make a key or pass value of it to macro \nodeprefix
\item [Happiness] This is a state of being.
\item [Sadness] This is an unfortunate state of being.
\end{description}
\end{document}


That code results in a few nodes that I could reference in a tikzpicture later on.

\node (lista1) {};
\node (lista2) {};
\node (listb1) {};
\node (listb2) {};
\node (listc1) {};
\node (listc2) {};


# Redefining description

A redefinition would include the node prefix optional parameter and reset the item count to 1 (\setcounter{itemcount}{1}) such that a new list will be ready to go with fresh numbers.

\makeatletter % Redefine description list https://tex.stackexchange.com/a/66386/13552
\renewenvironment{description}
{
\list{}{\labelwidth\z@ \itemindent-\leftmargin
\let\makelabel\descriptionlabel}
}
{
\endlist
}
\let\descriptionlabel\relax
\newcommand*\descriptionlabel[1]{\hspace\labelsep\normalfont\bfseries #1}
\makeatother


# Redefining item

A redefinition would include the \tmark macro.

Related Question for counter: TikZ: Automatic Numbering of Nodes, \value{counterName}

\expandafter\def\expandafter\description\expandafter{% https://tex.stackexchange.com/a/230316/13552
\description \let\olditem\item
\def\item[##1]{\olditem[##1]\mbox{}\\}}


If I understood correctly, you want something like this?

\documentclass{article}
\usepackage{fontspec}
\usepackage{xparse}
\usepackage{tikz}
\usepackage{enumitem}
\usepackage{etoolbox}

\newcounter{itemcounter}
\NewDocumentCommand{\tmark}{ m }{\tikz [remember picture,overlay] \node [draw] (#1) {};}

\pretocmd{\item}{\stepcounter{itemcounter}}{}{}
\BeforeBeginEnvironment{description}{\setcounter{itemcounter}{0}}

\newcommand\nodeprefix[1]{%
\renewcommand\makelabel[1]{\tmark{#1\theitemcounter}\bfseries##1}}

\begin{document}

\begin{description}[before={\nodeprefix{lista}}]
\item [Apple] This is a fruit.
\item [Broccoli] This is a vegetable.
\end{description}
\begin{description}[before={\nodeprefix{listb}}]
\item [Silver] This is a solid.
\item [Water] This is a liquid.
\end{description}
\begin{description}[before={\nodeprefix{listc}}]
\item [Happiness] This is a state of being.
\item [Sadness] This is an unfortunate state of being.
\end{description}

\begin{tikzpicture}[remember picture,overlay]
\draw[red!70!black,line width=1pt]
(lista1) -- ++(-30pt,0pt) |- (lista2)
(lista1) -- ++(-30pt,0pt) |- (listb1)
(lista1) -- ++(-30pt,0pt) |- (listb2)
(lista1) -- ++(-30pt,0pt) |- (listc1)
(lista1) -- ++(-30pt,0pt) |- (listc2);
\end{tikzpicture}

\end{document}


• Yes you did understand the concept. I can do it this way, but this makes making lists a verbose experience :) I was hoping to wrap up most of the work in a new definition of the description lists. (to make it clear what i mean: before={\renewcommand\makelabel[1]{\tmark{listc\theitemcounter}\bfseries##1}} is really a bunch of code to put in the body for each list that I would like to avoid.) – Jonathan Komar Sep 3 '15 at 19:36
• This answer seems to uses a similar redefinition of \makelabel in this answer tex.stackexchange.com/a/55989/13552 I only added this comment for the purpose of creating relationships between questions. – Jonathan Komar Sep 3 '15 at 20:05
• I accepted your answer, BUT there is a problem. I do not like that I cannot set \setlist[description]{style=nextline,labelwidth=0pt,leftmargin=30pt,itemindent=\dimexpr-20pt-\labelsep\relax} % Optional Global Setup from tex.stackexchange.com/a/262376/13552 My plan was to use an \hfill or something to get a brace like in tex.stackexchange.com/a/12418/13552. Sidenote: I added baseline={([yshift=-.8ex]current bounding box.center)} to \tmark for vertical alignment. – Jonathan Komar Sep 4 '15 at 5:57