# hide a certain item and remove the left empty line

Is there a way to define a new command \noitem where its contents are hidden, in the same way I put in MWE?

\documentclass{article}

\newcommand[2]{\noitem}{\item[]{}\vspace*{-\baselineskip}} % better define this

\begin{document}

\begin{description}
\item[test 1] this line is to appear
\noitem[test 2] this line is to be empty
\end{description}

\end{document}


I want to be able use two types of constructions inside a description environment: \noitem and \item. The \item is the regular as we all know. The \noitem simple hides the text inside the list, without leaving extra line or so. The purpose of \noitem is somehow similar to the use of % when you want to hide a part of your code. Moreover, I want to be able to use it elsewhere in the environment: in the beginning, in the middle, or at the end. The position inside the environment will be unknown to me, because this is to run inside other command.

The question is how to properly define the \noitem command to be used inside description, removing the extra line that \item[]{} leaves?

-
This looks a bit like an XY Problem. Could you elaborate a bit more on what you try to reach with this construct? –  Benedikt Bauer Mar 5 '13 at 12:55
If it;s not the last you could use \long\def\noitem#1\item{} If it is the last you could use \long\def\lastnoitem#1\end#2{} so long as there are no nested environments –  David Carlisle Mar 5 '13 at 12:55
Ok. Let's elaborate a bit more. I want to be able use two types of constructions inside a description environment: \noitem and \item. The \item is the regular as we all know. The \noitem simple hides the text inside the list, without leaving extra line or so. The purpose of \noitem is somehow similar to the use of % when you want to hide a part of your code. Moreover, I want to be able to use it elsewhere in the environment: in the beginning, in the middle, or at the end. The position inside the environment will be unknown to me, because this is to run inside other command. –  cacamailg Mar 5 '13 at 13:05
If you put the whole data field in braces \noitem[test 2] {this line is to be empty}, then you could define \newcommand\noitem[2][]{}, I think, and blot it out. Don't know if those extra braces are acceptable to you? –  Steven B. Segletes Mar 5 '13 at 13:16
It may have extra brackets, no problem with that. But it also to run inside description environment, that is why I put \item in the definition of \noitem. –  cacamailg Mar 5 '13 at 13:24

This seems to work, but only for first level description environment: don't nest them if there's a \noitem:

\documentclass{article}

\long\def\noitem#1\end{\noitemaux#1\item\end}
\makeatletter
\long\def\noitemaux#1\item#2\end{%
\if\relax\detokenize{#2}\relax
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
{\end}
{\remove@item #2\@nil\end}%
}
\long\def\remove@item#1\item\@nil{\item #1}
\makeatother

\begin{document}

\begin{description}
\noitem[test 0] this line is to be empty
\item[test 1] this line is to appear
\item[test 2] this line is to appear
\noitem[test 3] this line is to be empty
\noitem[test 4] this line is to be empty
\item[test 5] this line is to appear
\noitem[test 6] this line is to be empty
\end{description}

\end{document}


-
Thanks. Your solution is a first approach. However, I tried to use \noitem with empty arguments \noitem[]{} and/or when it is the first element in the list, but it didn't work out. –  cacamailg Mar 5 '13 at 13:54
@cacamailg The bug should be fixed –  egreg Mar 5 '13 at 14:22
Your answer is ok. However, know I am trying to use it inside a \expandafter\ifx ... \else \noitem[]{} \fi but it is giving me an error \end occurred when \ifx on line 48 was incomplete. I tried to replace \noitem[]{}, with \item[]{} and it compiles without the error. Any idea? –  cacamailg Mar 5 '13 at 16:01
You have to get rid of the \fi before \noitem is expanded. It has nothing to do with this question and probably is good for a follow-up. But I can't understand why you want to insert a \noitem[]{} in the first place, as it should do nothing at all! Just don't add it! –  egreg Mar 5 '13 at 16:04
Ok! Thank you very much! –  cacamailg Mar 5 '13 at 16:10