This mwe:

\starttext
\startluacode
local items = {}
-- Function to wrap the item with the appropriate stackingsteps
local function wrap_with_stackingsteps(item, levelsofsolution)

-- Start building the stackingsteps command
local stacking_command = "\\startstackingsteps[1"
-- Add additional levels dynamically based on levelsofsolution
if levelsofsolution >= 2 then
stacking_command = stacking_command .. ",2"
end

if levelsofsolution >= 3 then
for i = 3, levelsofsolution do
stacking_command = stacking_command .. ",{2:" .. i .. "}"
end
end

-- Close the stackingsteps command
stacking_command = stacking_command .. "] "

-- Wrap the item with the stackingsteps environment
return stacking_command .. item .. " \\stopstackingsteps"
end

-- Function to add items to the array
local function add_item(item)
levelsofsolution = 1
if string.match(item, "\2{") then
levelsofsolution = 2
end
if string.match(item, "\3{") then
levelsofsolution = 3
end
-- Wrap the item with the appropriate stackingsteps
item = wrap_with_stackingsteps(item, levelsofsolution)

-- Add the wrapped item to the array
table.insert(items, item)

end
-- Add items
add_item("The \2{quick} brown \3{fox}.")
add_item("Jumps over the* \2{lazy} dog.")
add_item("Another string.")
-- Print items
for _, item in ipairs(items) do
context([[\type{]] .. item .. "}")
context.par() -- Add a paragraph break
end
\stopluacode
\stoptext

gives this output:

\startstackingsteps[1,2,{2:3}] The \2{quick} brown \3{fox}.\stopstackingsteps
\startstackingsteps[1,2] Jumps over the* \2{lazy} dog. \stopstackingsteps
\startstackingsteps[1] Another string. \stopstackingsteps

which looks good. If I compile this output with

\starttext
\startstackingsteps[1,2,{2:3}] The \2{quick} brown \3{fox}.\stopstackingsteps
\startstackingsteps[1,2] Jumps over the* \2{lazy} dog. \stopstackingsteps
\startstackingsteps[1] Another string. \stopstackingsteps
\stoptext

I don’t get any error. Don’t worry about the commands \2{} and \3{}, I have 
defined them (that’s outside the scope of the mwe).

If in the mwe, I replace

context([[\type{]] .. item .. "}“)

with

context(item)

I get an „runaway error: end of file encountered“. If I leave out the 
wrap_with_stackingsteps step, I don’t get the error. Can somebody help please?
Thank you.
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : [email protected] / 
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

Reply via email to