- // no blank lines before environments!
- if (!next_layout.isEnvironment() || style == next_layout) {
+ if (style == next_layout
+ // no blank lines before environments!
+ || !next_layout.isEnvironment()
+ // unless there's a depth change
+ // FIXME What we really want to do here is put every \begin and \end
+ // tag on a new line (which was not the case with nested environments).
+ // But in the present state of play, we don't have access to the
+ // information whether the current TeX row is empty or not.
+ // For some ideas about how to fix this, see this thread:
+ // http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg145787.html
+ || nextpit->params().depth() != pit->params().depth()) {