# Check if list item is emtpy

I need to detect the presence of an empty item to shift the next one, as in the following example. I don't kwnow what's the best way to do this with luatex. Thanks for nany help about this.

\documentclass{article}
\usepackage{luatextra}

\makeatletter
\newcounter{@questions}
\newcounter{@question}[@questions]
\newcounter{@subquestion}[@question]
\newenvironment{questions}[1][]%
{
\refstepcounter{@questions}
\newcommand{\question}{\stepcounter{@question}\item[\hspace{1cm}\arabic{@question})]}
\newcommand{\subquestion}{\stepcounter{@subquestion}\item[\hspace{2cm}\alph{@subquestion})]}
\trivlist
}{%
\endtrivlist
}
\makeatother

\begin{document}

\begin{questions}
\question ok
\question
\subquestion ok
\subquestion ok
\question ok
\subquestion ok
\subquestion ok
\end{questions}

\end{document}


• \newcounter should be outside. You declare it once, then reuse it; not declare it any time you are using the environment. In any case, why not nested lists? – Manuel Apr 9 '16 at 12:07
• @Manuel : Message edited for \newcounter. And I prefer not to use nested lists, for a simpler syntax. – MB4E Apr 9 '16 at 12:16

This is mostly a hack, but it does work well. You could do it with just an environment {questionlist} and then incrementing a counter for the “depth”, that might be easier.

\documentclass{scrartcl}

\usepackage{etoolbox}
\usepackage[shortlabels]{enumitem}

\newlist{questionlistA}{enumerate}{1}
\setlist[questionlistA]{label=\textup{\arabic*)}}
\newlist{questionlistB}{enumerate}{1}
\setlist[questionlistB]{label=\textup{\alph*)}}

\makeatletter

\newenvironment{questions}[1][]
{\begin{questionlistA}[#1]
\newcommand*\question{\ifdefstring{\@currenvir}{questionlistA}{\item}{\end{questionlistB}\item}}%
\newcommand*\subquestion{\ifdefstring{\@currenvir}{questionlistB}{\item}{\begin{questionlistB}\item}}}
{\ifdefstring{\@currenvir}{questionlistB}{\end{questionlistB}}{}%
\end{questionlistA}}

\makeatother

\begin{document}

\begin{questions}
\question ok
\question
\subquestion ok
\subquestion ok
\question ok
\subquestion ok
\subquestion ok
\end{questions}

\end{document}


Of course, the first should be a \question, you can't have a \subquestion as first item.

• Thank you for the answer. I was doing the same thing before without environment. Juste some /question et /subquestion commands dealing with \everypar and \@hangfrom. I wanted to try with list, but I don't know if it is better or not. – MB4E Apr 9 '16 at 12:53