The attached patch finally does the long overdue switch from the superseded 
package "subfigure" to "subfig" (bug 3657). I think this is a must for 1.6.

While implementing this, I have polished our subfigure handling in several 
ways:

1. I have added general support for subfloats. This is provided by the package 
(so we now have not only subfigures, but also subtables, subalgorithms and in 
fact automatically working subfloats for any float that is defined via the 
layout files, provided that it is defined by means of float.sty)

2. I have changed the UI. Subfigures are no longer defined via the graphics 
dialog, which was bad design right from the beginning. I've also decided 
against a separate "subfig inset", which strikes me unneeded and unintuitive. 
Instead, I've simply intergrated subfloats into floats. Simply embed a float 
in a float to get a subfloat. The pro is that this is intuitive (IMO), saves 
code, and it makes transferring floats to subfloats (and vice versa) a 
breeze.

3. As a consequence of 2., we now also have proper subfigure/subfloat 
captions, which allow for labels, optional arguments etc. (bug 1619). The 
captions indicate if they belong to a subfloat, and they also have their own 
counter.

Two problems remain:

1. I've not implemented docbook support, because I don't know how docbook 
deals with this kind of stuff.

2. In the lyx2lyx reversion routine, there's a remaining problem: subfloats 
inside floats with top-captions are not properly reverted to ERT. I'm at my 
(python) wit's end, and I'd be grateful if I could get some helping hand 
here.

If there are no objections, I'll shove this in.

Jürgen
Index: src/TextClass.cpp
===================================================================
--- src/TextClass.cpp	(Revision 23363)
+++ src/TextClass.cpp	(Arbeitskopie)
@@ -763,8 +763,12 @@
 			    style, name, listName, builtin);
 		floatlist_->newFloat(fl);
 		// each float has its own counter
-		counters_->newCounter(from_ascii(type), from_ascii(within), 
+		counters_->newCounter(from_ascii(type), from_ascii(within),
 				      docstring(), docstring());
+		// also define sub-float counters
+		docstring const subtype = "sub-" + from_ascii(type);
+		counters_->newCounter(subtype, from_ascii(type),
+				      "\\alph{" + subtype + "}", docstring());
 	}
 
 	lexrc.popTable();
Index: src/insets/InsetCaption.cpp
===================================================================
--- src/insets/InsetCaption.cpp	(Revision 23363)
+++ src/insets/InsetCaption.cpp	(Arbeitskopie)
@@ -220,6 +220,9 @@
 int InsetCaption::latex(odocstream & os,
 			OutputParams const & runparams_in) const
 {
+	if (in_subfloat_)
+		// caption is output as an optional argument
+		return 0;
 	// This is a bit too simplistic to take advantage of
 	// caption options we must add more later. (Lgb)
 	// This code is currently only able to handle the simple
@@ -282,6 +285,7 @@
 	string const & type = cnts.current_float();
 	// Memorize type for addToToc().
 	type_ = type;
+	in_subfloat_ = cnts.isSubfloat();
 	if (type.empty())
 		full_label_ = buffer().B_("Senseless!!! ");
 	else {
@@ -292,11 +296,17 @@
 			name = buffer().B_("Listing");
 		else
 			name = buffer().B_(tclass.floats().getType(type).name());
-		if (cnts.hasCounter(from_utf8(type))) {
-			cnts.step(from_utf8(type));
+		docstring counter = from_utf8(type);
+		if (in_subfloat_) {
+			counter = "sub-" + from_utf8(type);
+			name = bformat(_("Sub-%1$s"),
+				       buffer().B_(tclass.floats().getType(type).name()));
+		}
+		if (cnts.hasCounter(counter)) {
+			cnts.step(counter);
 			full_label_ = bformat(from_ascii("%1$s %2$s:"), 
-					      name, 
-					      cnts.theCounter(from_utf8(type)));
+					      name,
+					      cnts.theCounter(counter));
 		} else
 			full_label_ = bformat(from_ascii("%1$s #:"), name);	
 	}
Index: src/insets/InsetGraphicsParams.h
===================================================================
--- src/insets/InsetGraphicsParams.h	(Revision 23363)
+++ src/insets/InsetGraphicsParams.h	(Arbeitskopie)
@@ -60,10 +60,6 @@
 	std::string rotateAngle;
 	/// Origin point of rotation
 	std::string rotateOrigin;
-	/// Do we have a subcaption?
-	bool subcaption;
-	/// The text of the subcaption.
-	std::string subcaptionText;
 	/// any userdefined special command
 	std::string special;
 
Index: src/insets/InsetGraphics.cpp
===================================================================
--- src/insets/InsetGraphics.cpp	(Revision 23363)
+++ src/insets/InsetGraphics.cpp	(Arbeitskopie)
@@ -22,8 +22,6 @@
       filename.
     * Add support for the 'picins' package.
     * Add support for the 'picinpar' package.
-    * Improve support for 'subfigure' - Allow to set the various options
-      that are possible.
 */
 
 /* NOTES:
@@ -764,13 +762,6 @@
 	// after the actual includegraphics command.
 	string before;
 	string after;
-	// Do we want subcaptions?
-	if (params().subcaption) {
-		if (runparams.moving_arg)
-			before += "\\protect";
-		before += "\\subfigure[" + params().subcaptionText + "]{";
-		after = '}';
-	}
 
 	if (runparams.moving_arg)
 		before += "\\protect";
@@ -898,9 +889,6 @@
 		if (contains(rel_file, "."))
 			features.require("lyxdot");
 	}
-
-	if (params().subcaption)
-		features.require("subfigure");
 }
 
 
Index: src/insets/InsetCaption.h
===================================================================
--- src/insets/InsetCaption.h	(Revision 23363)
+++ src/insets/InsetCaption.h	(Arbeitskopie)
@@ -87,6 +87,8 @@
 	///
 	std::string type_;
 	///
+	bool in_subfloat_;
+	///
 	docstring custom_label_;
 };
 
Index: src/insets/InsetGraphicsParams.cpp
===================================================================
--- src/insets/InsetGraphicsParams.cpp	(Revision 23363)
+++ src/insets/InsetGraphicsParams.cpp	(Arbeitskopie)
@@ -78,8 +78,6 @@
 
 	rotateAngle = "0";		// angle of rotation in degrees
 	rotateOrigin.erase();		// Origin of rotation
-	subcaption = false;		// subfigure
-	subcaptionText.erase();		// subfigure caption
 	special.erase();		// additional userdefined stuff
 }
 
@@ -102,8 +100,6 @@
 
 	rotateAngle = igp.rotateAngle;
 	rotateOrigin = igp.rotateOrigin;
-	subcaption = igp.subcaption;
-	subcaptionText = igp.subcaptionText;
 	special = igp.special;
 }
 
@@ -127,8 +123,6 @@
 
 	    left.rotateAngle == right.rotateAngle &&
 	    left.rotateOrigin == right.rotateOrigin &&
-	    left.subcaption == right.subcaption &&
-	    left.subcaptionText == right.subcaptionText &&
 	    left.special == right.special;
 }
 
@@ -180,10 +174,6 @@
 		os << "\trotateAngle " << rotateAngle << '\n';
 	if (!rotateOrigin.empty())
 		os << "\trotateOrigin " << rotateOrigin << '\n';
-	if (subcaption)
-		os << "\tsubcaption\n";
-	if (!subcaptionText.empty())
-		os << "\tsubcaptionText \"" << subcaptionText << '\"' << '\n';
 	if (!special.empty())
 		os << "\tspecial " << special << '\n';
 }
@@ -246,13 +236,6 @@
 	} else if (token == "rotateOrigin") {
 		lex.next();
 		rotateOrigin=lex.getString();
-	} else if (token == "subcaption") {
-		subcaption = true;
-	} else if (token == "subcaptionText") {
-		lex.eatLine();
-		string sub = lex.getString();
-		// strip surrounding " "
-		subcaptionText = sub.substr(1, sub.length() - 2);
 	} else if (token == "special") {
 		lex.eatLine();
 		special = lex.getString();
Index: src/insets/InsetFloat.cpp
===================================================================
--- src/insets/InsetFloat.cpp	(Revision 23363)
+++ src/insets/InsetFloat.cpp	(Arbeitskopie)
@@ -5,6 +5,7 @@
  *
  * \author Jürgen Vigna
  * \author Lars Gullik Bjønnes
+ * \author Jürgen Spitzmüller
  *
  * Full author contact details are available in file CREDITS.
  */
@@ -12,6 +13,7 @@
 #include <config.h>
 
 #include "InsetFloat.h"
+#include "InsetCaption.h"
 
 #include "Buffer.h"
 #include "BufferParams.h"
@@ -23,9 +25,11 @@
 #include "FloatList.h"
 #include "FuncRequest.h"
 #include "FuncStatus.h"
+#include "InsetList.h"
 #include "LaTeXFeatures.h"
 #include "Lexer.h"
 #include "OutputParams.h"
+#include "ParIterator.h"
 #include "TextClass.h"
 
 #include "support/debug.h"
@@ -131,6 +135,7 @@
 		params_.placement = params.placement;
 		params_.wide      = params.wide;
 		params_.sideways  = params.sideways;
+		params_.subfloat  = params.subfloat;
 		wide(params_.wide, cur.buffer().params());
 		sideways(params_.sideways, cur.buffer().params());
 		break;
@@ -143,6 +148,8 @@
 
 	case LFUN_MOUSE_RELEASE: {
 		if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
+			if (params_.subfloat)
+				break;
 			InsetFloatMailer(*this).showDialog(&cur.bv());
 			break;
 		}
@@ -177,14 +184,23 @@
 {
 	Counters & cnts = buffer().params().documentClass().counters();
 	string const saveflt = cnts.current_float();
+	bool const savesubflt = cnts.isSubfloat();
 
+	bool const subflt = it.innerInsetOfType(FLOAT_CODE);
+	// floats can only embed subfloats of their own kind
+	if (subflt)
+		params_.type = saveflt;
+	subfloat(subflt, buffer().params());
+
 	// Tell to captions what the current float is
 	cnts.current_float(params().type);
+	cnts.isSubfloat(subflt);
 
 	InsetCollapsable::updateLabels(it);
 
 	//reset afterwards
 	cnts.current_float(saveflt);
+	cnts.isSubfloat(savesubflt);
 }
 
 
@@ -250,6 +266,7 @@
 	params_.read(lex);
 	wide(params_.wide, buffer().params());
 	sideways(params_.sideways, buffer().params());
+	subfloat(params_.subfloat, buffer().params());
 	InsetCollapsable::read(lex);
 }
 
@@ -263,7 +280,10 @@
 	if (params_.sideways)
 		features.require("rotfloat");
 
-	features.useFloat(params_.type);
+	if (params_.subfloat)
+		features.require("subfig");
+
+	features.useFloat(params_.type, params_.subfloat);
 	InsetCollapsable::validate(features);
 }
 
@@ -282,6 +302,23 @@
 
 int InsetFloat::latex(odocstream & os, OutputParams const & runparams) const
 {
+	if (params_.subfloat) {
+		if (runparams.moving_arg)
+			os << "\\protect";
+		os << "\\subfloat";
+	
+		OutputParams rp = runparams;
+		docstring const caption = getCaption(rp);
+		if (!caption.empty()) {
+			os << caption;
+		}
+		os << '{';
+		int const i = InsetText::latex(os, runparams);
+		os << "}";
+	
+		return i + 1;
+	}
+
 	FloatList const & floats = buffer().params().documentClass().floats();
 	string tmptype = params_.type;
 	if (params_.sideways)
@@ -341,6 +378,7 @@
 
 int InsetFloat::docbook(odocstream & os, OutputParams const & runparams) const
 {
+	// FIXME Implement subfloat!
 	// FIXME UNICODE
 	os << '<' << from_ascii(params_.type) << '>';
 	int const i = InsetText::docbook(os, runparams);
@@ -352,9 +390,9 @@
 
 bool InsetFloat::insetAllowed(InsetCode code) const
 {
-	return code != FLOAT_CODE
-	    && code != FOOT_CODE
-	    && code != MARGIN_CODE;
+	return code != FOOT_CODE
+	    && code != MARGIN_CODE
+	    && (code != FLOAT_CODE || !params_.subfloat);
 }
 
 
@@ -386,6 +424,42 @@
 }
 
 
+void InsetFloat::subfloat(bool s, BufferParams const & bp)
+{
+	params_.subfloat = s;
+	docstring lab = _("float: ") + floatName(params_.type, bp);
+	if (s)
+		lab = _("subfloat: ") + floatName(params_.type, bp);
+	setLabel(lab);
+}
+
+
+docstring InsetFloat::getCaption(OutputParams const & runparams) const
+{
+	if (paragraphs().empty())
+		return docstring();
+
+	ParagraphList::const_iterator pit = paragraphs().begin();
+	for (; pit != paragraphs().end(); ++pit) {
+		InsetList::const_iterator it = pit->insetList().begin();
+		for (; it != pit->insetList().end(); ++it) {
+			Inset & inset = *it->inset;
+			if (inset.lyxCode() == CAPTION_CODE) {
+				odocstringstream ods;
+				InsetCaption * ins =
+					static_cast<InsetCaption *>(it->inset);
+				ins->getOptArg(ods, runparams);
+				ods << '[';
+				ins->getArgument(ods, runparams);
+				ods << ']';
+				return ods.str();
+			}
+		}
+	}
+	return docstring();
+}
+
+
 string const InsetFloatMailer::name_("float");
 
 InsetFloatMailer::InsetFloatMailer(InsetFloat & inset)
Index: src/insets/InsetFloat.h
===================================================================
--- src/insets/InsetFloat.h	(Revision 23363)
+++ src/insets/InsetFloat.h	(Arbeitskopie)
@@ -23,7 +23,7 @@
 class InsetFloatParams {
 public:
 	///
-	InsetFloatParams() : wide(false), sideways(false) {}
+	InsetFloatParams() : wide(false), sideways(false), subfloat(false) {}
 	///
 	void write(std::ostream & os) const;
 	///
@@ -36,6 +36,8 @@
 	bool wide;
 	///
 	bool sideways;
+	///
+	bool subfloat;
 };
 
 
@@ -79,6 +81,8 @@
 	///
 	void sideways(bool s, BufferParams const &);
 	///
+	void subfloat(bool s, BufferParams const &);
+	///
 	bool  showInsetDialog(BufferView *) const;
 	///
 	InsetFloatParams const & params() const { return params_; }
@@ -92,6 +96,8 @@
 	///
 	virtual Inset * clone() const;
 	///
+	docstring getCaption(OutputParams const &) const;
+	///
 	InsetFloatParams params_;
 	///
 	docstring name_;
Index: src/LaTeXFeatures.h
===================================================================
--- src/LaTeXFeatures.h	(Revision 23363)
+++ src/LaTeXFeatures.h	(Arbeitskopie)
@@ -82,7 +82,7 @@
 	*/
 	bool mustProvide(std::string const & name) const;
 	///
-	void useFloat(std::string const & name);
+	void useFloat(std::string const & name, bool subfloat = false);
 	///
 	void useLanguage(Language const *);
 	///
@@ -124,7 +124,7 @@
 	/// used languages (only those that are supported by babel)
 	LanguageList UsedLanguages_;
 	///
-	typedef std::set<std::string> UsedFloats;
+	typedef std::map<std::string, bool> UsedFloats;
 	///
 	UsedFloats usedFloats_;
 	///
Index: src/Counters.cpp
===================================================================
--- src/Counters.cpp	(Revision 23363)
+++ src/Counters.cpp	(Arbeitskopie)
@@ -171,6 +171,7 @@
 void Counters::reset()
 {
 	appendix_ = false;
+	subfloat_ = false;
 	current_float_.erase();
 	CounterList::iterator it = counterList.begin();
 	CounterList::iterator const end = counterList.end();
Index: src/Counters.h
===================================================================
--- src/Counters.h	(Revision 23363)
+++ src/Counters.h	(Arbeitskopie)
@@ -116,6 +116,10 @@
 	std::string const & current_float() const { return current_float_; }
 	/// Sets the current enclosing float.
 	void current_float(std::string const & f) { current_float_ = f; }
+	/// Are we in a subfloat?
+	bool isSubfloat() const { return subfloat_; }
+	/// Set the state variable indicating whether we are in a subfloat.
+	void isSubfloat(bool s) { subfloat_ = s; };
 private:
 	/// returns the expanded string representation of the counter
 	/// with recursion protection through callers.
@@ -137,6 +141,8 @@
 	bool appendix_;
 	/// The current enclosing float.
 	std::string current_float_;
+	/// Are we in a subfloat?
+	bool subfloat_;
 };
 
 
Index: src/frontends/qt4/GuiGraphics.cpp
===================================================================
--- src/frontends/qt4/GuiGraphics.cpp	(Revision 23363)
+++ src/frontends/qt4/GuiGraphics.cpp	(Arbeitskopie)
@@ -204,10 +204,6 @@
 	// setChecked(). Note, too, that clicked() would get called whenever it
 	// is clicked, even right clicked (I think), not just whenever it is
 	// toggled.
-	connect(subfigure, SIGNAL(toggled(bool)),
-		this, SLOT(change_adaptor()));
-	connect(subcaption, SIGNAL(textChanged(const QString&)),
-		this, SLOT(change_adaptor()));
 	connect(displayGB, SIGNAL(toggled(bool)),
 		this, SLOT(change_adaptor()));
 	connect(showCB, SIGNAL(currentIndexChanged(int)),
@@ -223,7 +219,6 @@
 	bc().setCancel(closePB);
 
 	bc().addReadOnly(latexoptions);
-	bc().addReadOnly(subfigure);
 	bc().addReadOnly(filenameL);
 	bc().addReadOnly(filename);
 	bc().addReadOnly(browsePB);
@@ -500,10 +495,6 @@
 	clip->setChecked(igp.clip);
 	unzipCB->setChecked(igp.noUnzip);
 
-	// Update the subcaption check button and input field
-	subfigure->setChecked(igp.subcaption);
-	subcaption->setText(toqstr(igp.subcaptionText));
-
 	int item = 0;
 	switch (igp.display) {
 		case graphics::DefaultDisplay: item = 0; break;
@@ -624,8 +615,6 @@
 
 	igp.draft = draftCB->isChecked();
 	igp.clip = clip->isChecked();
-	igp.subcaption = subfigure->isChecked();
-	igp.subcaptionText = fromqstr(subcaption->text());
 
 	switch (showCB->currentIndex()) {
 		case 0: igp.display = graphics::DefaultDisplay; break;
Index: src/frontends/qt4/ui/GraphicsUi.ui
===================================================================
--- src/frontends/qt4/ui/GraphicsUi.ui	(Revision 23363)
+++ src/frontends/qt4/ui/GraphicsUi.ui	(Arbeitskopie)
@@ -643,61 +643,6 @@
          </property>
         </widget>
        </item>
-       <item row="3" column="0" colspan="2" >
-        <widget class="QGroupBox" name="subfigure" >
-         <property name="focusPolicy" >
-          <enum>Qt::StrongFocus</enum>
-         </property>
-         <property name="title" >
-          <string>S&amp;ubfigure</string>
-         </property>
-         <property name="flat" >
-          <bool>true</bool>
-         </property>
-         <property name="checkable" >
-          <bool>true</bool>
-         </property>
-         <property name="checked" >
-          <bool>false</bool>
-         </property>
-         <layout class="QHBoxLayout" >
-          <property name="margin" >
-           <number>9</number>
-          </property>
-          <property name="spacing" >
-           <number>6</number>
-          </property>
-          <item>
-           <widget class="QLabel" name="CaptionLA" >
-            <property name="toolTip" >
-             <string>The caption for the sub-figure</string>
-            </property>
-            <property name="text" >
-             <string>Ca&amp;ption:</string>
-            </property>
-            <property name="buddy" >
-             <cstring>subcaption</cstring>
-            </property>
-           </widget>
-          </item>
-          <item>
-           <widget class="QLineEdit" name="subcaption" >
-            <property name="sizePolicy" >
-             <sizepolicy>
-              <hsizetype>3</hsizetype>
-              <vsizetype>0</vsizetype>
-              <horstretch>0</horstretch>
-              <verstretch>0</verstretch>
-             </sizepolicy>
-            </property>
-            <property name="toolTip" >
-             <string>The caption for the sub-figure</string>
-            </property>
-           </widget>
-          </item>
-         </layout>
-        </widget>
-       </item>
       </layout>
      </widget>
     </widget>
@@ -836,8 +781,6 @@
   <tabstop>latexoptions</tabstop>
   <tabstop>draftCB</tabstop>
   <tabstop>unzipCB</tabstop>
-  <tabstop>subfigure</tabstop>
-  <tabstop>subcaption</tabstop>
   <tabstop>displayGB</tabstop>
   <tabstop>showCB</tabstop>
   <tabstop>displayscale</tabstop>
Index: src/LaTeXFeatures.cpp
===================================================================
--- src/LaTeXFeatures.cpp	(Revision 23363)
+++ src/LaTeXFeatures.cpp	(Arbeitskopie)
@@ -433,9 +433,12 @@
 }
 
 
-void LaTeXFeatures::useFloat(string const & name)
+void LaTeXFeatures::useFloat(string const & name, bool subfloat)
 {
-	usedFloats_.insert(name);
+	if (!usedFloats_[name])
+		usedFloats_[name] = subfloat;
+	if (subfloat)
+		require("subfig");
 	// We only need float.sty if we use non builtin floats, or if we
 	// use the "H" modifier. This includes modified table and
 	// figure floats. (Lgb)
@@ -510,7 +513,7 @@
 	"rotating",
 	"latexsym",
 	"pifont",
-	"subfigure",
+	"subfig",
 	"varioref",
 	"prettyref",
 	/*For a successful cooperation of the `wrapfig' package with the
@@ -914,7 +917,7 @@
 	UsedFloats::const_iterator end = usedFloats_.end();
 	// ostringstream floats;
 	for (; cit != end; ++cit) {
-		Floating const & fl = floats.getType((*cit));
+		Floating const & fl = floats.getType((cit->first));
 
 		// For builtin floats we do nothing.
 		if (fl.builtin()) continue;
@@ -959,6 +962,8 @@
 			// used several times, when the same style is still in
 			// effect. (Lgb)
 		}
+		if (cit->second)
+			os << "\n\\newsubfloat{" << fl.type() << "}\n";
 	}
 }
 
Index: src/Buffer.cpp
===================================================================
--- src/Buffer.cpp	(Revision 23363)
+++ src/Buffer.cpp	(Arbeitskopie)
@@ -115,7 +115,7 @@
 
 namespace {
 
-int const LYX_FORMAT = 315; // Richard Heck: column separation
+int const LYX_FORMAT = 316; // JSpitzm: subfig support
 
 } // namespace anon
 
Index: lib/lyx2lyx/LyX.py
===================================================================
--- lib/lyx2lyx/LyX.py	(Revision 23363)
+++ lib/lyx2lyx/LyX.py	(Arbeitskopie)
@@ -80,7 +80,7 @@
                    ("1_3",     [221], minor_versions("1.3" , 7)),
                    ("1_4", range(222,246), minor_versions("1.4" , 5)),
                    ("1_5", range(246,277), minor_versions("1.5" , 2)),
-                   ("1_6", range(277,316), minor_versions("1.6" , 0))] # rgh: colsep
+                   ("1_6", range(277,317), minor_versions("1.6" , 0))] # jspitzm: subfig
 
 
 def formats_list():
Index: lib/lyx2lyx/lyx_1_6.py
===================================================================
--- lib/lyx2lyx/lyx_1_6.py	(Revision 23363)
+++ lib/lyx2lyx/lyx_1_6.py	(Arbeitskopie)
@@ -1241,6 +1241,127 @@
         i = i + 1
 
 
+def convert_subfig(document):
+    " Convert subfigures to subfloats. "
+    i = 0
+    while 1:
+        i = find_token(document.body, '\\begin_inset Graphics', i)
+        if i == -1:
+            return
+        j = find_end_of_inset(document.body, i)
+        if j == -1:
+            document.warning("Malformed lyx document: Missing '\\end_inset'.")
+            i = i + 1
+            continue
+        k = find_token(document.body, '\tsubcaption', i, j)
+        if k == -1:
+            i = i + 1
+            continue
+        l = find_token(document.body, '\tsubcaptionText', i, j)
+        caption = get_value(document.body, '\tsubcaptionText', i, j).strip('"')
+        savestr = document.body[i]
+        document.body[i] = '\\begin_inset Float figure\nwide false\nsideways false\n' \
+        'status open\n\n\\begin_layout PlainLayout\n\\begin_inset Caption\n\n\\begin_layout PlainLayout\n' \
+        + caption + '\n\\end_layout\n\n\\end_inset\n\n\\end_layout\n\n\\begin_layout PlainLayout\n' + savestr
+        savestr = document.body[j]
+        document.body[j] = '\n\\end_layout\n\n\\end_inset\n' + savestr
+        del document.body[k]
+        del document.body[l]
+
+
+def revert_subfig(document):
+    " Revert subfloats. "
+    i = 0
+    while 1:
+        i = find_token(document.body, '\\begin_inset Float', i)
+        if i == -1:
+            return
+        while 1:
+            j = find_end_of_inset(document.body, i)
+            if j == -1:
+                document.warning("Malformed lyx document: Missing '\\end_inset' (float).")
+                i = i + 1
+                continue
+            # look for embedded float (= subfloat)
+            k = find_token(document.body, '\\begin_inset Float', i + 1, j)
+            if k == -1:
+                break
+            l = find_end_of_inset(document.body, k)
+            if l == -1:
+                document.warning("Malformed lyx document: Missing '\\end_inset' (embedded float).")
+                i = i + 1
+                continue
+            m = find_token(document.body, "\\begin_layout PlainLayout", k + 1, l)
+            # caption?
+            cap = find_token(document.body, '\\begin_inset Caption', k + 1, l)
+            caption = ''
+            shortcap = ''
+            if cap != -1:
+                capend = find_end_of_inset(document.body, cap)
+                if capend == -1:
+                    document.warning("Malformed lyx document: Missing '\\end_inset' (caption).")
+                    return
+                # label?
+                label = ''
+                lbl = find_token(document.body, '\\begin_inset CommandInset label', cap, capend)
+                if lbl != -1:
+                    lblend = find_end_of_inset(document.body, lbl + 1)
+                    if lblend == -1:
+                        document.warning("Malformed lyx document: Missing '\\end_inset' (label).")
+                        return
+                    for line in document.body[lbl:lblend + 1]:
+                        if line.startswith('name '):
+                            label = line.split()[1].strip('"')
+                            break
+                else:
+                    lbl = capend
+                    lblend = capend
+                    label = ''
+                # opt arg?
+                opt = find_token(document.body, '\\begin_inset OptArg', cap, capend)
+                if opt != -1:
+                    optend = find_end_of_inset(document.body, opt)
+                    if optend == -1:
+                        document.warning("Malformed lyx document: Missing '\\end_inset' (OptArg).")
+                        return
+                    optc = find_token(document.body, "\\begin_layout PlainLayout", opt, optend)
+                    if optc == -1:
+                        document.warning("Malformed LyX document: Missing `\\begin_layout PlainLayout' in Float inset.")
+                        return
+                    optcend = find_end_of(document.body, optc, "\\begin_layout", "\\end_layout")
+                    for line in document.body[optc:optcend]:
+                        if not line.startswith('\\'):
+                            shortcap += line.strip()
+                else:
+                    opt = capend
+                    optend = capend
+                for line in document.body[cap:capend]:
+                    if line in document.body[lbl:lblend]:
+                        continue
+                    elif line in document.body[opt:optend]:
+                        continue
+                    elif not line.startswith('\\'):
+                        caption += line.strip()
+                if len(label) > 0:
+                    caption += "\\backslash\nlabel{" + label + "}"
+            document.body[l] = '\\begin_layout PlainLayout\n\\begin_inset ERT\nstatus collapsed\n\n' \
+            '\\begin_layout PlainLayout\n\n}\n\\end_layout\n\n\\end_inset\n\n\\end_layout\n\n\\begin_layout PlainLayout\n'
+            del document.body[cap:capend+1]
+            del document.body[k+1:m-1]
+            insertion = '\\begin_inset ERT\nstatus collapsed\n\n' \
+            '\\begin_layout PlainLayout\n\n\\backslash\n' \
+            'subfloat'
+            if len(shortcap) > 0:
+                insertion = insertion + "[" + shortcap + "]"
+            if len(caption) > 0:
+                insertion = insertion + "[" + caption + "]"
+            insertion = insertion + '{%\n\\end_layout\n\n\\end_inset\n\n\\end_layout\n'
+            document.body[k] = insertion
+            add_to_preamble(document,
+                            ['\\usepackage{subfig}\n'])
+        i = i + 1
+
+
 ##
 # Conversion hub
 #
@@ -1284,10 +1405,12 @@
            [312, []],
            [313, [convert_module_names]],
            [314, []],
-           [315, []]
+           [315, []],
+           [316, [convert_subfig]]
           ]
 
-revert =  [[314, [revert_colsep]],
+revert =  [[314, [revert_subfig]],
+           [314, [revert_colsep]],
            [313, []],
            [312, [revert_module_names]],
            [311, [revert_rotfloat, revert_widesideways]],
Index: lib/chkconfig.ltx
===================================================================
--- lib/chkconfig.ltx	(Revision 23363)
+++ lib/chkconfig.ltx	(Arbeitskopie)
@@ -251,7 +251,7 @@
 \TestPackage{rotfloat}
 \TestPackage{setspace}
 \TestPackage{soul}
-\TestPackage{subfigure}
+\TestPackage{subfig}
 \TestPackage{textcomp}
 \TestPackage{units}
 \TestPackage{url}
Index: lib/doc/LaTeXConfig.lyx
===================================================================
--- lib/doc/LaTeXConfig.lyx	(Revision 23363)
+++ lib/doc/LaTeXConfig.lyx	(Arbeitskopie)
@@ -1,5 +1,5 @@
 #LyX 1.6.0svn created this file. For more info see http://www.lyx.org/
-\lyxformat 315
+\lyxformat 316
 \begin_document
 \begin_header
 \textclass article
@@ -4307,14 +4307,14 @@
 \end_layout
 
 \begin_layout Subsection
-subfigure
+subfig
 \end_layout
 
 \begin_layout Description
 Found: 
 \begin_inset Info
 type  "package"
-arg   "subfigure"
+arg   "subfig"
 \end_inset
 
 
@@ -4323,17 +4323,18 @@
 \begin_layout Description
 CTAN: 
 \family typewriter
-macros/latex/contrib/subfigure
+macros/latex/contrib/subfig
 \end_layout
 
 \begin_layout Description
 Notes: The package 
 \family sans
-subfigure
+subfig
 \family default
- is used by LyX when you select ``subfigure'' in the EPS figure popup.
- Several figures marked in this way can be packed into a single float with
- individual subcaptions.
+ is used by LyX to produce subfloats (i.\InsetSpace \thinspace{}
+e., subfigures, subtables, etc.).
+ Subfloats are floats that are embedded inside other floats and that can
+ have individual subcaptions.
 \end_layout
 
 \begin_layout Subsection
Index: development/FORMAT
===================================================================
--- development/FORMAT	(Revision 23363)
+++ development/FORMAT	(Arbeitskopie)
@@ -1,6 +1,9 @@
 LyX file-format changes
 -----------------------
 
+2008-03-01 Jürgen Spitzmüller <[EMAIL PROTECTED]>
+	* Format incremented to 316: support for subfloats (subfig package).
+
 2008-02-18 Richard Heck <[EMAIL PROTECTED]>
 	* Format incremented to 315: support for column separation in page margins
 

Reply via email to