1

I want to save a list of items and their counters. here is what I wrote in latex

\documentclass{article}
\RequirePackage{etoolbox} % defines lists and their operations
\RequirePackage{tabulary} % defines content-based sizable tables
\newcounter{vpt}
\setcounter{vpt}{0}
\newcommand{\facility}[1]{\addtocounter{vpt}{1} \listcsgadd{FacilityList}{#1} 
\arabic{vpt}. $-->$ #1  }
\newcommand{\facilityno}[1]{\listcsgadd{FacilityNo}{#1} \arabic{vpt}. $-->$ #1  }
\begin{document}
I want to save the text and the counter\\
\facility{this is facility one}  \facilityno{\the\value{vpt}} \\
\facility{this is facility two}  \facilityno{\the\value{vpt}}\\
\facility{this is facility three}\facilityno{\the\value{vpt}} 
the texts are saved 
\begin{itemize}
\renewcommand*{\do}[1]{\item  #1} 
\dolistcsloop{FacilityList}
\end{itemize}  
%    But the counters are all 3??!!! 
\begin{itemize}
    \renewcommand*{\do}[1]{\item #1} 
    \dolistcsloop{FacilityNo}
\end{itemize}    
%     any comments?
\end{document}

1 Answer 1

1

Quick answer: You have to expand the value of your counter in \facilityno. I did this with inserting some \expandafters during the input, but I guess this isn't desirable syntax.

If you don't expand the argument, the list element is \the\value{vpt} which is expanded when you use the list element, at which point the counter state is 3.

\documentclass{article}
\RequirePackage{etoolbox} % defines lists and their operations
\RequirePackage{tabulary} % defines content-based sizable tables
\newcounter{vpt}
\setcounter{vpt}{0}
\newcommand{\facility}[1]{\addtocounter{vpt}{1} \listcsgadd{FacilityList}{#1} 
\arabic{vpt}. $-->$ #1  }
\newcommand{\facilityno}[1]{\listcsgadd{FacilityNo}{#1} \arabic{vpt}. $-->$ #1}
\begin{document}
I want to save the text and the counter\\
\facility{this is facility one}  \expandafter\facilityno\expandafter{\the\value{vpt}}\\
\facility{this is facility two}  \expandafter\facilityno\expandafter{\the\value{vpt}}\\
\facility{this is facility three}\expandafter\facilityno\expandafter{\the\value{vpt}} 
the texts are saved 
\begin{itemize}
\renewcommand*{\do}[1]{\item  #1} 
\dolistcsloop{FacilityList}
\end{itemize}  
%    But the counters are all 3??!!! 
\begin{itemize}
    \renewcommand*{\do}[1]{\item #1} 
    \dolistcsloop{FacilityNo}
\end{itemize}    
%     any comments?
\end{document}
1
  • thanks. Great help. I have managed to move all expandafter commands to newcommand and get what I wanted Jan 16, 2018 at 6:24

You must log in to answer this question.

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