#set ($figureBlock = $latex.block)
#set ($discard = $latex.tool.getStack('isInContainerAcceptingStandalone').push(true))


#set ($environmentName = $latex.tool.escape($latex.tool.figureTool.getFigureEnvironment($figureBlock)))
## We limit the parameter value to inline content to avoid introducing content not supported inside the parameters.
## Note: getInlineDescendants() doesn't ensure that the conversion to LaTeX will result in some valid content as
## an environment parameter (that will depend on then environment and what it supports).
#set ($environmentParameter = $latex.tool.figureTool.getFigureEnvironmentParameter($figureBlock))
#set ($plainTextDescendants = $latex.tool.getInlineDescendants($environmentParameter))
#set ($figureEnvironmentParameter = $stringtool.trim($latex.processor.process($plainTextDescendants)))
#if ("$!figureEnvironmentParameter" != '')
  #set ($figureEnvironmentParameter = "[${figureEnvironmentParameter}]")
#end
## The following code supports different types of environments:
## - "figure" environment, in this case $figureEnvironmentParameter represents the figure placement string (H, b, etc)
## - custom environment defined in the Preamble (possibly added there through the "Preamble after" UIXP). In this case,
##   $figureEnvironmentParameter can represent anything. For example, the Figure LaTeX and Numbered Content Extensions
##   use it as the caption (by overriding the DefaultFigureTool component).
\begin{$environmentName}$figureEnvironmentParameter
$latex.processor.process($latex.block.getChildren())
\end{$environmentName}##
#set ($discard = $latex.tool.getStack('isInContainerAcceptingStandalone').pop())