Abdelrazak Younes wrote: > Instead of doing this, you could pass a Text object instead of > ParagraphList. As the reference Buffer is also available, you can then > use Text::isMainText().
Ah, yes. Patch attached. Jürgen
Index: src/insets/InsetEnvironment.cpp =================================================================== --- src/insets/InsetEnvironment.cpp (Revision 22586) +++ src/insets/InsetEnvironment.cpp (Arbeitskopie) @@ -71,7 +71,7 @@ // FIXME UNICODE os << from_utf8(layout_->latexheader); TexRow texrow; - latexParagraphs(buf, paragraphs(), os, texrow, runparams, + latexParagraphs(buf, text_, os, texrow, runparams, layout_->latexparagraph); // FIXME UNICODE os << from_utf8(layout_->latexfooter); Index: src/insets/InsetText.cpp =================================================================== --- src/insets/InsetText.cpp (Revision 22586) +++ src/insets/InsetText.cpp (Arbeitskopie) @@ -287,7 +287,7 @@ OutputParams const & runparams) const { TexRow texrow; - latexParagraphs(buf, paragraphs(), os, texrow, runparams); + latexParagraphs(buf, text_, os, texrow, runparams); return texrow.rows(); } Index: src/output_latex.h =================================================================== --- src/output_latex.h (Revision 22586) +++ src/output_latex.h (Arbeitskopie) @@ -23,9 +23,9 @@ class BufferParams; class Encoding; class Paragraph; -class ParagraphList; class OutputParams; class TexRow; +class Text; /// Export up to \p number optarg insets int latexOptArgInsets(Buffer const & buf, Paragraph const & par, @@ -38,7 +38,7 @@ \sa Buffer::writeLaTeXSource for the reason. */ void latexParagraphs(Buffer const & buf, - ParagraphList const & paragraphs, + Text const & text, odocstream & ofs, TexRow & texrow, OutputParams const &, Index: src/mathed/InsetMathMBox.cpp =================================================================== --- src/mathed/InsetMathMBox.cpp (Revision 22586) +++ src/mathed/InsetMathMBox.cpp (Arbeitskopie) @@ -98,7 +98,7 @@ { os << "\\mbox{\n"; TexRow texrow; - latexParagraphs(buf, text_.paragraphs(), os, texrow, runparams); + latexParagraphs(buf, text_, os, texrow, runparams); os << "}"; return texrow.rows(); } Index: src/output_latex.cpp =================================================================== --- src/output_latex.cpp (Revision 22586) +++ src/output_latex.cpp (Arbeitskopie) @@ -56,14 +56,14 @@ ParagraphList::const_iterator TeXEnvironment(Buffer const & buf, - ParagraphList const & paragraphs, + Text const & text, ParagraphList::const_iterator pit, odocstream & os, TexRow & texrow, OutputParams const & runparams); ParagraphList::const_iterator TeXOnePar(Buffer const & buf, - ParagraphList const & paragraphs, + Text const & text, ParagraphList::const_iterator pit, odocstream & os, TexRow & texrow, OutputParams const & runparams, @@ -72,7 +72,7 @@ ParagraphList::const_iterator TeXDeeper(Buffer const & buf, - ParagraphList const & paragraphs, + Text const & text, ParagraphList::const_iterator pit, odocstream & os, TexRow & texrow, OutputParams const & runparams) @@ -80,13 +80,15 @@ LYXERR(Debug::LATEX) << "TeXDeeper... " << &*pit << endl; ParagraphList::const_iterator par = pit; + ParagraphList const & paragraphs = text.paragraphs(); + while (par != paragraphs.end() && par->params().depth() == pit->params().depth()) { if (par->layout()->isEnvironment()) { - par = TeXEnvironment(buf, paragraphs, par, + par = TeXEnvironment(buf, text, par, os, texrow, runparams); } else { - par = TeXOnePar(buf, paragraphs, par, + par = TeXOnePar(buf, text, par, os, texrow, runparams); } } @@ -98,7 +100,7 @@ ParagraphList::const_iterator TeXEnvironment(Buffer const & buf, - ParagraphList const & paragraphs, + Text const & text, ParagraphList::const_iterator pit, odocstream & os, TexRow & texrow, OutputParams const & runparams) @@ -109,6 +111,8 @@ Layout_ptr const & style = pit->layout(); + ParagraphList const & paragraphs = text.paragraphs(); + Language const * const par_language = pit->getParLanguage(bparams); Language const * const doc_language = bparams.language; Language const * const prev_par_language = @@ -186,7 +190,7 @@ ParagraphList::const_iterator par = pit; do { - par = TeXOnePar(buf, paragraphs, par, os, texrow, runparams); + par = TeXOnePar(buf, text, par, os, texrow, runparams); if (par == paragraphs.end()) { // Make sure that the last paragraph is @@ -214,7 +218,7 @@ os << '\n'; texrow.newline(); } - par = TeXDeeper(buf, paragraphs, par, os, texrow, + par = TeXDeeper(buf, text, par, os, texrow, runparams); } } while (par != paragraphs.end() @@ -271,7 +275,7 @@ ParagraphList::const_iterator TeXOnePar(Buffer const & buf, - ParagraphList const & paragraphs, + Text const & text, ParagraphList::const_iterator pit, odocstream & os, TexRow & texrow, OutputParams const & runparams_in, @@ -281,7 +285,10 @@ << everypar << "'" << endl; BufferParams const & bparams = buf.params(); Layout_ptr style; + ParagraphList const & paragraphs = text.paragraphs(); + bool const maintext = text.isMainText(buf); + // In an inset with unlimited length (all in one row), // force layout to default if (!pit->forceDefaultParagraphs()) @@ -293,31 +300,12 @@ runparams.moving_arg |= style->needprotect; // we are at the beginning of an inset and CJK is already open. - if (pit == paragraphs.begin() && runparams.local_font != 0 && + if (pit == paragraphs.begin() && !maintext && open_encoding_ == CJK) { cjk_inherited_ = true; open_encoding_ = none; } - if (pit == paragraphs.begin() && runparams.local_font == 0) { - // Open a CJK environment at the beginning of the main buffer - // if the document's language is a CJK language - if (bparams.encoding().package() == Encoding::CJK) { - os << "\\begin{CJK}{" << from_ascii(bparams.encoding().latexName()) - << "}{}%\n"; - texrow.newline(); - open_encoding_ = CJK; - } - if (!lyxrc.language_auto_begin && !bparams.language->babel().empty()) { - // FIXME UNICODE - os << from_utf8(subst(lyxrc.language_command_begin, - "$$lang", - bparams.language->babel())) - << '\n'; - texrow.newline(); - } - } - // This paragraph's language Language const * const par_language = pit->getParLanguage(bparams); // The document's language @@ -672,7 +660,7 @@ switch (open_encoding_) { case CJK: { // end of main text - if (runparams.local_font == 0) { + if (maintext) { os << '\n'; texrow.newline(); os << "\\end{CJK}\n"; @@ -693,16 +681,6 @@ // do nothing break; } - // auto_end tag only if the last par is in a babel language - if (runparams.local_font == 0 && !lyxrc.language_auto_end && - !bparams.language->babel().empty() && - font.language()->encoding()->package() != Encoding::CJK) { - os << from_utf8(subst(lyxrc.language_command_end, - "$$lang", - bparams.language->babel())) - << '\n'; - texrow.newline(); - } } // If this is the last paragraph, and a local_font was set upon entering @@ -742,7 +720,7 @@ // LaTeX all paragraphs void latexParagraphs(Buffer const & buf, - ParagraphList const & paragraphs, + Text const & text, odocstream & os, TexRow & texrow, OutputParams const & runparams, @@ -750,7 +728,9 @@ { bool was_title = false; bool already_title = false; - TextClass const & tclass = buf.params().getTextClass(); + BufferParams const & bparams = buf.params(); + TextClass const & tclass = bparams.getTextClass(); + ParagraphList const & paragraphs = text.paragraphs(); ParagraphList::const_iterator par = paragraphs.begin(); ParagraphList::const_iterator endpar = paragraphs.end(); @@ -765,9 +745,32 @@ const_cast<OutputParams&>(runparams).par_end = 0; } + bool const maintext = text.isMainText(buf); + + // Open a CJK environment at the beginning of the main buffer + // if the document's language is a CJK language + if (maintext && bparams.encoding().package() == Encoding::CJK) { + os << "\\begin{CJK}{" << from_ascii(bparams.encoding().latexName()) + << "}{}%\n"; + texrow.newline(); + open_encoding_ = CJK; + } + // if "auto begin" is switched off, explicitely switch the + // language on at start + if (maintext && !lyxrc.language_auto_begin && + !bparams.language->babel().empty()) { + // FIXME UNICODE + os << from_utf8(subst(lyxrc.language_command_begin, + "$$lang", + bparams.language->babel())) + << '\n'; + texrow.newline(); + } + + ParagraphList::const_iterator lastpar; // if only_body while (par != endpar) { - ParagraphList::const_iterator lastpar = par; + lastpar = par; // well we have to check if we are in an inset with unlimited // length (all in one row) if that is true then we don't allow // any special options in the paragraph and also we don't allow @@ -805,18 +808,18 @@ } if (layout->is_environment) { - par = TeXOnePar(buf, paragraphs, par, os, texrow, + par = TeXOnePar(buf, text, par, os, texrow, runparams, everypar); } else if (layout->isEnvironment() || !par->params().leftIndent().zero()) { - par = TeXEnvironment(buf, paragraphs, par, os, + par = TeXEnvironment(buf, text, par, os, texrow, runparams); } else { - par = TeXOnePar(buf, paragraphs, par, os, texrow, + par = TeXOnePar(buf, text, par, os, texrow, runparams, everypar); } } else { - par = TeXOnePar(buf, paragraphs, par, os, texrow, + par = TeXOnePar(buf, text, par, os, texrow, runparams, everypar); } if (std::distance(lastpar, par) >= std::distance(lastpar, endpar)) @@ -834,9 +837,19 @@ } texrow.newline(); } + // if "auto end" is switched off, explicitely close the language at the end + // but only if the last par is in a babel language + if (maintext && !lyxrc.language_auto_end && !bparams.language->babel().empty() && + lastpar->getParLanguage(bparams)->encoding()->package() != Encoding::CJK) { + os << from_utf8(subst(lyxrc.language_command_end, + "$$lang", + bparams.language->babel())) + << '\n'; + texrow.newline(); + } // If the last paragraph is an environment, we'll have to close // CJK at the very end to do proper nesting. - if (open_encoding_ == CJK) { + if (maintext && open_encoding_ == CJK) { os << "\\end{CJK}\n"; texrow.newline(); open_encoding_ = none; Index: src/Buffer.cpp =================================================================== --- src/Buffer.cpp (Revision 22586) +++ src/Buffer.cpp (Arbeitskopie) @@ -1073,7 +1073,7 @@ } // the real stuff - latexParagraphs(*this, paragraphs(), os, texrow(), runparams); + latexParagraphs(*this, text(), os, texrow(), runparams); // Restore the parenthood if needed if (output_preamble) @@ -1826,7 +1826,7 @@ // output paragraphs if (isLatex()) { texrow().reset(); - latexParagraphs(*this, paragraphs(), os, texrow(), runparams); + latexParagraphs(*this, text(), os, texrow(), runparams); } else { // DocBook docbookParagraphs(paragraphs(), *this, os, runparams);