-
I have the following snippet below. I'm having a formatting issue. When the content of the second fmta block is inserted in node 2 of the first fmat block, the formatting is not respected. Here's the output I get when the snippet expands: \begin{figure}[htpb]
\centering
\begin{minipage}[b]{30\textwidth}
\includegraphics[width=\textwidth]{path}
\caption{caption}
\label{fig:label}
\end{minipage}
\hfill
\begin{minipage}[b]{30\textwidth}
\includegraphics[width=\textwidth]{path}
\caption{caption}
\label{fig:label}
\end{minipage}
\hfill
\begin{minipage}[b]{30\textwidth}
\includegraphics[width=\textwidth]{path}
\caption{caption}
\label{fig:label}
\end{minipage}
\end{figure}
The formatting I expect is: \begin{figure}[htpb]
\centering
\begin{minipage}[b]{30\textwidth}
\includegraphics[width=\textwidth]{path}
\caption{caption}
\label{fig:label}
\end{minipage}
\hfill
\begin{minipage}[b]{30\textwidth}
\includegraphics[width=\textwidth]{path}
\caption{caption}
\label{fig:label}
\end{minipage}
\hfill
\begin{minipage}[b]{30\textwidth}
\includegraphics[width=\textwidth]{path}
\caption{caption}
\label{fig:label}
\end{minipage}
\end{figure} Here's the snippet definition. s(
{ trig = "(%d+)fig", dscr = "minipage figures", regTrig = true },
fmta(
[[
\begin{figure}[<>]
\centering
<>
\end{figure}
]],
{
i(1, "htpb"),
d(2, function(_, snip)
local n_figs = tonumber(snip.captures[1])
local fig_size = tostring(math.floor (90 / n_figs))
local nodes = {}
for j = 1, n_figs do
local fig_node = sn(j,
fmta([[
\begin{minipage}[b]{<>\textwidth}
\includegraphics[width=\textwidth]{<>}
\caption{<>}
\label{fig:<>}
\end{minipage}
]],
{
t(fig_size),
i(1, "path"),
i(2, "caption"),
i(3, "label"),
}
)
)
table.insert(nodes, fig_node)
if j == n_figs then
table.insert(nodes, t({""}))
else
table.insert(nodes, t({"", "\t\\hfill", ""}))
end
end
return sn(nil, nodes)
end, nil)
}
)
), How can I ensure that the snippet is correctly formatted when it expands? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
|
Beta Was this translation helpful? Give feedback.
-
Ah, the problem should be that, unlike vscode, the indent before the |
Beta Was this translation helpful? Give feedback.
Ah, the problem should be that, unlike vscode, the indent before the
<>
is not applied to all nodes inside thefmta
placed at<>
. You can take a look atindentSnippetNode
, it will take care of applying indent to all lines.(ie. replace
sn(j, ...)
withisn(j, ..., "$PARENT_INDENT\t")
)