diff --git a/lib/layouts/stdinsets.inc b/lib/layouts/stdinsets.inc index 7eb3fc9ac6..1224644e27 100644 --- a/lib/layouts/stdinsets.inc +++ b/lib/layouts/stdinsets.inc @@ -86,6 +86,7 @@ InsetLayout Note:Comment Size Small EndFont MultiPar true + Display false HTMLTag !-- HTMLIsBlock false End @@ -119,6 +120,7 @@ InsetLayout Note:Greyedout Size Small EndFont MultiPar true + Display false HTMLStyle div.note_greyedout { display: inline; diff --git a/src/Buffer.cpp b/src/Buffer.cpp index b4e03b99d0..23c16406f4 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -1366,8 +1366,7 @@ void Buffer::writeLaTeXSource(odocstream & os, if (output_preamble) { if (!runparams.nice) { // code for usual, NOT nice-latex-file - os << "\\batchmode\n"; // changed - // from \nonstopmode + os << "\\batchmode\n"; // changed from \nonstopmode d->texrow.newline(); } if (!original_path.empty()) { @@ -1454,7 +1453,8 @@ void Buffer::writeLaTeXSource(odocstream & os, } // the real stuff - latexParagraphs(*this, text(), os, d->texrow, runparams); + otexstream ots(os); + latexParagraphs(*this, text(), ots, d->texrow, runparams); // Restore the parenthood if needed if (output_preamble) @@ -3133,9 +3133,11 @@ void Buffer::getSourceCode(odocstream & os, string const format, else if (runparams.flavor == OutputParams::HTML) { XHTMLStream xs(os); xhtmlParagraphs(text(), *this, xs, runparams); - } else + } else { // latex or literate - latexParagraphs(*this, text(), os, texrow, runparams); + otexstream ots(os); + latexParagraphs(*this, text(), ots, texrow, runparams); + } } } diff --git a/src/Changes.cpp b/src/Changes.cpp index 598a5bdb5f..c237df6237 100644 --- a/src/Changes.cpp +++ b/src/Changes.cpp @@ -391,7 +391,7 @@ docstring getLaTeXMarkup(docstring const & macro, docstring const & author, } //namespace anon -int Changes::latexMarkChange(odocstream & os, BufferParams const & bparams, +int Changes::latexMarkChange(otexstream & os, BufferParams const & bparams, Change const & oldChange, Change const & change, OutputParams const & runparams) { diff --git a/src/Changes.h b/src/Changes.h index cb5f57b080..435d44bca3 100644 --- a/src/Changes.h +++ b/src/Changes.h @@ -103,7 +103,7 @@ public: /// output latex to mark a transition between two change types /// returns length of text outputted - static int latexMarkChange(odocstream & os, BufferParams const & bparams, + static int latexMarkChange(otexstream & os, BufferParams const & bparams, Change const & oldChange, Change const & change, OutputParams const & runparams); diff --git a/src/Font.cpp b/src/Font.cpp index 402db84308..46cba97231 100644 --- a/src/Font.cpp +++ b/src/Font.cpp @@ -438,7 +438,7 @@ int Font::latexWriteStartChanges(odocstream & os, BufferParams const & bparams, /// Writes ending block of LaTeX needed to close use of this font // Returns number of chars written // This one corresponds to latexWriteStartChanges(). (Asger) -int Font::latexWriteEndChanges(odocstream & os, BufferParams const & bparams, +int Font::latexWriteEndChanges(otexstream & os, BufferParams const & bparams, OutputParams const & runparams, Font const & base, Font const & next, @@ -531,7 +531,7 @@ int Font::latexWriteEndChanges(odocstream & os, BufferParams const & bparams, // We need to close the encoding even if it does not change // to do correct environment nesting Encoding const * const ascii = encodings.fromLyXName("ascii"); - pair const c = switchEncoding(os, bparams, + pair const c = switchEncoding(os.os(), bparams, runparams, *ascii); LASSERT(c.first, /**/); count += c.second; diff --git a/src/Font.h b/src/Font.h index 2cdd5c1f2e..02b996e24f 100644 --- a/src/Font.h +++ b/src/Font.h @@ -27,6 +27,7 @@ class BufferParams; class Language; class LaTeXFeatures; class OutputParams; +class otexstream; /// class Font { @@ -81,7 +82,7 @@ public: Returns number of chars written. Base is the font state we want to achieve. */ - int latexWriteEndChanges(odocstream &, BufferParams const & bparams, + int latexWriteEndChanges(otexstream &, BufferParams const & bparams, OutputParams const & runparams, Font const & base, Font const & next, diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp index 090a1d84d7..bdf264f972 100644 --- a/src/LaTeXFeatures.cpp +++ b/src/LaTeXFeatures.cpp @@ -163,7 +163,9 @@ static docstring const tabularnewline_def = from_ascii( static docstring const lyxgreyedout_def = from_ascii( "%% The greyedout annotation environment\n" - "\\newenvironment{lyxgreyedout}{\\textcolor{note_fontcolor}\\bgroup}{\\egroup}\n"); + "\\newenvironment{lyxgreyedout}\n" + " {\\textcolor{note_fontcolor}\\bgroup\\ignorespaces}\n" + " {\\ignorespacesafterend\\egroup}\n"); // We want to omit the file extension for includegraphics, but this does not // work when the filename contains other dots. diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index 3036d45763..b8db16590c 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -288,14 +288,14 @@ public: /// Output the surrogate pair formed by \p c and \p next to \p os. /// \return the number of characters written. - int latexSurrogatePair(odocstream & os, char_type c, char_type next, + int latexSurrogatePair(otexstream & os, char_type c, char_type next, OutputParams const &); /// Output a space in appropriate formatting (or a surrogate pair /// if the next character is a combining character). /// \return whether a surrogate pair was output. bool simpleTeXBlanks(OutputParams const &, - odocstream &, TexRow & texrow, + otexstream &, TexRow & texrow, pos_type i, unsigned int & column, Font const & font, @@ -304,20 +304,20 @@ public: /// Output consecutive unicode chars, belonging to the same script as /// specified by the latex macro \p ltx, to \p os starting from \p i. /// \return the number of characters written. - int writeScriptChars(odocstream & os, docstring const & ltx, + int writeScriptChars(otexstream & os, docstring const & ltx, Change const &, Encoding const &, pos_type & i); /// This could go to ParagraphParameters if we want to. - int startTeXParParams(BufferParams const &, odocstream &, TexRow &, + int startTeXParParams(BufferParams const &, otexstream &, TexRow &, OutputParams const &) const; /// This could go to ParagraphParameters if we want to. - int endTeXParParams(BufferParams const &, odocstream &, TexRow &, + int endTeXParParams(BufferParams const &, otexstream &, TexRow &, OutputParams const &) const; /// void latexInset(BufferParams const &, - odocstream &, + otexstream &, TexRow & texrow, OutputParams &, Font & running_font, Font & basefont, @@ -330,7 +330,7 @@ public: /// void latexSpecialChar( - odocstream & os, + otexstream & os, OutputParams const & runparams, Font const & running_font, Change const & running_change, @@ -341,18 +341,18 @@ public: /// bool latexSpecialT1( char_type const c, - odocstream & os, + otexstream & os, pos_type i, unsigned int & column); /// bool latexSpecialTypewriter( char_type const c, - odocstream & os, + otexstream & os, pos_type i, unsigned int & column); /// bool latexSpecialPhrase( - odocstream & os, + otexstream & os, pos_type & i, unsigned int & column, OutputParams const & runparams); @@ -837,7 +837,7 @@ int Paragraph::eraseChars(pos_type start, pos_type end, bool trackChanges) } -int Paragraph::Private::latexSurrogatePair(odocstream & os, char_type c, +int Paragraph::Private::latexSurrogatePair(otexstream & os, char_type c, char_type next, OutputParams const & runparams) { // Writing next here may circumvent a possible font change between @@ -866,7 +866,7 @@ int Paragraph::Private::latexSurrogatePair(odocstream & os, char_type c, bool Paragraph::Private::simpleTeXBlanks(OutputParams const & runparams, - odocstream & os, TexRow & texrow, + otexstream & os, TexRow & texrow, pos_type i, unsigned int & column, Font const & font, @@ -911,7 +911,7 @@ bool Paragraph::Private::simpleTeXBlanks(OutputParams const & runparams, } -int Paragraph::Private::writeScriptChars(odocstream & os, +int Paragraph::Private::writeScriptChars(otexstream & os, docstring const & ltx, Change const & runningChange, Encoding const & encoding, @@ -1005,7 +1005,7 @@ bool Paragraph::Private::isTextAt(string const & str, pos_type pos) const void Paragraph::Private::latexInset(BufferParams const & bparams, - odocstream & os, + otexstream & os, TexRow & texrow, OutputParams & runparams, Font & running_font, @@ -1021,7 +1021,7 @@ void Paragraph::Private::latexInset(BufferParams const & bparams, LASSERT(inset, /**/); if (style.pass_thru) { - inset->plaintext(os, runparams); + inset->plaintext(os.os(), runparams); return; } @@ -1066,7 +1066,7 @@ void Paragraph::Private::latexInset(BufferParams const & bparams, } bool close = false; - odocstream::pos_type const len = os.tellp(); + odocstream::pos_type const len = os.os().tellp(); if (inset->forceLTR() && running_font.isRightToLeft() @@ -1138,7 +1138,7 @@ void Paragraph::Private::latexInset(BufferParams const & bparams, texrow.start(owner_->id(), i + 1); column = 0; } else { - column += (unsigned int)(os.tellp() - len); + column += (unsigned int)(os.os().tellp() - len); } if (owner_->isDeleted(i)) @@ -1146,14 +1146,13 @@ void Paragraph::Private::latexInset(BufferParams const & bparams, } -void Paragraph::Private::latexSpecialChar( - odocstream & os, - OutputParams const & runparams, - Font const & running_font, - Change const & running_change, - Layout const & style, - pos_type & i, - unsigned int & column) +void Paragraph::Private::latexSpecialChar(otexstream & os, + OutputParams const & runparams, + Font const & running_font, + Change const & running_change, + Layout const & style, + pos_type & i, + unsigned int & column) { char_type const c = text_[i]; @@ -1278,7 +1277,7 @@ void Paragraph::Private::latexSpecialChar( } -bool Paragraph::Private::latexSpecialT1(char_type const c, odocstream & os, +bool Paragraph::Private::latexSpecialT1(char_type const c, otexstream & os, pos_type i, unsigned int & column) { switch (c) { @@ -1306,7 +1305,7 @@ bool Paragraph::Private::latexSpecialT1(char_type const c, odocstream & os, } -bool Paragraph::Private::latexSpecialTypewriter(char_type const c, odocstream & os, +bool Paragraph::Private::latexSpecialTypewriter(char_type const c, otexstream & os, pos_type i, unsigned int & column) { switch (c) { @@ -1328,7 +1327,7 @@ bool Paragraph::Private::latexSpecialTypewriter(char_type const c, odocstream & } -bool Paragraph::Private::latexSpecialPhrase(odocstream & os, pos_type & i, +bool Paragraph::Private::latexSpecialPhrase(otexstream & os, pos_type & i, unsigned int & column, OutputParams const & runparams) { // FIXME: if we have "LaTeX" with a font @@ -1364,20 +1363,21 @@ void Paragraph::Private::validate(LaTeXFeatures & features) const // output is wrong if this paragraph contains content // that needs to switch encoding. odocstringstream ods; + otexstream os(ods); if (is_command) { ods << '\\' << from_ascii(layout_->latexname()); // we have to provide all the optional arguments here, even though // the last one is the only one we care about. // Separate handling of optional argument inset. if (layout_->optargs != 0 || layout_->reqargs != 0) - latexArgInsets(*owner_, ods, features.runparams(), - layout_->reqargs, layout_->optargs); + latexArgInsets(*owner_, os, features.runparams(), + layout_->reqargs, layout_->optargs); else - ods << from_ascii(layout_->latexparam()); + os << from_ascii(layout_->latexparam()); } docstring::size_type const length = ods.str().length(); // this will output "{" at the beginning, but not at the end - owner_->latex(bp, f, ods, tr, features.runparams(), 0, -1, true); + owner_->latex(bp, f, os, tr, features.runparams(), 0, -1, true); if (ods.str().length() > length) { if (is_command) ods << '}'; @@ -2134,7 +2134,7 @@ void adjust_row_column(string const & str, TexRow & texrow, int & column) int Paragraph::Private::startTeXParParams(BufferParams const & bparams, - odocstream & os, TexRow & texrow, + otexstream & os, TexRow & texrow, OutputParams const & runparams) const { int column = 0; @@ -2209,7 +2209,7 @@ int Paragraph::Private::startTeXParParams(BufferParams const & bparams, int Paragraph::Private::endTeXParParams(BufferParams const & bparams, - odocstream & os, TexRow & texrow, + otexstream & os, TexRow & texrow, OutputParams const & runparams) const { int column = 0; @@ -2281,7 +2281,7 @@ int Paragraph::Private::endTeXParParams(BufferParams const & bparams, // This one spits out the text of the paragraph void Paragraph::latex(BufferParams const & bparams, Font const & outerfont, - odocstream & os, TexRow & texrow, + otexstream & os, TexRow & texrow, OutputParams const & runparams, int start_pos, int end_pos, bool force) const { @@ -2433,8 +2433,9 @@ void Paragraph::latex(BufferParams const & bparams, if (!runparams.pass_thru && !style.pass_thru && runparams.encoding->package() != Encoding::none && font.language()->encoding()->package() != Encoding::none) { - pair const enc_switch = switchEncoding(os, bparams, - runparams, *(font.language()->encoding())); + pair const enc_switch = + switchEncoding(os.os(), bparams, runparams, + *(font.language()->encoding())); if (enc_switch.first) { column += enc_switch.second; runparams.encoding = font.language()->encoding(); diff --git a/src/Paragraph.h b/src/Paragraph.h index 154e9efc40..ed8d7f4027 100644 --- a/src/Paragraph.h +++ b/src/Paragraph.h @@ -55,6 +55,7 @@ class TexRow; class Toc; class WordLangTuple; class XHTMLStream; +class otexstream; class FontSpan { public: @@ -168,7 +169,7 @@ public: void validate(LaTeXFeatures &) const; /// \param force means: output even if layout.inpreamble is true. - void latex(BufferParams const &, Font const & outerfont, odocstream &, + void latex(BufferParams const &, Font const & outerfont, otexstream &, TexRow & texrow, OutputParams const &, int start_pos = 0, int end_pos = -1, bool force = false) const; diff --git a/src/frontends/qt4/FindAndReplace.cpp b/src/frontends/qt4/FindAndReplace.cpp index 0291ebaa11..46e4989fd2 100644 --- a/src/frontends/qt4/FindAndReplace.cpp +++ b/src/frontends/qt4/FindAndReplace.cpp @@ -143,7 +143,8 @@ bool FindAndReplaceWidget::eventFilter(QObject * obj, QEvent * event) static docstring buffer_to_latex(Buffer & buffer) { OutputParams runparams(&buffer.params().encoding()); - odocstringstream os; + odocstringstream ods; + otexstream os(ods); runparams.nice = true; runparams.flavor = OutputParams::LATEX; runparams.linelen = 80; //lyxrc.plaintext_linelen; @@ -154,10 +155,9 @@ static docstring buffer_to_latex(Buffer & buffer) for (pit_type pit = 0; pit != endpit; ++pit) { TeXOnePar(buffer, buffer.text(), pit, os, buffer.texrow(), runparams); - LYXERR(Debug::FIND, "searchString up to here: " - << os.str()); + LYXERR(Debug::FIND, "searchString up to here: " << ods.str()); } - return os.str(); + return ods.str(); } diff --git a/src/insets/Inset.h b/src/insets/Inset.h index 6bcddbe69e..1dfa76fc7b 100644 --- a/src/insets/Inset.h +++ b/src/insets/Inset.h @@ -56,6 +56,7 @@ class ParIterator; class Text; class TocList; class XHTMLStream; +class otexstream; namespace graphics { class PreviewLoader; } @@ -464,7 +465,7 @@ public: * \sa Buffer::writeLaTeXSource for the reason. * \return the number of rows (\n's) of generated LaTeX code. */ - virtual int latex(odocstream &, OutputParams const &) const { return 0; } + virtual int latex(otexstream &, OutputParams const &) const { return 0; } /// returns true to override begin and end inset in file virtual bool directWrite() const; /// diff --git a/src/insets/InsetArgument.cpp b/src/insets/InsetArgument.cpp index 55a97f3e5f..33a6c00e2e 100644 --- a/src/insets/InsetArgument.cpp +++ b/src/insets/InsetArgument.cpp @@ -33,7 +33,7 @@ void InsetArgument::write(ostream & os) const } -int InsetArgument::latex(odocstream &, OutputParams const &) const +int InsetArgument::latex(otexstream &, OutputParams const &) const { return 0; } @@ -56,11 +56,12 @@ docstring InsetArgument::xhtml(XHTMLStream &, OutputParams const &) const return docstring(); } -int InsetArgument::latexArgument(odocstream & os, +int InsetArgument::latexArgument(otexstream & os, OutputParams const & runparams, bool optional) const { odocstringstream ss; - int ret = InsetText::latex(ss, runparams); + otexstream ots(ss); + int ret = InsetText::latex(ots, runparams); docstring str = ss.str(); if (optional && str.find(']') != docstring::npos) str = '{' + str + '}'; diff --git a/src/insets/InsetArgument.h b/src/insets/InsetArgument.h index 43000f9bc4..0a3052f9b4 100644 --- a/src/insets/InsetArgument.h +++ b/src/insets/InsetArgument.h @@ -30,7 +30,7 @@ public: InsetArgument(Buffer *); /// Outputting the parameter of a LaTeX command - int latexArgument(odocstream &, OutputParams const &, + int latexArgument(otexstream &, OutputParams const &, bool optional) const; /// bool hasSettings() const { return false; } @@ -41,7 +41,7 @@ private: /// docstring name() const { return from_ascii("Argument"); } /// Standard LaTeX output -- short-circuited - int latex(odocstream &, OutputParams const &) const; + int latex(otexstream &, OutputParams const &) const; /// Standard plain text output -- short-circuited int plaintext(odocstream &, OutputParams const &) const; /// Standard DocBook output -- short-circuited diff --git a/src/insets/InsetBibtex.cpp b/src/insets/InsetBibtex.cpp index f61e1661a5..bf14e48054 100644 --- a/src/insets/InsetBibtex.cpp +++ b/src/insets/InsetBibtex.cpp @@ -235,7 +235,7 @@ static string normalizeName(Buffer const & buffer, } -int InsetBibtex::latex(odocstream & os, OutputParams const & runparams) const +int InsetBibtex::latex(otexstream & os, OutputParams const & runparams) const { // the sequence of the commands: // 1. \bibliographystyle{style} diff --git a/src/insets/InsetBibtex.h b/src/insets/InsetBibtex.h index 73141f455d..954783228c 100644 --- a/src/insets/InsetBibtex.h +++ b/src/insets/InsetBibtex.h @@ -50,7 +50,7 @@ public: /// DisplayType display() const { return AlignCenter; } /// - int latex(odocstream &, OutputParams const &) const; + int latex(otexstream &, OutputParams const &) const; /// void collectBibKeys(InsetIterator const &) const; /// diff --git a/src/insets/InsetBox.cpp b/src/insets/InsetBox.cpp index e6fc2f71a9..c053c5b587 100644 --- a/src/insets/InsetBox.cpp +++ b/src/insets/InsetBox.cpp @@ -237,7 +237,7 @@ bool InsetBox::getStatus(Cursor & cur, FuncRequest const & cmd, } -int InsetBox::latex(odocstream & os, OutputParams const & runparams) const +int InsetBox::latex(otexstream & os, OutputParams const & runparams) const { BoxType btype = boxtranslator().find(params_.type); diff --git a/src/insets/InsetBox.h b/src/insets/InsetBox.h index 8c7303246e..a001d7121a 100644 --- a/src/insets/InsetBox.h +++ b/src/insets/InsetBox.h @@ -111,7 +111,7 @@ private: /// bool noFontChange() const { return true; } /// - int latex(odocstream &, OutputParams const &) const; + int latex(otexstream &, OutputParams const &) const; /// int plaintext(odocstream &, OutputParams const &) const; /// diff --git a/src/insets/InsetBranch.cpp b/src/insets/InsetBranch.cpp index 5285cc72f7..cc81635fa8 100644 --- a/src/insets/InsetBranch.cpp +++ b/src/insets/InsetBranch.cpp @@ -203,7 +203,7 @@ bool InsetBranch::isBranchSelected() const } -int InsetBranch::latex(odocstream & os, OutputParams const & runparams) const +int InsetBranch::latex(otexstream & os, OutputParams const & runparams) const { return isBranchSelected() ? InsetText::latex(os, runparams) : 0; } diff --git a/src/insets/InsetBranch.h b/src/insets/InsetBranch.h index c1d2264e15..616abe04b4 100644 --- a/src/insets/InsetBranch.h +++ b/src/insets/InsetBranch.h @@ -65,7 +65,7 @@ private: /// ColorCode backgroundColor(PainterInfo const &) const; /// - int latex(odocstream &, OutputParams const &) const; + int latex(otexstream &, OutputParams const &) const; /// int plaintext(odocstream &, OutputParams const &) const; /// diff --git a/src/insets/InsetCaption.cpp b/src/insets/InsetCaption.cpp index 89235d739c..293c3861e1 100644 --- a/src/insets/InsetCaption.cpp +++ b/src/insets/InsetCaption.cpp @@ -228,7 +228,7 @@ bool InsetCaption::getStatus(Cursor & cur, FuncRequest const & cmd, } -int InsetCaption::latex(odocstream & os, +int InsetCaption::latex(otexstream & os, OutputParams const & runparams_in) const { if (runparams_in.inFloat == OutputParams::SUBFLOAT) @@ -290,14 +290,14 @@ docstring InsetCaption::xhtml(XHTMLStream & xs, OutputParams const & rp) const } -int InsetCaption::getArgument(odocstream & os, +int InsetCaption::getArgument(otexstream & os, OutputParams const & runparams) const { return InsetText::latex(os, runparams); } -int InsetCaption::getOptArg(odocstream & os, +int InsetCaption::getOptArg(otexstream & os, OutputParams const & runparams) const { return latexArgInsets(paragraphs()[0], os, runparams, 0, 1); diff --git a/src/insets/InsetCaption.h b/src/insets/InsetCaption.h index ced0402c79..bc0b674de6 100644 --- a/src/insets/InsetCaption.h +++ b/src/insets/InsetCaption.h @@ -27,9 +27,9 @@ public: /// docstring name() const; /// return the mandatory argument (LaTeX format) only - int getArgument(odocstream & os, OutputParams const &) const; + int getArgument(otexstream & os, OutputParams const &) const; /// return the optional argument(s) only - int getOptArg(odocstream & os, OutputParams const &) const; + int getOptArg(otexstream & os, OutputParams const &) const; /// return the caption text int getCaptionAsPlaintext(odocstream & os, OutputParams const &) const; /// return the caption text as HTML @@ -67,7 +67,7 @@ private: // Update the counters of this inset and of its contents void updateBuffer(ParIterator const &, UpdateType); /// - int latex(odocstream & os, OutputParams const &) const; + int latex(otexstream & os, OutputParams const &) const; /// int plaintext(odocstream & os, OutputParams const & runparams) const; /// diff --git a/src/insets/InsetCitation.cpp b/src/insets/InsetCitation.cpp index 3735eaf6f1..8a427c66ef 100644 --- a/src/insets/InsetCitation.cpp +++ b/src/insets/InsetCitation.cpp @@ -556,7 +556,7 @@ void InsetCitation::forToc(docstring & os, size_t) const // the \cite command is valid. Eg, the user has natbib enabled, inputs some // citations and then changes his mind, turning natbib support off. The output // should revert to \cite[]{} -int InsetCitation::latex(odocstream & os, OutputParams const & runparams) const +int InsetCitation::latex(otexstream & os, OutputParams const & runparams) const { CiteEngine cite_engine = buffer().params().citeEngine(); BiblioInfo const & bi = buffer().masterBibInfo(); diff --git a/src/insets/InsetCitation.h b/src/insets/InsetCitation.h index 11a9d00c79..1c3de97cc8 100644 --- a/src/insets/InsetCitation.h +++ b/src/insets/InsetCitation.h @@ -43,7 +43,7 @@ public: /// InsetCode lyxCode() const { return CITE_CODE; } /// - int latex(odocstream &, OutputParams const &) const; + int latex(otexstream &, OutputParams const &) const; /// int plaintext(odocstream &, OutputParams const &) const; /// diff --git a/src/insets/InsetCommand.cpp b/src/insets/InsetCommand.cpp index f2aa3fffd2..05fe55deb4 100644 --- a/src/insets/InsetCommand.cpp +++ b/src/insets/InsetCommand.cpp @@ -119,7 +119,7 @@ void InsetCommand::setParams(InsetCommandParams const & p) } -int InsetCommand::latex(odocstream & os, OutputParams const & runparams_in) const +int InsetCommand::latex(otexstream & os, OutputParams const & runparams_in) const { OutputParams runparams = runparams_in; os << getCommand(runparams); diff --git a/src/insets/InsetCommand.h b/src/insets/InsetCommand.h index a70f3d2065..6f4c3521b0 100644 --- a/src/insets/InsetCommand.h +++ b/src/insets/InsetCommand.h @@ -76,7 +76,7 @@ public: /// void draw(PainterInfo & pi, int x, int y) const; /// - int latex(odocstream &, OutputParams const &) const; + int latex(otexstream &, OutputParams const &) const; /// int plaintext(odocstream &, OutputParams const &) const; /// diff --git a/src/insets/InsetExternal.cpp b/src/insets/InsetExternal.cpp index 78d7de47a2..67671ac135 100644 --- a/src/insets/InsetExternal.cpp +++ b/src/insets/InsetExternal.cpp @@ -518,13 +518,14 @@ static bool isPreviewWanted(InsetExternalParams const & params) static docstring latexString(InsetExternal const & inset) { - odocstringstream os; + odocstringstream ods; + otexstream os(ods); // We don't need to set runparams.encoding since it is not used by // latex(). OutputParams runparams(0); runparams.flavor = OutputParams::LATEX; inset.latex(os, runparams); - return os.str(); + return ods.str(); } @@ -635,7 +636,7 @@ void InsetExternal::read(Lexer & lex) } -int InsetExternal::latex(odocstream & os, OutputParams const & runparams) const +int InsetExternal::latex(otexstream & os, OutputParams const & runparams) const { if (params_.draft) { // FIXME UNICODE @@ -666,14 +667,14 @@ int InsetExternal::latex(odocstream & os, OutputParams const & runparams) const if (cit != et.formats.end()) { return external::writeExternal(params_, "PDFLaTeX", - buffer(), os, + buffer(), os.os(), *(runparams.exportdata), external_in_tmpdir, dryrun); } } - return external::writeExternal(params_, "LaTeX", buffer(), os, + return external::writeExternal(params_, "LaTeX", buffer(), os.os(), *(runparams.exportdata), external_in_tmpdir, dryrun); diff --git a/src/insets/InsetExternal.h b/src/insets/InsetExternal.h index a5c1c2c58f..2e28c6115a 100644 --- a/src/insets/InsetExternal.h +++ b/src/insets/InsetExternal.h @@ -109,7 +109,7 @@ public: /// Update not loaded previews void updatePreview(); /// \returns the number of rows (\n's) of generated code. - int latex(odocstream &, OutputParams const &) const; + int latex(otexstream &, OutputParams const &) const; /// docstring contextMenuName() const; /// diff --git a/src/insets/InsetFloat.cpp b/src/insets/InsetFloat.cpp index 7e8bb7f7de..c24824c4eb 100644 --- a/src/insets/InsetFloat.cpp +++ b/src/insets/InsetFloat.cpp @@ -325,7 +325,7 @@ docstring InsetFloat::xhtml(XHTMLStream & xs, OutputParams const & rp) const } -int InsetFloat::latex(odocstream & os, OutputParams const & runparams_in) const +int InsetFloat::latex(otexstream & os, OutputParams const & runparams_in) const { if (runparams_in.inFloat != OutputParams::NONFLOAT) { if (runparams_in.moving_arg) @@ -372,24 +372,27 @@ int InsetFloat::latex(odocstream & os, OutputParams const & runparams_in) const placement = buf_placement; } - // The \n is used to force \begin{} to appear in a new line. - // The % is needed to prevent two consecutive \n chars in the case - // when the current output line is empty. - os << "%\n\\begin{" << from_ascii(tmptype) << '}'; + // clear counter + os.countLines(); + // Force \begin{} to appear in a new line. + os << breakln << "\\begin{" << from_ascii(tmptype) << '}'; // We only output placement if different from the def_placement. // sidewaysfloats always use their own page if (!placement.empty() && !params_.sideways) { os << '[' << from_ascii(placement) << ']'; } os << '\n'; + int lines = os.countLines(); - int const i = InsetText::latex(os, runparams); + lines += InsetText::latex(os, runparams); - // The \n is used to force \end{} to appear in a new line. - // Also in this case, we care that the current output line is not empty. - os << "%\n\\end{" << from_ascii(tmptype) << "}\n"; + // clear counter + os.countLines(); + // Force \end{} to appear in a new line. + os << breakln << "\\end{" << from_ascii(tmptype) << "}\n"; + lines += os.countLines(); - return i + 4; + return lines; } @@ -484,9 +487,10 @@ docstring InsetFloat::getCaption(OutputParams const & runparams) const return docstring(); odocstringstream ods; - ins->getOptArg(ods, runparams); + otexstream os(ods); + ins->getOptArg(os, runparams); ods << '['; - ins->getArgument(ods, runparams); + ins->getArgument(os, runparams); ods << ']'; return ods.str(); } diff --git a/src/insets/InsetFloat.h b/src/insets/InsetFloat.h index cc1e066588..1ad57041ec 100644 --- a/src/insets/InsetFloat.h +++ b/src/insets/InsetFloat.h @@ -81,7 +81,7 @@ private: /// InsetCode lyxCode() const { return FLOAT_CODE; } /// - int latex(odocstream &, OutputParams const &) const; + int latex(otexstream &, OutputParams const &) const; /// int plaintext(odocstream &, OutputParams const &) const; /// diff --git a/src/insets/InsetFloatList.cpp b/src/insets/InsetFloatList.cpp index 1261e014b2..e52f416aa5 100644 --- a/src/insets/InsetFloatList.cpp +++ b/src/insets/InsetFloatList.cpp @@ -113,7 +113,7 @@ void InsetFloatList::read(Lexer & lex) } -int InsetFloatList::latex(odocstream & os, OutputParams const &) const +int InsetFloatList::latex(otexstream & os, OutputParams const &) const { FloatList const & floats = buffer().params().documentClass().floats(); FloatList::const_iterator cit = floats[to_ascii(getParam("type"))]; diff --git a/src/insets/InsetFloatList.h b/src/insets/InsetFloatList.h index 9c8d0f3412..e03e541d54 100644 --- a/src/insets/InsetFloatList.h +++ b/src/insets/InsetFloatList.h @@ -38,7 +38,7 @@ public: /// void read(Lexer &); /// - int latex(odocstream &, OutputParams const &) const; + int latex(otexstream &, OutputParams const &) const; /// int docbook(odocstream &, OutputParams const &) const { return 0; } /// diff --git a/src/insets/InsetFoot.cpp b/src/insets/InsetFoot.cpp index a061c47029..ef7707a91b 100644 --- a/src/insets/InsetFoot.cpp +++ b/src/insets/InsetFoot.cpp @@ -84,7 +84,7 @@ docstring InsetFoot::toolTip(BufferView const & bv, int x, int y) const } -int InsetFoot::latex(odocstream & os, OutputParams const & runparams_in) const +int InsetFoot::latex(otexstream & os, OutputParams const & runparams_in) const { OutputParams runparams = runparams_in; // footnotes in titling commands like \title have moving arguments diff --git a/src/insets/InsetFoot.h b/src/insets/InsetFoot.h index 621b2bf392..90ec99076f 100644 --- a/src/insets/InsetFoot.h +++ b/src/insets/InsetFoot.h @@ -32,7 +32,7 @@ private: /// docstring name() const { return from_ascii("Foot"); } /// - int latex(odocstream &, OutputParams const &) const; + int latex(otexstream &, OutputParams const &) const; /// int plaintext(odocstream &, OutputParams const &) const; /// diff --git a/src/insets/InsetGraphics.cpp b/src/insets/InsetGraphics.cpp index 68627e0585..3195b5ca0a 100644 --- a/src/insets/InsetGraphics.cpp +++ b/src/insets/InsetGraphics.cpp @@ -746,7 +746,7 @@ string InsetGraphics::prepareFile(OutputParams const & runparams) const } -int InsetGraphics::latex(odocstream & os, +int InsetGraphics::latex(otexstream & os, OutputParams const & runparams) const { // If there is no file specified or not existing, diff --git a/src/insets/InsetGraphics.h b/src/insets/InsetGraphics.h index 9d40e78d33..058a9d1cb2 100644 --- a/src/insets/InsetGraphics.h +++ b/src/insets/InsetGraphics.h @@ -72,7 +72,7 @@ private: #fragile == true# means, that the inset should take care about fragile commands by adding a #\protect# before. */ - int latex(odocstream &, OutputParams const &) const; + int latex(otexstream &, OutputParams const &) const; /// int plaintext(odocstream &, OutputParams const &) const; /// diff --git a/src/insets/InsetHyperlink.cpp b/src/insets/InsetHyperlink.cpp index 85aaf43482..e3125c3b52 100644 --- a/src/insets/InsetHyperlink.cpp +++ b/src/insets/InsetHyperlink.cpp @@ -108,7 +108,7 @@ void InsetHyperlink::viewTarget() const } -int InsetHyperlink::latex(odocstream & os, +int InsetHyperlink::latex(otexstream & os, OutputParams const & runparams) const { docstring url = getParam("target"); diff --git a/src/insets/InsetHyperlink.h b/src/insets/InsetHyperlink.h index ec64924565..8b6d8fb04f 100644 --- a/src/insets/InsetHyperlink.h +++ b/src/insets/InsetHyperlink.h @@ -46,7 +46,7 @@ public: /// void validate(LaTeXFeatures &) const; /// - int latex(odocstream &, OutputParams const &) const; + int latex(otexstream &, OutputParams const &) const; /// int plaintext(odocstream &, OutputParams const &) const; /// diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp index 97b7592644..a2b85976db 100644 --- a/src/insets/InsetInclude.cpp +++ b/src/insets/InsetInclude.cpp @@ -479,7 +479,7 @@ Buffer * InsetInclude::loadIfNeeded() const } -int InsetInclude::latex(odocstream & os, OutputParams const & runparams) const +int InsetInclude::latex(otexstream & os, OutputParams const & runparams) const { string incfile = to_utf8(params()["filename"]); @@ -960,14 +960,15 @@ bool preview_wanted(InsetCommandParams const & params, Buffer const & buffer) docstring latexString(InsetInclude const & inset) { - odocstringstream os; + odocstringstream ods; + otexstream os(ods); // We don't need to set runparams.encoding since this will be done // by latex() anyway. OutputParams runparams(0); runparams.flavor = OutputParams::LATEX; inset.latex(os, runparams); - return os.str(); + return ods.str(); } diff --git a/src/insets/InsetInclude.h b/src/insets/InsetInclude.h index 2cd2a762a0..357003a151 100644 --- a/src/insets/InsetInclude.h +++ b/src/insets/InsetInclude.h @@ -87,7 +87,7 @@ public: /// bool hasSettings() const { return true; } /// - int latex(odocstream &, OutputParams const &) const; + int latex(otexstream &, OutputParams const &) const; /// int plaintext(odocstream &, OutputParams const &) const; /// diff --git a/src/insets/InsetIndex.cpp b/src/insets/InsetIndex.cpp index 386e22bf00..2badf7c6aa 100644 --- a/src/insets/InsetIndex.cpp +++ b/src/insets/InsetIndex.cpp @@ -57,7 +57,7 @@ InsetIndex::InsetIndex(Buffer * buf, InsetIndexParams const & params) {} -int InsetIndex::latex(odocstream & os, +int InsetIndex::latex(otexstream & os, OutputParams const & runparams_in) const { OutputParams runparams(runparams_in); @@ -76,7 +76,8 @@ int InsetIndex::latex(odocstream & os, // get contents of InsetText as LaTeX and plaintext odocstringstream ourlatex; - InsetText::latex(ourlatex, runparams); + otexstream ots(ourlatex); + InsetText::latex(ots, runparams); odocstringstream ourplain; InsetText::plaintext(ourplain, runparams); docstring latexstr = ourlatex.str(); @@ -557,7 +558,7 @@ bool InsetPrintIndex::getStatus(Cursor & cur, FuncRequest const & cmd, } -int InsetPrintIndex::latex(odocstream & os, OutputParams const & runparams_in) const +int InsetPrintIndex::latex(otexstream & os, OutputParams const & runparams_in) const { if (!buffer().masterBuffer()->params().use_indices) { if (getParam("type") == from_ascii("idx")) diff --git a/src/insets/InsetIndex.h b/src/insets/InsetIndex.h index 8ac0e5e125..4578c17401 100644 --- a/src/insets/InsetIndex.h +++ b/src/insets/InsetIndex.h @@ -58,10 +58,10 @@ private: void read(Lexer & lex); /// int docbook(odocstream &, OutputParams const &) const; - /// + /// docstring xhtml(XHTMLStream &, OutputParams const &) const; /// - int latex(odocstream &, OutputParams const &) const; + int latex(otexstream &, OutputParams const &) const; /// bool showInsetDialog(BufferView *) const; /// @@ -100,8 +100,8 @@ public: /// InsetCode lyxCode() const { return INDEX_PRINT_CODE; } /// - int latex(odocstream &, OutputParams const &) const; - /// + int latex(otexstream &, OutputParams const &) const; + /// docstring xhtml(XHTMLStream &, OutputParams const &) const; /// void doDispatch(Cursor & cur, FuncRequest & cmd); diff --git a/src/insets/InsetLayout.cpp b/src/insets/InsetLayout.cpp index 4408b9d0b3..2b71a2256a 100644 --- a/src/insets/InsetLayout.cpp +++ b/src/insets/InsetLayout.cpp @@ -39,7 +39,7 @@ InsetLayout::InsetLayout() : passthru_(false), parbreakisnewline_(false), freespacing_(false), keepempty_(false), forceltr_(false), needprotect_(false), intoc_(false), spellcheck_(true), - resetsfont_(true) + resetsfont_(true), display_(true) { labelfont_.setColor(Color_error); } @@ -81,6 +81,7 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass) IL_COUNTER, IL_CUSTOMPARS, IL_DECORATION, + IL_DISPLAY, IL_FONT, IL_FORCELTR, IL_FORCEPLAIN, @@ -122,6 +123,7 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass) { "counter", IL_COUNTER}, { "custompars", IL_CUSTOMPARS }, { "decoration", IL_DECORATION }, + { "display", IL_DISPLAY }, { "end", IL_END }, { "font", IL_FONT }, { "forceltr", IL_FORCELTR }, @@ -345,6 +347,9 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass) case IL_RESETSFONT: lex >> resetsfont_; break; + case IL_DISPLAY: + lex >> display_; + break; case IL_END: getout = true; break; diff --git a/src/insets/InsetLayout.h b/src/insets/InsetLayout.h index 502428beb0..5b88cb8983 100644 --- a/src/insets/InsetLayout.h +++ b/src/insets/InsetLayout.h @@ -144,6 +144,8 @@ public: bool spellcheck() const { return spellcheck_; } /// bool resetsFont() const { return resetsfont_; } + /// + bool isDisplay() const { return display_; } private: /// void makeDefaultCSS() const; @@ -232,6 +234,8 @@ private: bool spellcheck_; /// bool resetsfont_; + /// + bool display_; }; /// diff --git a/src/insets/InsetLine.cpp b/src/insets/InsetLine.cpp index a91a31ed5e..f81fe2d532 100644 --- a/src/insets/InsetLine.cpp +++ b/src/insets/InsetLine.cpp @@ -161,7 +161,7 @@ void InsetLine::draw(PainterInfo & pi, int x, int y) const } -int InsetLine::latex(odocstream & os, OutputParams const &) const +int InsetLine::latex(otexstream & os, OutputParams const &) const { bool have_offset = true; Length offset_len = Length(to_ascii(getParam("offset"))); diff --git a/src/insets/InsetLine.h b/src/insets/InsetLine.h index 9612970ce1..1f3eda65c2 100644 --- a/src/insets/InsetLine.h +++ b/src/insets/InsetLine.h @@ -48,7 +48,7 @@ private: bool hasSettings() const { return true; } void metrics(MetricsInfo &, Dimension &) const; void draw(PainterInfo & pi, int x, int y) const; - int latex(odocstream &, OutputParams const &) const; + int latex(otexstream &, OutputParams const &) const; int plaintext(odocstream &, OutputParams const &) const; void doDispatch(Cursor & cur, FuncRequest & cmd); bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const; diff --git a/src/insets/InsetListings.cpp b/src/insets/InsetListings.cpp index 7b37e05941..c10c54bdd1 100644 --- a/src/insets/InsetListings.cpp +++ b/src/insets/InsetListings.cpp @@ -126,7 +126,7 @@ void InsetListings::read(Lexer & lex) } -int InsetListings::latex(odocstream & os, OutputParams const & runparams) const +int InsetListings::latex(otexstream & os, OutputParams const & runparams) const { string param_string = params().params(); // NOTE: I use {} to quote text, which is an experimental feature @@ -159,8 +159,8 @@ int InsetListings::latex(odocstream & os, OutputParams const & runparams) const (outer_language->encoding()->hasFixedWidth()) ? outer_language->encoding() : encodings.fromLyXName("iso8859-1"); - pair const c = switchEncoding(os, buffer().params(), - runparams, *lstenc, true); + pair const c = switchEncoding(os.os(), + buffer().params(), runparams, *lstenc, true); runparams.encoding = lstenc; encoding_switched = true; } @@ -237,10 +237,12 @@ int InsetListings::latex(odocstream & os, OutputParams const & runparams) const OutputParams rp = runparams; rp.moving_arg = true; docstring const caption = getCaption(rp); + // clear counter + os.countLines(); if (param_string.empty() && caption.empty()) - os << "\n\\begin{lstlisting}\n"; + os << breakln << "\\begin{lstlisting}\n"; else { - os << "\n\\begin{lstlisting}["; + os << breakln << "\\begin{lstlisting}["; if (!caption.empty()) { os << "caption={" << caption << '}'; if (!param_string.empty()) @@ -248,15 +250,14 @@ int InsetListings::latex(odocstream & os, OutputParams const & runparams) const } os << from_utf8(param_string) << "]\n"; } - lines += 2; - os << code << "\n\\end{lstlisting}\n"; - lines += 2; + os << code << breakln << "\\end{lstlisting}\n"; + lines += os.countLines(); } if (encoding_switched){ // Switch back - pair const c = switchEncoding(os, buffer().params(), - runparams, *save_enc, true); + pair const c = switchEncoding(os.os(), + buffer().params(), runparams, *save_enc, true); runparams.encoding = save_enc; } @@ -391,8 +392,9 @@ docstring InsetListings::getCaption(OutputParams const & runparams) const return docstring(); odocstringstream ods; - ins->getOptArg(ods, runparams); - ins->getArgument(ods, runparams); + otexstream os(ods); + ins->getOptArg(os, runparams); + ins->getArgument(os, runparams); // the caption may contain \label{} but the listings // package prefer caption={}, label={} docstring cap = ods.str(); diff --git a/src/insets/InsetListings.h b/src/insets/InsetListings.h index 7ce6575638..9dc5a56e23 100644 --- a/src/insets/InsetListings.h +++ b/src/insets/InsetListings.h @@ -55,7 +55,7 @@ private: /// void read(Lexer & lex); /// - int latex(odocstream &, OutputParams const &) const; + int latex(otexstream &, OutputParams const &) const; /// docstring xhtml(XHTMLStream &, OutputParams const &) const; /// diff --git a/src/insets/InsetNewline.cpp b/src/insets/InsetNewline.cpp index 88c77c00f7..87a35def35 100644 --- a/src/insets/InsetNewline.cpp +++ b/src/insets/InsetNewline.cpp @@ -142,7 +142,7 @@ ColorCode InsetNewline::ColorName() const } -int InsetNewline::latex(odocstream & os, OutputParams const & rp) const +int InsetNewline::latex(otexstream & os, OutputParams const & rp) const { switch (params_.kind) { case InsetNewlineParams::NEWLINE: diff --git a/src/insets/InsetNewline.h b/src/insets/InsetNewline.h index 85bf1275ba..76c090670f 100644 --- a/src/insets/InsetNewline.h +++ b/src/insets/InsetNewline.h @@ -60,7 +60,7 @@ private: /// void draw(PainterInfo & pi, int x, int y) const; /// - int latex(odocstream &, OutputParams const &) const; + int latex(otexstream &, OutputParams const &) const; /// int plaintext(odocstream &, OutputParams const &) const; /// diff --git a/src/insets/InsetNewpage.cpp b/src/insets/InsetNewpage.cpp index b405cd2cfd..6a141df2d9 100644 --- a/src/insets/InsetNewpage.cpp +++ b/src/insets/InsetNewpage.cpp @@ -213,7 +213,7 @@ ColorCode InsetNewpage::ColorName() const } -int InsetNewpage::latex(odocstream & os, OutputParams const &) const +int InsetNewpage::latex(otexstream & os, OutputParams const &) const { switch (params_.kind) { case InsetNewpageParams::NEWPAGE: diff --git a/src/insets/InsetNewpage.h b/src/insets/InsetNewpage.h index 30c064cf28..2af7f8affc 100644 --- a/src/insets/InsetNewpage.h +++ b/src/insets/InsetNewpage.h @@ -63,7 +63,7 @@ private: /// void draw(PainterInfo & pi, int x, int y) const; /// - int latex(odocstream &, OutputParams const &) const; + int latex(otexstream &, OutputParams const &) const; /// int plaintext(odocstream &, OutputParams const &) const; /// diff --git a/src/insets/InsetNomencl.cpp b/src/insets/InsetNomencl.cpp index 0665ed26bf..535d9c095e 100644 --- a/src/insets/InsetNomencl.cpp +++ b/src/insets/InsetNomencl.cpp @@ -294,7 +294,7 @@ docstring nomenclWidest(Buffer const & buffer, OutputParams const & runparams) } // namespace anon -int InsetPrintNomencl::latex(odocstream & os, OutputParams const & runparams_in) const +int InsetPrintNomencl::latex(otexstream & os, OutputParams const & runparams_in) const { OutputParams runparams = runparams_in; int lines = 0; diff --git a/src/insets/InsetNomencl.h b/src/insets/InsetNomencl.h index b50f72279e..d1437f243e 100644 --- a/src/insets/InsetNomencl.h +++ b/src/insets/InsetNomencl.h @@ -96,7 +96,7 @@ public: /// DisplayType display() const { return AlignCenter; } /// - int latex(odocstream &, OutputParams const &) const; + int latex(otexstream &, OutputParams const &) const; /// docstring contextMenuName() const; //@} diff --git a/src/insets/InsetNote.cpp b/src/insets/InsetNote.cpp index 995a4ad693..acb9cb6b91 100644 --- a/src/insets/InsetNote.cpp +++ b/src/insets/InsetNote.cpp @@ -220,7 +220,7 @@ bool InsetNote::isMacroScope() const } -int InsetNote::latex(odocstream & os, OutputParams const & runparams_in) const +int InsetNote::latex(otexstream & os, OutputParams const & runparams_in) const { if (params_.type == InsetNoteParams::Note) return 0; @@ -233,7 +233,12 @@ int InsetNote::latex(odocstream & os, OutputParams const & runparams_in) const } odocstringstream ss; - InsetCollapsable::latex(ss, runparams); + otexstream ots(ss); + ots.canBreakLine(os.canBreakLine()); + InsetCollapsable::latex(ots, runparams); + docstring const str = ss.str(); + os << str; + // the space after the comment in 'a[comment] b' will be eaten by the // comment environment since the space before b is ignored with the // following latex output: @@ -245,11 +250,10 @@ int InsetNote::latex(odocstream & os, OutputParams const & runparams_in) const // b // // Adding {} before ' b' fixes this. - if (params_.type == InsetNoteParams::Comment) - ss << "{}"; + // The {} will be automatically added, but only if needed, by + // telling otexstream to protect an immediately following space. + os.protectSpace(ots.protectSpace()); - docstring const str = ss.str(); - os << str; runparams_in.encoding = runparams.encoding; // Return how many newlines we issued. return int(count(str.begin(), str.end(), '\n')); diff --git a/src/insets/InsetNote.h b/src/insets/InsetNote.h index ae8fa2f742..c331db7cb2 100644 --- a/src/insets/InsetNote.h +++ b/src/insets/InsetNote.h @@ -79,7 +79,7 @@ private: /// bool isMacroScope() const; /// - int latex(odocstream &, OutputParams const &) const; + int latex(otexstream &, OutputParams const &) const; /// int plaintext(odocstream &, OutputParams const &) const; /// diff --git a/src/insets/InsetPhantom.cpp b/src/insets/InsetPhantom.cpp index 64f7799831..27a68c0ba9 100644 --- a/src/insets/InsetPhantom.cpp +++ b/src/insets/InsetPhantom.cpp @@ -307,7 +307,7 @@ docstring InsetPhantom::toolTip(BufferView const &, int, int) const } -int InsetPhantom::latex(odocstream & os, OutputParams const & runparams) const +int InsetPhantom::latex(otexstream & os, OutputParams const & runparams) const { if (params_.type == InsetPhantomParams::Phantom) os << "\\phantom{"; diff --git a/src/insets/InsetPhantom.h b/src/insets/InsetPhantom.h index c5a805b64d..c49895c5f3 100644 --- a/src/insets/InsetPhantom.h +++ b/src/insets/InsetPhantom.h @@ -76,7 +76,7 @@ private: /// bool neverIndent() const { return true; } /// - int latex(odocstream &, OutputParams const &) const; + int latex(otexstream &, OutputParams const &) const; /// int plaintext(odocstream &, OutputParams const &) const; /// diff --git a/src/insets/InsetPreview.cpp b/src/insets/InsetPreview.cpp index eddf0a55ed..c1b8e3fa5e 100644 --- a/src/insets/InsetPreview.cpp +++ b/src/insets/InsetPreview.cpp @@ -70,8 +70,9 @@ void InsetPreview::addPreview(DocIterator const & inset_pos, void InsetPreview::preparePreview(DocIterator const & pos) const { odocstringstream str; + otexstream os(str); OutputParams runparams(&pos.buffer()->params().encoding()); - latex(str, runparams); + latex(os, runparams); docstring const snippet = str.str(); preview_->addPreview(snippet, *pos.buffer()); } diff --git a/src/insets/InsetQuotes.cpp b/src/insets/InsetQuotes.cpp index e8fe106cd5..ff7c6babd1 100644 --- a/src/insets/InsetQuotes.cpp +++ b/src/insets/InsetQuotes.cpp @@ -261,7 +261,7 @@ void InsetQuotes::read(Lexer & lex) } -int InsetQuotes::latex(odocstream & os, OutputParams const & runparams) const +int InsetQuotes::latex(otexstream & os, OutputParams const & runparams) const { const int quoteind = quote_index[side_][language_]; string qstr; diff --git a/src/insets/InsetQuotes.h b/src/insets/InsetQuotes.h index 3baabe3066..d13603e9bd 100644 --- a/src/insets/InsetQuotes.h +++ b/src/insets/InsetQuotes.h @@ -78,7 +78,7 @@ public: /// void read(Lexer & lex); /// - int latex(odocstream &, OutputParams const &) const; + int latex(otexstream &, OutputParams const &) const; /// int plaintext(odocstream &, OutputParams const &) const; /// diff --git a/src/insets/InsetRef.cpp b/src/insets/InsetRef.cpp index 4607c1efad..2f8aa2f93c 100644 --- a/src/insets/InsetRef.cpp +++ b/src/insets/InsetRef.cpp @@ -136,7 +136,7 @@ docstring InsetRef::getEscapedLabel(OutputParams const & rp) const } -int InsetRef::latex(odocstream & os, OutputParams const & rp) const +int InsetRef::latex(otexstream & os, OutputParams const & rp) const { string const cmd = getCmdName(); if (cmd != "formatted") { diff --git a/src/insets/InsetRef.h b/src/insets/InsetRef.h index 2394bb4c1c..8f8ce848a2 100644 --- a/src/insets/InsetRef.h +++ b/src/insets/InsetRef.h @@ -51,7 +51,7 @@ public: /// DisplayType display() const { return Inline; } /// - int latex(odocstream &, OutputParams const &) const; + int latex(otexstream &, OutputParams const &) const; /// int plaintext(odocstream &, OutputParams const &) const; /// diff --git a/src/insets/InsetScript.cpp b/src/insets/InsetScript.cpp index 9e729d5790..7268be5962 100644 --- a/src/insets/InsetScript.cpp +++ b/src/insets/InsetScript.cpp @@ -334,7 +334,7 @@ void InsetScript::validate(LaTeXFeatures & features) const } -int InsetScript::latex(odocstream & os, OutputParams const & runparams) const +int InsetScript::latex(otexstream & os, OutputParams const & runparams) const { switch (params_.type) { case InsetScriptParams::Subscript: diff --git a/src/insets/InsetScript.h b/src/insets/InsetScript.h index eb3b55632a..c9ac1d30e0 100644 --- a/src/insets/InsetScript.h +++ b/src/insets/InsetScript.h @@ -88,7 +88,7 @@ public: /// virtual void validate(LaTeXFeatures &) const; /// - int latex(odocstream &, OutputParams const &) const; + int latex(otexstream &, OutputParams const &) const; /// int plaintext(odocstream &, OutputParams const &) const; /// diff --git a/src/insets/InsetSpace.cpp b/src/insets/InsetSpace.cpp index faebeec5d3..023da44028 100644 --- a/src/insets/InsetSpace.cpp +++ b/src/insets/InsetSpace.cpp @@ -521,7 +521,7 @@ void InsetSpace::read(Lexer & lex) } -int InsetSpace::latex(odocstream & os, OutputParams const & runparams) const +int InsetSpace::latex(otexstream & os, OutputParams const & runparams) const { switch (params_.kind) { case InsetSpaceParams::NORMAL: diff --git a/src/insets/InsetSpace.h b/src/insets/InsetSpace.h index c7697b0bab..7af103f827 100644 --- a/src/insets/InsetSpace.h +++ b/src/insets/InsetSpace.h @@ -120,7 +120,7 @@ public: /// Will not be used when lyxf3 void read(Lexer & lex); /// - int latex(odocstream &, OutputParams const &) const; + int latex(otexstream &, OutputParams const &) const; /// int plaintext(odocstream &, OutputParams const &) const; /// diff --git a/src/insets/InsetSpecialChar.cpp b/src/insets/InsetSpecialChar.cpp index 67d7613c4e..d0a5d10a58 100644 --- a/src/insets/InsetSpecialChar.cpp +++ b/src/insets/InsetSpecialChar.cpp @@ -205,7 +205,7 @@ void InsetSpecialChar::read(Lexer & lex) } -int InsetSpecialChar::latex(odocstream & os, +int InsetSpecialChar::latex(otexstream & os, OutputParams const & rp) const { switch (kind_) { diff --git a/src/insets/InsetSpecialChar.h b/src/insets/InsetSpecialChar.h index 8ae4f4d4ca..e402ef7c7c 100644 --- a/src/insets/InsetSpecialChar.h +++ b/src/insets/InsetSpecialChar.h @@ -59,7 +59,7 @@ public: /// Will not be used when lyxf3 void read(Lexer & lex); /// - int latex(odocstream &, OutputParams const &) const; + int latex(otexstream &, OutputParams const &) const; /// int plaintext(odocstream &, OutputParams const &) const; /// diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp index 24dacc5be6..48229d413a 100644 --- a/src/insets/InsetTabular.cpp +++ b/src/insets/InsetTabular.cpp @@ -2022,7 +2022,7 @@ bool Tabular::isPartOfMultiRow(row_type row, col_type column) const } -int Tabular::TeXTopHLine(odocstream & os, row_type row, string const lang) const +int Tabular::TeXTopHLine(otexstream & os, row_type row, string const lang) const { // we only output complete row lines and the 1st row here, the rest // is done in Tabular::TeXBottomHLine(...) @@ -2085,7 +2085,7 @@ int Tabular::TeXTopHLine(odocstream & os, row_type row, string const lang) const } -int Tabular::TeXBottomHLine(odocstream & os, row_type row, string const lang) const +int Tabular::TeXBottomHLine(otexstream & os, row_type row, string const lang) const { // we output bottomlines of row r and the toplines of row r+1 // if the latter do not span the whole tabular @@ -2158,8 +2158,8 @@ int Tabular::TeXBottomHLine(odocstream & os, row_type row, string const lang) co } -int Tabular::TeXCellPreamble(odocstream & os, idx_type cell, - bool & ismulticol, bool & ismultirow) const +int Tabular::TeXCellPreamble(otexstream & os, idx_type cell, + bool & ismulticol, bool & ismultirow) const { int ret = 0; row_type const r = cellRow(cell); @@ -2308,8 +2308,8 @@ int Tabular::TeXCellPreamble(odocstream & os, idx_type cell, } -int Tabular::TeXCellPostamble(odocstream & os, idx_type cell, - bool ismulticol, bool ismultirow) const +int Tabular::TeXCellPostamble(otexstream & os, idx_type cell, + bool ismulticol, bool ismultirow) const { int ret = 0; row_type const r = cellRow(cell); @@ -2336,7 +2336,7 @@ int Tabular::TeXCellPostamble(odocstream & os, idx_type cell, } -int Tabular::TeXLongtableHeaderFooter(odocstream & os, +int Tabular::TeXLongtableHeaderFooter(otexstream & os, OutputParams const & runparams) const { if (!is_long_tabular) @@ -2448,7 +2448,7 @@ bool Tabular::isValidRow(row_type row) const } -int Tabular::TeXRow(odocstream & os, row_type row, +int Tabular::TeXRow(otexstream & os, row_type row, OutputParams const & runparams) const { idx_type cell = cellIndex(row, 0); @@ -2591,7 +2591,7 @@ int Tabular::TeXRow(odocstream & os, row_type row, } -int Tabular::latex(odocstream & os, OutputParams const & runparams) const +int Tabular::latex(otexstream & os, OutputParams const & runparams) const { int ret = 0; @@ -2718,8 +2718,10 @@ int Tabular::latex(odocstream & os, OutputParams const & runparams) const else os << "\\end{tabular}"; if (rotate) { - os << "\n\\end{sideways}"; - ++ret; + // clear counter + os.countLines(); + os << breakln << "\\end{sideways}"; + ret += os.countLines(); } return ret; @@ -4718,7 +4720,7 @@ Inset::DisplayType InsetTabular::display() const } -int InsetTabular::latex(odocstream & os, OutputParams const & runparams) const +int InsetTabular::latex(otexstream & os, OutputParams const & runparams) const { return tabular.latex(os, runparams); } diff --git a/src/insets/InsetTabular.h b/src/insets/InsetTabular.h index 712a313272..9cc8adcb37 100644 --- a/src/insets/InsetTabular.h +++ b/src/insets/InsetTabular.h @@ -447,7 +447,7 @@ public: /// void read(Lexer &); /// - int latex(odocstream &, OutputParams const &) const; + int latex(otexstream &, OutputParams const &) const; /// int docbook(odocstream & os, OutputParams const &) const; /// @@ -713,19 +713,19 @@ public: /// // helper function for Latex returns number of newlines /// - int TeXTopHLine(odocstream &, row_type row, std::string const lang) const; + int TeXTopHLine(otexstream &, row_type row, std::string const lang) const; /// - int TeXBottomHLine(odocstream &, row_type row, std::string const lang) const; + int TeXBottomHLine(otexstream &, row_type row, std::string const lang) const; /// - int TeXCellPreamble(odocstream &, idx_type cell, bool & ismulticol, bool & ismultirow) const; + int TeXCellPreamble(otexstream &, idx_type cell, bool & ismulticol, bool & ismultirow) const; /// - int TeXCellPostamble(odocstream &, idx_type cell, bool ismulticol, bool ismultirow) const; + int TeXCellPostamble(otexstream &, idx_type cell, bool ismulticol, bool ismultirow) const; /// - int TeXLongtableHeaderFooter(odocstream &, OutputParams const &) const; + int TeXLongtableHeaderFooter(otexstream &, OutputParams const &) const; /// bool isValidRow(row_type const row) const; /// - int TeXRow(odocstream &, row_type const row, + int TeXRow(otexstream &, row_type const row, OutputParams const &) const; /// // helper functions for plain text @@ -802,7 +802,7 @@ public: /// DisplayType display() const; /// - int latex(odocstream &, OutputParams const &) const; + int latex(otexstream &, OutputParams const &) const; /// int plaintext(odocstream &, OutputParams const &) const; /// diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index f35320b8e7..56d88e620b 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -370,7 +370,7 @@ void InsetText::validate(LaTeXFeatures & features) const } -int InsetText::latex(odocstream & os, OutputParams const & runparams) const +int InsetText::latex(otexstream & os, OutputParams const & runparams) const { // This implements the standard way of handling the LaTeX // output of a text inset, either a command or an @@ -388,10 +388,16 @@ int InsetText::latex(odocstream & os, OutputParams const & runparams) const os << from_utf8(il.latexparam()); os << '{'; } else if (il.latextype() == InsetLayout::ENVIRONMENT) { - os << "%\n\\begin{" << from_utf8(il.latexname()) << "}\n"; + // clear counter + os.countLines(); + if (il.isDisplay()) + os << breakln; + else + os << safebreakln; + os << "\\begin{" << from_utf8(il.latexname()) << "}\n"; if (!il.latexparam().empty()) os << from_utf8(il.latexparam()); - rows += 2; + rows += os.countLines(); } } OutputParams rp = runparams; @@ -412,8 +418,17 @@ int InsetText::latex(odocstream & os, OutputParams const & runparams) const if (il.latextype() == InsetLayout::COMMAND) { os << "}"; } else if (il.latextype() == InsetLayout::ENVIRONMENT) { - os << "%\n\\end{" << from_utf8(il.latexname()) << "}\n"; - rows += 2; + // clear counter + os.countLines(); + // A comment environment doesn't need a % before \n\end + if (il.isDisplay() || runparams.inComment) + os << breakln; + else + os << safebreakln; + os << "\\end{" << from_utf8(il.latexname()) << "}\n"; + if (!il.isDisplay()) + os.protectSpace(true); + rows += os.countLines(); } } return rows; diff --git a/src/insets/InsetText.h b/src/insets/InsetText.h index 1dca10e468..e8d8ba6a94 100644 --- a/src/insets/InsetText.h +++ b/src/insets/InsetText.h @@ -73,7 +73,7 @@ public: Text & text() { return text_; } Text const & text() const { return text_; } /// - int latex(odocstream &, OutputParams const &) const; + int latex(otexstream &, OutputParams const &) const; /// int plaintext(odocstream &, OutputParams const &) const; /// diff --git a/src/insets/InsetVSpace.cpp b/src/insets/InsetVSpace.cpp index e73db774d5..18ae4dcf13 100644 --- a/src/insets/InsetVSpace.cpp +++ b/src/insets/InsetVSpace.cpp @@ -201,7 +201,7 @@ void InsetVSpace::draw(PainterInfo & pi, int x, int y) const } -int InsetVSpace::latex(odocstream & os, OutputParams const &) const +int InsetVSpace::latex(otexstream & os, OutputParams const &) const { os << from_ascii(space_.asLatexCommand(buffer().params())) << '\n'; return 1; diff --git a/src/insets/InsetVSpace.h b/src/insets/InsetVSpace.h index e065462ced..ef4b7c11f4 100644 --- a/src/insets/InsetVSpace.h +++ b/src/insets/InsetVSpace.h @@ -45,7 +45,7 @@ private: /// void draw(PainterInfo & pi, int x, int y) const; /// - int latex(odocstream &, OutputParams const &) const; + int latex(otexstream &, OutputParams const &) const; /// int plaintext(odocstream &, OutputParams const &) const; /// diff --git a/src/insets/InsetWrap.cpp b/src/insets/InsetWrap.cpp index a3eca3c5a2..f245d00e46 100644 --- a/src/insets/InsetWrap.cpp +++ b/src/insets/InsetWrap.cpp @@ -182,7 +182,7 @@ void InsetWrap::validate(LaTeXFeatures & features) const } -int InsetWrap::latex(odocstream & os, OutputParams const & runparams_in) const +int InsetWrap::latex(otexstream & os, OutputParams const & runparams_in) const { OutputParams runparams(runparams_in); runparams.inFloat = OutputParams::MAINFLOAT; diff --git a/src/insets/InsetWrap.h b/src/insets/InsetWrap.h index b1539fc971..674d2869c2 100644 --- a/src/insets/InsetWrap.h +++ b/src/insets/InsetWrap.h @@ -65,7 +65,7 @@ private: /// docstring toolTip(BufferView const & bv, int x, int y) const; /// - int latex(odocstream &, OutputParams const &) const; + int latex(otexstream &, OutputParams const &) const; /// int plaintext(odocstream &, OutputParams const &) const; /// diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp index 752aaaec5b..1e45b6502b 100644 --- a/src/lyxfind.cpp +++ b/src/lyxfind.cpp @@ -914,6 +914,7 @@ docstring latexifyFromCursor(DocIterator const & cur, int len) TexRow texrow; odocstringstream ods; + otexstream os(ods); OutputParams runparams(&buf.params().encoding()); runparams.nice = false; runparams.flavor = OutputParams::LATEX; @@ -926,7 +927,7 @@ docstring latexifyFromCursor(DocIterator const & cur, int len) pos_type endpos = cur.paragraph().size(); if (len != -1 && endpos > cur.pos() + len) endpos = cur.pos() + len; - TeXOnePar(buf, *cur.innerText(), cur.pit(), ods, texrow, runparams, + TeXOnePar(buf, *cur.innerText(), cur.pit(), os, texrow, runparams, string(), cur.pos(), endpos); LYXERR(Debug::FIND, "Latexified text: '" << lyx::to_utf8(ods.str()) << "'"); } else if (cur.inMathed()) { @@ -1219,13 +1220,14 @@ static void findAdvReplace(BufferView * bv, FindAndReplaceOptions const & opt, M sel_len = repl_buffer.paragraphs().begin()->size(); } else { odocstringstream ods; + otexstream os(ods); OutputParams runparams(&repl_buffer.params().encoding()); runparams.nice = false; runparams.flavor = OutputParams::LATEX; runparams.linelen = 8000; //lyxrc.plaintext_linelen; runparams.dryrun = true; TexRow texrow; - TeXOnePar(repl_buffer, repl_buffer.text(), 0, ods, texrow, runparams); + TeXOnePar(repl_buffer, repl_buffer.text(), 0, os, texrow, runparams); //repl_buffer.getSourceCode(ods, 0, repl_buffer.paragraphs().size(), false); docstring repl_latex = ods.str(); LYXERR(Debug::FIND, "Latexified replace_buffer: '" << repl_latex << "'"); diff --git a/src/mathed/InsetFormulaMacro.cpp b/src/mathed/InsetFormulaMacro.cpp index eaa89d70e3..d43fa0c737 100644 --- a/src/mathed/InsetFormulaMacro.cpp +++ b/src/mathed/InsetFormulaMacro.cpp @@ -70,14 +70,16 @@ void InsetFormulaMacro::write(ostream & os) const } -int InsetFormulaMacro::latex(odocstream & os, +int InsetFormulaMacro::latex(otexstream & os, OutputParams const & runparams) const { //lyxerr << "InsetFormulaMacro::latex" << endl; - WriteStream wi(os, runparams.moving_arg, true, + WriteStream wi(os.os(), runparams.moving_arg, true, runparams.dryrun ? WriteStream::wsDryrun: WriteStream::wsDefault, runparams.encoding); + wi.canBreakLine(os.canBreakLine()); tmpl()->write(wi); + os.canBreakLine(wi.canBreakLine()); return 2; } diff --git a/src/mathed/InsetFormulaMacro.h b/src/mathed/InsetFormulaMacro.h index 6e3752a36d..0e4e3ba700 100644 --- a/src/mathed/InsetFormulaMacro.h +++ b/src/mathed/InsetFormulaMacro.h @@ -44,7 +44,7 @@ public: /// void write(std::ostream & os) const; /// - int latex(odocstream & os, OutputParams const &) const; + int latex(otexstream & os, OutputParams const &) const; /// int plaintext(odocstream &, OutputParams const &) const; /// diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp index 2efcae774d..f06f7eba22 100644 --- a/src/mathed/InsetMathHull.cpp +++ b/src/mathed/InsetMathHull.cpp @@ -779,9 +779,9 @@ void InsetMathHull::header_write(WriteStream & os) const case hullEquation: if (n) - os << "\\begin{equation" << star(n) << "}\n"; + os << "\n\\begin{equation" << star(n) << "}\n"; else - os << "\\[\n"; + os << "\n\\[\n"; break; case hullEqnArray: @@ -789,17 +789,17 @@ void InsetMathHull::header_write(WriteStream & os) const case hullFlAlign: case hullGather: case hullMultline: - os << "\\begin{" << hullName(type_) << star(n) << "}\n"; + os << "\n\\begin{" << hullName(type_) << star(n) << "}\n"; break; case hullAlignAt: case hullXAlignAt: - os << "\\begin{" << hullName(type_) << star(n) << '}' + os << "\n\\begin{" << hullName(type_) << star(n) << '}' << '{' << static_cast((ncols() + 1)/2) << "}\n"; break; case hullXXAlignAt: - os << "\\begin{" << hullName(type_) << '}' + os << "\n\\begin{" << hullName(type_) << '}' << '{' << static_cast((ncols() + 1)/2) << "}\n"; break; @@ -808,7 +808,7 @@ void InsetMathHull::header_write(WriteStream & os) const break; default: - os << "\\begin{unknown" << star(n) << "}\n"; + os << "\n\\begin{unknown" << star(n) << "}\n"; break; } } @@ -1920,6 +1920,7 @@ int InsetMathHull::docbook(odocstream & os, OutputParams const & runparams) cons ++ms.tab(); ms.cr(); ms.os() << '<' << bname << '>'; odocstringstream ls; + otexstream ols(ls); if (runparams.flavor == OutputParams::XML) { ms << MTag("alt role='tex' "); // Workaround for db2latex: db2latex always includes equations with @@ -1936,7 +1937,7 @@ int InsetMathHull::docbook(odocstream & os, OutputParams const & runparams) cons ms << ETag("math"); } else { ms << MTag("alt role='tex'"); - res = latex(ls, runparams); + res = latex(ols, runparams); ms << from_utf8(subst(subst(to_utf8(ls.str()), "&", "&"), "<", "<")); ms << ETag("alt"); } diff --git a/src/mathed/InsetMathMBox.cpp b/src/mathed/InsetMathMBox.cpp index bf27b8d102..4d1f3503c2 100644 --- a/src/mathed/InsetMathMBox.cpp +++ b/src/mathed/InsetMathMBox.cpp @@ -75,7 +75,8 @@ void InsetMathMBox::write(WriteStream & ws) const ws << "\\mbox{\n"; TexRow texrow; OutputParams runparams(&buffer().params().encoding()); - latexParagraphs(buffer(), text_.text(), ws.os(), texrow, runparams); + otexstream os(ws.os()); + latexParagraphs(buffer(), text_.text(), os, texrow, runparams); ws.addlines(texrow.rows()); ws << "}"; } else { @@ -88,7 +89,7 @@ void InsetMathMBox::write(WriteStream & ws) const } -int InsetMathMBox::latex(odocstream & os, OutputParams const & runparams) const +int InsetMathMBox::latex(otexstream & os, OutputParams const & runparams) const { os << "\\mbox{\n"; TexRow texrow; diff --git a/src/mathed/InsetMathMBox.h b/src/mathed/InsetMathMBox.h index eca4fcbfaa..be5dcc6705 100644 --- a/src/mathed/InsetMathMBox.h +++ b/src/mathed/InsetMathMBox.h @@ -46,7 +46,7 @@ public: /// void write(WriteStream & os) const; /// - int latex(odocstream & os, OutputParams const & runparams) const; + int latex(otexstream & os, OutputParams const & runparams) const; /// void mathmlize(MathStream &) const; /// diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp index e400974c94..1c6437d973 100644 --- a/src/mathed/InsetMathNest.cpp +++ b/src/mathed/InsetMathNest.cpp @@ -394,12 +394,14 @@ void InsetMathNest::normalize(NormalStream & os) const } -int InsetMathNest::latex(odocstream & os, OutputParams const & runparams) const +int InsetMathNest::latex(otexstream & os, OutputParams const & runparams) const { - WriteStream wi(os, runparams.moving_arg, true, + WriteStream wi(os.os(), runparams.moving_arg, true, runparams.dryrun ? WriteStream::wsDryrun : WriteStream::wsDefault, runparams.encoding); + wi.canBreakLine(os.canBreakLine()); write(wi); + os.canBreakLine(wi.canBreakLine()); return wi.line(); } diff --git a/src/mathed/InsetMathNest.h b/src/mathed/InsetMathNest.h index d9c1f09f42..ee1e38cb58 100644 --- a/src/mathed/InsetMathNest.h +++ b/src/mathed/InsetMathNest.h @@ -111,7 +111,7 @@ public: /// writes [, name(), and args in [] void normalize(NormalStream & os) const; /// - int latex(odocstream & os, OutputParams const & runparams) const; + int latex(otexstream & os, OutputParams const & runparams) const; /// bool setMouseHover(BufferView const * bv, bool mouse_hover); /// diff --git a/src/mathed/MathFactory.cpp b/src/mathed/MathFactory.cpp index 913c44ce7d..ab290cb369 100644 --- a/src/mathed/MathFactory.cpp +++ b/src/mathed/MathFactory.cpp @@ -528,11 +528,12 @@ bool createInsetMath_fromDialogStr(docstring const & str, MathData & ar) InsetSpaceParams isp(true); InsetSpace::string2params(to_utf8(str), isp); InsetSpace is(isp); - odocstringstream os; + odocstringstream ods; + otexstream os(ods); Encoding const * const ascii = encodings.fromLyXName("ascii"); OutputParams op(ascii); is.latex(os, op); - mathed_parse_cell(ar, os.str()); + mathed_parse_cell(ar, ods.str()); if (ar.size() == 2) { // remove "{}" if (ar[1].nucleus()->asBraceInset()) diff --git a/src/output_latex.cpp b/src/output_latex.cpp index 0bf0ad8d4e..a5473bf481 100644 --- a/src/output_latex.cpp +++ b/src/output_latex.cpp @@ -77,7 +77,7 @@ struct TeXEnvironementData static TeXEnvironementData prepareEnvironement(Buffer const & buf, Text const & text, - ParagraphList::const_iterator pit, odocstream & os, TexRow & texrow, + ParagraphList::const_iterator pit, otexstream & os, TexRow & texrow, OutputParams const & runparams) { TeXEnvironementData data; @@ -202,7 +202,7 @@ static TeXEnvironementData prepareEnvironement(Buffer const & buf, Text const & } -static void finishEnvironement(odocstream & os, TexRow & texrow, +static void finishEnvironement(otexstream & os, TexRow & texrow, OutputParams const & runparams, TeXEnvironementData const & data) { if (open_encoding_ == CJK && data.cjk_nested) { @@ -239,7 +239,7 @@ static void finishEnvironement(odocstream & os, TexRow & texrow, void TeXEnvironment(Buffer const & buf, Text const & text, OutputParams const & runparams, - pit_type & pit, odocstream & os, TexRow & texrow) + pit_type & pit, otexstream & os, TexRow & texrow) { ParagraphList const & paragraphs = text.paragraphs(); ParagraphList::const_iterator par = paragraphs.constIterator(pit); @@ -326,7 +326,7 @@ void TeXEnvironment(Buffer const & buf, } // namespace anon -int latexArgInsets(Paragraph const & par, odocstream & os, +int latexArgInsets(Paragraph const & par, otexstream & os, OutputParams const & runparams, unsigned int reqargs, unsigned int optargs) { @@ -383,7 +383,7 @@ int latexArgInsets(Paragraph const & par, odocstream & os, namespace { // output the proper paragraph start according to latextype. -void parStartCommand(Paragraph const & par, odocstream & os, TexRow & texrow, +void parStartCommand(Paragraph const & par, otexstream & os, TexRow & texrow, OutputParams const & runparams,Layout const & style) { switch (style.latextype) { @@ -419,7 +419,7 @@ void parStartCommand(Paragraph const & par, odocstream & os, TexRow & texrow, void TeXOnePar(Buffer const & buf, Text const & text, pit_type pit, - odocstream & os, TexRow & texrow, + otexstream & os, TexRow & texrow, OutputParams const & runparams_in, string const & everypar, int start_pos, int end_pos) @@ -487,9 +487,9 @@ void TeXOnePar(Buffer const & buf, // task because in the other user of parStartCommand // the code is different (JMarc) if (style.isCommand()) - os << from_ascii("}\n"); + os << "}\n"; else - os << from_ascii("\n"); + os << '\n'; texrow.newline(); if (!style.parbreak_is_newline) { os << '\n'; @@ -659,8 +659,8 @@ void TeXOnePar(Buffer const & buf, if (i != 0 && encoding->package() == Encoding::CJK) continue; - pair enc_switch = switchEncoding(os, bparams, runparams, - *encoding); + pair enc_switch = switchEncoding(os.os(), + bparams, runparams, *encoding); // the following is necessary after a CJK environment in a multilingual // context (nesting issue). if (par_language->encoding()->package() == Encoding::CJK @@ -941,7 +941,7 @@ void TeXOnePar(Buffer const & buf, // LaTeX all paragraphs void latexParagraphs(Buffer const & buf, Text const & text, - odocstream & os, + otexstream & os, TexRow & texrow, OutputParams const & runparams, string const & everypar) @@ -1065,12 +1065,11 @@ void latexParagraphs(Buffer const & buf, if (was_title && !already_title) { if (tclass.titletype() == TITLE_ENVIRONMENT) { os << "\\end{" << from_ascii(tclass.titlename()) - << "}\n"; - } - else { + << "}\n"; + } else { os << "\\" << from_ascii(tclass.titlename()) - << "\n"; - } + << "\n"; + } texrow.newline(); } diff --git a/src/output_latex.h b/src/output_latex.h index 798da92a22..ebb299a835 100644 --- a/src/output_latex.h +++ b/src/output_latex.h @@ -36,7 +36,7 @@ class Text; /// ones are given, we'll output: {}. The optional ones /// must all come first. int latexArgInsets(Paragraph const & par, - odocstream & os, OutputParams const & runparams, + otexstream & os, OutputParams const & runparams, unsigned int reqargs, unsigned int optargs); /** Export \p paragraphs of buffer \p buf to LaTeX. @@ -46,7 +46,7 @@ int latexArgInsets(Paragraph const & par, */ void latexParagraphs(Buffer const & buf, Text const & text, - odocstream & ofs, + otexstream & ofs, TexRow & texrow, OutputParams const &, std::string const & everypar = std::string()); @@ -64,7 +64,7 @@ std::pair switchEncoding(odocstream & os, void TeXOnePar(Buffer const & buf, Text const & text, pit_type pit, - odocstream & os, TexRow & texrow, + otexstream & os, TexRow & texrow, OutputParams const & runparams, std::string const & everypar = std::string(), int start_pos = -1, int end_pos = -1); diff --git a/src/support/docstream.cpp b/src/support/docstream.cpp index 5ae2ff3224..56472058c5 100644 --- a/src/support/docstream.cpp +++ b/src/support/docstream.cpp @@ -13,6 +13,7 @@ #include "support/docstream.h" #include "support/unicode.h" +#include #include #include #include @@ -401,6 +402,141 @@ odocstream & operator<<(odocstream & os, char c) } #endif + +void otexstream::put(char_type const & c) +{ + if (protectspace_) { + if (!canbreakline_ && c == ' ') + os_ << "{}"; + protectspace_ = false; + } + os_.put(c); + if (c == '\n') { + ++lines_; + canbreakline_ = false; + } else + canbreakline_ = true; +} + + +BreakLine breakln; +SafeBreakLine safebreakln; + + +otexstream & operator<<(otexstream & ots, BreakLine) +{ + if (ots.canBreakLine()) { + ots.os().put('\n'); + ots.canBreakLine(false); + ots.addLines(1); + } + ots.protectSpace(false); + return ots; +} + + +otexstream & operator<<(otexstream & ots, SafeBreakLine) +{ + if (ots.canBreakLine()) { + ots.os() << "%\n"; + ots.canBreakLine(false); + ots.addLines(1); + } + ots.protectSpace(false); + return ots; +} + + +otexstream & operator<<(otexstream & ots, SetEnc e) +{ + ots.os() << e; + ots.canBreakLine(true); + ots.protectSpace(false); + return ots; +} + + +otexstream & operator<<(otexstream & ots, docstring const & s) +{ + size_t const len = s.length(); + + // Check whether there's something to output + if (len == 0) + return ots; + + if (ots.protectSpace()) { + if (!ots.canBreakLine() && s[0] == ' ') + ots.os() << "{}"; + ots.protectSpace(false); + } + ots.os() << s; + ots.addLines(count(s.begin(), s.end(), '\n')); + ots.canBreakLine(s[len - 1] != '\n'); + return ots; +} + + +otexstream & operator<<(otexstream & ots, char const * s) +{ + size_t const len = strlen(s); + + // Check whether there's something to output + if (len == 0) + return ots; + + if (ots.protectSpace()) { + if (!ots.canBreakLine() && s[0] == ' ') + ots.os() << "{}"; + ots.protectSpace(false); + } + ots.os() << s; + ots.addLines(count(s, s + len, '\n')); + ots.canBreakLine(s[len - 1] != '\n'); + return ots; +} + + +otexstream & operator<<(otexstream & ots, char c) +{ + if (ots.protectSpace()) { + if (!ots.canBreakLine() && c == ' ') + ots.os() << "{}"; + ots.protectSpace(false); + } + ots.os() << c; + if (c == '\n') + ots.addLines(1); + ots.canBreakLine(c != '\n'); + return ots; +} + + +otexstream & operator<<(otexstream & ots, double d) +{ + ots.os() << d; + ots.canBreakLine(true); + ots.protectSpace(false); + return ots; +} + + +otexstream & operator<<(otexstream & ots, int i) +{ + ots.os() << i; + ots.canBreakLine(true); + ots.protectSpace(false); + return ots; +} + + +otexstream & operator<<(otexstream & ots, unsigned int i) +{ + ots.os() << i; + ots.canBreakLine(true); + ots.protectSpace(false); + return ots; +} + } #if ! defined(USE_WCHAR_T) && defined(__GNUC__) diff --git a/src/support/docstream.h b/src/support/docstream.h index 0a2d42b38b..167bdd1e21 100644 --- a/src/support/docstream.h +++ b/src/support/docstream.h @@ -82,6 +82,77 @@ typedef std::basic_istringstream idocstringstream; /// UCS4 output stringstream typedef std::basic_ostringstream odocstringstream; +/** Wrapper class for odocstream. + This class helps ensuring that no blank lines may be inadvertently output. + Use the special variables "breakln" and "safebreakln" as if they were + iomanip's to ensure that the next output will start at the beginning of + a line. Using "breakln", a '\n' char will be output if needed, while + using "safebreakln", "%\n" will be output if needed. + Use countLines() to retrieve the number of \n output since previous call. + */ + +class otexstream { +public: + /// + explicit otexstream(odocstream & os) + : os_(os), lines_(0), canbreakline_(false), protectspace_(false) + {} + /// + odocstream & os() { return os_; } + /// + void put(char_type const & c); + /// + size_t countLines() { size_t l = lines_; lines_ = 0; return l; } + /// + void addLines(size_t n) { lines_ += n; } + /// + void canBreakLine(bool breakline) { canbreakline_ = breakline; } + /// + bool canBreakLine() const { return canbreakline_; } + /// + void protectSpace(bool protectspace) { protectspace_ = protectspace; } + /// + bool protectSpace() const { return protectspace_; }; +private: + /// + odocstream & os_; + /// + size_t lines_; + /// + bool canbreakline_; + /// + bool protectspace_; +}; + +/// Helper structs for breaking a line +struct BreakLine { + char n; +}; + +struct SafeBreakLine { + char n; +}; + +extern BreakLine breakln; +extern SafeBreakLine safebreakln; + +/// +otexstream & operator<<(otexstream &, BreakLine); +/// +otexstream & operator<<(otexstream &, SafeBreakLine); +/// +otexstream & operator<<(otexstream &, docstring const &); +/// +otexstream & operator<<(otexstream &, char const *); +/// +otexstream & operator<<(otexstream &, char); +/// +otexstream & operator<<(otexstream &, double); +/// +otexstream & operator<<(otexstream &, int); +/// +otexstream & operator<<(otexstream &, unsigned int); + /// Helper struct for changing stream encoding struct SetEnc { SetEnc(std::string const & e) : encoding(e) {} @@ -100,6 +171,7 @@ SetEnc setEncoding(std::string const & encoding); \endcode */ odocstream & operator<<(odocstream & os, SetEnc e); +otexstream & operator<<(otexstream & os, SetEnc e); idocstream & operator<<(idocstream & os, SetEnc e); }