On Mon, Jan 28, 2002 at 05:45:36PM +0000, John Levon wrote:
 
> On Mon, Jan 28, 2002 at 05:42:24PM +0000, John Levon wrote:
> 
> > > your float is the first object in a description environment and
> > > therefore a label! But a label can't be a float ...
> > 
> > indeed, the real bug is that we allow this.
> 
> bug #223
> 
> john

A part fix, part workaround is attached.

This was a bit tricky. LyX is teeming with insets nowadays and most of
them are quite OK and make sense in a Description or List label. Even
footnotes!

Just a few of them are PITAs. This patch tests for them and alerts, one
per offending inset. I tested this on my Fundamental Geodesy lecture
notes (200+ pages, lots of pictures, math etc.) and it works fine. 
I admit it's a bit ad-hoc, but it doesn't look out of place in 
paragraph.C ;-)

The alert box doesn't show the location, but the invariably ensueing 
LaTeX error box does.

Give this a swirl on some big files. I think it is OK but haven't tested
extensively.

-- Martin

Index: paragraph.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/paragraph.C,v
retrieving revision 1.185
diff -u -b -B -p -r1.185 paragraph.C
--- paragraph.C 2002/01/19 20:24:02     1.185
+++ paragraph.C 2002/01/29 14:41:28
@@ -43,6 +43,8 @@
 #include "support/LAssert.h"
 #include "support/textutils.h"
 
+#include "frontends/Alert.h"
+
 #include <algorithm>
 #include <fstream>
 #include <csignal>
@@ -1558,9 +1560,12 @@ bool Paragraph::simpleTeXOnePar(Buffer c
                main_body = beginningOfMainBody();
 
        int column = 0;
+       bool env_label = false;
+       bool new_warning = true;
 
        if (main_body > 0) {
                os << '[';
+               env_label = true;
                ++column;
                basefont = getLabelFont(bparams);
        } else {
@@ -1599,6 +1604,7 @@ bool Paragraph::simpleTeXOnePar(Buffer c
                                basefont = getLayoutFont(bparams);
                                running_font = basefont;
                                os << ']';
+                               env_label = false;
                                ++column;
                        }
                        if (style.isCommand()) {
@@ -1612,6 +1618,26 @@ bool Paragraph::simpleTeXOnePar(Buffer c
                
                value_type c = getChar(i);
 
+               // Here we test if we have an inset in the label of a list
+               // environment that really, really shouldn't be there. Like
+               // graphics etc. But math, ERT, even footnote are OK.
+               // These typically give latexing errors and are thus easy
+               // to locate.
+               if (env_label && new_warning && c == META_INSET) {
+                       Inset::Code thisinset = getInset(i)->lyxCode();
+                       bool problem_inset = 
+                                                       (  thisinset == 
+Inset::GRAPHICS_CODE
+                                                       || thisinset == 
+Inset::FLOAT_CODE
+                                                       || thisinset == 
+Inset::MARGIN_CODE
+                                                       || thisinset == 
+Inset::MINIPAGE_CODE);
+                       if (c == META_INSET && problem_inset) {
+                       Alert::alert(_("Inset in environment label; are you sure?"),
+                                                _("(This is probably not what you 
+intended)"));
+                       // Only once per offending inset
+                       new_warning = false;
+                       }
+               }
+               
                // Fully instantiated font
                LyXFont font = getFont(bparams, i);
 

Attachment: msg32136/pgp00000.pgp
Description: PGP signature

Reply via email to