Repository navigation
|
I have a function which generates a row of nodes for use in LaTex. local function generate_row_of_nodes(index, columns)
local nodes = {}
for j = 1, columns-1 do
table.insert(nodes, i(j, tostring(j)))
table.insert(nodes, t(" & "))
end
table.insert(nodes, i(columns, tostring(columns)))
table.insert(nodes, t(" \\\\"))
return sn(index, nodes)
endI have another function, which uses the previous function, that generates a table of nodes. local function generate_table_of_nodes(rows, columns, indent_string)
local nodes = {}
for j = 1, rows-1 do
table.insert(nodes, generate_row_of_nodes(j, columns))
table.insert(nodes, t({"", ""}))
end
table.insert(nodes, generate_row_of_nodes(rows, columns))
return isn(nil, nodes, "$PARENT_INDENT\t" .. indent_string)
endUsing these two functions, I create a table environment snippet as shown below. I notice that when using s(
{ trig = "(%d+)x(%d)table", dscr = "table", regTrig = true },
fmta(
[[
\begin{table}[h]
\centering
\begin{tabular}{<>}
\hline
<>
\hline
<>
\hline
\end{tabular}
\caption{<>}
\label{tbl:<>}
\end{table}
]],
{
f(function(_, snip)
return string.rep("|c", tonumber(snip.captures[2]) - 1) .. "|c|"
end),
d(1, function(_, snip)
return generate_row_of_nodes(nil, snip.captures[2])
end),
d(2, function(_, snip)
return generate_table_of_nodes(snip.captures[1], snip.captures[2], "\t")
end),
i(3, "caption"),
i(4, "label"),
}
)
) |
Answered by
L3MON4D3
Jul 16, 2023
Replies: 1 comment 13 replies
|
Pretty sure its just that one of these indices is wrong.. Have you tried adding some |
13 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So
tonumberon those should do it (AFAIK lua does this automatically, sometimes, but we don't check that the index is actually a number)