I am looking for a convenient way to code nestable "contexts" whose extents are displayed through indentation. Each context consists of a sequence of "statements" (i.e. lines) and/or (1 level deeper) "children" contexts.
The desired results would look something like this:
This statement is in the "outermost" context.
Let's call this context 0.
This statement is in the next context.
Let's call it context 1.
Statements are expected to be short.
Behold: an even deeper context.
OK, back to context 1.
The number of statements in each context is arbitrary.
So is the number of subcontexts in a context.
But context level can change by at most 1 at a time.
OK, let's finish this example...
We're almost done.
There!
As I'm thinking of it, the LaTeX source code for the above would look something like this:
\begin{context}
This statement is in the "outermost" context. \\
Let's call this context 0.
\begin{context}
This statement is in the next context. \\
Let's call it context 1. \\
Statements are expected to be short.
\begin{context}
Behold: an even deeper context.
\end{context}
OK, back to context 1. \\
The number of statements in each context is arbitrary.
\begin{context}
So is the number of subcontexts in a context. \\
But context level can change by at most 1 at a time.
\end{context}
OK, let's finish this example...
\end{context}
We're almost done. \\
There!
\end{context}
There are a couple of finer points regarding linebreaks and line wrapping. First, it would be great if a simple newline (rather than \\) were enough to indicate a linebreak, but somehow I doubt that this would be easy to do.
The second point refers to a feature that I did not know how to illustrate in the example above. It concerns "multiline" statements. Even though the typical statement will be short enough to not require any linebreaks, there may be rare instances (especially for deeply nested contexts) where a linebreak may be necessary, resulting in a multiline statement. Therefore, it would be good if the separation between individual statements were larger than the one between the lines in a multiline statement (but ideally just large enough to make the difference visually noticeable). Of course, for the occasional multiline statement, the leftmost endpoint of all its lines should line up vertically; i.e. all these lines should be left-justified, though at a common (possibly non-zero) indentation level.
Can someone show me how to define the \begin{context}/\end{context} sequence?
EDIT: Please see this math.stackexchange.com post, and in particular its Example section, for an illustration of the application I have in mind. (It turns out that that post includes some a custom extension to MathJax that the author uses to code its displays, but that code does not work for me when I use it in a regular LaTeX file.)

\begin{quote} ... \end{quote}to implement contexts works suprisingly well! It requires suppressing automatic indentation, which I got. I still need to figure out how to make the separation "between contexts" (i.e. between the first line of the quoted content and the preceding line in the enclosing context) be identical to the separatation between the statements at the same level within a context. Other than that, this is amazingly close to what I described in my question. I'd be happy to accept it if you care to post it as an answer. – kjo May 20 '22 at 09:27