# environment within environment within command

So.... I'm trying to create (what I assume) is to be a simple command that tries to do some nice formatting. Here is what I have.

\usepackage{enumitem}
\newenvironment{question}{\bf}{\normalfont}
\newcommand{\qna}[2]{
\fcolorbox{black}{yellow}{
\begin{question}
#1
\end{question}
#2
}
}


Now, this seems to work perfectly when I input any string.

\qna{Here's a q}{Here's an answer}


BUT I'm getting into issues when I try and pass in a non string as my second variable. Example

\qna{Here's a q}{Here an answer in list format
\begin{enumerate}
\end{enumerate}
}


The error I'm getting is

Something's wrong--perhaps a missing \item. }


I don't see what I'm doing wrong and what a potential way of fixing it would be.

Minimal Working Example:

\documentclass[11pt]{book}

\usepackage{enumitem}
\usepackage{xcolor}

\newenvironment{question}{\bf}{\normalfont}
\newcommand{\qna}[2]{
\fcolorbox{black}{yellow}{
\begin{question}
#1
\end{question}
#2
}
}

\begin{document}
\qna{test}{test}
\end{document}

• Please help us to help you and 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}. – user31729 Jan 16 '15 at 9:44
• (1) you should not be using \it and \bf, those are not LaTeX, (2) your problem might be that the colorbox need what ever it is surrounding to be a box, at least when you are adding lists. Try addin a minipage. BTW: Are you sure you want to use a syntax like this, it seems rather cumbersome. Have a look at the environ package, that might be useful. – daleif Jan 16 '15 at 9:44
• please always post complete test documents not fragments so this is not tested but \fcolorbox like \mbox is a hmode (LR mode) construct that does not allow display constructs like lists, you probably want \fcolorbox{black}{yelow}{\begin{minipage}{.7\textwidth}\begin{question}.. Also ypu are missing % from teh ends of most of your lines in the definition which will produce bad spaces in the output – David Carlisle Jan 16 '15 at 9:45
• Sorry for posting fragments everyone. I've created a MWE and posted at the bottom. – Aram Papazian Jan 16 '15 at 9:48
• You know that there are packages like exsheets and classes like exam for this, right? No real need to invent the wheel once more. – Johannes_B Jan 16 '15 at 9:49

The problem with \fcolorbox is that does not allow lists inside it. A minipage or parbox would help in this case, but both are not breakable. I used the tcolorbox package and the tcolorbox environment to provide for a breakable box (amongst many,many other configurable options, e.g. box corners, color, title line etc.)

In addition, a package like exam or exsheets are designed for such tasks.

I used xparse's \NewDocumentCommand for 'easier' long arguments to the command instead of \newcommand.

\documentclass{article}

\usepackage{xcolor}
\usepackage{enumitem}
\usepackage{xparse}%
\usepackage[breakable]{tcolorbox}
\newenvironment{question}{\bfseries}{\normalfont}%

\NewDocumentCommand{\qna}{+m+m}{%
\begin{tcolorbox}[breakable,colback=yellow]
\begin{question}
#1
\end{question}
#2
\end{tcolorbox}
}

\begin{document}

\qna{Here's a q}{Here an answer in list format
\begin{enumerate}