TeX command into Environment
You can use xparse
, which has many more features than environ
and doesn't need \BODY
.
I also fixed a few weaknesses in the proposed code: issuing \leavevmode
upon entering the environment helps in getting the margin note aligned in case it is at the beginning of a paragraph. Inside the \marginpar
it avoids a spurious line when \color{cyan}
is issued.
\documentclass{book}
\usepackage{xcolor}
\usepackage{xparse}
\NewDocumentEnvironment{marginnotesone}{+b}
{%
\leavevmode
\marginpar{%
\leavevmode\fontsize{9.5}{12}\selectfont\raggedright\color{cyan}#1%
}%
}%
{}
\begin{document}
\begin{marginnotesone}
The analyst must know what information is really needed, and
obtain a representative sample, pp. 6, 9
\end{marginnotesone}
The analyst must know what information is really needed, and
obtain a representative sample, pp. 6, 9
The analyst must know what information is really needed, and
obtain a representative sample, pp. 6, 9
The analyst must know what information is really needed, and
obtain a representative sample, pp. 6, 9
The analyst must know what information is really needed, and
obtain a representative sample, pp. 6, 9
\end{document}
You can use the environ
package for that. Then you merely need to replace #1
by \BODY
.
\documentclass{book}
\usepackage{xcolor}
\usepackage{environ}
\NewEnviron{marginnotesone}{\marginpar{%
\fontsize{9.5}{12}\selectfont\raggedright\textcolor{cyan}{\BODY}}}
\begin{document}
\begin{marginnotesone}
The analyst must know what information is really needed, and
obtain a representative sample, pp. 6, 9
\end{marginnotesone}
The analyst must know what information is really needed, and
obtain a representative sample, pp. 6, 9
The analyst must know what information is really needed, and
obtain a representative sample, pp. 6, 9
The analyst must know what information is really needed, and
obtain a representative sample, pp. 6, 9
The analyst must know what information is really needed, and
obtain a representative sample, pp. 6, 9
\end{document}