+void TeXEnvironment(Buffer const & buf, Text const & text,
+ OutputParams const & runparams,
+ pit_type & pit, otexstream & os)
+{
+ ParagraphList const & paragraphs = text.paragraphs();
+ ParagraphList::const_iterator par = paragraphs.constIterator(pit);
+ LYXERR(Debug::LATEX, "TeXEnvironment for paragraph " << pit);
+
+ Layout const & current_layout = par->layout();
+ depth_type const current_depth = par->params().depth();
+ Length const & current_left_indent = par->params().leftIndent();
+
+ // This is for debugging purpose at the end.
+ pit_type const par_begin = pit;
+ for (; pit < runparams.par_end; ++pit) {
+
+ ParagraphList::const_iterator par = paragraphs.constIterator(pit);
+
+ // check first if this is an higher depth paragraph.
+ bool go_out = (par->params().depth() < current_depth);
+ if (par->params().depth() == current_depth) {
+ // This environment is finished.
+ go_out |= (par->layout() != current_layout);
+ go_out |= (par->params().leftIndent() != current_left_indent);
+ }
+ if (go_out) {
+ // nothing to do here, restore pit and go out.
+ pit--;
+ break;
+ }
+
+ if (par->layout() == current_layout
+ && par->params().depth() == current_depth
+ && par->params().leftIndent() == current_left_indent) {
+ // We are still in the same environment so TeXOnePar and continue;
+ TeXOnePar(buf, text, pit, os, runparams);
+ continue;
+ }
+
+ // We are now in a deeper environment.
+ // Either par->layout() != current_layout
+ // Or par->params().depth() > current_depth
+ // Or par->params().leftIndent() != current_left_indent)
+
+ if (par->layout().isParagraph()) {
+ // FIXME (Lgb): How to handle this?
+ //&& !suffixIs(os, "\n\n")
+
+ // (ARRae) There should be at least one '\n' already but we need there to
+ // be two for Standard paragraphs that are depth-increment'ed to be
+ // output correctly. However, tables can also be paragraphs so
+ // don't adjust them.
+ //
+
+ // FIXME (Lgb): Will it ever harm to have one '\n' too
+ // many? i.e. that we sometimes will have
+ // three in a row.
+ os << '\n';
+ }
+
+ // FIXME This test should not be necessary.
+ // We should perhaps issue an error if it is.
+ bool const force_plain_layout = text.inset().forcePlainLayout();
+ Layout const & style = force_plain_layout
+ ? buf.params().documentClass().plainLayout()
+ : par->layout();
+
+ if (!style.isEnvironment()) {
+ // This is a standard paragraph, no need to call TeXEnvironment.
+ TeXOnePar(buf, text, pit, os, runparams);
+ continue;
+ }
+
+ // This is a new environment.
+ TeXEnvironmentData const data =
+ prepareEnvironment(buf, text, par, os, runparams);
+ // Recursive call to TeXEnvironment!
+ TeXEnvironment(buf, text, runparams, pit, os);
+ finishEnvironment(os, runparams, data);
+ }