X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Foutput_latex.cpp;h=1185e2d6e343149dbb0e7eddbb740958c9bed6ea;hb=104fdcc9be40df19d50cddad7f8ae9ab63bbf5f7;hp=8a33d51dc403497728ec856376104dda614f215b;hpb=d644ba0087329b4da6e37ca893236b510c5d15ed;p=lyx.git diff --git a/src/output_latex.cpp b/src/output_latex.cpp index 8a33d51dc4..1185e2d6e3 100644 --- a/src/output_latex.cpp +++ b/src/output_latex.cpp @@ -434,6 +434,22 @@ void TeXEnvironment(Buffer const & buf, Text const & text, continue; } + // Do not output empty environments if the whole paragraph has + // been deleted with ct and changes are not output. + if (size_t(pit + 1) < paragraphs.size()) { + ParagraphList::const_iterator nextpar = paragraphs.constIterator(pit + 1); + Paragraph const & cpar = paragraphs.at(pit); + if ((par->layout() != nextpar->layout() + || par->params().depth() == nextpar->params().depth() + || par->params().leftIndent() == nextpar->params().leftIndent()) + && !runparams.for_search && cpar.size() > 0 + && cpar.isDeleted(0, cpar.size()) && !buf.params().output_changes) { + if (!buf.params().output_changes && !cpar.parEndChange().deleted()) + os << '\n' << '\n'; + continue; + } + } + // This is a new environment. TeXEnvironmentData const data = prepareEnvironment(buf, text, par, os, runparams); @@ -745,7 +761,7 @@ void TeXOnePar(Buffer const & buf, // Do not output empty commands if the whole paragraph has // been deleted with ct and changes are not output. if (!runparams_in.for_search && style.latextype != LATEX_ENVIRONMENT - && par.isDeleted(0, par.size()) && !bparams.output_changes) + && par.size() > 0 && par.isDeleted(0, par.size()) && !bparams.output_changes) return; LYXERR(Debug::LATEX, "TeXOnePar for paragraph " << pit << " ptr " << &par << " '" @@ -769,11 +785,14 @@ void TeXOnePar(Buffer const & buf, state->open_encoding_ = none; } + // This paragraph is merged and we do not show changes in the output + bool const merged_par = !bparams.output_changes && par.parEndChange().deleted(); + if (text.inset().isPassThru()) { Font const outerfont = text.outerFont(pit); // No newline before first paragraph in this lyxtext - if (pit > 0 && !text.inset().getLayout().parbreakIgnored()) { + if (pit > 0 && !text.inset().getLayout().parbreakIgnored() && !merged_par) { os << '\n'; if (!text.inset().getLayout().parbreakIsNewline()) os << '\n'; @@ -799,7 +818,8 @@ void TeXOnePar(Buffer const & buf, // Due to the moving argument, some fragile // commands (labels, index entries) // are output after this command (#2154) - runparams.postpone_fragile_stuff = true; + runparams.postpone_fragile_stuff = + bparams.postpone_fragile_content; if (intitle_command) os << '{'; @@ -813,17 +833,20 @@ void TeXOnePar(Buffer const & buf, if (par.needsCProtection(runparams.moving_arg) && contains(runparams.active_chars, '^')) os << "\\endgroup"; - os << "\n"; + if (merged_par) + os << "{}"; + else + os << "\n"; } - else + else if (!merged_par) os << '\n'; - if (!style.parbreak_is_newline) { + if (!style.parbreak_is_newline && !merged_par) { os << '\n'; } else if (nextpar && !style.isEnvironment()) { Layout const nextstyle = text.inset().forcePlainLayout() ? bparams.documentClass().plainLayout() : nextpar->layout(); - if (nextstyle.name() != style.name()) + if (nextstyle.name() != style.name() && !merged_par) os << '\n'; } @@ -910,7 +933,8 @@ void TeXOnePar(Buffer const & buf, // Due to the moving argument, some fragile // commands (labels, index entries) // are output after this command (#2154) - runparams.postpone_fragile_stuff = true; + runparams.postpone_fragile_stuff = + bparams.postpone_fragile_content; os << '{'; } @@ -1127,7 +1151,8 @@ void TeXOnePar(Buffer const & buf, // Due to the moving argument, some fragile // commands (labels, index entries) // are output after this command (#2154) - runparams.postpone_fragile_stuff = true; + runparams.postpone_fragile_stuff = + bparams.postpone_fragile_content; } Font const outerfont = text.outerFont(pit); @@ -1176,7 +1201,7 @@ void TeXOnePar(Buffer const & buf, && nextpar->getDepth() < par.getDepth())) close_lang_switch = using_begin_end; if (nextpar && par.params().depth() < nextpar->params().depth()) - pending_newline = !text.inset().getLayout().parbreakIgnored(); + pending_newline = !text.inset().getLayout().parbreakIgnored() && !merged_par; break; case LATEX_ENVIRONMENT: { // if it's the last paragraph of the current environment @@ -1195,7 +1220,7 @@ void TeXOnePar(Buffer const & buf, default: // we don't need it for the last paragraph and in InTitle commands!!! if (nextpar && !intitle_command) - pending_newline = !text.inset().getLayout().parbreakIgnored(); + pending_newline = !text.inset().getLayout().parbreakIgnored() && !merged_par; } // InTitle commands use switches (not environments) for space settings @@ -1332,6 +1357,14 @@ void TeXOnePar(Buffer const & buf, bool const last_was_separator = par.size() > 0 && par.isEnvSeparator(par.size() - 1); + // Signify added/deleted par break in output if show changes in output + if (nextpar && !os.afterParbreak() && !last_was_separator + && bparams.output_changes && par.parEndChange().changed()) { + Changes::latexMarkChange(os, bparams, Change(Change::UNCHANGED), + par.parEndChange(), runparams); + os << bparams.encoding().latexString(docstring(1, 0x00b6)).first << "}"; + } + if (pending_newline) { if (unskip_newline) // prevent unwanted whitespace @@ -1345,7 +1378,8 @@ void TeXOnePar(Buffer const & buf, if (nextpar && state->open_encoding_ == CJK && bparams.encoding().iconvName() != "UTF-8" && bparams.encoding().package() != Encoding::CJK - && (nextpar_language->encoding()->package() != Encoding::CJK + && ((nextpar_language && + nextpar_language->encoding()->package() != Encoding::CJK) || (nextpar->layout().isEnvironment() && nextpar->isMultiLingual(bparams))) // inbetween environments, CJK has to be closed later (nesting!) && (!style.isEnvironment() || !nextpar->layout().isEnvironment())) { @@ -1415,7 +1449,7 @@ void TeXOnePar(Buffer const & buf, // TeXEnvironment, because it is needed in this case if (nextpar && !os.afterParbreak() && !last_was_separator) { Layout const & next_layout = nextpar->layout(); - if (!text.inset().getLayout().parbreakIgnored()) + if (!text.inset().getLayout().parbreakIgnored() && !merged_par) // Make sure to start a new line os << breakln; // A newline '\n' is always output before a command, @@ -1459,7 +1493,10 @@ void TeXOnePar(Buffer const & buf, && next_layout.align == nextpar->getAlign(bparams)) || (style.align != par.getAlign(bparams) && tclass.isDefaultLayout(next_layout))) { - os << '\n'; + // and omit paragraph break if it has been deleted with ct + // and changes are not shown in output + if (!merged_par) + os << '\n'; } } } @@ -1620,6 +1657,22 @@ void latexParagraphs(Buffer const & buf, continue; } + // Do not output empty environments if the whole paragraph has + // been deleted with ct and changes are not output. + if (size_t(pit + 1) < paragraphs.size()) { + ParagraphList::const_iterator nextpar = paragraphs.constIterator(pit + 1); + Paragraph const & cpar = paragraphs.at(pit); + if ((par->layout() != nextpar->layout() + || par->params().depth() == nextpar->params().depth() + || par->params().leftIndent() == nextpar->params().leftIndent()) + && !runparams.for_search && cpar.size() > 0 + && cpar.isDeleted(0, cpar.size()) && !bparams.output_changes) { + if (!bparams.output_changes && !cpar.parEndChange().deleted()) + os << '\n' << '\n'; + continue; + } + } + TeXEnvironmentData const data = prepareEnvironment(buf, text, par, os, runparams); // pit can be changed in TeXEnvironment. @@ -1635,8 +1688,11 @@ void latexParagraphs(Buffer const & buf, //os << '\n'; } - // It might be that we only have a title in this document - if (was_title && !already_title) { + // It might be that we only have a title in this document. + // But if we're in a branch, this is not the end of + // the document. (There may be some other checks of this + // kind that are needed.) + if (was_title && !already_title && !runparams.inbranch) { if (tclass.titletype() == TITLE_ENVIRONMENT) { os << "\\end{" << from_ascii(tclass.titlename()) << "}\n";