Defining 'newcommand' without brackets
This is possible using TeX's \def
, where you require a specific argument text. The argument text includes both the specific sequence to be replaced, as well as the arguments in the form #X
(where X
is a number from 1
through 9
):
\documentclass{article}
\def\teststart#1\testend{left-#1-right}
\begin{document}
\teststart this is something \testend
\end{document}
If you want to allow for paragraph breaks between \teststart
and \testend
, then you need to make the definition using \long
\documentclass{article}
\long\def\teststart#1\testend{left-#1-right}
\begin{document}
\teststart this is
something \testend
\end{document}
You can define an environment this way:
\newenvironment{test}{<commands to execute at beginning}{<commands for end}
You use the environment like this:
\begin{test} bla-bla-bla \end{test}
If you want to apply a command to the contents of the environment as a whole, you can do this with the environ
package. The macro \BODY
stands for the whole body of the environment, so you can apply a command to it.
\usepackage{environ}
\NewEnviron{test}{<before>\dosomethingtobody{\BODY}<after>}
A higher level possibility is with xparse
:
\usepackage{xparse}
\NewDocumentCommand{\teststart}{+u{\testend}}{%
do something with #1%
}
The +
allows the argument to contain blank lines.