I am trying to iterate through a list of data. The data has sections mixed between the items.
When a section appears, I need to typeset it with \section, then I need to create a itemize environment to hold the next set of items. However, that is where things break. For some reason, I can't create the environment in the middle of the compilation of the list. I tried with \begin{itemize} and \end{itemize}, as well with \itemize and \enditemize. But I get errors regarding the items.
\documentclass{article}
\usepackage{pgffor,pgfkeys}
\def\myenvir{document}
\pgfkeys{/test/.cd,
section/.code = {%
\def\tempa{document}% if current_environment=document
\ifx\tempa\myenvir%
\section{#1}\gdef\myenvir{itemize}\itemize%
\else%
\enditemize\section{#1}\itemize%
\fi%
},
question/.code = {%
\item #1
},
style/.estyle={#1}
}
\def\questions{
section = section 1,
question=question 1,
question=question 2,
section = section 2,
question=question 1,
question=question 2,
section = section 3
}
\pagestyle{empty}
\begin{document}
%\itemize
\foreach \x in \questions {\pgfkeys{/test/.cd,style/.expanded=\x}}
\enditemize
\end{document}
What is the correct way of approaching this? I thought that I can close and open the environments any time, but it seems that is not possible. Also, is there a way to check if the next item is a section and then close it then? But probably that will lead to the same problem of not having the opening and closing explicitly.
itemizeenvironment (which is what the cited question gave as an example). But as I look a little deeper at your code (and I don't pretend to understandpgf), it seems instead that you want to exit the itemize, perform a new section, and re-enter a newitemize. In that case, there probably is no direct connection. – Steven B. Segletes Apr 09 '15 at 00:12