This patch solves the old bug of outputting something like \begin{description} \item[$a[1]$] this is the first item \end{description} where the ] in the formula will be mistaken for the end of the optional argument. The solution here is to enclose all \item[] arguments into curly brackets.
Similarly, I fix optional arguments, but only if they contain the character ] Finally, this outputs ] in text mode directly, instead of using {]}, The idea is that it is hopefully not necessary to hide the square bracket anymore, since the hiding is done at a upper level. I'm applying this right now, but I'd appreciate comments, since I plan to put this in 1.3.x too. JMarc
Index: src/ChangeLog =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/ChangeLog,v retrieving revision 1.1953 diff -u -r1.1953 ChangeLog --- src/ChangeLog 13 Aug 2004 19:14:11 -0000 1.1953 +++ src/ChangeLog 13 Aug 2004 21:45:39 -0000 @@ -1,5 +1,12 @@ 2004-08-13 Jean-Marc Lasgouttes <[EMAIL PROTECTED]> + * paragraph_pimpl.C (simpleTeXSpecialChars): remove special + treatment for ']' + + * paragraph.C (simpleTeXOnePar): when we have a \item with + optional argument, enclose the argument with curly brackets (in + case it contains a closing square bracket) + * text2.C (editXY): * text3.C (checkInsetHit): constify Index: src/paragraph.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph.C,v retrieving revision 1.372 diff -u -r1.372 paragraph.C --- src/paragraph.C 5 Aug 2004 15:14:29 -0000 1.372 +++ src/paragraph.C 13 Aug 2004 21:45:39 -0000 @@ -920,8 +920,10 @@ unsigned int column = 0; if (body_pos > 0) { - os << '['; - ++column; + // the optional argument is kept in curly brackets in + // case it contains a ']' + os << "[{"; + column += 2; basefont = getLabelFont(bparams, outerfont); } else { basefont = getLayoutFont(bparams, outerfont); @@ -959,8 +961,8 @@ } basefont = getLayoutFont(bparams, outerfont); running_font = basefont; - os << ']'; - ++column; + os << "}] "; + column +=3; } if (style->isCommand()) { os << '{'; Index: src/paragraph_pimpl.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph_pimpl.C,v retrieving revision 1.96 diff -u -r1.96 paragraph_pimpl.C --- src/paragraph_pimpl.C 5 Aug 2004 15:14:29 -0000 1.96 +++ src/paragraph_pimpl.C 13 Aug 2004 21:45:39 -0000 @@ -666,7 +666,7 @@ column += 17; break; - case '*': case '[': case ']': + case '*': case '[': // avoid being mistaken for optional arguments os << '{' << c << '}'; column += 2; Index: src/insets/ChangeLog =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/ChangeLog,v retrieving revision 1.1030 diff -u -r1.1030 ChangeLog --- src/insets/ChangeLog 13 Aug 2004 19:14:13 -0000 1.1030 +++ src/insets/ChangeLog 13 Aug 2004 21:45:40 -0000 @@ -1,7 +1,9 @@ 2004-08-13 Jean-Marc Lasgouttes <[EMAIL PROTECTED]> - * insettext.C (editXY): + * insetoptarg.C (latexOptional): if the optional argument contains + a ']' enclose it in {curly brackets} + * insettext.C (editXY): * insettabular.C (editXY): * insetcollapsable.C (editXY): * insetbase.C (editXY): constify Index: src/insets/insetoptarg.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetoptarg.C,v retrieving revision 1.23 diff -u -r1.23 insetoptarg.C --- src/insets/insetoptarg.C 25 Mar 2004 09:16:28 -0000 1.23 +++ src/insets/insetoptarg.C 13 Aug 2004 21:45:40 -0000 @@ -17,10 +17,12 @@ #include "LColor.h" #include "paragraph.h" +#include <sstream> using std::string; using std::auto_ptr; using std::ostream; +using std::ostringstream; InsetOptArg::InsetOptArg(BufferParams const & ins) @@ -72,8 +74,11 @@ int InsetOptArg::latexOptional(Buffer const & buf, ostream & os, OutputParams const & runparams) const { - os << '['; - int const i = InsetText::latex(buf, os, runparams); - os << ']'; - return i + 2; + ostringstream ss; + InsetText::latex(buf, ss, runparams); + string str = ss.str(); + if (str.find(']') != string::npos) + str = '{' + str + '}'; + os << '[' << str << ']'; + return str.length() + 2; }