Fix bug 3750: this code is a kludge and should be removed when tex2lyx is

updated to support format >= 257 (with InsetCaption).

	* src/Layout.cpp (forCaption): new method. Returns a pointer to a newly 
	allocated Layout suitable for representing a caption.

	* src/tex2lyx/tex2lyx.cpp (tex2lyx): allocate a captionlayout object

	* src/tex2lyx/text.cpp: use the captionlayout object to recognize the 
	\caption command.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18962 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jean-Marc Lasgouttes 2007-07-02 16:02:41 +00:00
parent ca339eb199
commit a6f32927ea
5 changed files with 28 additions and 1 deletions

View File

@ -820,5 +820,16 @@ string const & Layout::depends_on() const
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

View File

@ -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_;

View File

@ -68,6 +68,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());
@ -427,6 +428,7 @@ void tex2lyx(std::istream &is, std::ostream &os)
stringstream ss;
TextClass textclass = parse_preamble(p, ss, documentclass);
captionlayout = Layout_ptr(Layout::forCaption());
active_environments.push_back("document");
Context context(true, textclass);

View File

@ -33,7 +33,7 @@ TextClass const parse_preamble(Parser & p, std::ostream & os, std::string const
/// 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 &);

View File

@ -1514,6 +1514,15 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
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)