pit_type & pit, otexstream & os)
{
ParagraphList const & paragraphs = text.paragraphs();
- ParagraphList::const_iterator ipar = paragraphs.constIterator(pit);
+ ParagraphList::const_iterator ipar = paragraphs.iterator_at(pit);
LYXERR(Debug::LATEX, "TeXEnvironment for paragraph " << pit);
Layout const & current_layout = ipar->layout();
// 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);
+ ParagraphList::const_iterator par = paragraphs.iterator_at(pit);
// check first if this is an higher depth paragraph.
bool go_out = (par->params().depth() < current_depth);
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.iterator_at(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);
// other arguments, consider this.
for (auto const & larg : latexargs) {
Layout::latexarg const & arg = larg.second;
- if ((!arg.presetarg.empty() || !arg.defaultarg.empty()) && !arg.requires.empty()) {
- vector<string> req = getVectorFromString(arg.requires);
+ if ((!arg.presetarg.empty() || !arg.defaultarg.empty()) && !arg.required.empty()) {
+ vector<string> req = getVectorFromString(arg.required);
required.insert(required.end(), req.begin(), req.end());
}
}
latexargs.find(arg->name());
if (lit != latexargs.end()) {
Layout::latexarg const & larg = lit->second;
- vector<string> req = getVectorFromString(larg.requires);
+ vector<string> req = getVectorFromString(larg.required);
move(req.begin(), req.end(), back_inserter(required));
}
}
Layout const current_layout = pit->layout();
// get the first paragraph in sequence with this layout and depth
- pit_type offset = 0;
+ ptrdiff_t offset = 0;
while (true) {
- if (lyx::prev(pit, offset) == pars.begin())
+ if (prev(pit, offset) == pars.begin())
break;
- ParagraphList::const_iterator priorpit = lyx::prev(pit, offset + 1);
+ ParagraphList::const_iterator priorpit = prev(pit, offset + 1);
if (priorpit->layout() == current_layout
&& priorpit->params().depth() == current_depth)
++offset;
break;
}
- ParagraphList::const_iterator spit = lyx::prev(pit, offset);
+ ParagraphList::const_iterator spit = prev(pit, offset);
for (; spit != pars.end(); ++spit) {
if (spit->layout() != current_layout ||
{
switch (style.latextype) {
case LATEX_COMMAND:
- if (par.needsCProtection(runparams.moving_arg))
+ if (par.needsCProtection(runparams.moving_arg)) {
+ if (contains(runparams.active_chars, '^'))
+ // cprotect relies on ^ being on catcode 7
+ os << "\\begingroup\\catcode`\\^=7";
os << "\\cprotect";
+ }
os << '\\' << from_ascii(style.latexname());
// Command arguments
if (style.inpreamble && !force)
return;
+ // 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.size() > 0 && par.isDeleted(0, par.size()) && !bparams.output_changes)
+ return;
+
LYXERR(Debug::LATEX, "TeXOnePar for paragraph " << pit << " ptr " << &par << " '"
<< everypar << "'");
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';
Paragraph const * nextpar = runparams.isLastPar
? nullptr : ¶graphs.at(pit + 1);
- bool const intitle_command = style.intitle && style.latextype == LATEX_COMMAND;
+ bool const intitle_command = style.intitle && style.isCommand();
+ // Intitle commands switch languages locally, thus increase
+ // language nesting level
+ if (intitle_command)
+ state->nest_level_ += 1;
if (style.pass_thru) {
Font const outerfont = text.outerFont(pit);
// 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 << '{';
// I did not create a parEndCommand for this minuscule
// task because in the other user of parStartCommand
// the code is different (JMarc)
- if (style.isCommand())
- os << "}\n";
- else
+ if (style.isCommand()) {
+ os << "}";
+ if (par.needsCProtection(runparams.moving_arg)
+ && contains(runparams.active_chars, '^'))
+ os << "\\endgroup";
+ if (merged_par)
+ os << "{}";
+ else
+ os << "\n";
+ }
+ 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';
}
&& priorpar->layout().isEnvironment()
&& (priorpar->getDepth() > par.getDepth()
|| (priorpar->getDepth() == par.getDepth()
- && priorpar->layout() != par.layout()));
+ && priorpar->layout() != par.layout()));
+
+ // We need to ignore previous intitle commands since languages
+ // are switched locally there (# 11514)
+ // There might be paragraphs before the title, so we check this.
+ Paragraph * prior_nontitle_par = nullptr;
+ if (!intitle_command) {
+ pit_type ppit = pit;
+ while (ppit > 0) {
+ --ppit;
+ Paragraph const * tmppar = ¶graphs.at(ppit);
+ if (tmppar->layout().intitle && tmppar->layout().isCommand())
+ continue;
+ prior_nontitle_par = const_cast<Paragraph*>(tmppar);
+ break;
+ }
+ }
Language const * const prev_language =
- runparams_in.for_search ?
- languages.getLanguage("ignore")
- :(priorpar && !priorpar->isPassThru())
- ? (use_prev_env_language ? state->prev_env_language_
- : priorpar->getParLanguage(bparams))
- : outer_language;
+ runparams_in.for_search
+ ? languages.getLanguage("ignore")
+ : (prior_nontitle_par && !prior_nontitle_par->isPassThru())
+ ? (use_prev_env_language
+ ? state->prev_env_language_
+ : prior_nontitle_par->getParLanguage(bparams))
+ : outer_language;
bool const use_polyglossia = runparams.use_polyglossia;
string const par_lang = use_polyglossia ?
// 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 << '{';
}
&& runparams.local_font != nullptr
&& outer_language->rightToLeft()
&& !par_language->rightToLeft();
- bool const localswitch = runparams_in.for_search
+ bool const localswitch =
+ (runparams_in.for_search
|| text.inset().forceLocalFontSwitch()
|| (using_begin_end && text.inset().forcePlainLayout())
- || in_polyglossia_rtl_env;
+ || in_polyglossia_rtl_env)
+ && !text.inset().forceParDirectionSwitch();
if (localswitch) {
lang_begin_command = use_polyglossia ?
"\\text$$lang$$opts{" : lyxrc.language_command_local;
if ((runparams.encoding->package() != Encoding::CJK
|| bparams.useNonTeXFonts
|| runparams.for_search)
- && (par_lang != openLanguageName(state) || localswitch)
+ && (par_lang != openLanguageName(state) || localswitch || intitle_command)
&& !par_lang.empty()) {
string bc = use_polyglossia ?
getPolyglossiaBegin(lang_begin_command, par_lang,
// 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);
os << runparams.post_macro;
runparams.post_macro.clear();
}
+ if (par.needsCProtection(runparams.moving_arg)
+ && contains(runparams.active_chars, '^'))
+ os << "\\endgroup";
if (runparams.encoding != prev_encoding) {
runparams.encoding = prev_encoding;
os << setEncoding(prev_encoding->iconvName());
&& 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
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
// InTitle commands need to be closed after the language has been closed.
if (intitle_command) {
- if (is_command) {
- os << '}';
- if (!style.postcommandargs().empty())
- latexArgInsets(par, os, runparams, style.postcommandargs(), "post:");
- if (!runparams.post_macro.empty()) {
- // Output the stored fragile commands (labels, indices etc.)
- // that need to be output after the command with moving argument.
- os << runparams.post_macro;
- runparams.post_macro.clear();
- }
- if (runparams.encoding != prev_encoding) {
- runparams.encoding = prev_encoding;
- os << setEncoding(prev_encoding->iconvName());
- }
+ os << '}';
+ if (!style.postcommandargs().empty())
+ latexArgInsets(par, os, runparams, style.postcommandargs(), "post:");
+ if (!runparams.post_macro.empty()) {
+ // Output the stored fragile commands (labels, indices etc.)
+ // that need to be output after the command with moving argument.
+ os << runparams.post_macro;
+ runparams.post_macro.clear();
+ }
+ if (par.needsCProtection(runparams.moving_arg)
+ && contains(runparams.active_chars, '^'))
+ os << "\\endgroup";
+ if (runparams.encoding != prev_encoding) {
+ runparams.encoding = prev_encoding;
+ os << setEncoding(prev_encoding->iconvName());
}
}
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
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())) {
// Also pass the post_macros upstream
runparams_in.post_macro = runparams.post_macro;
+ // These need to be passed upstream as well
+ runparams_in.need_maketitle = runparams.need_maketitle;
+ runparams_in.have_maketitle = runparams.have_maketitle;
// we don't need a newline for the last paragraph!!!
// 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,
&& !text.inset().getLayout().parbreakIgnored()
&& style.latextype != LATEX_ITEM_ENVIRONMENT
&& style.latextype != LATEX_LIST_ENVIRONMENT
- && style.align == par.getAlign()
+ && style.align == par.getAlign(bparams)
&& nextpar->getDepth() == par.getDepth()
- && nextpar->getAlign() == par.getAlign())
+ && nextpar->getAlign(bparams) == par.getAlign(bparams))
|| (!next_layout.isEnvironment()
&& nextpar->getDepth() > par.getDepth()
- && nextpar->getAlign() == next_layout.align)
+ && nextpar->getAlign(bparams) == next_layout.align)
|| (!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())
- || (style.align != par.getAlign()
+ && style.align == par.getAlign(bparams)
+ && 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';
}
}
}
+ // Reset language nesting level after intitle command
+ if (intitle_command)
+ state->nest_level_ -= 1;
+
LYXERR(Debug::LATEX, "TeXOnePar for paragraph " << pit << " done; ptr "
<< &par << " next " << nextpar);
&& runparams.use_CJK))
) {
docstring const cjkenc = bparams.encoding().iconvName() == "UTF-8"
- ? from_ascii("UTF8") : from_ascii(bparams.encoding().latexName());
+ ? from_ascii("UTF8")
+ : from_ascii(bparams.encoding().latexName());
os << "\\begin{CJK}{" << cjkenc
<< "}{" << from_ascii(bparams.fonts_cjk) << "}%\n";
state->open_encoding_ = CJK;
pit_type pit = runparams.par_begin;
// lastpit is for the language check after the loop.
pit_type lastpit = pit;
- // variables used in the loop:
- bool was_title = false;
- bool already_title = false;
DocumentClass const & tclass = bparams.documentClass();
// Did we already warn about inTitle layout mixing? (we only warn once)
bool gave_layout_warning = false;
for (; pit < runparams.par_end; ++pit) {
lastpit = pit;
- ParagraphList::const_iterator par = paragraphs.constIterator(pit);
+ ParagraphList::const_iterator par = paragraphs.iterator_at(pit);
// FIXME This check should not be needed. We should
// perhaps issue an error if it is.
tclass.plainLayout() : par->layout();
if (layout.intitle) {
- if (already_title) {
+ if (runparams.have_maketitle) {
if (!gave_layout_warning && !runparams.dryrun) {
gave_layout_warning = true;
frontend::Alert::warning(_("Error in latexParagraphs"),
"could lead to missing or incorrect output."
), layout.name()));
}
- } else if (!was_title) {
- was_title = true;
+ } else if (!runparams.need_maketitle) {
+ runparams.need_maketitle = true;
if (tclass.titletype() == TITLE_ENVIRONMENT) {
os << "\\begin{"
<< from_ascii(tclass.titlename())
<< "}\n";
}
}
- } else if (was_title && !already_title && !layout.inpreamble) {
+ } else if (runparams.need_maketitle && !runparams.have_maketitle
+ && !layout.inpreamble && !text.inset().isInTitle()) {
if (tclass.titletype() == TITLE_ENVIRONMENT) {
os << "\\end{" << from_ascii(tclass.titlename())
<< "}\n";
os << "\\" << from_ascii(tclass.titlename())
<< "\n";
}
- already_title = true;
- was_title = false;
+ runparams.have_maketitle = true;
+ runparams.need_maketitle = false;
}
if (layout.isCommand() && !layout.latexname().empty()
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.iterator_at(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.
//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 an inset, this is not the end of
+ // the document. (There may be some other checks of this
+ // kind that are needed.)
+ if (runparams.need_maketitle && !runparams.have_maketitle && maintext) {
if (tclass.titletype() == TITLE_ENVIRONMENT) {
os << "\\end{" << from_ascii(tclass.titlename())
<< "}\n";
// if "auto end" is switched off, explicitly close the language at the end
// but only if the last par is in a babel or polyglossia language
+ Language const * const lastpar_language =
+ paragraphs.at(lastpit).getParLanguage(bparams);
if (maintext && !lyxrc.language_auto_end && !mainlang.empty() &&
- paragraphs.at(lastpit).getParLanguage(bparams)->encoding()->package() != Encoding::CJK) {
+ lastpar_language->encoding()->package() != Encoding::CJK) {
os << from_utf8(subst(lang_end_command,
"$$lang",
mainlang))
<< '\n';
- if (using_begin_end)
+ // If we have language_auto_begin, the stack will
+ // already be empty, nothing to pop()
+ if (using_begin_end && !lyxrc.language_auto_begin)
popLanguageName();
}
state->open_encoding_ = none;
}
// Likewise for polyglossia or when using begin/end commands
- // or after an active branch inset with a language switch
+ // or at the very end of an active branch inset with a language switch
Language const * const outer_language = (runparams.local_font != nullptr)
? runparams.local_font->language() : bparams.language;
string const & prev_lang = runparams.use_polyglossia
? getPolyglossiaEnvName(outer_language)
: outer_language->babel();
+ string const lastpar_lang = runparams.use_polyglossia ?
+ getPolyglossiaEnvName(lastpar_language): lastpar_language->babel();
string const & cur_lang = openLanguageName(state);
if (((runparams.inbranch && langOpenedAtThisLevel(state) && prev_lang != cur_lang)
|| (maintext && !is_child)) && !cur_lang.empty()) {
<< '\n';
if (using_begin_end)
popLanguageName();
- } else if (runparams.inbranch && !using_begin_end && prev_lang != cur_lang) {
+ } else if (runparams.inbranch && !using_begin_end
+ && prev_lang != lastpar_lang && !lastpar_lang.empty()) {
+ // with !using_begin_end, cur_lang is empty, so we need to
+ // compare against the paragraph language (and we are in the
+ // last paragraph at this point)
os << subst(lang_begin_command, "$$lang", prev_lang) << '\n';
}
OutputParams const & runparams, Encoding const & newEnc,
bool force, bool noswitchmacro)
{
- // Never switch encoding with non-TeX fonts (always "utf8plain"),
- // with LuaTeX and TeX fonts (only one encoding accepted by luainputenc),
+ // Never switch encoding with XeTeX/LuaTeX
// or if we're in a moving argument or inherit the outer encoding.
- if (bparams.useNonTeXFonts
- || runparams.flavor == OutputParams::LUATEX
- || runparams.flavor == OutputParams::DVILUATEX
- || newEnc.name() == "inherit")
- return make_pair(false, 0);
+ if (runparams.isFullUnicode() || newEnc.name() == "inherit")
+ return make_pair(false, 0);
// Only switch for auto-selected legacy encodings (inputenc setting
// "auto-legacy" or "auto-legacy-plain").