]> git.lyx.org Git - lyx.git/blobdiff - src/output_latex.cpp
Reintroduce the code related to InsetEnvSeparator
[lyx.git] / src / output_latex.cpp
index f461ba2faabb7df0580f0f6c1135f0117224801e..735b898eb9871d0017202a8a7e24f2637d070061 100644 (file)
@@ -203,7 +203,7 @@ static TeXEnvironmentData prepareEnvironment(Buffer const & buf,
 
 
 static void finishEnvironment(otexstream & os, OutputParams const & runparams,
-                              TeXEnvironmentData const & data)
+                             TeXEnvironmentData const & data)
 {
        if (open_encoding_ == CJK && data.cjk_nested) {
                // We need to close the encoding even if it does not change
@@ -232,6 +232,10 @@ static void finishEnvironment(otexstream & os, OutputParams const & runparams,
                                os << setEncoding(data.prev_encoding->iconvName());
                }
        }
+
+       // Check whether we should output a blank line after the environment
+       if (!data.style->nextnoindent)
+               os << '\n';
 }
 
 
@@ -311,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;
@@ -785,7 +801,7 @@ void TeXOnePar(Buffer const & buf,
        bool const useSetSpace = bparams.documentClass().provides("SetSpace");
        if (par.allowParagraphCustomization()) {
                if (par.params().startOfAppendix()) {
-                       os << "\\appendix\n";
+                       os << "\n\\appendix\n";
                }
 
                if (!par.params().spacing().isDefault()
@@ -844,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: {
@@ -861,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;
        }
 
@@ -940,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
@@ -1008,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();
@@ -1025,9 +1042,13 @@ 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.
+                       // is unchanged, or (case 5) the current alignment is
+                       // changed and a standard paragraph follows.
+                       DocumentClass const & tclass = bparams.documentClass();
                        if ((style == next_layout
                             && !style.parbreak_is_newline
                             && style.latextype != LATEX_ITEM_ENVIRONMENT
@@ -1038,10 +1059,15 @@ 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()
-                               && next_layout.align == nextpar->getAlign())) {
+                               && next_layout.align == nextpar->getAlign())
+                           || (style.align != par.getAlign()
+                               && tclass.isDefaultLayout(next_layout))) {
                                os << '\n';
                        }
                }