Attached is what I believe a cleaner implementation of
clearpage/cleardoublepage. Please, tex2lyx and lyx2lyx experts, fix
tex2lyx and lyx2lyx so that I can apply it.

Thanks.
Bo
Index: src/LyXAction.C
===================================================================
--- src/LyXAction.C	(revision 16016)
+++ src/LyXAction.C	(working copy)
@@ -369,6 +369,8 @@
 		{ 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_NOACTION, "", Noop }
 	};
Index: src/insets/insetpagebreak.C
===================================================================
--- src/insets/insetpagebreak.C	(revision 16016)
+++ src/insets/insetpagebreak.C	(working copy)
@@ -38,7 +38,7 @@
 
 void InsetPagebreak::write(Buffer const &, ostream & os) const
 {
-	os << "\n\\newpage\n";
+	os << "\n" << latexLabel() << '\n';
 }
 
 
@@ -53,7 +53,7 @@
 
 void InsetPagebreak::draw(PainterInfo & pi, int x, int y) const
 {
-	static docstring const label = _("Page Break");
+	docstring const label = _(insetLabel());
 
 	LyXFont font;
 	font.setColor(LColor::pagebreak);
@@ -80,7 +80,7 @@
 int InsetPagebreak::latex(Buffer const &, odocstream & os,
 			  OutputParams const &) const
 {
-	os << "\\newpage{}";
+	os << from_ascii(latexLabel()) << "{}";
 	return 0;
 }
 
@@ -100,5 +100,4 @@
 	return 0;
 }
 
-
 } // namespace lyx
Index: src/insets/insetpagebreak.h
===================================================================
--- src/insets/insetpagebreak.h	(revision 16016)
+++ src/insets/insetpagebreak.h	(working copy)
@@ -20,7 +20,6 @@
 
 class InsetPagebreak : public InsetOld {
 public:
-
 	InsetPagebreak() {}
 
 	InsetBase::Code lyxCode() const { return InsetBase::LINE_CODE; }
@@ -29,7 +28,7 @@
 
 	void draw(PainterInfo & pi, int x, int y) const;
 
-	int latex(Buffer const &, odocstream &,
+	virtual int latex(Buffer const &, odocstream &,
 		  OutputParams const &) const;
 
 	int plaintext(Buffer const &, odocstream &,
@@ -40,11 +39,16 @@
 
 	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; }
 
 	bool display() const { return true; }
+
+	virtual std::string insetLabel() const { return "Page Break"; }
+
+	virtual std::string latexLabel() const { return "\\newpage"; }
+
 private:
 	virtual std::auto_ptr<InsetBase> doClone() const
 	{
@@ -53,6 +57,37 @@
 };
 
 
+class InsetClearPage : public InsetPagebreak {
+public:
+	InsetClearPage() {}
+
+	std::string insetLabel() const { return "Clear Page"; }
+	
+	std::string latexLabel() const { return "\\clearpage"; }
+
+private:
+	virtual std::auto_ptr<InsetBase> doClone() const
+	{
+		return std::auto_ptr<InsetBase>(new InsetClearPage);
+	}
+};
+
+
+class InsetClearDoublePage : public InsetPagebreak {
+public:
+	InsetClearDoublePage() {}
+
+	std::string insetLabel() const { return "Clear Double Page"; }
+	
+	std::string latexLabel() const { return "\\cleardoublepage"; }
+
+private:
+	virtual std::auto_ptr<InsetBase> doClone() const
+	{
+		return std::auto_ptr<InsetBase>(new InsetClearDoublePage);
+	}
+};
+
 } // namespace lyx
 
 #endif // INSET_NEWLINE_H
Index: src/insets/insetert.C
===================================================================
--- src/insets/insetert.C	(revision 16016)
+++ src/insets/insetert.C	(working copy)
@@ -322,6 +322,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/factory.C
===================================================================
--- src/factory.C	(revision 16016)
+++ 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: src/text3.C
===================================================================
--- src/text3.C	(revision 16016)
+++ src/text3.C	(working copy)
@@ -1187,6 +1187,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 +1800,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:
Index: src/lfuns.h
===================================================================
--- src/lfuns.h	(revision 16016)
+++ src/lfuns.h	(working copy)
@@ -377,6 +377,9 @@
 	LFUN_TOOLBAR_TOGGLE_STATE,       // bpeng 20061101
 	LFUN_NOMENCL_INSERT,			// Ugras
 	LFUN_NOMENCL_PRINT,			// Ugras
+	LFUN_CLEARPAGE_INSERT,
+	//290
+	LFUN_CLEARDOUBLEPAGE_INSERT,
 
 	LFUN_LASTACTION                  // end of the table
 };
Index: src/tex2lyx/text.C
===================================================================
--- src/tex2lyx/text.C	(revision 16016)
+++ 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";
+			// FIXME: what about \\pagebreak?
+			os << "\n\\" << t.cs() << "\n";
 			skip_braces(p); // eat {}
 		}
 
Index: src/text.C
===================================================================
--- src/text.C	(revision 16016)
+++ src/text.C	(working copy)
@@ -316,6 +316,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: lib/lyx2lyx/lyx_1_5.py
===================================================================
--- lib/lyx2lyx/lyx_1_5.py	(revision 16016)
+++ lib/lyx2lyx/lyx_1_5.py	(working copy)
@@ -603,6 +603,45 @@
     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
 
 ##
 # Conversion hub
@@ -619,7 +658,8 @@
            [253, []],
            [254, [convert_esint]]]
 
-revert =  [[253, [revert_esint]],
+revert =  [[254, [revert_clearpage, revert_cleardoublepage]],
+           [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 16016)
+++ 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"

Reply via email to