title should read I am a half-hero now :) What is missing is:
linebreak code is working but there is no ui entry. therefore I skip some parts of the code: - there is no separate draw() function for linebreak, but it uses the code from the newline. if you have any idea how to implement it, please go ahead. - no documentation for linebreak. Attached is the patch and the documentation for the UsersGuide.lyx. Since the diff file is too big (I don't know why..) I have attached the doc as a separate file. Please smb put it at the end of section 6.6.4. Forcing Page Breaks. regards, Ugras
Index: src/insets/insetpagebreak.h
===================================================================
--- src/insets/insetpagebreak.h (revision 16009)
+++ src/insets/insetpagebreak.h (working copy)
@@ -21,16 +21,18 @@
class InsetPagebreak : public InsetOld {
public:
- InsetPagebreak() {}
+ InsetPagebreak();
+ InsetPagebreak(lyx::docstring const & label_);
+
InsetBase::Code lyxCode() const { return InsetBase::LINE_CODE; }
void metrics(MetricsInfo &, Dimension &) const;
void draw(PainterInfo & pi, int x, int y) const;
- int latex(Buffer const &, odocstream &,
- OutputParams const &) const;
+ virtual int latex(Buffer const &, odocstream &,
+ OutputParams const &) const;
int plaintext(Buffer const &, odocstream &,
OutputParams const &) const;
@@ -40,7 +42,7 @@
void read(Buffer const &, LyXLex & lex);
- void write(Buffer const & buf, std::ostream & os) const;
+ virtual void write(Buffer const & buf, std::ostream & os) const;
/// We don't need \begin_inset and \end_inset
bool directWrite() const { return true; }
@@ -50,9 +52,42 @@
{
return std::auto_ptr<InsetBase>(new InsetPagebreak);
}
+
+ lyx::docstring const label_;
};
+
+class InsetClearPage : public InsetPagebreak {
+public:
+
+ InsetClearPage();
+ int latex(Buffer const &, odocstream &,
+ OutputParams const &) const;
+ void write(Buffer const & buf, std::ostream & os) const;
+private:
+ virtual std::auto_ptr<InsetBase> doClone() const
+ {
+ return std::auto_ptr<InsetBase>(new InsetClearPage);
+ }
+};
+
+
+
+class InsetClearDoublePage : public InsetPagebreak {
+public:
+
+ InsetClearDoublePage();
+ int latex(Buffer const &, odocstream &,
+ OutputParams const &) const;
+ void write(Buffer const & buf, std::ostream & os) const;
+private:
+ virtual std::auto_ptr<InsetBase> doClone() const
+ {
+ return std::auto_ptr<InsetBase>(new InsetClearDoublePage);
+ }
+};
+
} // namespace lyx
#endif // INSET_NEWLINE_H
Index: src/insets/insetpagebreak.C
===================================================================
--- src/insets/insetpagebreak.C (revision 16009)
+++ src/insets/insetpagebreak.C (working copy)
@@ -29,7 +29,16 @@
using std::endl;
using std::ostream;
+InsetPagebreak::InsetPagebreak()
+ :label_(_("Page Break"))
+{
+}
+InsetPagebreak::InsetPagebreak(lyx::docstring const & label)
+ :label_(label)
+{
+}
+
void InsetPagebreak::read(Buffer const &, LyXLex &)
{
/* Nothing to read */
@@ -53,7 +62,6 @@
void InsetPagebreak::draw(PainterInfo & pi, int x, int y) const
{
- static docstring const label = _("Page Break");
LyXFont font;
font.setColor(LColor::pagebreak);
@@ -62,12 +70,12 @@
int w = 0;
int a = 0;
int d = 0;
- theFontMetrics(font).rectText(label, w, a, d);
+ theFontMetrics(font).rectText(label_, w, a, d);
int const text_start = int(x + (dim_.wid - w) / 2);
int const text_end = text_start + w;
- pi.pain.rectText(text_start, y + d, label, font,
+ pi.pain.rectText(text_start, y + d, label_, font,
LColor::none, LColor::none);
pi.pain.line(x, y, text_start, y,
@@ -101,4 +109,43 @@
}
+///////////////////////////////////////////////////////////////
+
+InsetClearPage::InsetClearPage()
+ :InsetPagebreak(_("Clear Page"))
+{
+}
+
+void InsetClearPage::write(Buffer const &, ostream & os) const
+{
+ os << "\n\\clearpage\n";
+}
+
+int InsetClearPage::latex(Buffer const &, odocstream & os,
+ OutputParams const &) const
+{
+ os << "\\clearpage{}";
+ return 0;
+}
+
+
+///////////////////////////////////////////////////////////////
+
+InsetClearDoublePage::InsetClearDoublePage()
+ :InsetPagebreak(_("Clear Double Page"))
+{
+}
+
+void InsetClearDoublePage::write(Buffer const &, ostream & os) const
+{
+ os << "\n\\cleardoublepage\n";
+}
+
+int InsetClearDoublePage::latex(Buffer const &, odocstream & os,
+ OutputParams const &) const
+{
+ os << "\\cleardoublepage{}";
+ return 0;
+}
+
} // namespace lyx
Index: src/insets/insetbase.C
===================================================================
--- src/insets/insetbase.C (revision 16009)
+++ src/insets/insetbase.C (working copy)
@@ -87,6 +87,7 @@
InsetName("environment", InsetBase::ENVIRONMENT_CODE),
InsetName("hfill", InsetBase::HFILL_CODE),
InsetName("newline", InsetBase::NEWLINE_CODE),
+ InsetName("linebreak", InsetBase::LINEBREAK_CODE),
InsetName("line", InsetBase::LINE_CODE),
InsetName("branch", InsetBase::BRANCH_CODE),
InsetName("box", InsetBase::BOX_CODE),
Index: src/insets/insetbase.h
===================================================================
--- src/insets/insetbase.h (revision 16009)
+++ src/insets/insetbase.h (working copy)
@@ -327,7 +327,9 @@
///
NOMENCL_CODE, // 45
///
- NOMENCL_PRINT_CODE
+ NOMENCL_PRINT_CODE,
+ ///
+ LINEBREAK_CODE
};
/** returns the Code corresponding to the \c name.
Index: src/insets/insetnewline.C
===================================================================
--- src/insets/insetnewline.C (revision 16009)
+++ src/insets/insetnewline.C (working copy)
@@ -122,6 +122,17 @@
{
return true;
}
+void InsetLineBreak::write(Buffer const &, ostream & os) const
+{
+ os << "\n\\linebreak\n";
+}
+int InsetLineBreak::latex(Buffer const &, odocstream & os,
+ OutputParams const &) const
+{
+ os << "\\linebreak{}";
+ return 0;
+}
+
} // namespace lyx
Index: src/insets/insetnewline.h
===================================================================
--- src/insets/insetnewline.h (revision 16009)
+++ src/insets/insetnewline.h (working copy)
@@ -54,6 +54,23 @@
};
+class InsetLineBreak : public InsetNewline {
+public:
+ InsetLineBreak() {}
+
+ InsetBase::Code lyxCode() const { return InsetBase::LINEBREAK_CODE; }
+
+ int latex(Buffer const &, odocstream &,
+ OutputParams const &) const;
+
+ void write(Buffer const & buf, std::ostream & os) const;
+private:
+ virtual std::auto_ptr<InsetBase> doClone() const
+ {
+ return std::auto_ptr<InsetBase>(new InsetLineBreak);
+ }
+};
+
} // namespace lyx
#endif // INSET_NEWLINE_H
Index: src/insets/insetert.C
===================================================================
--- src/insets/insetert.C (revision 16009)
+++ src/insets/insetert.C (working copy)
@@ -285,6 +285,7 @@
case LFUN_ACCENT_UNDERDOT:
case LFUN_APPENDIX:
case LFUN_BREAK_LINE:
+ case LFUN_BREAK_LINEBREAK:
case LFUN_CAPTION_INSERT:
case LFUN_DEPTH_DECREMENT:
case LFUN_DEPTH_INCREMENT:
@@ -322,6 +323,8 @@
case LFUN_BIBITEM_INSERT:
case LFUN_LINE_INSERT:
case LFUN_PAGEBREAK_INSERT:
+ case LFUN_CLEARPAGE_INSERT:
+ case LFUN_CLEARDOUBLEPAGE_INSERT:
case LFUN_LANGUAGE:
case LFUN_LAYOUT:
case LFUN_LAYOUT_PARAGRAPH:
Index: src/lfuns.h
===================================================================
--- src/lfuns.h (revision 16009)
+++ src/lfuns.h (working copy)
@@ -377,6 +377,10 @@
LFUN_TOOLBAR_TOGGLE_STATE, // bpeng 20061101
LFUN_NOMENCL_INSERT, // Ugras
LFUN_NOMENCL_PRINT, // Ugras
+ LFUN_CLEARPAGE_INSERT,
+ //290
+ LFUN_CLEARDOUBLEPAGE_INSERT,
+ LFUN_BREAK_LINEBREAK,
LFUN_LASTACTION // end of the table
};
Index: src/LyXAction.C
===================================================================
--- src/LyXAction.C (revision 16009)
+++ src/LyXAction.C (working copy)
@@ -369,6 +369,9 @@
{ LFUN_TOOLBAR_TOGGLE_STATE, "", NoBuffer },
{ LFUN_NOMENCL_INSERT, "nomencl-insert", Noop },
{ LFUN_NOMENCL_PRINT, "nomencl-print", Noop },
+ { LFUN_CLEARPAGE_INSERT, "clearpage-insert", Noop },
+ { LFUN_CLEARDOUBLEPAGE_INSERT, "cleardoublepage-insert", Noop },
+ { LFUN_BREAK_LINEBREAK, "linebreak-insert", Noop },
{ LFUN_NOACTION, "", Noop }
};
Index: src/text3.C
===================================================================
--- src/text3.C (revision 16009)
+++ src/text3.C (working copy)
@@ -561,6 +561,17 @@
break;
}
+ case LFUN_BREAK_LINEBREAK: {
+ // Not allowed by LaTeX (labels or empty par)
+ if (cur.pos() > cur.paragraph().beginOfBody()) {
+ cap::replaceSelection(cur);
+ cur.insert(new InsetLineBreak);
+ cur.posRight();
+ moveCursor(cur, false);
+ }
+ break;
+ }
+
case LFUN_CHAR_DELETE_FORWARD:
if (!cur.selection()) {
if (cur.pos() == cur.paragraph().size())
@@ -1187,6 +1198,8 @@
case LFUN_HFILL_INSERT:
case LFUN_LINE_INSERT:
case LFUN_PAGEBREAK_INSERT:
+ case LFUN_CLEARPAGE_INSERT:
+ case LFUN_CLEARDOUBLEPAGE_INSERT:
// do nothing fancy
doInsertInset(cur, this, cmd, false, false);
cur.posRight();
@@ -1798,6 +1811,8 @@
case LFUN_SELF_INSERT:
case LFUN_LINE_INSERT:
case LFUN_PAGEBREAK_INSERT:
+ case LFUN_CLEARPAGE_INSERT:
+ case LFUN_CLEARDOUBLEPAGE_INSERT:
case LFUN_MATH_DISPLAY:
case LFUN_MATH_IMPORT_SELECTION:
case LFUN_MATH_MODE:
@@ -1840,6 +1855,7 @@
case LFUN_BUFFER_BEGIN_SELECT:
case LFUN_BUFFER_END_SELECT:
case LFUN_UNICODE_INSERT:
+ case LFUN_BREAK_LINEBREAK:
// these are handled in our dispatch()
enable = true;
break;
Index: src/text.C
===================================================================
--- src/text.C (revision 16009)
+++ src/text.C (working copy)
@@ -306,6 +306,10 @@
auto_ptr<InsetBase> inset(new InsetNewline);
inset->read(buf, lex);
par.insertInset(par.size(), inset.release(), font, change);
+ } else if (token == "\\linebreak") {
+ auto_ptr<InsetBase> inset(new InsetLineBreak);
+ inset->read(buf, lex);
+ par.insertInset(par.size(), inset.release(), font, change);
} else if (token == "\\LyXTable") {
auto_ptr<InsetBase> inset(new InsetTabular(buf));
inset->read(buf, lex);
@@ -316,6 +320,10 @@
par.insertInset(par.size(), new InsetLine, font, change);
} else if (token == "\\newpage") {
par.insertInset(par.size(), new InsetPagebreak, font, change);
+ } else if (token == "\\clearpage") {
+ par.insertInset(par.size(), new InsetClearPage, font, change);
+ } else if (token == "\\cleardoublepage") {
+ par.insertInset(par.size(), new InsetClearDoublePage, font, change);
} else if (token == "\\change_unchanged") {
change = Change(Change::UNCHANGED);
} else if (token == "\\change_inserted") {
Index: src/paragraph.C
===================================================================
--- src/paragraph.C (revision 16009)
+++ src/paragraph.C (working copy)
@@ -1259,7 +1259,8 @@
bool Paragraph::isNewline(pos_type pos) const
{
return isInset(pos)
- && getInset(pos)->lyxCode() == InsetBase::NEWLINE_CODE;
+ && (getInset(pos)->lyxCode() == InsetBase::NEWLINE_CODE ||
+ getInset(pos)->lyxCode() == InsetBase::LINEBREAK_CODE);
}
Index: src/tex2lyx/text.C
===================================================================
--- src/tex2lyx/text.C (revision 16009)
+++ src/tex2lyx/text.C (working copy)
@@ -2216,10 +2216,12 @@
skip_braces(p);
}
- else if (t.cs() == "newpage") {
+ else if (t.cs() == "newpage" ||
+ t.cs() == "clearpage" ||
+ t.cs() == "cleardoublepage" ) {
context.check_layout(os);
// FIXME: what about \\clearpage and \\pagebreak?
- os << "\n\\newpage\n";
+ os << "\n\\" << t.cs() << "\n";
skip_braces(p); // eat {}
}
Index: src/factory.C
===================================================================
--- src/factory.C (revision 16009)
+++ src/factory.C (working copy)
@@ -88,6 +88,12 @@
case LFUN_PAGEBREAK_INSERT:
return new InsetPagebreak;
+ case LFUN_CLEARPAGE_INSERT:
+ return new InsetClearPage;
+
+ case LFUN_CLEARDOUBLEPAGE_INSERT:
+ return new InsetClearDoublePage;
+
case LFUN_CHARSTYLE_INSERT: {
string s = cmd.getArg(0);
LyXTextClass tclass = params.getLyXTextClass();
Index: lib/lyx2lyx/lyx_1_5.py
===================================================================
--- lib/lyx2lyx/lyx_1_5.py (revision 16009)
+++ lib/lyx2lyx/lyx_1_5.py (working copy)
@@ -603,7 +603,66 @@
if (use_esint == 2):
document.preamble.append('\\usepackage{esint}')
+def revert_clearpage(document):
+ " clearpage -> ERT"
+ i = 0
+ while 1:
+ i = find_token(document.body, "\\clearpage", i)
+ if i == -1:
+ break
+ document.body[i:i+1] = ['\\begin_inset ERT',
+ 'status collapsed',
+ '',
+ '\\begin_layout %s' % document.default_layout,
+ '',
+ '',
+ '\\backslash',
+ 'clearpage',
+ '\\end_layout',
+ '',
+ '\\end_inset']
+ i = i + 1
+
+def revert_cleardoublepage(document):
+ " cleardoublepage -> ERT"
+ i = 0
+ while 1:
+ i = find_token(document.body, "\\cleardoublepage", i)
+ if i == -1:
+ break
+ document.body[i:i+1] = ['\\begin_inset ERT',
+ 'status collapsed',
+ '',
+ '\\begin_layout %s' % document.default_layout,
+ '',
+ '',
+ '\\backslash',
+ 'cleardoublepage',
+ '\\end_layout',
+ '',
+ '\\end_inset']
+ i = i + 1
+def revert_linebreak(document):
+ " linebreak -> ERT"
+ i = 0
+ while 1:
+ i = find_token(document.body, "\\linebreak", i)
+ if i == -1:
+ break
+ document.body[i:i+1] = ['\\begin_inset ERT',
+ 'status collapsed',
+ '',
+ '\\begin_layout %s' % document.default_layout,
+ '',
+ '',
+ '\\backslash',
+ 'linebreak',
+ '\\end_layout',
+ '',
+ '\\end_inset']
+ i = i + 1
+
##
# Conversion hub
#
@@ -619,7 +678,8 @@
[253, []],
[254, [convert_esint]]]
-revert = [[253, [revert_esint]],
+revert = [[254, [revert_clearpage, revert_cleardoublepage, revert_linebreak]],
+ [253, [revert_esint]],
[252, [revert_nomenclature, revert_printnomenclature]],
[251, [revert_commandparams]],
[250, [revert_cs_label]],
Index: lib/ui/stdmenus.ui
===================================================================
--- lib/ui/stdmenus.ui (revision 16009)
+++ lib/ui/stdmenus.ui (working copy)
@@ -334,6 +334,8 @@
Item "Ligature Break|k" "ligature-break-insert"
Item "Line Break|B" "break-line"
Item "Page Break|a" "pagebreak-insert"
+ Item "Clear Page" "clearpage-insert"
+ Item "Clear Double Page" "cleardoublepage-insert"
End
Menu "insert_math"
clearpage.lyx
Description: application/lyx
