From a70e21a34e36f9e4caeacaa065cfdfc02bff86c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Spitzm=C3=BCller?= Date: Mon, 8 Feb 2010 17:39:55 +0000 Subject: [PATCH] Patch by John McCabe-Dansted to fix bug #6502: Wrong line count with parent math macros: * TeXRow.{cpp,h}: - new helper function to insert multiple newline at once. * mathed/MacroTable.{cpp,h}: * mathed/MacroTemplate.{cpp,h}: - make write() an int, returning number of newlines * Buffer.cpp (writeLaTeXSource): - update texrow's newline on parent macro output. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33367 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Buffer.cpp | 7 +++++-- src/TexRow.cpp | 6 ++++++ src/TexRow.h | 3 +++ src/mathed/MacroTable.cpp | 6 +++--- src/mathed/MacroTable.h | 2 +- src/mathed/MathMacroTemplate.cpp | 11 +++++++++-- src/mathed/MathMacroTemplate.h | 2 +- 7 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index e4948df8b5..6ac6b72865 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -1341,8 +1341,11 @@ void Buffer::writeLaTeXSource(odocstream & os, // output the parent macros MacroSet::iterator it = parentMacros.begin(); MacroSet::iterator end = parentMacros.end(); - for (; it != end; ++it) - (*it)->write(os, true); + for (; it != end; ++it) { + int num_lines = (*it)->write(os, true); + d->texrow.newlines(num_lines); + } + } // output_preamble d->texrow.start(paragraphs().begin()->id(), 0); diff --git a/src/TexRow.cpp b/src/TexRow.cpp index f95602ec3a..f019c25ea3 100644 --- a/src/TexRow.cpp +++ b/src/TexRow.cpp @@ -44,6 +44,12 @@ void TexRow::newline() rowlist.push_back(tmp); } +void TexRow::newlines(int num_lines) +{ + for (int i = 0; i < num_lines; ++i) { + newline(); + } +} bool TexRow::getIdFromRow(int row, int & id, int & pos) const { diff --git a/src/TexRow.h b/src/TexRow.h index da406d08ad..55c9c25ff2 100644 --- a/src/TexRow.h +++ b/src/TexRow.h @@ -37,6 +37,9 @@ public: /// Insert node when line is completed void newline(); + /// Insert multiple nodes when zero or more lines are completed + void newlines(int num_lines); + /** * getIdFromRow - find pid and position for a given row * @param row row number to find diff --git a/src/mathed/MacroTable.cpp b/src/mathed/MacroTable.cpp index 5c0604017b..20a713a513 100644 --- a/src/mathed/MacroTable.cpp +++ b/src/mathed/MacroTable.cpp @@ -152,7 +152,7 @@ void MacroData::updateData() const } -void MacroData::write(odocstream & os, bool overwriteRedefinition) const +int MacroData::write(odocstream & os, bool overwriteRedefinition) const { updateData(); @@ -160,14 +160,14 @@ void MacroData::write(odocstream & os, bool overwriteRedefinition) const Inset * inset = pos_.nextInset(); if (inset == 0 || inset->lyxCode() != MATHMACRO_CODE) { lyxerr << "BUG: No macro template found by MacroData" << endl; - return; + return 0; } // output template MathMacroTemplate const & tmpl = static_cast(*inset); WriteStream wi(os, false, true, WriteStream::wsDefault); - tmpl.write(wi, overwriteRedefinition); + return tmpl.write(wi, overwriteRedefinition); } diff --git a/src/mathed/MacroTable.h b/src/mathed/MacroTable.h index 24e896c6b2..88427d68fd 100644 --- a/src/mathed/MacroTable.h +++ b/src/mathed/MacroTable.h @@ -81,7 +81,7 @@ public: MacroType & type() { return type_; } /// output as TeX macro, only works for lazy MacroData!!! - void write(odocstream & os, bool overwriteRedefinition) const; + int write(odocstream & os, bool overwriteRedefinition) const; /// bool operator==(MacroData const & x) const { diff --git a/src/mathed/MathMacroTemplate.cpp b/src/mathed/MathMacroTemplate.cpp index f7214cb5b3..5c1dd7bf37 100644 --- a/src/mathed/MathMacroTemplate.cpp +++ b/src/mathed/MathMacroTemplate.cpp @@ -1154,8 +1154,10 @@ void MathMacroTemplate::write(WriteStream & os) const } -void MathMacroTemplate::write(WriteStream & os, bool overwriteRedefinition) const +int MathMacroTemplate::write(WriteStream & os, bool overwriteRedefinition) const { + int num_lines = 0; + if (os.latex()) { if (optionals_ > 0) { // macros with optionals use the xargs package, e.g.: @@ -1218,11 +1220,16 @@ void MathMacroTemplate::write(WriteStream & os, bool overwriteRedefinition) cons if (os.latex()) { // writing .tex. done. os << "\n"; + ++num_lines; } else { // writing .lyx, write special .tex export only if necessary - if (!cell(displayIdx()).empty()) + if (!cell(displayIdx()).empty()) { os << "\n{" << cell(displayIdx()) << '}'; + ++num_lines; + } } + + return num_lines; } diff --git a/src/mathed/MathMacroTemplate.h b/src/mathed/MathMacroTemplate.h index 4a496e0857..f56ccb6207 100644 --- a/src/mathed/MathMacroTemplate.h +++ b/src/mathed/MathMacroTemplate.h @@ -49,7 +49,7 @@ public: void write(WriteStream & os) const; /// Output LaTeX code, but assume that the macro is not definied yet /// if overwriteRedefinition is true - void write(WriteStream & os, bool overwriteRedefinition) const; + int write(WriteStream & os, bool overwriteRedefinition) const; /// int plaintext(odocstream &, OutputParams const &) const; ///