3

I'm using probsoln, and I want to put the solution as a marginpar and with footnotesize. Please look at the MWE below. Writelatex won't compile, spitting out

LaTeX Error: \begin{solutionnew} on input line 27 ended by \end{solution}.

TEX Studio compiles, but shows the same error.

And besides setting it as marginpar, I'd like to align it with the beginning of the problem, not with the end. Maybe with a vspace?

Thanks

MWE (it works without errors if you comment the three lines before \begin{document}):

\documentclass{article}

\usepackage{environ} 
\usepackage{probsoln}
\showanswers

\begin{defproblem}{problem1}
We want to know the answer to The Ultimate Question of Life, the Universe, and     Everything 
\begin{onlysolution}
\begin{solution}
The answer is 42
\end{solution}
\end{onlysolution}
\end{defproblem}

%%This is how I'm trying to embrace in a marginpar the probsoln solution enviroment
\NewEnviron{solutionnew}{%
  \marginpar{\footnotesize My solution name:\\ \BODY}}

\renewenvironment{solution}{\begin{solutionnew}}{\end{solutionnew}}


\begin{document}
\useproblem{problem1}
\end{document}
3

I changed the \renewenvironment line to

\renewenvironment{solution}{\solutionnew}{\endsolutionnew}

You also seemed to be missing the ending part of the environment definition in solutionnew which I just added as a {}. Perhaps a macro form would be more suitable.

I also recommend making the \marginpar ragged.

See original answer here and FOLLOW UP farther below.

Here is the MWE:

\documentclass{article}

\usepackage{environ} 
\usepackage{probsoln}
\showanswers

\begin{defproblem}{problem1}
We want to know the answer to The Ultimate Question of Life, the Universe, and     Everything 
\begin{onlysolution}
\begin{solution}
The answer is 42
\end{solution}
\end{onlysolution}
\end{defproblem}

%%This is how I'm trying to embrace in a marginpar the probsoln solution enviroment
\NewEnviron{solutionnew}{%
  \marginpar{\raggedright\footnotesize My solution name:\\ \BODY}}{}

\renewenvironment{solution}{\solutionnew}{\endsolutionnew}


\begin{document}
\useproblem{problem1}
\end{document}

enter image description here

FOLLOW UP: In response to comment by OP, one can get the solution at the top of the problem by listing the solution environments before the problem content. Note, however, that a \leavevmode has been added, to deal with the problem of \marginpar being issued as the first item in a paragraph.

\documentclass{article}
\usepackage{lipsum}
\usepackage{environ} 
\usepackage{probsoln}
\showanswers

\begin{defproblem}{problem1}
\begin{onlysolution}
\begin{solution}
The answer is 42
\end{solution}
\end{onlysolution}
We want to know the answer to The Ultimate Question of Life, the Universe, and     Everything 

\lipsum[1]
\end{defproblem}

%%This is how I'm trying to embrace in a marginpar the probsoln solution enviroment
\NewEnviron{solutionnew}{%
  \leavevmode\marginpar{\raggedright\footnotesize My solution name:\\ \BODY}}{}

\renewenvironment{solution}{\solutionnew}{\endsolutionnew}


\begin{document}
\useproblem{problem1}
\end{document}

enter image description here

  • Is it possible to align the beginning of the solution with the first line of the problem? – Pablo B. Oct 29 '14 at 17:42
  • @PabloB. Please see follow up in my answer. – Steven B. Segletes Oct 29 '14 at 18:00

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.