* Support a script also around the ] of an optional parameter

Test case:
"\newcommand{\foo}[2][a]{(#1,#2)} \foo[A]^1b" should give (a,_)^1b

This is implemented for non-optional parameters for long time for
cases like \foo ab^2 


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22646 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Stefan Schimanski 2008-01-22 17:26:54 +00:00
parent 0df54152bc
commit daeb335db3
2 changed files with 26 additions and 6 deletions

View File

@ -561,7 +561,7 @@ void MathData::attachMacroParameters(Cursor * cur,
// find arguments behind the macro
if (!interactiveInit) {
collectOptionalParameters(cur, macroOptionals, detachedArgs, p,
macroPos, thisPos, thisSlice);
scriptToPutAround, macroPos, thisPos, thisSlice);
collectParameters(cur, macroNumArgs, detachedArgs, p,
scriptToPutAround, macroPos, thisPos, thisSlice);
}
@ -614,10 +614,13 @@ void MathData::attachMacroParameters(Cursor * cur,
void MathData::collectOptionalParameters(Cursor * cur,
const size_type numOptionalParams, vector<MathData> & params,
size_t & pos, const pos_type macroPos, const int thisPos, const int thisSlice)
size_t & pos, MathAtom & scriptToPutAround,
const pos_type macroPos, const int thisPos, const int thisSlice)
{
// insert optional arguments?
while (params.size() < numOptionalParams && pos < size()) {
while (params.size() < numOptionalParams
&& pos < size()
&& !scriptToPutAround.nucleus()) {
// is a [] block following which could be an optional parameter?
if (operator[](pos)->getChar() != '[')
break;
@ -625,9 +628,23 @@ void MathData::collectOptionalParameters(Cursor * cur,
// found possible optional argument, look for "]"
size_t right = pos + 1;
for (; right < size(); ++right) {
if (operator[](right)->getChar() == ']')
MathAtom & cell = operator[](right);
if (cell->getChar() == ']')
// found right end
break;
// maybe "]" with a script around?
InsetMathScript * script = cell.nucleus()->asScriptInset();
if (!script)
continue;
if (script->nuc().size() != 1)
continue;
if (script->nuc()[0]->getChar() == ']') {
// script will be put around the macro later
scriptToPutAround = cell;
break;
}
}
// found?
@ -676,7 +693,9 @@ void MathData::collectParameters(Cursor * cur,
const pos_type macroPos, const int thisPos, const int thisSlice)
{
// insert normal arguments
for (; params.size() < numParams && pos < size();) {
while (params.size() < numParams
&& pos < size()
&& !scriptToPutAround.nucleus()) {
MathAtom & cell = operator[](pos);
// fix cursor

View File

@ -181,7 +181,8 @@ private:
///
void collectOptionalParameters(Cursor * cur,
const size_type numOptionalParams, std::vector<MathData> & params,
size_t & pos, const pos_type macroPos, const int thisPos, const int thisSlice);
size_t & pos, MathAtom & scriptToPutAround,
const pos_type macroPos, const int thisPos, const int thisSlice);
///
void collectParameters(Cursor * cur,
const size_type numParams, std::vector<MathData> & params,