[Tex/LaTex] Unexpected change in pagination when ‘no’ change in contents, using `boxedmini2e`

boxesminipagepage-breaking

I am using the package boxedminipage2e to produce several framed boxes with some text inside.
Because these boxes have a fixed height and width, I am expecting that whether or not these boxes contain text, the pagination of the document will be the same.
{This is what I mean in the title of this question 'no' change in contents.}

But when I add text inside these boxes, the pagination changes. I don't understand why, and I don't want it to.

I need both versions of the document {with / without text} to have the same pagination {one version with blank space inside the boxes, and another version with the answers}.

The adding/removing text inside the boxes is done via a kind of hack: I comment out the body using a new environment. I remember this hack from somewhere on this site.

The MWE is below. It may be more detailed than required, but reproducing the error is very finicky!

The key line is 16. If I comment this out, thus putting text into the box, the pagination of the document changes —it actually tightens up— and I don't understand why and I don't want it to.

My question: how can I stop this repagination so I can retain two identically-paginated versions of the same document, one with boxes containing text, and one with the same boxes but with no text?

\documentclass[12pt,oneside]{report}
\usepackage[a4paper, top=1.0in, bottom=1in, inner=1.6in, outer=1in, includefoot] {geometry}
\usepackage{boxedminipage2e}
\usepackage{environ}
\usepackage[compact]{titlesec}
\usepackage{polyglossia,}
\setlength{\parskip}{4.5ex plus 0.2ex minus 0.2ex }
\setlength{\parindent}{0pt}
\setmainlanguage{arabic}
\setotherlanguage{english}
\newfontfamily\arabicfont[Script=Arabic, Scale=1.70]{Scheherazade}
\NewEnviron{teacheronly}[1]
{
\begin{boxedminipage}[t][#1][t]{\linewidth}
\begin{english}
    \BODY% Comment this to remove `...more marked tex...`
\end{english}
\mbox{}
\end{boxedminipage}
}
\pagestyle{plain}
\begin{document}
\section{ففف غغغ جكجج للل ددد }
اهسيجحد هايحجدس هايس دهاسيج د؛هايسج 

؛اسح

\begin{teacheronly}{1in}

\end{teacheronly}

ا؛حسد ةه؛اوسحد ؛هاسح  اهسدح ؛هاوسحد 

\begin{teacheronly}{1in}

\end{teacheronly}

الوعد  ”وَتَتَبَارَكُ فِيكَ جَمِيعُ قَبَائِلِ ٱلْأَرْضِ" -هو متحقق إزّي؟

\begin{teacheronly}{1in}

\end{teacheronly}

\section{نتوقع إيه  بعد كده تتت ثثث ظظظ}

إاسكلدجح ايسودغ يسدو غيشوغ يسدوح صسخيه؛وح ص
اةيهسوح يسهدوحص هوسدصح 

\begin{teacheronly}{1in}
Read  and write what you expect to happen next in the story.
\end{teacheronly}


\end{document}


\end{teacheronly}


ا؛حسد ةه؛اوسحد ؛هاسح  اهسدح ؛هاوسحد 


\begin{teacheronly}{1in}

\end{teacheronly}

الوعد  ”وَتَتَبَارَكُ فِيكَ جَمِيعُ قَبَائِلِ ٱلْأَرْضِ" -هو متحقق إزّي؟

\begin{teacheronly}{1in}

\end{teacheronly}

\section{نتوقع إيه  بعد كده تتت ثثث ظظظ}
إاسكلدجح ايسودغ يسدو غيشوغ يسدوح صسخيه؛وح ص
اةيهسوح يسهدوحص هوسدصح 

\begin{teacheronly}{1in}
Read  and write what you expect to happen next in the story.
\end{teacheronly}


\end{document}

Best Answer

You have to fill the boxes with something invisible in case you don't want the text to be seen.

I added an easier interface than commenting out \BODY.

\documentclass[12pt,oneside]{report}
\usepackage[a4paper, top=1.0in, bottom=1in, inner=1.6in, outer=1in, includefoot] {geometry}
\usepackage{boxedminipage2e}
\usepackage{environ}
\usepackage[compact]{titlesec}
\usepackage{polyglossia,}
\setlength{\parskip}{4.5ex plus 0.2ex minus 0.2ex }
\setlength{\parindent}{0pt}
\setmainlanguage{arabic}
\setotherlanguage{english}
\newfontfamily\arabicfont[Script=Arabic, Scale=1.70]{Scheherazade}

\newif\ifteacher
\NewEnviron{teacheronly}[1]{%
  \begin{boxedminipage}[t][#1][t]{\linewidth}
  \ifteacher
    \begin{english}
    \BODY% Comment this to remove `...more marked tex...`
    \end{english}
  \else
    \hrule height 0pt width \textwidth
  \fi
  \end{boxedminipage}
}
\pagestyle{plain}
\begin{document}

\teachertrue

\section{ففف غغغ جكجج للل ددد }
اهسيجحد هايحجدس هايس دهاسيج د؛هايسج 

؛اسح

\begin{teacheronly}{1in}

\end{teacheronly}

ا؛حسد ةه؛اوسحد ؛هاسح  اهسدح ؛هاوسحد 

\begin{teacheronly}{1in}

\end{teacheronly}

الوعد  ”وَتَتَبَارَكُ فِيكَ جَمِيعُ قَبَائِلِ ٱلْأَرْضِ" -هو متحقق إزّي؟

\begin{teacheronly}{1in}

\end{teacheronly}

\section{نتوقع إيه  بعد كده تتت ثثث ظظظ}

إاسكلدجح ايسودغ يسدو غيشوغ يسدوح صسخيه؛وح ص
اةيهسوح يسهدوحص هوسدصح 

\begin{teacheronly}{1in}
Read  and write what you expect to happen next in the story.
\end{teacheronly}


\clearpage\teacherfalse

\section{ففف غغغ جكجج للل ددد }
اهسيجحد هايحجدس هايس دهاسيج د؛هايسج 

؛اسح

\begin{teacheronly}{1in}

\end{teacheronly}

ا؛حسد ةه؛اوسحد ؛هاسح  اهسدح ؛هاوسحد 

\begin{teacheronly}{1in}

\end{teacheronly}

الوعد  ”وَتَتَبَارَكُ فِيكَ جَمِيعُ قَبَائِلِ ٱلْأَرْضِ" -هو متحقق إزّي؟

\begin{teacheronly}{1in}

\end{teacheronly}

\section{نتوقع إيه  بعد كده تتت ثثث ظظظ}

إاسكلدجح ايسودغ يسدو غيشوغ يسدوح صسخيه؛وح ص
اةيهسوح يسهدوحص هوسدصح 

\begin{teacheronly}{1in}
Read  and write what you expect to happen next in the story.
\end{teacheronly}

\end{document}

enter image description here