# A comment after the xsim solution environment is being printed

If I add a comment after the solution environment of the xsim package the comment is printed before the solution.

\documentclass[]{article}
\usepackage{xsim}

\begin{document}
\begin{exercise} % execice 1
Statement of exercise 1
\end{exercise}
\begin{solution}[print] % I need a comment here
Solution of exercise 1
\end{solution}
\end{document}

• The package has a github site where bugs can be reported. But probably is it a side effect of the verbatim reading and writing of the content and difficult to avoid. Put the comment on the next line. – Ulrike Fischer Aug 5 '19 at 14:36

This behaviour is not a bug. It is a side effect of the contents being read verbatim and then being written to an external file.

Actually, this is mentioned in the manual (section 5 about how the exercise environments work):

Another thing to keep in mind: the environment in many ways works the same way as the filecontents environment. This also means that you cannot have comments on the first line of the environments:

\begin{exercise}[points=2] % this comment will cause trouble
Lorem ipsum
\end{exercise}


\documentclass[]{article}
\usepackage{xsim}

\begin{document}

\begin{exercise}
% execice 1
Statement of exercise 1
\end{exercise}
\begin{solution}[print]
% I need a comment here
Solution of exercise 1
\end{solution}

\end{document}