>>>>> "Georg" == Georg Baum <[EMAIL PROTECTED]> writes:

Georg> Well, if the command is named \caption then it will be some
Georg> sort of caption. I don't see any problem if the caption inset
Georg> is used in this case. 

Here is what I came up with. Since the code in output_command_layout
is a bit complicated to my taste (to make a specialized version), I
decided to create a fake layout and use it directly. The code in
Layout.* is necessary because the relevant members are private. I try
to write it to be as unintrusive as possible.

Is it better?

JMarc

Index: src/Layout.h
===================================================================
--- src/Layout.h	(révision 18938)
+++ src/Layout.h	(copie de travail)
@@ -338,6 +338,11 @@ public:
 	/// Depth of XML command
 	int commanddepth;
 
+	/// Return a pointer on a new layout suitable to describe a caption.
+	/// FIXME: remove this eventually. This is only for tex2lyx
+	/// until it has proper support for the caption inset (JMarc)
+	static Layout * forCaption();
+
 private:
 	/// Name of the layout/paragraph environment
 	std::string name_;
Index: src/Layout.cpp
===================================================================
--- src/Layout.cpp	(révision 18938)
+++ src/Layout.cpp	(copie de travail)
@@ -820,5 +820,16 @@ string const & Layout::depends_on() cons
 	return depends_on_;
 }
 
+Layout * Layout::forCaption()
+{
+	Layout * lay = new Layout();
+	lay->name_ = "Caption";
+	lay->latexname_ = "caption";
+	lay->latextype = LATEX_COMMAND;
+	lay->optionalargs = 1;
+	return lay;
+}
+
+
 
 } // namespace lyx
Index: src/tex2lyx/tex2lyx.cpp
===================================================================
--- src/tex2lyx/tex2lyx.cpp	(révision 18938)
+++ src/tex2lyx/tex2lyx.cpp	(copie de travail)
@@ -67,6 +67,7 @@ using support::isFileReadable;
 
 namespace fs = boost::filesystem;
 
+Layout_ptr captionlayout;
 
 // Hacks to allow the thing to link in the lyxlayout stuff
 LyXErr lyxerr(std::cerr.rdbuf());
@@ -426,6 +427,7 @@ void tex2lyx(std::istream &is, std::ostr
 
 	stringstream ss;
 	TextClass textclass = parse_preamble(p, ss, documentclass);
+	captionlayout = Layout_ptr(Layout::forCaption());
 
 	active_environments.push_back("document");
 	Context context(true, textclass);
Index: src/tex2lyx/tex2lyx.h
===================================================================
--- src/tex2lyx/tex2lyx.h	(révision 18938)
+++ src/tex2lyx/tex2lyx.h	(copie de travail)
@@ -33,7 +33,7 @@ TextClass const parse_preamble(Parser & 
 
 /// used packages with options
 extern std::map<std::string, std::vector<std::string> > used_packages;
-
+extern Layout_ptr captionlayout;
 
 /// in text.cpp
 std::string translate_len(std::string const &);
Index: src/tex2lyx/text.cpp
===================================================================
--- src/tex2lyx/text.cpp	(révision 18938)
+++ src/tex2lyx/text.cpp	(copie de travail)
@@ -1514,6 +1514,15 @@ void parse_text(Parser & p, ostream & os
 			p.skip_spaces();
 		}
 
+		// Special handling for \caption
+		// FIXME: remove this when InsetCaption is supported.
+		else if (context.new_layout_allowed &&
+			 t.cs() == captionlayout->latexname()) {
+			output_command_layout(os, p, outer, context, 
+					      captionlayout);
+			p.skip_spaces();
+		}
+
 		else if (t.cs() == "includegraphics") {
 			bool const clip = p.next_token().asInput() == "*";
 			if (clip)

Reply via email to