Hi Guillaume,

now I’m getting:

/Users/stephan/git/lyx/src/output_docbook.cpp:108:7: error: invalid operands to 
binary expression ('odocstream' (aka 'basic_ostream<wchar_t, 
char_traits<wchar_t> >') and 'int')
                        os << '\n';
                        ~~ ^  ~~~~

I have to add another include in src/output_docbook.cpp
+#include <iostream>

and in src/VCBackend.cpp
+#include <iostream>

which leads to another error in VCBackend.cpp:

/Users/stephan/git/lyx/src/VCBackend.cpp:1338:16: error: implicit instantiation 
of undefined template 'std::__1::basic_ostringstream<char, 
std::__1::char_traits<char>,
      std::__1::allocator<char> >'
        ostringstream os;
                      ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iosfwd:123:33:
 note: template is declared here
    class _LIBCPP_TYPE_VIS_ONLY basic_ostringstream;
                                ^

The next problem is:

/Users/stephan/git/lyx/src/RowPainter.cpp:691:55: error: use of undeclared 
identifier 'abs'
                        pi_.pain.fillRectangle(int(xo_ + min(x1, x2)), y1, 
abs(x2 - x1),

When adding the obvious include "#include <cmath>“ it turns out that there is 
no abs for int values.

/Users/stephan/git/lyx/src/RowPainter.cpp:691:55: error: call to 'abs' is 
ambiguous
                        pi_.pain.fillRectangle(int(xo_ + min(x1, x2)), y1, 
abs(x2 - x1),
                                                                           ^~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:664:1:
 note: candidate function
abs(float __lcpp_x) _NOEXCEPT {return fabsf(__lcpp_x);}
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:668:1:
 note: candidate function
abs(double __lcpp_x) _NOEXCEPT {return fabs(__lcpp_x);}
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:672:1:
 note: candidate function
abs(long double __lcpp_x) _NOEXCEPT {return fabsl(__lcpp_x);}
^

A change like the following helps.
-                       pi_.pain.fillRectangle(int(xo_ + min(x1, x2)), y1, 
abs(x2 - x1),
+                       pi_.pain.fillRectangle(int(xo_ + min(x1, x2)), y1, 
abs(float(x2 - x1)),

But then it's the same story in the next file. So I don’t know how the proper 
fix should look like.
 
/Users/stephan/git/lyx/src/TextMetrics.cpp:1355:8: error: call to 'abs' is 
ambiguous
                        if (abs(p.x_ - x) < abs(p.x_ + dim.wid - x))
                            ^~~

Stephan

> Am 04.07.2016 um 02:42 schrieb Guillaume Munch <g...@lyx.org>:
> 
> commit 670efa8f646218f2a378f0cc614c4c37a9f6b89a
> Author: Guillaume Munch <g...@lyx.org>
> Date:   Sun Jun 19 03:39:38 2016 +0100
> 
>    Rationalise includes
> 
>    Modifying TexRow.h or texstream.h no longer triggers the recompilation of 
> the
>    complete source tree.
> ---
> src/Buffer.cpp                       |   23 ++++++++++++-----------
> src/Buffer.h                         |    6 +++---
> src/BufferParams.cpp                 |    1 +
> src/Changes.cpp                      |    1 +
> src/Changes.h                        |    4 ++--
> src/Compare.cpp                      |    1 +
> src/Converter.h                      |    1 -
> src/Cursor.cpp                       |    4 ++--
> src/Font.cpp                         |    1 +
> src/Format.cpp                       |    1 +
> src/LaTeXFonts.cpp                   |    1 +
> src/PDFOptions.cpp                   |    1 +
> src/Paragraph.cpp                    |    4 ++--
> src/TexRow.cpp                       |   20 ++++++++++----------
> src/TexRow.h                         |   33 +++++++++++++++++----------------
> src/frontends/qt4/FindAndReplace.cpp |    1 +
> src/frontends/qt4/GuiViewSource.cpp  |    1 +
> src/frontends/qt4/GuiViewSource.h    |    8 +++++++-
> src/graphics/PreviewLoader.cpp       |    4 ++--
> src/graphics/epstools.cpp            |    1 +
> src/insets/ExternalSupport.cpp       |    1 +
> src/insets/ExternalSupport.h         |    4 +++-
> src/insets/InsetArgument.cpp         |    6 ++++--
> src/insets/InsetBibtex.cpp           |    1 +
> src/insets/InsetBox.cpp              |    2 ++
> src/insets/InsetCaption.cpp          |    2 ++
> src/insets/InsetCitation.cpp         |    1 +
> src/insets/InsetCommand.cpp          |    1 +
> src/insets/InsetExternal.cpp         |   10 ++++------
> src/insets/InsetFloat.cpp            |   10 +++++-----
> src/insets/InsetFloatList.cpp        |    1 +
> src/insets/InsetGraphics.cpp         |    1 +
> src/insets/InsetHyperlink.cpp        |    1 +
> src/insets/InsetIPA.cpp              |    6 +++---
> src/insets/InsetIPAMacro.cpp         |    1 +
> src/insets/InsetInclude.cpp          |    4 ++--
> src/insets/InsetIndex.cpp            |    4 ++--
> src/insets/InsetLine.cpp             |    1 +
> src/insets/InsetListings.cpp         |    4 ++--
> src/insets/InsetNewline.cpp          |    1 +
> src/insets/InsetNewpage.cpp          |    1 +
> src/insets/InsetNomencl.cpp          |    1 +
> src/insets/InsetPhantom.cpp          |    1 +
> src/insets/InsetPreview.cpp          |    4 ++--
> src/insets/InsetQuotes.cpp           |    1 +
> src/insets/InsetRef.cpp              |    1 +
> src/insets/InsetSeparator.cpp        |    1 +
> src/insets/InsetSpace.cpp            |    1 +
> src/insets/InsetSpecialChar.cpp      |    1 +
> src/insets/InsetTabular.cpp          |    5 +++--
> src/insets/InsetText.cpp             |    1 +
> src/insets/InsetVSpace.cpp           |    1 +
> src/insets/InsetWrap.cpp             |    1 +
> src/lyxfind.cpp                      |    9 +++------
> src/mathed/InsetMath.cpp             |    9 +++------
> src/mathed/InsetMath.h               |    5 +++--
> src/mathed/InsetMathGrid.cpp         |    9 +++++----
> src/mathed/InsetMathHull.cpp         |   24 +++++++++---------------
> src/mathed/InsetMathNest.cpp         |    8 ++++----
> src/mathed/MacroTable.cpp            |    3 +--
> src/mathed/MathFactory.cpp           |    4 ++--
> src/mathed/MathMacroTemplate.cpp     |    3 +--
> src/mathed/MathStream.cpp            |   13 ++++++++-----
> src/mathed/MathStream.h              |    7 +++++--
> src/mathed/MathSupport.cpp           |    9 +++------
> src/output_latex.cpp                 |    1 +
> src/tex2lyx/dummy_impl.cpp           |   13 -------------
> src/texstream.cpp                    |   25 ++++++++++++++++++++++---
> src/texstream.h                      |   26 ++++++++++++++++++--------
> 69 files changed, 210 insertions(+), 157 deletions(-)
> 
> diff --git a/src/Buffer.cpp b/src/Buffer.cpp
> index 08f3148..a64e4b6 100644
> --- a/src/Buffer.cpp
> +++ b/src/Buffer.cpp
> @@ -57,6 +57,7 @@
> #include "PDFOptions.h"
> #include "SpellChecker.h"
> #include "sgml.h"
> +#include "texstream.h"
> #include "TexRow.h"
> #include "Text.h"
> #include "TextClass.h"
> @@ -1684,7 +1685,7 @@ bool Buffer::makeLaTeXFile(FileName const & fname,
>       ErrorList & errorList = d->errorLists["Export"];
>       errorList.clear();
>       bool failed_export = false;
> -     otexstream os(ofs, d->texrow);
> +     otexstream os(ofs);
> 
>       // make sure we are ready to export
>       // this needs to be done before we validate
> @@ -1694,7 +1695,6 @@ bool Buffer::makeLaTeXFile(FileName const & fname,
>       updateMacroInstances(OutputUpdate);
> 
>       try {
> -             os.texrow().reset();
>               writeLaTeXSource(os, original_path, runparams, output);
>       }
>       catch (EncodingException const & e) {
> @@ -1725,6 +1725,8 @@ bool Buffer::makeLaTeXFile(FileName const & fname,
>               lyx_exit(1);
>       }
> 
> +     d->texrow = move(os.texrow());
> +
>       ofs.close();
>       if (ofs.fail()) {
>               failed_export = true;
> @@ -3715,14 +3717,13 @@ unique_ptr<TexRow> Buffer::getSourceCode(odocstream & 
> os, string const & format,
>                       LaTeXFeatures features(*this, params(), runparams);
>                       params().validate(features);
>                       runparams.use_polyglossia = features.usePolyglossia();
> -                     texrow = make_unique<TexRow>();
> -                     texrow->newline();
> -                     texrow->newline();
>                       // latex or literate
> -                     otexstream ots(os, *texrow);
> -
> +                     otexstream ots(os);
> +                     // output above
> +                     ots.texrow().newlines(2);
>                       // the real stuff
>                       latexParagraphs(*this, text(), ots, runparams);
> +                     texrow = ots.releaseTexRow();
>                       texrow->finalize();
> 
>                       // Restore the parenthood
> @@ -3758,13 +3759,13 @@ unique_ptr<TexRow> Buffer::getSourceCode(odocstream & 
> os, string const & format,
>                               writeDocBookSource(os, absFileName(), 
> runparams, output);
>               } else {
>                       // latex or literate
> -                     texrow = make_unique<TexRow>();
> -                     texrow->newline();
> -                     texrow->newline();
> -                     otexstream ots(os, *texrow);
> +                     otexstream ots(os);
> +                     // output above
> +                     ots.texrow().newlines(2);
>                       if (master)
>                               runparams.is_child = true;
>                       writeLaTeXSource(ots, string(), runparams, output);
> +                     texrow = ots.releaseTexRow();
>                       texrow->finalize();
>               }
>       }
> diff --git a/src/Buffer.h b/src/Buffer.h
> index 7acf1f3..477a8ac 100644
> --- a/src/Buffer.h
> +++ b/src/Buffer.h
> @@ -13,7 +13,6 @@
> #define BUFFER_H
> 
> #include "OutputEnums.h"
> -#include "OutputParams.h"
> 
> #include "support/unique_ptr.h"
> #include "support/strfwd.h"
> @@ -51,6 +50,7 @@ class MacroData;
> class MacroNameSet;
> class MacroSet;
> class OutputParams;
> +class otexstream;
> class Paragraph;
> class ParConstIterator;
> class ParIterator;
> @@ -325,13 +325,13 @@ public:
>           method with a string stream if the output is supposed to go to a
>           file. \code
>           ofdocstream ofs;
> -         otexstream os(ofs, texrow);
> +         otexstream os(ofs);
>           ofs.open("test.tex");
>           writeLaTeXSource(os, ...);
>           ofs.close();
>           \endcode is NOT equivalent to \code
>           odocstringstream oss;
> -         otexstream os(oss, texrow);
> +         otexstream os(oss);
>           writeLaTeXSource(os, ...);
>           ofdocstream ofs;
>           ofs.open("test.tex");
> diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp
> index d2218e0..7af4397 100644
> --- a/src/BufferParams.cpp
> +++ b/src/BufferParams.cpp
> @@ -38,6 +38,7 @@
> #include "LyXRC.h"
> #include "OutputParams.h"
> #include "Spacing.h"
> +#include "texstream.h"
> #include "TexRow.h"
> #include "VSpace.h"
> #include "PDFOptions.h"
> diff --git a/src/Changes.cpp b/src/Changes.cpp
> index 1626f50..0d464d8 100644
> --- a/src/Changes.cpp
> +++ b/src/Changes.cpp
> @@ -22,6 +22,7 @@
> #include "MetricsInfo.h"
> #include "OutputParams.h"
> #include "Paragraph.h"
> +#include "texstream.h"
> #include "TocBackend.h"
> 
> #include "support/debug.h"
> diff --git a/src/Changes.h b/src/Changes.h
> index 9638396..ea6e4b3 100644
> --- a/src/Changes.h
> +++ b/src/Changes.h
> @@ -21,8 +21,6 @@
> #include "support/types.h"
> #include "support/lyxtime.h"
> 
> -#include "texstream.h"
> -
> #include <vector>
> 
> 
> @@ -32,9 +30,11 @@ class AuthorList;
> class Buffer;
> class DocIterator;
> class OutputParams;
> +class otexstream;
> class PainterInfo;
> class FontInfo;
> 
> +
> class Change {
> public:
>       /// the type of change
> diff --git a/src/Compare.cpp b/src/Compare.cpp
> index 68570b8..b2f6439 100644
> --- a/src/Compare.cpp
> +++ b/src/Compare.cpp
> @@ -19,6 +19,7 @@
> 
> #include "insets/InsetText.h"
> 
> +#include "support/docstream.h"
> #include "support/lassert.h"
> #include "support/lyxalgo.h"
> #include "support/qstring_helpers.h"
> diff --git a/src/Converter.h b/src/Converter.h
> index 9a72d8c..082b2d3 100644
> --- a/src/Converter.h
> +++ b/src/Converter.h
> @@ -29,7 +29,6 @@ class Buffer;
> class ErrorList;
> class Format;
> class Formats;
> -class OutputParams;
> 
> 
> ///
> diff --git a/src/Cursor.cpp b/src/Cursor.cpp
> index 2894f9d..8d5c63b 100644
> --- a/src/Cursor.cpp
> +++ b/src/Cursor.cpp
> @@ -31,6 +31,7 @@
> #include "Paragraph.h"
> #include "ParIterator.h"
> #include "Row.h"
> +#include "texstream.h"
> #include "Text.h"
> #include "TextMetrics.h"
> #include "TocBackend.h"
> @@ -1566,8 +1567,7 @@ void Cursor::normalize()
>                       << pos() << ' ' << lastpos() <<  " in idx: " << idx()
>                      << " in atom: '";
>               odocstringstream os;
> -             TexRow texrow(false);
> -             otexrowstream ots(os,texrow);
> +             otexrowstream ots(os, false);
>               WriteStream wi(ots, false, true, WriteStream::wsDefault);
>               inset().asInsetMath()->write(wi);
>               lyxerr << to_utf8(os.str()) << endl;
> diff --git a/src/Font.cpp b/src/Font.cpp
> index f0814a3..0ca4080 100644
> --- a/src/Font.cpp
> +++ b/src/Font.cpp
> @@ -25,6 +25,7 @@
> #include "LyXRC.h"
> #include "output_latex.h"
> #include "OutputParams.h"
> +#include "texstream.h"
> 
> #include "support/lassert.h"
> #include "support/convert.h"
> diff --git a/src/Format.cpp b/src/Format.cpp
> index eba00b9..503bfc5 100644
> --- a/src/Format.cpp
> +++ b/src/Format.cpp
> @@ -23,6 +23,7 @@
> #include "support/gettext.h"
> #include "support/lstrings.h"
> #include "support/mutex.h"
> +#include "support/docstream.h"
> #include "support/os.h"
> #include "support/PathChanger.h"
> #include "support/Systemcall.h"
> diff --git a/src/LaTeXFonts.cpp b/src/LaTeXFonts.cpp
> index 676179f..bc4151c 100644
> --- a/src/LaTeXFonts.cpp
> +++ b/src/LaTeXFonts.cpp
> @@ -19,6 +19,7 @@
> 
> #include "support/convert.h"
> #include "support/debug.h"
> +#include "support/docstream.h"
> #include "support/FileName.h"
> #include "support/filetools.h"
> #include "support/gettext.h"
> diff --git a/src/PDFOptions.cpp b/src/PDFOptions.cpp
> index 6734bea..77763be 100644
> --- a/src/PDFOptions.cpp
> +++ b/src/PDFOptions.cpp
> @@ -15,6 +15,7 @@
> 
> #include "Encoding.h"
> #include "Lexer.h"
> +#include "texstream.h"
> 
> #include "support/convert.h"
> #include "support/debug.h"
> diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp
> index c29ca4c..507702f 100644
> --- a/src/Paragraph.cpp
> +++ b/src/Paragraph.cpp
> @@ -40,6 +40,7 @@
> #include "ParagraphParameters.h"
> #include "SpellChecker.h"
> #include "sgml.h"
> +#include "texstream.h"
> #include "TextClass.h"
> #include "TexRow.h"
> #include "Text.h"
> @@ -1377,13 +1378,12 @@ void Paragraph::Private::validate(LaTeXFeatures & 
> features) const
>               BufferParams const & bp = features.runparams().is_child
>                       ? buf.masterParams() : buf.params();
>               Font f;
> -             TexRow texrow;
>               // Using a string stream here circumvents the encoding
>               // switching machinery of odocstream. Therefore the
>               // output is wrong if this paragraph contains content
>               // that needs to switch encoding.
>               odocstringstream ods;
> -             otexstream os(ods, texrow);
> +             otexstream os(ods, false);
>               if (is_command) {
>                       os << '\\' << from_ascii(layout_->latexname());
>                       // we have to provide all the optional arguments here, 
> even though
> diff --git a/src/TexRow.cpp b/src/TexRow.cpp
> index 21be0b8..4e23cf7 100644
> --- a/src/TexRow.cpp
> +++ b/src/TexRow.cpp
> @@ -53,7 +53,7 @@ void TexRow::RowEntryList::forceAddEntry(RowEntry const & 
> entry)
> }
> 
> 
> -TexRow::TextEntry TexRow::RowEntryList::getTextEntry() const
> +TextEntry TexRow::RowEntryList::getTextEntry() const
> {
>       if (text_entry_ < size())
>               return operator[](text_entry_).text;
> @@ -61,7 +61,7 @@ TexRow::TextEntry TexRow::RowEntryList::getTextEntry() const
> }
> 
> 
> -TexRow::RowEntry TexRow::RowEntryList::entry() const
> +RowEntry TexRow::RowEntryList::entry() const
> {
>       if (0 < size())
>               return operator[](0);
> @@ -77,8 +77,8 @@ void TexRow::RowEntryList::append(RowEntryList const & row)
> }
> 
> 
> -TexRow::TextEntry const TexRow::text_none = { -1, 0 };
> -TexRow::RowEntry const TexRow::row_none = { false, { TexRow::text_none } };
> +TextEntry const TexRow::text_none = { -1, 0 };
> +RowEntry const TexRow::row_none = { false, { TexRow::text_none } };
> 
> 
> bool TexRow::isNone(TextEntry const & t)
> @@ -101,7 +101,7 @@ void TexRow::reset(bool enable)
> }
> 
> 
> -TexRow::RowEntry TexRow::textEntry(int id, int pos)
> +RowEntry TexRow::textEntry(int id, int pos)
> {
>       RowEntry entry;
>       entry.is_math = false;
> @@ -111,7 +111,7 @@ TexRow::RowEntry TexRow::textEntry(int id, int pos)
> }
> 
> 
> -TexRow::RowEntry TexRow::mathEntry(uid_type id, idx_type cell)
> +RowEntry TexRow::mathEntry(uid_type id, idx_type cell)
> {
>       RowEntry entry;
>       entry.is_math = true;
> @@ -121,8 +121,8 @@ TexRow::RowEntry TexRow::mathEntry(uid_type id, idx_type 
> cell)
> }
> 
> 
> -bool operator==(TexRow::RowEntry const & entry1,
> -                             TexRow::RowEntry const & entry2)
> +bool operator==(RowEntry const & entry1,
> +                             RowEntry const & entry2)
> {
>       return entry1.is_math == entry2.is_math
>               && (entry1.is_math
> @@ -216,7 +216,7 @@ bool TexRow::getIdFromRow(int row, int & id, int & pos) 
> const
> }
> 
> 
> -TexRow::RowEntry TexRow::rowEntryFromCursorSlice(CursorSlice const & slice)
> +RowEntry TexRow::rowEntryFromCursorSlice(CursorSlice const & slice)
> {
>       RowEntry entry;
>       InsetMath * insetMath = slice.asInsetMath();
> @@ -408,7 +408,7 @@ std::pair<int,int> TexRow::rowFromDocIterator(DocIterator 
> const & dit) const
>               // matches either at a deeper level, or at the same level but 
> not
>               // before.
>               for (size_t i = best_slice; i < n; ++i) {
> -                     TexRow::RowEntry entry_i = 
> rowEntryFromCursorSlice(dit[i]);
> +                     RowEntry entry_i = rowEntryFromCursorSlice(dit[i]);
>                       if (sameParOrInsetMath(*it, entry_i)) {
>                               if (comparePos(*it, entry_i) >= 0
>                                       && (i > best_slice
> diff --git a/src/TexRow.h b/src/TexRow.h
> index c072ec1..9e41b0a 100644
> --- a/src/TexRow.h
> +++ b/src/TexRow.h
> @@ -46,26 +46,27 @@ typedef void const * uid_type;
> typedef size_t idx_type;
> 
> 
> +/// an individual par id/pos <=> row mapping
> +struct TextEntry { int id; int pos; };
> +
> +/// an individual math id/cell <=> row mapping
> +struct MathEntry { uid_type id; idx_type cell; };
> +
> +/// a container for passing entries around
> +struct RowEntry {
> +     bool is_math;// true iff the union is a math
> +     union {
> +             struct TextEntry text;
> +             struct MathEntry math;
> +     };
> +};
> +
> +
> /// Represents the correspondence between paragraphs and the generated
> /// LaTeX file
> 
> class TexRow {
> public:
> -     /// an individual par id/pos <=> row mapping
> -     struct TextEntry { int id; int pos; };
> -
> -     /// an individual math id/cell <=> row mapping
> -     struct MathEntry { uid_type id; idx_type cell; };
> -
> -     /// a container for passing entries around
> -     struct RowEntry {
> -             bool is_math;// true iff the union is a math
> -             union {
> -                     struct TextEntry text;
> -                     struct MathEntry math;
> -             };
> -     };
> -
>       // For each row we store a list of one special TextEntry and several
>       // RowEntries. (The order is important.)  We only want one text entry
>       // because we do not want to store every position in the lyx file. On 
> the
> @@ -205,7 +206,7 @@ private:
>       bool enabled_;
> };
> 
> -bool operator==(TexRow::RowEntry const &, TexRow::RowEntry const &);
> +bool operator==(RowEntry const &, RowEntry const &);
> 
> LyXErr & operator<<(LyXErr &, TexRow &);
> 
> diff --git a/src/frontends/qt4/FindAndReplace.cpp 
> b/src/frontends/qt4/FindAndReplace.cpp
> index ac7084a..4411074 100644
> --- a/src/frontends/qt4/FindAndReplace.cpp
> +++ b/src/frontends/qt4/FindAndReplace.cpp
> @@ -33,6 +33,7 @@
> #include "frontends/alert.h"
> 
> #include "support/debug.h"
> +#include "support/docstream.h"
> #include "support/filetools.h"
> #include "support/FileName.h"
> #include "support/gettext.h"
> diff --git a/src/frontends/qt4/GuiViewSource.cpp 
> b/src/frontends/qt4/GuiViewSource.cpp
> index 46dd358..4be43e2 100644
> --- a/src/frontends/qt4/GuiViewSource.cpp
> +++ b/src/frontends/qt4/GuiViewSource.cpp
> @@ -22,6 +22,7 @@
> #include "Cursor.h"
> #include "Format.h"
> #include "Paragraph.h"
> +#include "TexRow.h"
> 
> #include "support/debug.h"
> #include "support/lassert.h"
> diff --git a/src/frontends/qt4/GuiViewSource.h 
> b/src/frontends/qt4/GuiViewSource.h
> index 428da05..dbe36c7 100644
> --- a/src/frontends/qt4/GuiViewSource.h
> +++ b/src/frontends/qt4/GuiViewSource.h
> @@ -18,20 +18,26 @@
> 
> #include "Buffer.h"
> #include "DockView.h"
> -#include "TexRow.h"
> 
> #include <QDockWidget>
> #include <QString>
> #include <QTimer>
> 
> +
> class QTextDocument;
> 
> +
> namespace lyx {
> +
> +class TexRow;
> +
> +
> namespace frontend {
> 
> class GuiViewSource;
> class LaTeXHighlighter;
> 
> +
> class ViewSourceWidget : public QWidget, public Ui::ViewSourceUi
> {
>       Q_OBJECT
> diff --git a/src/graphics/PreviewLoader.cpp b/src/graphics/PreviewLoader.cpp
> index bc174da..1f78d77 100644
> --- a/src/graphics/PreviewLoader.cpp
> +++ b/src/graphics/PreviewLoader.cpp
> @@ -25,6 +25,7 @@
> #include "output.h"
> #include "OutputParams.h"
> #include "TexRow.h"
> +#include "texstream.h"
> 
> #include "frontends/Application.h" // hexName
> 
> @@ -625,8 +626,7 @@ void PreviewLoader::Impl::startLoading(bool wait)
>               return;
>       }
> 
> -     TexRow texrow;
> -     otexstream os(of, texrow);
> +     otexstream os(of);
>       OutputParams runparams(&enc);
>       LaTeXFeatures features(buffer_, buffer_.params(), runparams);
> 
> diff --git a/src/graphics/epstools.cpp b/src/graphics/epstools.cpp
> index 17aedfc..2fd67dc 100644
> --- a/src/graphics/epstools.cpp
> +++ b/src/graphics/epstools.cpp
> @@ -26,6 +26,7 @@
> #include "Format.h"
> 
> #include "support/debug.h"
> +#include "support/docstream.h"
> #include "support/filetools.h"
> #include "support/FileName.h"
> #include "support/regex.h"
> diff --git a/src/insets/ExternalSupport.cpp b/src/insets/ExternalSupport.cpp
> index 7ea6d56..f208a95 100644
> --- a/src/insets/ExternalSupport.cpp
> +++ b/src/insets/ExternalSupport.cpp
> @@ -22,6 +22,7 @@
> #include "Exporter.h"
> #include "Format.h"
> #include "Mover.h"
> +#include "texstream.h"
> 
> #include "frontends/alert.h"
> 
> diff --git a/src/insets/ExternalSupport.h b/src/insets/ExternalSupport.h
> index 1000735..cd42572 100644
> --- a/src/insets/ExternalSupport.h
> +++ b/src/insets/ExternalSupport.h
> @@ -13,13 +13,15 @@
> #ifndef EXTERNALSUPPORT_H
> #define EXTERNALSUPPORT_H
> 
> -#include "texstream.h"
> +#include <string>
> +
> 
> namespace lyx {
> 
> class Buffer;
> class ExportData;
> class InsetExternalParams;
> +class otexstream;
> 
> namespace external {
> 
> diff --git a/src/insets/InsetArgument.cpp b/src/insets/InsetArgument.cpp
> index b65257a..da807d2 100644
> --- a/src/insets/InsetArgument.cpp
> +++ b/src/insets/InsetArgument.cpp
> @@ -24,6 +24,8 @@
> #include "Lexer.h"
> #include "OutputParams.h"
> #include "ParIterator.h"
> +#include "TexRow.h"
> +#include "texstream.h"
> 
> #include "support/convert.h"
> #include "support/debug.h"
> @@ -268,9 +270,8 @@ void InsetArgument::latexArgument(otexstream & os,
>               OutputParams const & runparams_in, docstring const & ldelim,
>               docstring const & rdelim, docstring const & presetarg) const
> {
> -     TexRow texrow;
>       odocstringstream ss;
> -     otexstream ots(ss, texrow);
> +     otexstream ots(ss);
>       OutputParams runparams = runparams_in;
>       if (!pass_thru_chars_.empty())
>               runparams.pass_thru_chars += pass_thru_chars_;
> @@ -281,6 +282,7 @@ void InsetArgument::latexArgument(otexstream & os,
>               str = presetarg + sep + str;
>       if (ldelim != "{" && support::contains(str, rdelim))
>               str = '{' + str + '}';
> +     // TODO: append texrow information
>       os << ldelim << str << rdelim;
> }
> 
> diff --git a/src/insets/InsetBibtex.cpp b/src/insets/InsetBibtex.cpp
> index e3202ec..13c91b0 100644
> --- a/src/insets/InsetBibtex.cpp
> +++ b/src/insets/InsetBibtex.cpp
> @@ -27,6 +27,7 @@
> #include "output_xhtml.h"
> #include "OutputParams.h"
> #include "PDFOptions.h"
> +#include "texstream.h"
> #include "TextClass.h"
> 
> #include "frontends/alert.h"
> diff --git a/src/insets/InsetBox.cpp b/src/insets/InsetBox.cpp
> index ea18afa..28d79c0 100644
> --- a/src/insets/InsetBox.cpp
> +++ b/src/insets/InsetBox.cpp
> @@ -27,6 +27,8 @@
> #include "Lexer.h"
> #include "MetricsInfo.h"
> #include "output_xhtml.h"
> +#include "TexRow.h"
> +#include "texstream.h"
> #include "TextClass.h"
> 
> #include "support/debug.h"
> diff --git a/src/insets/InsetCaption.cpp b/src/insets/InsetCaption.cpp
> index 05b7dc7..613249b 100644
> --- a/src/insets/InsetCaption.cpp
> +++ b/src/insets/InsetCaption.cpp
> @@ -32,6 +32,8 @@
> #include "OutputParams.h"
> #include "Paragraph.h"
> #include "ParIterator.h"
> +#include "TexRow.h"
> +#include "texstream.h"
> #include "TextClass.h"
> #include "TextMetrics.h"
> #include "TocBackend.h"
> diff --git a/src/insets/InsetCitation.cpp b/src/insets/InsetCitation.cpp
> index 2b9033f..13fddd7 100644
> --- a/src/insets/InsetCitation.cpp
> +++ b/src/insets/InsetCitation.cpp
> @@ -24,6 +24,7 @@
> #include "LaTeXFeatures.h"
> #include "output_xhtml.h"
> #include "ParIterator.h"
> +#include "texstream.h"
> #include "TocBackend.h"
> 
> #include "support/debug.h"
> diff --git a/src/insets/InsetCommand.cpp b/src/insets/InsetCommand.cpp
> index fcda3cd..879d9a3 100644
> --- a/src/insets/InsetCommand.cpp
> +++ b/src/insets/InsetCommand.cpp
> @@ -21,6 +21,7 @@
> #include "FuncStatus.h"
> #include "Lexer.h"
> #include "MetricsInfo.h"
> +#include "texstream.h"
> 
> #include "insets/InsetBox.h"
> #include "insets/InsetBranch.h"
> diff --git a/src/insets/InsetExternal.cpp b/src/insets/InsetExternal.cpp
> index 5a7a07a..1a19748 100644
> --- a/src/insets/InsetExternal.cpp
> +++ b/src/insets/InsetExternal.cpp
> @@ -30,6 +30,7 @@
> #include "MetricsInfo.h"
> #include "OutputParams.h"
> #include "output_latex.h"
> +#include "texstream.h"
> #include "TocBackend.h"
> 
> #include "frontends/alert.h"
> @@ -560,9 +561,8 @@ static bool isPreviewWanted(InsetExternalParams const & 
> params)
> 
> static docstring latexString(InsetExternal const & inset)
> {
> -     TexRow texrow;
>       odocstringstream ods;
> -     otexstream os(ods, texrow);
> +     otexstream os(ods, false);
>       // We don't need to set runparams.encoding since it is not used by
>       // latex().
>       OutputParams runparams(0);
> @@ -730,8 +730,7 @@ int InsetExternal::plaintext(odocstringstream & os,
>       if (runparams.for_tooltip)
>               return 0;
> 
> -     TexRow texrow;
> -     otexstream ots(os, texrow);
> +     otexstream ots(os, false);
>       ots << '\n'; // output external material on a new line
>       external::writeExternal(params_, "Ascii", buffer(), ots,
>                               *(runparams.exportdata), false,
> @@ -743,9 +742,8 @@ int InsetExternal::plaintext(odocstringstream & os,
> int InsetExternal::docbook(odocstream & os,
>                          OutputParams const & runparams) const
> {
> -     TexRow texrow;
>       odocstringstream ods;
> -     otexstream ots(ods, texrow);
> +     otexstream ots(ods, false);
>       external::writeExternal(params_, "DocBook", buffer(), ots,
>                               *(runparams.exportdata), false,
>                               runparams.dryrun || runparams.inComment);
> diff --git a/src/insets/InsetFloat.cpp b/src/insets/InsetFloat.cpp
> index ae1bf63..8d35c64 100644
> --- a/src/insets/InsetFloat.cpp
> +++ b/src/insets/InsetFloat.cpp
> @@ -29,6 +29,8 @@
> #include "Lexer.h"
> #include "output_xhtml.h"
> #include "ParIterator.h"
> +#include "TexRow.h"
> +#include "texstream.h"
> #include "TextClass.h"
> 
> #include "support/debug.h"
> @@ -493,9 +495,8 @@ bool InsetFloat::allowsCaptionVariation(std::string const 
> & newtype) const
> 
> docstring InsetFloat::getCaption(OutputParams const & runparams) const
> {
> -     TexRow texrow(false);
>       odocstringstream ods;
> -     otexstream os(ods, texrow);
> +     otexstream os(ods, false);
>       getCaption(os, runparams);
>       return ods.str();
> }
> @@ -514,15 +515,14 @@ void InsetFloat::getCaption(otexstream & os,
>       ins->getArgs(os, runparams);
> 
>       os << '[';
> -     TexRow texrow;
>       odocstringstream ods;
> -     otexstream oss(ods, texrow);
> +     otexstream oss(ods);
>       ins->getArgument(oss, runparams);
>       docstring arg = ods.str();
>       // Protect ']'
>       if (arg.find(']') != docstring::npos)
>               arg = '{' + arg + '}';
> -     os.append(arg, texrow);
> +     os.append(arg, move(oss.texrow()));
>       os << ']';
> }
> 
> diff --git a/src/insets/InsetFloatList.cpp b/src/insets/InsetFloatList.cpp
> index 6deb46c..2d9c33d 100644
> --- a/src/insets/InsetFloatList.cpp
> +++ b/src/insets/InsetFloatList.cpp
> @@ -26,6 +26,7 @@
> #include "Lexer.h"
> #include "Paragraph.h"
> #include "output_xhtml.h"
> +#include "texstream.h"
> #include "TextClass.h"
> #include "TocBackend.h"
> 
> diff --git a/src/insets/InsetGraphics.cpp b/src/insets/InsetGraphics.cpp
> index dc617fb..85f1a07 100644
> --- a/src/insets/InsetGraphics.cpp
> +++ b/src/insets/InsetGraphics.cpp
> @@ -68,6 +68,7 @@ TODO
> #include "OutputParams.h"
> #include "output_xhtml.h"
> #include "sgml.h"
> +#include "texstream.h"
> #include "TocBackend.h"
> 
> #include "frontends/alert.h"
> diff --git a/src/insets/InsetHyperlink.cpp b/src/insets/InsetHyperlink.cpp
> index 54f1f2c..8b3433c 100644
> --- a/src/insets/InsetHyperlink.cpp
> +++ b/src/insets/InsetHyperlink.cpp
> @@ -22,6 +22,7 @@
> #include "LaTeXFeatures.h"
> #include "OutputParams.h"
> #include "output_xhtml.h"
> +#include "texstream.h"
> 
> #include "support/docstream.h"
> #include "support/FileName.h"
> diff --git a/src/insets/InsetIPA.cpp b/src/insets/InsetIPA.cpp
> index 1da5a24..3876358 100644
> --- a/src/insets/InsetIPA.cpp
> +++ b/src/insets/InsetIPA.cpp
> @@ -22,6 +22,7 @@
> #include "MetricsInfo.h"
> #include "OutputParams.h"
> #include "RenderPreview.h"
> +#include "texstream.h"
> 
> #include "frontends/Painter.h"
> 
> @@ -120,9 +121,8 @@ void InsetIPA::addPreview(DocIterator const & inset_pos,
> 
> void InsetIPA::preparePreview(DocIterator const & pos) const  
> {
> -     TexRow texrow;
> -     odocstringstream str;  
> -     otexstream os(str, texrow);
> +     odocstringstream str;
> +     otexstream os(str, false);
>       OutputParams runparams(&pos.buffer()->params().encoding());
>       latex(os, runparams);
>       docstring const snippet = str.str();
> diff --git a/src/insets/InsetIPAMacro.cpp b/src/insets/InsetIPAMacro.cpp
> index fd96a19..0d7a41b 100644
> --- a/src/insets/InsetIPAMacro.cpp
> +++ b/src/insets/InsetIPAMacro.cpp
> @@ -23,6 +23,7 @@
> #include "Lexer.h"
> #include "MetricsInfo.h"
> #include "output_xhtml.h"
> +#include "texstream.h"
> 
> #include "frontends/FontMetrics.h"
> #include "frontends/Painter.h"
> diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp
> index 1031f3a..47c9a61 100644
> --- a/src/insets/InsetInclude.cpp
> +++ b/src/insets/InsetInclude.cpp
> @@ -36,6 +36,7 @@
> #include "output_plaintext.h"
> #include "output_xhtml.h"
> #include "OutputParams.h"
> +#include "texstream.h"
> #include "TextClass.h"
> #include "TocBackend.h"
> 
> @@ -1085,9 +1086,8 @@ bool preview_wanted(InsetCommandParams const & params, 
> Buffer const & buffer)
> 
> docstring latexString(InsetInclude const & inset)
> {
> -     TexRow texrow;
>       odocstringstream ods;
> -     otexstream os(ods, texrow);
> +     otexstream os(ods, false);
>       // We don't need to set runparams.encoding since this will be done
>       // by latex() anyway.
>       OutputParams runparams(0);
> diff --git a/src/insets/InsetIndex.cpp b/src/insets/InsetIndex.cpp
> index aff4080..5c8a9dd 100644
> --- a/src/insets/InsetIndex.cpp
> +++ b/src/insets/InsetIndex.cpp
> @@ -28,6 +28,7 @@
> #include "output_latex.h"
> #include "output_xhtml.h"
> #include "sgml.h"
> +#include "texstream.h"
> #include "TextClass.h"
> #include "TocBackend.h"
> 
> @@ -74,9 +75,8 @@ void InsetIndex::latex(otexstream & os, OutputParams const 
> & runparams_in) const
>       }
> 
>       // get contents of InsetText as LaTeX and plaintext
> -     TexRow texrow;
>       odocstringstream ourlatex;
> -     otexstream ots(ourlatex, texrow);
> +     otexstream ots(ourlatex);
>       InsetText::latex(ots, runparams);
>       odocstringstream ourplain;
>       InsetText::plaintext(ourplain, runparams);
> diff --git a/src/insets/InsetLine.cpp b/src/insets/InsetLine.cpp
> index 087dba7..73ce540 100644
> --- a/src/insets/InsetLine.cpp
> +++ b/src/insets/InsetLine.cpp
> @@ -25,6 +25,7 @@
> #include "MetricsInfo.h"
> #include "OutputParams.h"
> #include "output_xhtml.h"
> +#include "texstream.h"
> #include "Text.h"
> 
> #include "frontends/FontMetrics.h"
> diff --git a/src/insets/InsetListings.cpp b/src/insets/InsetListings.cpp
> index 91125d8..e4b8c7f 100644
> --- a/src/insets/InsetListings.cpp
> +++ b/src/insets/InsetListings.cpp
> @@ -30,6 +30,7 @@
> #include "output_xhtml.h"
> #include "OutputParams.h"
> #include "TextClass.h"
> +#include "texstream.h"
> 
> #include "support/debug.h"
> #include "support/docstream.h"
> @@ -395,9 +396,8 @@ docstring InsetListings::getCaption(OutputParams const & 
> runparams) const
>       if (ins == 0)
>               return docstring();
> 
> -     TexRow texrow;
>       odocstringstream ods;
> -     otexstream os(ods, texrow);
> +     otexstream os(ods, false);
>       ins->getArgs(os, runparams);
>       ins->getArgument(os, runparams);
> 
> diff --git a/src/insets/InsetNewline.cpp b/src/insets/InsetNewline.cpp
> index 99cbf14..411da12 100644
> --- a/src/insets/InsetNewline.cpp
> +++ b/src/insets/InsetNewline.cpp
> @@ -21,6 +21,7 @@
> #include "MetricsInfo.h"
> #include "OutputParams.h"
> #include "output_xhtml.h"
> +#include "texstream.h"
> 
> #include "frontends/Application.h"
> #include "frontends/FontMetrics.h"
> diff --git a/src/insets/InsetNewpage.cpp b/src/insets/InsetNewpage.cpp
> index 418bf8b..b369ce1 100644
> --- a/src/insets/InsetNewpage.cpp
> +++ b/src/insets/InsetNewpage.cpp
> @@ -20,6 +20,7 @@
> #include "MetricsInfo.h"
> #include "OutputParams.h"
> #include "output_xhtml.h"
> +#include "texstream.h"
> #include "Text.h"
> #include "TextMetrics.h"
> 
> diff --git a/src/insets/InsetNomencl.cpp b/src/insets/InsetNomencl.cpp
> index f75ef15..2595b14 100644
> --- a/src/insets/InsetNomencl.cpp
> +++ b/src/insets/InsetNomencl.cpp
> @@ -31,6 +31,7 @@
> #include "OutputParams.h"
> #include "output_xhtml.h"
> #include "sgml.h"
> +#include "texstream.h"
> #include "TocBackend.h"
> 
> #include "frontends/FontMetrics.h"
> diff --git a/src/insets/InsetPhantom.cpp b/src/insets/InsetPhantom.cpp
> index c6efe9a..8fb9d94 100644
> --- a/src/insets/InsetPhantom.cpp
> +++ b/src/insets/InsetPhantom.cpp
> @@ -28,6 +28,7 @@
> #include "Lexer.h"
> #include "MetricsInfo.h"
> #include "OutputParams.h"
> +#include "texstream.h"
> #include "TextClass.h"
> 
> #include "support/docstream.h"
> diff --git a/src/insets/InsetPreview.cpp b/src/insets/InsetPreview.cpp
> index 7577741..53cfb23 100644
> --- a/src/insets/InsetPreview.cpp
> +++ b/src/insets/InsetPreview.cpp
> @@ -19,6 +19,7 @@
> #include "MetricsInfo.h"
> #include "OutputParams.h"
> #include "RenderPreview.h"
> +#include "texstream.h"
> 
> #include "frontends/Painter.h"
> 
> @@ -81,9 +82,8 @@ void InsetPreview::addPreview(DocIterator const & inset_pos,
> 
> void InsetPreview::preparePreview(DocIterator const & pos) const
> {
> -     TexRow texrow;
>       odocstringstream str;
> -     otexstream os(str, texrow);
> +     otexstream os(str, false);
>       OutputParams runparams(&pos.buffer()->params().encoding());
>       latex(os, runparams);
> 
> diff --git a/src/insets/InsetQuotes.cpp b/src/insets/InsetQuotes.cpp
> index ba5a127..84e004b 100644
> --- a/src/insets/InsetQuotes.cpp
> +++ b/src/insets/InsetQuotes.cpp
> @@ -24,6 +24,7 @@
> #include "MetricsInfo.h"
> #include "OutputParams.h"
> #include "output_xhtml.h"
> +#include "texstream.h"
> 
> #include "frontends/FontMetrics.h"
> #include "frontends/Painter.h"
> diff --git a/src/insets/InsetRef.cpp b/src/insets/InsetRef.cpp
> index 7731ad8..146a85d 100644
> --- a/src/insets/InsetRef.cpp
> +++ b/src/insets/InsetRef.cpp
> @@ -23,6 +23,7 @@
> #include "output_xhtml.h"
> #include "ParIterator.h"
> #include "sgml.h"
> +#include "texstream.h"
> #include "TocBackend.h"
> 
> #include "support/debug.h"
> diff --git a/src/insets/InsetSeparator.cpp b/src/insets/InsetSeparator.cpp
> index 27aeb7c..9beda1d 100644
> --- a/src/insets/InsetSeparator.cpp
> +++ b/src/insets/InsetSeparator.cpp
> @@ -20,6 +20,7 @@
> #include "MetricsInfo.h"
> #include "OutputParams.h"
> #include "output_xhtml.h"
> +#include "texstream.h"
> 
> #include "frontends/Application.h"
> #include "frontends/FontMetrics.h"
> diff --git a/src/insets/InsetSpace.cpp b/src/insets/InsetSpace.cpp
> index 6ab6f9a..7d76f3f 100644
> --- a/src/insets/InsetSpace.cpp
> +++ b/src/insets/InsetSpace.cpp
> @@ -27,6 +27,7 @@
> #include "MetricsInfo.h"
> #include "OutputParams.h"
> #include "output_xhtml.h"
> +#include "texstream.h"
> 
> #include "support/debug.h"
> #include "support/docstream.h"
> diff --git a/src/insets/InsetSpecialChar.cpp b/src/insets/InsetSpecialChar.cpp
> index 8671d2b..3d32f40 100644
> --- a/src/insets/InsetSpecialChar.cpp
> +++ b/src/insets/InsetSpecialChar.cpp
> @@ -20,6 +20,7 @@
> #include "Lexer.h"
> #include "MetricsInfo.h"
> #include "output_xhtml.h"
> +#include "texstream.h"
> 
> #include "frontends/FontMetrics.h"
> #include "frontends/Painter.h"
> diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp
> index 7804232..0834f1a 100644
> --- a/src/insets/InsetTabular.cpp
> +++ b/src/insets/InsetTabular.cpp
> @@ -45,6 +45,8 @@
> #include "Paragraph.h"
> #include "ParagraphParameters.h"
> #include "ParIterator.h"
> +#include "TexRow.h"
> +#include "texstream.h"
> #include "TextClass.h"
> #include "TextMetrics.h"
> 
> @@ -2685,8 +2687,7 @@ void Tabular::TeXRow(otexstream & os, row_type row,
> void Tabular::latex(otexstream & os, OutputParams const & runparams) const
> {
>       bool const is_tabular_star = !tabular_width.zero();
> -     TexRow::RowEntry pos = TexRow::textEntry(runparams.lastid,
> -                                                                             
>          runparams.lastpos);
> +     RowEntry pos = TexRow::textEntry(runparams.lastid, runparams.lastpos);
> 
>       //+---------------------------------------------------------------------
>       //+                      first the opening preamble                    +
> diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp
> index 99b1381..b67f6b4 100644
> --- a/src/insets/InsetText.cpp
> +++ b/src/insets/InsetText.cpp
> @@ -48,6 +48,7 @@
> #include "Row.h"
> #include "sgml.h"
> #include "TexRow.h"
> +#include "texstream.h"
> #include "TextClass.h"
> #include "Text.h"
> #include "TextMetrics.h"
> diff --git a/src/insets/InsetVSpace.cpp b/src/insets/InsetVSpace.cpp
> index 7edbebf..461933c 100644
> --- a/src/insets/InsetVSpace.cpp
> +++ b/src/insets/InsetVSpace.cpp
> @@ -24,6 +24,7 @@
> #include "MetricsInfo.h"
> #include "OutputParams.h"
> #include "output_xhtml.h"
> +#include "texstream.h"
> #include "Text.h"
> 
> #include "support/debug.h"
> diff --git a/src/insets/InsetWrap.cpp b/src/insets/InsetWrap.cpp
> index 00223ad..c8c0ef8 100644
> --- a/src/insets/InsetWrap.cpp
> +++ b/src/insets/InsetWrap.cpp
> @@ -27,6 +27,7 @@
> #include "LaTeXFeatures.h"
> #include "Lexer.h"
> #include "output_xhtml.h"
> +#include "texstream.h"
> #include "TextClass.h"
> 
> #include "support/debug.h"
> diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp
> index 69a9b80..cc8d1cf 100644
> --- a/src/lyxfind.cpp
> +++ b/src/lyxfind.cpp
> @@ -727,9 +727,8 @@ private:
> static docstring buffer_to_latex(Buffer & buffer)
> {
>       OutputParams runparams(&buffer.params().encoding());
> -     TexRow texrow(false);
>       odocstringstream ods;
> -     otexstream os(ods, texrow);
> +     otexstream os(ods, false);
>       runparams.nice = true;
>       runparams.flavor = OutputParams::LATEX;
>       runparams.linelen = 80; //lyxrc.plaintext_linelen;
> @@ -1048,9 +1047,8 @@ docstring latexifyFromCursor(DocIterator const & cur, 
> int len)
>       Buffer const & buf = *cur.buffer();
>       LBUFERR(buf.params().isLatex());
> 
> -     TexRow texrow(false);
>       odocstringstream ods;
> -     otexstream os(ods, texrow);
> +     otexstream os(ods, false);
>       OutputParams runparams(&buf.params().encoding());
>       runparams.nice = false;
>       runparams.flavor = OutputParams::LATEX;
> @@ -1395,9 +1393,8 @@ static void findAdvReplace(BufferView * bv, 
> FindAndReplaceOptions const & opt, M
>               LYXERR(Debug::FIND, "After pasteParagraphList() cur=" << cur << 
> endl);
>               sel_len = repl_buffer.paragraphs().begin()->size();
>       } else if (cur.inMathed()) {
> -             TexRow texrow(false);
>               odocstringstream ods;
> -             otexstream os(ods, texrow);
> +             otexstream os(ods, false);
>               OutputParams runparams(&repl_buffer.params().encoding());
>               runparams.nice = false;
>               runparams.flavor = OutputParams::LATEX;
> diff --git a/src/mathed/InsetMath.cpp b/src/mathed/InsetMath.cpp
> index f71febc..87952f5 100644
> --- a/src/mathed/InsetMath.cpp
> +++ b/src/mathed/InsetMath.cpp
> @@ -53,8 +53,7 @@ void InsetMath::dump() const
> {
>       lyxerr << "---------------------------------------------" << endl;
>       odocstringstream os;
> -     TexRow texrow(false);
> -     otexrowstream ots(os,texrow);
> +     otexrowstream ots(os, false);
>       WriteStream wi(ots, false, true, WriteStream::wsDefault);
>       write(wi);
>       lyxerr << to_utf8(os.str());
> @@ -158,8 +157,7 @@ HullType InsetMath::getType() const
> ostream & operator<<(ostream & os, MathAtom const & at)
> {
>       odocstringstream oss;
> -     TexRow texrow(false);
> -     otexrowstream ots(oss,texrow);
> +     otexrowstream ots(oss, false);
>       WriteStream wi(ots, false, false, WriteStream::wsDefault);
>       at->write(wi);
>       return os << to_utf8(oss.str());
> @@ -168,8 +166,7 @@ ostream & operator<<(ostream & os, MathAtom const & at)
> 
> odocstream & operator<<(odocstream & os, MathAtom const & at)
> {
> -     TexRow texrow(false);
> -     otexrowstream ots(os,texrow);
> +     otexrowstream ots(os, false);
>       WriteStream wi(ots, false, false, WriteStream::wsDefault);
>       at->write(wi);
>       return os;
> diff --git a/src/mathed/InsetMath.h b/src/mathed/InsetMath.h
> index 088fce6..3bab681 100644
> --- a/src/mathed/InsetMath.h
> +++ b/src/mathed/InsetMath.h
> @@ -17,8 +17,6 @@
> 
> #include "insets/Inset.h"
> 
> -#include "TexRow.h"
> -
> 
> namespace lyx {
> 
> @@ -93,6 +91,9 @@ class TextPainter;
> class TextMetricsInfo;
> class ReplaceData;
> 
> +/// Type of unique identifiers for math insets (used in TexRow)
> +typedef void const * uid_type;
> +
> 
> class InsetMath : public Inset {
> public:
> diff --git a/src/mathed/InsetMathGrid.cpp b/src/mathed/InsetMathGrid.cpp
> index 1c830c1..f2d88a2 100644
> --- a/src/mathed/InsetMathGrid.cpp
> +++ b/src/mathed/InsetMathGrid.cpp
> @@ -22,10 +22,11 @@
> #include "Buffer.h"
> #include "BufferParams.h"
> #include "BufferView.h"
> -#include "CutAndPaste.h"
> -#include "FuncStatus.h"
> #include "Cursor.h"
> +#include "CutAndPaste.h"
> #include "FuncRequest.h"
> +#include "FuncStatus.h"
> +#include "TexRow.h"
> 
> #include "frontends/Clipboard.h"
> #include "frontends/Painter.h"
> @@ -1268,8 +1269,8 @@ void InsetMathGrid::write(WriteStream & os,
>               for (col_type col = beg_col; col < end_col;) {
>                       int nccols = 1;
>                       idx_type const idx = index(row, col);
> -                     TexRow::RowEntry entry = 
> os.texrow().mathEntry(id(),idx);
> -                     os.texrow().startMath(id(),idx);
> +                     RowEntry entry = TexRow::mathEntry(id(),idx);
> +                     os.texrow().start(entry);
>                       if (col >= lastcol) {
>                               ++col;
>                               continue;
> diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp
> index 88a4c1d..5dffc3d 100644
> --- a/src/mathed/InsetMathHull.cpp
> +++ b/src/mathed/InsetMathHull.cpp
> @@ -43,6 +43,7 @@
> #include "Paragraph.h"
> #include "ParIterator.h"
> #include "sgml.h"
> +#include "TexRow.h"
> #include "TextClass.h"
> #include "TextPainter.h"
> #include "TocBackend.h"
> @@ -614,8 +615,7 @@ void InsetMathHull::metricsT(TextMetricsInfo const & mi, 
> Dimension & dim) const
>               InsetMathGrid::metricsT(mi, dim);
>       } else {
>               odocstringstream os;
> -             TexRow texrow(false);
> -             otexrowstream ots(os,texrow);
> +             otexrowstream ots(os, false);
>               WriteStream wi(ots, false, true, WriteStream::wsDefault);
>               write(wi);
>               dim.wid = os.str().size();
> @@ -631,8 +631,7 @@ void InsetMathHull::drawT(TextPainter & pain, int x, int 
> y) const
>               InsetMathGrid::drawT(pain, x, y);
>       } else {
>               odocstringstream os;
> -             TexRow texrow(false);
> -             otexrowstream ots(os,texrow);
> +             otexrowstream ots(os, false);
>               WriteStream wi(ots, false, true, WriteStream::wsDefault);
>               write(wi);
>               pain.draw(x, y, os.str().c_str());
> @@ -651,8 +650,7 @@ static docstring latexString(InsetMathHull const & inset)
>       static Encoding const * encoding = 0;
>       if (inset.isBufferValid())
>               encoding = &(inset.buffer().params().encoding());
> -     TexRow texrow(false);
> -     otexrowstream ots(ls,texrow);
> +     otexrowstream ots(ls, false);
>       WriteStream wi(ots, false, true, WriteStream::wsPreview, encoding);
>       inset.write(wi);
>       return ls.str();
> @@ -2182,8 +2180,7 @@ bool InsetMathHull::searchForward(BufferView * bv, 
> string const & str,
> void InsetMathHull::write(ostream & os) const
> {
>       odocstringstream oss;
> -     TexRow texrow(false);
> -     otexrowstream ots(oss,texrow);
> +     otexrowstream ots(oss, false);
>       WriteStream wi(ots, false, false, WriteStream::wsDefault);
>       oss << "Formula ";
>       write(wi);
> @@ -2226,8 +2223,7 @@ int InsetMathHull::plaintext(odocstringstream & os,
>       }
> 
>       odocstringstream oss;
> -     TexRow texrow(false);
> -     otexrowstream ots(oss,texrow);
> +     otexrowstream ots(oss, false);
>       Encoding const * const enc = encodings.fromLyXName("utf8");
>       WriteStream wi(ots, false, true, WriteStream::wsDefault, enc);
> 
> @@ -2269,8 +2265,7 @@ int InsetMathHull::docbook(odocstream & os, 
> OutputParams const & runparams) cons
>       ++ms.tab(); ms.cr(); ms.os() << '<' << bname << '>';
> 
>       odocstringstream ls;
> -     TexRow texrow;
> -     otexstream ols(ls, texrow);
> +     otexstream ols(ls);
>       if (runparams.flavor == OutputParams::XML) {
>               ms << MTag("alt role='tex' ");
>               // Workaround for db2latex: db2latex always includes equations 
> with
> @@ -2288,7 +2283,7 @@ int InsetMathHull::docbook(odocstream & os, 
> OutputParams const & runparams) cons
>       } else {
>               ms << MTag("alt role='tex'");
>               latex(ols, runparams);
> -             res = texrow.rows();
> +             res = ols.texrow().rows();
>               ms << from_utf8(subst(subst(to_utf8(ls.str()), "&", "&amp;"), 
> "<", "&lt;"));
>               ms << ETag("alt");
>       }
> @@ -2537,8 +2532,7 @@ docstring InsetMathHull::xhtml(XHTMLStream & xs, 
> OutputParams const & op) const
>               // Unfortunately, we cannot use latexString() because we do not 
> want
>               // $...$ or whatever.
>               odocstringstream ls;
> -             TexRow texrow(false);
> -             otexrowstream ots(ls,texrow);
> +             otexrowstream ots(ls, false);
>               WriteStream wi(ots, false, true, WriteStream::wsPreview);
>               ModeSpecifier specifier(wi, MATH_MODE);
>               mathAsLatex(wi);
> diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp
> index 87b7f42..223e31a 100644
> --- a/src/mathed/InsetMathNest.cpp
> +++ b/src/mathed/InsetMathNest.cpp
> @@ -52,6 +52,7 @@
> #include "LyXRC.h"
> #include "MetricsInfo.h"
> #include "OutputParams.h"
> +#include "TexRow.h"
> #include "Text.h"
> 
> #include "frontends/Application.h"
> @@ -251,8 +252,7 @@ bool InsetMathNest::idxLast(Cursor & cur) const
> void InsetMathNest::dump() const
> {
>       odocstringstream oss;
> -     TexRow texrow(false);
> -     otexrowstream ots(oss,texrow);
> +     otexrowstream ots(oss, false);
>       WriteStream os(ots);
>       os << "---------------------------------------------\n";
>       write(os);
> @@ -407,8 +407,8 @@ void InsetMathNest::latex(otexstream & os, OutputParams 
> const & runparams) const
>                       runparams.dryrun ? WriteStream::wsDryrun : 
> WriteStream::wsDefault,
>                       runparams.encoding);
>       wi.canBreakLine(os.canBreakLine());
> -     Changer dummy = 
> wi.changeRowEntry(os.texrow().textEntry(runparams.lastid,
> -                                                             
> runparams.lastpos));
> +     Changer dummy = wi.changeRowEntry(TexRow::textEntry(runparams.lastid,
> +                                                         runparams.lastpos));
>       write(wi);
>       // Reset parbreak status after a math inset.
>       os.lastChar(0);
> diff --git a/src/mathed/MacroTable.cpp b/src/mathed/MacroTable.cpp
> index 9ff4bfe..5f43fa7 100644
> --- a/src/mathed/MacroTable.cpp
> +++ b/src/mathed/MacroTable.cpp
> @@ -200,8 +200,7 @@ int MacroData::write(odocstream & os, bool 
> overwriteRedefinition) const
>       // output template
>       MathMacroTemplate const & tmpl =
>               static_cast<MathMacroTemplate const &>(*inset);
> -     TexRow texrow(false);
> -     otexrowstream ots(os,texrow);
> +     otexrowstream ots(os, false);
>       WriteStream wi(ots, false, true, WriteStream::wsDefault);
>       return tmpl.write(wi, overwriteRedefinition);
> }
> diff --git a/src/mathed/MathFactory.cpp b/src/mathed/MathFactory.cpp
> index 82f885b..f7c21e8 100644
> --- a/src/mathed/MathFactory.cpp
> +++ b/src/mathed/MathFactory.cpp
> @@ -73,6 +73,7 @@
> #include "LyX.h" // use_gui
> #include "OutputParams.h"
> 
> +
> using namespace std;
> using namespace lyx::support;
> 
> @@ -669,9 +670,8 @@ bool createInsetMath_fromDialogStr(docstring const & str, 
> MathData & ar)
>               InsetSpaceParams isp(true);
>               InsetSpace::string2params(to_utf8(str), isp);
>               InsetSpace is(isp);
> -             TexRow texrow;
>               odocstringstream ods;
> -             otexstream os(ods, texrow);
> +             otexstream os(ods, false);
>               Encoding const * const ascii = encodings.fromLyXName("ascii");
>               OutputParams op(ascii);
>               is.latex(os, op);
> diff --git a/src/mathed/MathMacroTemplate.cpp 
> b/src/mathed/MathMacroTemplate.cpp
> index 5c7ae70..31250e2 100644
> --- a/src/mathed/MathMacroTemplate.cpp
> +++ b/src/mathed/MathMacroTemplate.cpp
> @@ -1172,8 +1172,7 @@ void MathMacroTemplate::read(Lexer & lex)
> void MathMacroTemplate::write(ostream & os) const
> {
>       odocstringstream oss;
> -     TexRow texrow(false);
> -     otexrowstream ots(oss,texrow);
> +     otexrowstream ots(oss, false);
>       WriteStream wi(ots, false, false, WriteStream::wsDefault);
>       oss << "FormulaMacro\n";
>       write(wi);
> diff --git a/src/mathed/MathStream.cpp b/src/mathed/MathStream.cpp
> index c1c0830..eb567ff 100644
> --- a/src/mathed/MathStream.cpp
> +++ b/src/mathed/MathStream.cpp
> @@ -16,6 +16,8 @@
> #include "MathData.h"
> #include "MathExtern.h"
> 
> +#include "TexRow.h"
> +
> #include "support/docstring.h"
> #include "support/RefChanger.h"
> #include "support/textutils.h"
> @@ -128,7 +130,8 @@ WriteStream::WriteStream(otexrowstream & os, bool 
> fragile, bool latex,
>       : os_(os), fragile_(fragile), firstitem_(false), latex_(latex),
>         output_(output), pendingspace_(false), pendingbrace_(false),
>         textmode_(false), locked_(0), ascii_(0), canbreakline_(true),
> -       line_(0), encoding_(encoding), row_entry_(TexRow::row_none)
> +       line_(0), encoding_(encoding),
> +       row_entry_(make_unique<RowEntry>(TexRow::row_none))
> {}
> 
> 
> @@ -177,17 +180,17 @@ void WriteStream::asciiOnly(bool ascii)
> }
> 
> 
> -Changer WriteStream::changeRowEntry(TexRow::RowEntry entry)
> +Changer WriteStream::changeRowEntry(RowEntry entry)
> {
> -     return make_change(row_entry_, entry);
> +     return make_change(*row_entry_, entry);
> }
> 
> 
> bool WriteStream::startOuterRow()
> {
> -     if (TexRow::isNone(row_entry_))
> +     if (TexRow::isNone(*row_entry_))
>               return false;
> -     return texrow().start(row_entry_);
> +     return texrow().start(*row_entry_);
> }
> 
> 
> diff --git a/src/mathed/MathStream.h b/src/mathed/MathStream.h
> index a9465cc..d1cfb94 100644
> --- a/src/mathed/MathStream.h
> +++ b/src/mathed/MathStream.h
> @@ -17,6 +17,7 @@
> 
> #include "support/Changer.h"
> #include "support/strfwd.h"
> +#include "support/unique_ptr.h"
> 
> 
> namespace lyx {
> @@ -25,6 +26,7 @@ class Encoding;
> class InsetMath;
> class MathAtom;
> class MathData;
> +class RowEntry;
> 
> //
> // LaTeX/LyX
> @@ -88,7 +90,7 @@ public:
>       Encoding const * encoding() const { return encoding_; }
> 
>       /// Temporarily change the TexRow information about the outer row entry.
> -     Changer changeRowEntry(TexRow::RowEntry entry);
> +     Changer changeRowEntry(RowEntry entry);
>       /// TexRow::starts the innermost outer math inset
>       /// returns true if the outer row entry will appear at this line
>       bool startOuterRow();
> @@ -120,7 +122,8 @@ private:
>       ///
>       Encoding const * encoding_;
>       /// Row entry we are in
> -     TexRow::RowEntry row_entry_;
> +     /// (it is a pointer to allow forward-declaration)
> +     unique_ptr<RowEntry> row_entry_;
> };
> 
> ///
> diff --git a/src/mathed/MathSupport.cpp b/src/mathed/MathSupport.cpp
> index e18a351..42f7376 100644
> --- a/src/mathed/MathSupport.cpp
> +++ b/src/mathed/MathSupport.cpp
> @@ -919,8 +919,7 @@ bool isAlphaSymbol(MathAtom const & at)
> docstring asString(MathData const & ar)
> {
>       odocstringstream os;
> -     TexRow texrow(false);
> -     otexrowstream ots(os,texrow);
> +     otexrowstream ots(os, false);
>       WriteStream ws(ots);
>       ws << ar;
>       return os.str();
> @@ -938,8 +937,7 @@ void asArray(docstring const & str, MathData & ar, 
> Parse::flags pf)
> docstring asString(InsetMath const & inset)
> {
>       odocstringstream os;
> -     TexRow texrow(false);
> -     otexrowstream ots(os,texrow);
> +     otexrowstream ots(os, false);
>       WriteStream ws(ots);
>       inset.write(ws);
>       return os.str();
> @@ -949,8 +947,7 @@ docstring asString(InsetMath const & inset)
> docstring asString(MathAtom const & at)
> {
>       odocstringstream os;
> -     TexRow texrow(false);
> -     otexrowstream ots(os,texrow);
> +     otexrowstream ots(os, false);
>       WriteStream ws(ots);
>       at->write(ws);
>       return os.str();
> diff --git a/src/output_latex.cpp b/src/output_latex.cpp
> index 5d385e5..370b7a0 100644
> --- a/src/output_latex.cpp
> +++ b/src/output_latex.cpp
> @@ -23,6 +23,7 @@
> #include "OutputParams.h"
> #include "Paragraph.h"
> #include "ParagraphParameters.h"
> +#include "texstream.h"
> #include "TextClass.h"
> 
> #include "insets/InsetBibitem.h"
> diff --git a/src/tex2lyx/dummy_impl.cpp b/src/tex2lyx/dummy_impl.cpp
> index 7807a7d..7709663 100644
> --- a/src/tex2lyx/dummy_impl.cpp
> +++ b/src/tex2lyx/dummy_impl.cpp
> @@ -48,19 +48,6 @@ namespace Alert {
> 
> 
> //
> -// Dummy TexRow support (needed by docstream)
> -//
> -
> -
> -void TexRow::newline()
> -{}
> -
> -
> -void TexRow::newlines(int)
> -{}
> -
> -
> -//
> // Dummy LyXRC support
> //
> 
> diff --git a/src/texstream.cpp b/src/texstream.cpp
> index 16f8dfb..f748f8a 100644
> --- a/src/texstream.cpp
> +++ b/src/texstream.cpp
> @@ -11,6 +11,9 @@
> #include <config.h>
> 
> #include "texstream.h"
> +
> +#include "TexRow.h"
> +
> #include "support/lstrings.h"
> #include "support/unicode.h"
> 
> @@ -30,10 +33,26 @@ using lyx::support::split;
> namespace lyx {
> 
> 
> -void otexrowstream::append(docstring const & str, TexRow const & texrow)
> +otexrowstream::otexrowstream(odocstream & os, bool enable)
> +     : os_(os), texrow_(make_unique<TexRow>(enable))
> +{}
> +
> +
> +otexrowstream::~otexrowstream() = default;
> +
> +
> +unique_ptr<TexRow> && otexrowstream::releaseTexRow()
> +{
> +     auto p = make_unique<TexRow>();
> +     swap(texrow_, p);
> +     return move(p);
> +}
> +
> +
> +void otexrowstream::append(docstring const & str, TexRow texrow)
> {
>       os_ << str;
> -     texrow_.append(texrow);
> +     texrow_->append(move(texrow));
> }
> 
> 
> @@ -41,7 +60,7 @@ void otexrowstream::put(char_type const & c)
> {
>       os_.put(c);
>       if (c == '\n')
> -             texrow_.newline();
> +             texrow_->newline();
> }
> 
> 
> diff --git a/src/texstream.h b/src/texstream.h
> index c81bbf9..f6f4211 100644
> --- a/src/texstream.h
> +++ b/src/texstream.h
> @@ -12,11 +12,17 @@
> #ifndef LYX_TEXSTREAM_H
> #define LYX_TEXSTREAM_H
> 
> -#include "TexRow.h"
> #include "support/docstream.h"
> +#include "support/unique_ptr.h"
> 
> namespace lyx {
> 
> +class TexRow;
> +
> +
> +// declared below
> +class otexstringstream;
> +
> /** Wrapper class for odocstream.
>     This class is used to automatically count the lines of the exported latex
>     code.
> @@ -25,21 +31,24 @@ namespace lyx {
> class otexrowstream {
> public:
>       ///
> -     otexrowstream(odocstream & os, TexRow & texrow)
> -             : os_(os), texrow_(texrow) {}
> +     explicit otexrowstream(odocstream & os, bool enable = true);
> +     /// defaulted
> +     ~otexrowstream();
>       ///
>       odocstream & os() { return os_; }
>       ///
> -     TexRow & texrow() { return texrow_; }
> +     TexRow & texrow() { return *texrow_; }
> +     ///
> +     unique_ptr<TexRow> && releaseTexRow();
>       ///
>       void put(char_type const & c);
>       ///
> -     void append(docstring const &, TexRow const &);
> +     void append(docstring const & str, TexRow texrow);
> private:
>       ///
>       odocstream & os_;
>       ///
> -     TexRow & texrow_;
> +     unique_ptr<TexRow> texrow_;
> };
> 
> ///
> @@ -70,8 +79,8 @@ otexrowstream & operator<<(otexrowstream & ots, Type value);
> class otexstream : public otexrowstream {
> public:
>       ///
> -     otexstream(odocstream & os, TexRow & texrow)
> -             : otexrowstream(os, texrow), canbreakline_(false),
> +     explicit otexstream(odocstream & os, bool enable = true)
> +             : otexrowstream(os, enable), canbreakline_(false),
>                 protectspace_(false), parbreak_(true), lastchar_(0) {}
>       ///
>       void put(char_type const & c);
> @@ -135,6 +144,7 @@ otexstream & operator<<(otexstream &, char);
> template <typename Type>
> otexstream & operator<<(otexstream & ots, Type value);
> 
> +
> }
> 
> #endif

Reply via email to