I cannot find any documentation at all on the samepage environment (aside from a cryptic comment on p229 of the LaTeX book that "The \samepage command still works, but is now of little use", which may or may not be relevant to the environment of the same name). This answer and the name of the environment suggests it should keep its contents on the same page, however it doesn't, as this MWE demonstrates:
\documentclass{article} \usepackage{lipsum} \usepackage{parskip} \begin{document} \lipsum[4-8] \begin{samepage} foo bar \end{samepage} \end{document} This breaks the page between the 'foo' and the 'bar'. Am I misusing the samepage environment? Is it documented anywhere?
This example requires xelatex rather than latex, but you can see the same in latex by adding a third line to the samepage environment.

\end{document}to get output, it makes a single page.\end{document}. Usexelatexand you'll see the problem. Question updated accordingly.