1

I would like to make a bank of problems of similar type--however, I only want to display the first of each time. For example:

\begin{bank}  
\begin{exercise} 2+2
\end{exercise}

\begin{exercise} 4+3
\end{exercise}
\end{bank}

Would only show the exercise 2+2. Any help on this would be great.

Note: this questions seems similar to Getting the first line of an environment

and I've tried something like:

\def\getline#1\par{%
\gdef\theline{#1}#1%
}

\newenvironment{bank}{%
  \getline%
}{\theline}

but this displays the contents of bank, and then the first environment.

3

The following MWE uses environ to define the exercise environment and then condition on whether or not to set its contents (\BODY). The condition is set to true at the start of bank, and set to false after setting the first \BODY.

enter image description here

\documentclass{article}
\usepackage{environ}% http://ctan.org/pkg/environ
\newif\iffirstexercise% Condition for first exercise
\newenvironment{bank}
  {\firstexercisetrue}% Allow first exercise environment to be set
  {}
\NewEnviron{exercise}{%
  \iffirstexercise
    \BODY% Set body of exercise environment
  \fi%
  \global\firstexercisefalse% No more exercise environments are set
}
\begin{document}

\begin{bank}
\begin{exercise} $2+2$
\end{exercise}

\begin{exercise} $4+3$
\end{exercise}
\end{bank}

\begin{bank}
\begin{exercise} $7-6$
\end{exercise}

\begin{exercise} $4-3$
\end{exercise}
\end{bank}

\end{document}
1

Because your exercise is unspecified, the code is changed a little.

\documentclass{article}
\usepackage{exercise}
\begin{document}

\long\def\bbank#1  STOP #2\ebank{#1}

%\begin{bank}  
\bbank
%\begin{exercise}
\[
 2+2
\]
%\end{exercise}
% No new paragraph
STOP

%\begin{exercise} 
\[
4+3
\]
%\end{exercise}
%\end{bank}


\[
4+3
\]

\ebank

\end{document}

All the work is made by \long\def\bbank#1 STOP #2\ebank{#1}. The defintion is long, because your text may be longer than a paragraph. STOP is a string that never appears in your code. Please observe, that in this defintion STOP doesn't begin a new paragraph, what is commented in an example of usage.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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