From 0786aa3247b1b063a54364ede636d75b45f683a3 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Fri, 13 Aug 2004 23:30:26 +0000 Subject: [PATCH] fix problems with ] in optional latex arguments git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8919 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 8 ++++++++ src/insets/ChangeLog | 4 +++- src/insets/insetoptarg.C | 13 +++++++++---- src/paragraph.C | 10 ++++++---- src/paragraph_pimpl.C | 2 +- 5 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 64aab4179c..39eddedea9 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -19,6 +19,14 @@ 2004-08-13 Jean-Marc Lasgouttes + * 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): * text2.C (editXY): * text3.C (checkInsetHit): constify diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 753aac8eb9..6916fdfec2 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,7 +1,9 @@ 2004-08-13 Jean-Marc Lasgouttes - * 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 diff --git a/src/insets/insetoptarg.C b/src/insets/insetoptarg.C index ed829859cb..2e47c6b6a4 100644 --- a/src/insets/insetoptarg.C +++ b/src/insets/insetoptarg.C @@ -17,10 +17,12 @@ #include "LColor.h" #include "paragraph.h" +#include using std::string; using std::auto_ptr; using std::ostream; +using std::ostringstream; InsetOptArg::InsetOptArg(BufferParams const & ins) @@ -72,8 +74,11 @@ int InsetOptArg::latex(Buffer const &, ostream &, 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; } diff --git a/src/paragraph.C b/src/paragraph.C index 7073f641ed..153648a936 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -920,8 +920,10 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf, 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 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf, } basefont = getLayoutFont(bparams, outerfont); running_font = basefont; - os << ']'; - ++column; + os << "}] "; + column +=3; } if (style->isCommand()) { os << '{'; diff --git a/src/paragraph_pimpl.C b/src/paragraph_pimpl.C index 6792ee42b5..84c269d04b 100644 --- a/src/paragraph_pimpl.C +++ b/src/paragraph_pimpl.C @@ -666,7 +666,7 @@ void Paragraph::Pimpl::simpleTeXSpecialChars(Buffer const & buf, column += 17; break; - case '*': case '[': case ']': + case '*': case '[': // avoid being mistaken for optional arguments os << '{' << c << '}'; column += 2; -- 2.39.2