Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I tried defining a new command \Quest as follows but the error

Lonely \item--perhaps a missing list environment

appears.

\def\solnversion{0} %%set this to 1 to get solutions
\newcommand\Quest[3]{\item\ifnum\solnversion=1 #3\else #2\fi}

But if the \item command is removed, the error

Something's wrong--perhaps a missing \item

appears instead. How should the code be corrected?

share|improve this question
    
Regardless of whether it works or not, this isn't the right way of doing this. It should look more like this: \newif\ifsolutions \solutionsfalse \newcommand\Quest[3]{\item \ifsolutions#3\else#2\fi}. For other ways of using conditionals, see tex.stackexchange.com/questions/5894/… –  kahen Mar 19 '13 at 8:02
1  
Welcome to TeX.sx! Please add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. –  benwilfut Mar 19 '13 at 8:04
3  
The first error might occur, if you place \Quest in your LaTeX document outside any itemize or enumerate environment. An MWE would really help :) –  Ronny Mar 19 '13 at 8:14
    
@kahen It's not directly related to the main question but your comment about \ifnum looks incorrect to me. The if syntax in the question is valid. There is no need to declare a new if if you are just testing a number. –  David Carlisle Mar 19 '13 at 9:33
add comment

1 Answer

Something's wrong--perhaps a missing \item

Is a notorious error message in LaTeX, it is almost never caused by a missing \item. It is actually generated if you use \addvspace in horizontal mode. As you have not given any context all we can say is that whatever you passed in as argument #2 or #3 is not allowed at the place where you used the command. The newcommand and the \ifnum test are not really relevant to the error.

Since the command you are passing as argument needs to be in vertical mode, a wild guess is that putting it in vertical mode might be sufficient, \par will end the previous paragraph and get TeX into vertical mode so perhaps

\newcommand\Quest[3]{\par\ifnum\solnversion=1 #3\else #2\fi}

will work, If not (and in future questions) Please supply a complete small document that shows the problem,

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.