]> git.lyx.org Git - lyx.git/blobdiff - src/output_latex.cpp
Reintroduce the code related to InsetEnvSeparator
[lyx.git] / src / output_latex.cpp
index 4f8f14a86a75d9f3e32b4ebee63bd0a1cb3f7c42..735b898eb9871d0017202a8a7e24f2637d070061 100644 (file)
@@ -202,9 +202,7 @@ static TeXEnvironmentData prepareEnvironment(Buffer const & buf,
 }
 
 
-static void finishEnvironment(Buffer const & buf, Text const & text,
-                             pit_type nextpit, otexstream & os,
-                             OutputParams const & runparams,
+static void finishEnvironment(otexstream & os, OutputParams const & runparams,
                              TeXEnvironmentData const & data)
 {
        if (open_encoding_ == CJK && data.cjk_nested) {
@@ -236,11 +234,7 @@ static void finishEnvironment(Buffer const & buf, Text const & text,
        }
 
        // Check whether we should output a blank line after the environment
-       DocumentClass const & tclass = buf.params().documentClass();
-       ParagraphList const & pars = text.paragraphs();
-       bool next_style_is_default = (nextpit >= runparams.par_end) ? false
-               : tclass.isDefaultLayout(pars.constIterator(nextpit)->layout());
-       if (!data.style->nextnoindent && next_style_is_default)
+       if (!data.style->nextnoindent)
                os << '\n';
 }
 
@@ -306,7 +300,7 @@ void TeXEnvironment(Buffer const & buf, Text const & text,
                        prepareEnvironment(buf, text, par, os, runparams);
                // Recursive call to TeXEnvironment!
                TeXEnvironment(buf, text, runparams, pit, os);
-               finishEnvironment(buf, text, pit + 1, os, runparams, data);
+               finishEnvironment(os, runparams, data);
        }
 
        if (pit != runparams.par_end)
@@ -321,6 +315,18 @@ void getArgInsets(otexstream & os, OutputParams const & runparams, Layout::LaTeX
        if (argnr == 0)
                return;
 
+       // Default and preset args are always output, so if they require
+       // other arguments, consider this.
+       Layout::LaTeXArgMap::const_iterator lit = latexargs.begin();
+       Layout::LaTeXArgMap::const_iterator const lend = latexargs.end();
+       for (; lit != lend; ++lit) {
+               Layout::latexarg arg = (*lit).second;
+               if ((!arg.presetarg.empty() || !arg.defaultarg.empty()) && !arg.requires.empty()) {
+                               vector<string> req = getVectorFromString(arg.requires);
+                               required.insert(required.end(), req.begin(), req.end());
+                       }
+       }
+
        for (unsigned int i = 1; i <= argnr; ++i) {
                map<int, InsetArgument const *>::const_iterator lit = ilist.find(i);
                bool inserted = false;
@@ -854,9 +860,7 @@ void TeXOnePar(Buffer const & buf,
        switch (style.latextype) {
        case LATEX_ITEM_ENVIRONMENT:
        case LATEX_LIST_ENVIRONMENT:
-               if (nextpar
-                   && (par.params().depth() < nextpar->params().depth())
-                   && !par.isEnvSeparator(par.size() - 1))
+               if (nextpar && par.params().depth() < nextpar->params().depth())
                        pending_newline = true;
                break;
        case LATEX_ENVIRONMENT: {
@@ -871,8 +875,7 @@ void TeXOnePar(Buffer const & buf,
        // fall through possible
        default:
                // we don't need it for the last paragraph!!!
-               // or if the last thing is an environment separator
-               if (nextpar && !par.isEnvSeparator(par.size() - 1))
+               if (nextpar)
                        pending_newline = true;
        }
 
@@ -950,11 +953,15 @@ void TeXOnePar(Buffer const & buf,
        if (closing_rtl_ltr_environment)
                os << "}";
 
+       bool const last_was_separator =
+               par.size() > 0 && par.isEnvSeparator(par.size() - 1);
+
        if (pending_newline) {
                if (unskip_newline)
                        // prevent unwanted whitespace
                        os << '%';
-               os << '\n';
+               if (!os.afterParbreak() && !last_was_separator)
+                       os << '\n';
        }
 
        // if this is a CJK-paragraph and the next isn't, close CJK
@@ -1018,7 +1025,7 @@ void TeXOnePar(Buffer const & buf,
        // we don't need a newline for the last paragraph!!!
        // Note from JMarc: we will re-add a \n explicitly in
        // TeXEnvironment, because it is needed in this case
-       if (nextpar && !par.isEnvSeparator(par.size() - 1)) {
+       if (nextpar && !os.afterParbreak() && !last_was_separator) {
                // Make sure to start a new line
                os << breakln;
                Layout const & next_layout = nextpar->layout();
@@ -1035,9 +1042,11 @@ void TeXOnePar(Buffer const & buf,
                        // unchanged, or (case 2) the following is a
                        // non-environment paragraph whose depth is increased
                        // but whose alignment is unchanged, or (case 3) the
+                       // paragraph is not an environment and the next one is a
+                       // non-itemize-like env at lower depth, or (case 4) the
                        // paragraph is a command not followed by an environment
                        // and the alignment of the current and next paragraph
-                       // is unchanged, or (case 4) the current alignment is
+                       // is unchanged, or (case 5) the current alignment is
                        // changed and a standard paragraph follows.
                        DocumentClass const & tclass = bparams.documentClass();
                        if ((style == next_layout
@@ -1050,6 +1059,9 @@ void TeXOnePar(Buffer const & buf,
                            || (!next_layout.isEnvironment()
                                && nextpar->getDepth() > par.getDepth()
                                && nextpar->getAlign() == par.getAlign())
+                           || (!style.isEnvironment()
+                               && next_layout.latextype == LATEX_ENVIRONMENT
+                               && nextpar->getDepth() < par.getDepth())
                            || (style.isCommand()
                                && !next_layout.isEnvironment()
                                && style.align == par.getAlign()
@@ -1177,7 +1189,7 @@ void latexParagraphs(Buffer const & buf,
                        prepareEnvironment(buf, text, par, os, runparams);
                // pit can be changed in TeXEnvironment.
                TeXEnvironment(buf, text, runparams, pit, os);
-               finishEnvironment(buf, text, pit + 1, os, runparams, data);
+               finishEnvironment(os, runparams, data);
        }
 
        if (pit == runparams.par_end) {