上下文 - 循环中创建框时出错

上下文 - 循环中创建框时出错

下面的代码创建了一个盒子数组来表示一个数组。

\startMPinclusions
 input boxes ;
\stopMPinclusions

\starttext
\startluacode
function createGraphic(k,c,indH)
    local i=1
    local j=65
    context.startuseMPgraphic(name)
    context("boxjoin(a.se=b.sw; a.ne=b.nw);")
    while k[i] do
        bname=string.char(j)
        context("boxit."..bname.."(btex "..k[i].." etex)("..c[i]..");drawboxed("..bname..");")
        i=i+1
        j=j+1
    end
     context.stopuseMPgraphic()
    context.useMPgraphic(name)
end

a={51,31,4,22,23,45,23,43,54,22,11,34}
colors={"blue","blue","blue","blue","blue","blue","blue","blue","blue","white","white","white"}
createGraphic(a,colors)

输出为

现在我想动态更改颜色并createGraphic()循环调用。所以我编写了以下函数来更改颜色数组。

function refreshColors(yellowEndIndex,redIndex,blueIndex)
        print(yellowEndIndex..","..redIndex..","..blueIndex)
        local ccnt=1
        while a[ccnt] do
                if ccnt < yellowEndIndex then
                    colors[ccnt] = "yellow"
                elseif ccnt == redIndex then
                    colors[ccnt] = "red"
                elseif ccnt == blueIndex then
                    colors[ccnt] = "blue"
                else
                    colors[ccnt] = "white"
                end
                ccnt= ccnt+1
        end
end
refreshColors(2,4,6)
createGraphic(a,colors)

现在,输出是

另外,当我refreshColors()在循环内和createGraphic()外部调用时,没有错误。

for i=1,10,1 do
    refreshColors(i,0,0)
end
createGraphic(a,colors)

现在输出是

但是,当我调用createGraphic()内部循环时,会发生错误。

for i=1,10,1 do
    refreshColors(i,0,0)
 createGraphic(a,colors)
end

Texworks 抛出的错误消息是

error on line 33 in file try.tex: terminal: ! Inconsistent equation (off by -1).

第 33 行是

colors[ccnt] = "red"

以下是盒子.mp在程序中使用。

我想在createGraphic()循环内部调用。为什么会出现错误?

答案1

问题一定出boxes.mp 在宏中boxit,替换

@#col = cellColor;

@#col := cellColor;

这可能会让它起作用......

相关内容