John McCabe-Dansted
Mon, 08 Feb 2010 03:33:00 -0800
On Mon, Feb 8, 2010 at 4:30 PM, Jürgen Spitzmüller <sp...@lyx.org> wrote: > John McCabe-Dansted wrote: >> Do you mean something like the writeLaTeX function in BufferParams.cpp >> that has TexRow passed in, and itself calls "texrow.newline();"? > > I mean, make the write function an int and then call texrow.newline() > accordingly in the buffer function.
Something like the attached then? -- John C. McCabe-Dansted
Index: mathed/MacroTable.h
===================================================================
--- mathed/MacroTable.h (revision 33347)
+++ mathed/MacroTable.h (working copy)
@@ -81,7 +81,7 @@
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 {
Index: mathed/MathMacroTemplate.h
===================================================================
--- mathed/MathMacroTemplate.h (revision 33347)
+++ mathed/MathMacroTemplate.h (working copy)
@@ -49,7 +49,8 @@
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;
///
Index: mathed/MathMacroTemplate.cpp
===================================================================
--- mathed/MathMacroTemplate.cpp (revision 33347)
+++ mathed/MathMacroTemplate.cpp (working copy)
@@ -1154,7 +1154,7 @@
}
-void MathMacroTemplate::write(WriteStream & os, bool overwriteRedefinition) const
+int MathMacroTemplate::write(WriteStream & os, bool overwriteRedefinition) const
{
if (os.latex()) {
if (optionals_ > 0) {
@@ -1223,6 +1223,8 @@
if (!cell(displayIdx()).empty())
os << "\n{" << cell(displayIdx()) << '}';
}
+
+ return 1; //Remember to change if number of newlines changes
}
Index: mathed/MacroTable.cpp
===================================================================
--- mathed/MacroTable.cpp (revision 33347)
+++ mathed/MacroTable.cpp (working copy)
@@ -152,7 +152,7 @@
}
-void MacroData::write(odocstream & os, bool overwriteRedefinition) const
+int MacroData::write(odocstream & os, bool overwriteRedefinition) const
{
updateData();
@@ -160,14 +160,14 @@
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<MathMacroTemplate const &>(*inset);
WriteStream wi(os, false, true, WriteStream::wsDefault);
- tmpl.write(wi, overwriteRedefinition);
+ return tmpl.write(wi, overwriteRedefinition);
}
Index: TexRow.h
===================================================================
--- TexRow.h (revision 33347)
+++ TexRow.h (working copy)
@@ -37,6 +37,9 @@
/// 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
Index: TexRow.cpp
===================================================================
--- TexRow.cpp (revision 33347)
+++ TexRow.cpp (working copy)
@@ -44,7 +44,15 @@
rowlist.push_back(tmp);
}
+void TexRow::newlines(int num_lines)
+{
+ int i;
+ for (i=0;i<num_lines;i++) {
+ newline();
+ }
+}
bool TexRow::getIdFromRow(int row, int & id, int & pos) const
{
if (row <= 0 || row > int(rowlist.size())) {
Index: Buffer.cpp
===================================================================
--- Buffer.cpp (revision 33347)
+++ Buffer.cpp (working copy)
@@ -1341,8 +1341,11 @@
// 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_new_lines=(*it)->write(os, true);
+ d->texrow.newlines(num_new_lines);
+ }
+
} // output_preamble
d->texrow.start(paragraphs().begin()->id(), 0);