Introduce a wrapper class for odocstream to help ensuring that no

blank lines may be inadvertently output. This is achieved by using two
special iomanip-like variables (breakln and safebreakln) in the lyx::
namespace. When they are inserted in the stream, a newline is output
only if not already at the beginning of a line. The difference between
breakln and safebreakln is that, if needed, the former outputs '\n'
and the latter "%\n".
In future, the new class will also be used for counting the number of
newlines issued. Even if the infractrure for doing that is already in
place, the counting is essentially still done the old way.
There are still places in the code where the functionality of the
class could be used, most probably. ATM, it is used for InsetTabular,
InsetListings, InsetFloat, and InsetText.
The Comment and GreyedOut insets required a special treatment and a
new InsetLayout parameter (Display) has been introduced. The default
for Display is "true", meaning that the corresponding latex
environment is of "display" type, i.e., it stands on its own, whereas
"false" means that the contents appear inline with the text. The
latter is the case for both Comment and GreyedOut insets.
Mostly, the only visible effects on latex exports should be the
disappearing of some redundant % chars and the appearing/disappearing
of null {} latex groups after a comment or lyxgreyedout environments
(they are related to the presence or absence of a space immediately
after those environments), as well as the fact that math environments
are now started on their own lines.
As a last thing, only the latex code between \begin{document} and
\end{document} goes through the new class, the preamble being directly
output through odocstream, as usual.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37360 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Enrico Forestieri 2011-01-29 02:41:13 +00:00
parent 021618142f
commit 1ef605f625
89 changed files with 491 additions and 224 deletions

View File

@ -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;

View File

@ -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);
}
}
}

View File

@ -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)
{

View File

@ -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);

View File

@ -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<bool, int> const c = switchEncoding(os, bparams,
pair<bool, int> const c = switchEncoding(os.os(), bparams,
runparams, *ascii);
LASSERT(c.first, /**/);
count += c.second;

View File

@ -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,

View File

@ -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.

View File

@ -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<bool, int> const enc_switch = switchEncoding(os, bparams,
runparams, *(font.language()->encoding()));
pair<bool, int> const enc_switch =
switchEncoding(os.os(), bparams, runparams,
*(font.language()->encoding()));
if (enc_switch.first) {
column += enc_switch.second;
runparams.encoding = font.language()->encoding();

View File

@ -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;

View File

@ -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();
}

View File

@ -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;
///

View File

@ -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 + '}';

View File

@ -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

View File

@ -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}

View File

@ -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;
///

View File

@ -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);

View File

@ -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;
///

View File

@ -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;
}

View File

@ -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;
///

View File

@ -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);

View File

@ -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;
///

View File

@ -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();

View File

@ -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;
///

View File

@ -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);

View File

@ -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;
///

View File

@ -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);

View File

@ -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;
///

View File

@ -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{<floatname>} 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{<floatname>} 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{<floatname>} 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{<floatname>} 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();
}

View File

@ -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;
///

View File

@ -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"))];

View File

@ -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; }
///

View File

@ -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

View File

@ -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;
///

View File

@ -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,

View File

@ -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;
///

View File

@ -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");

View File

@ -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;
///

View File

@ -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();
}

View File

@ -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;
///

View File

@ -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"))

View File

@ -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);

View File

@ -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;

View File

@ -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_;
};
///

View File

@ -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")));

View File

@ -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;

View File

@ -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<bool, int> const c = switchEncoding(os, buffer().params(),
runparams, *lstenc, true);
pair<bool, int> 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<bool, int> const c = switchEncoding(os, buffer().params(),
runparams, *save_enc, true);
pair<bool, int> 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();

View File

@ -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;
///

View File

@ -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:

View File

@ -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;
///

View File

@ -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:

View File

@ -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;
///

View File

@ -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;

View File

@ -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;
//@}

View File

@ -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'));

View File

@ -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;
///

View File

@ -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{";

View File

@ -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;
///

View File

@ -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());
}

View File

@ -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;

View File

@ -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;
///

View File

@ -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") {

View File

@ -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;
///

View File

@ -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:

View File

@ -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;
///

View File

@ -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:

View File

@ -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;
///

View File

@ -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_) {

View File

@ -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;
///

View File

@ -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);
}

View File

@ -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;
///

View File

@ -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;

View File

@ -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;
///

View File

@ -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;

View File

@ -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;
///

View File

@ -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;

View File

@ -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;
///

View File

@ -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 << "'");

View File

@ -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;
}

View File

@ -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;
///

View File

@ -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<unsigned int>((ncols() + 1)/2) << "}\n";
break;
case hullXXAlignAt:
os << "\\begin{" << hullName(type_) << '}'
os << "\n\\begin{" << hullName(type_) << '}'
<< '{' << static_cast<unsigned int>((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()), "&", "&amp;"), "<", "&lt;"));
ms << ETag("alt");
}

View File

@ -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;

View File

@ -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;
///

View File

@ -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();
}

View File

@ -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);
///

View File

@ -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())

View File

@ -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<bool, int> enc_switch = switchEncoding(os, bparams, runparams,
*encoding);
pair<bool, int> 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();
}

View File

@ -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<bool, int> 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);

View File

@ -13,6 +13,7 @@
#include "support/docstream.h"
#include "support/unicode.h"
#include <algorithm>
#include <cerrno>
#include <cstdio>
#include <cstring>
@ -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__)

View File

@ -82,6 +82,77 @@ typedef std::basic_istringstream<char_type> idocstringstream;
/// UCS4 output stringstream
typedef std::basic_ostringstream<char_type> 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);
}