As mentioned in the comments, you don't directly define either commands or environments with xtemplate
. You probably want to use xparse
for that. Although I suppose you logically could define a separate template or instance for the ending part, I'm having trouble envisioning a use case for that. When are you going to need to have different parameters for the beginning and and of the environment?
The way I use template instances within environments is to have the code in \DeclareTemplateCode
handle the initialization at the beginning of the environment and then create a separate function to handle the closing. Then your environment defined with xparse
can just call those two functions, which is in keeping with the expl3
philosophy of keeping the user interface separate from the coding layer.
Here's an illustration:
\documentclass{article}
\usepackage{xparse,xtemplate}
\usepackage{lineno}
\usepackage{lipsum}
\ExplSyntaxOn
\DeclareObjectType{test}{0}
\DeclareTemplateInterface{test}{default}{0}
{
linenum-modulus : code = 5
}
\DeclareTemplateCode{test}{default}{0}
{
linenum-modulus = \modulolinenumbers[#1]
}
{
\AssignTemplateKeys
% just something for illustration
\linenumbers
}
\cs_new_protected:Nn \smith_testme_stop:
{
% Do cleanup here
}
\DeclareInstance{test}{first}{default}{}
\NewDocumentEnvironment{testme}{}
{
\UseInstance{test}{first}
}
{
\smith_testme_stop:
}
\ExplSyntaxOff
\begin{document}
\begin{testme}
\lipsum[1]
\end{testme}
\lipsum[2]
\end{document}
xtemplate
. This package provides commands likeUseInstance
, which can be used for creating both commands and environments. "Creating things" itself, should be done viaxparse
.