5

First of all, I'm sorry if this is a bit of an obvious newbie question, I've tried reading as many of the posts on here about doing this sort of thing, but was unable to get any of them to work.

I'm working on a macro which draws a vertical line down the side of some text, the following version works perfectly when used like \sbshort{Foo Bar}

\long\def\sbshort #1 {\par{\bigbreak\vbox{\hbox{\vrule\kern3.5pt\everypar{\leftskip 5pt\rightskip 2.75pt}\vbox{\noindent {#1}}}}\par}}

However when I try to use the environ package as follows:

\NewEnviron{TestEnviron}{\sbshort{\BODY}}
\begin{TestEnviron}
Foo Bar
\end{TestEnviron}

I receive the error Argument of \env@ignore has an extra }.

Marco Daniel
  • 95,681

2 Answers2

5

There is a spurious space in your definition, that could be simplified in many ways: for example

\newcommand{\sbshort}[1]{%
  \par\bigbreak
  \vbox{
    \hbox{\vrule\kern5.5pt
      \vbox{\advance\hsize-5.9pt \noindent#1\par}%
    }}\par}

However, a high level package can do the same and also allow page breaks inside your environment:

\usepackage{mdframed}
\newmdenv[
  skipabove=\bigskipamount,
  skipbelow=\bigskipamount,
  innerleftmargin=5pt,
  innerrightmargin=0pt,
  innertopmargin=0pt,
  innerbottommargin=0pt,
  rightmargin=0pt,
  topline=false,
  bottomline=false,
  rightline=false]
  {TestEnviron}
egreg
  • 1,121,712
2

I have had some problems with the usage of environ package, but I solved them the following way: Suppose we want an environment equivalent of \foobar{lorem impsum or anything}, let's say \begin{FOOBAR}lorem ipsum or anything\end{FOOBAR}

% \makeatletter because we use at-signs in the macros
\makeatletter

% The environment foobar@env only stores the \BODY in \foobar@BODY
\NewEnviron{FOOBAR@env}{\global\let\FOOBAR@BODY\BODY\relax}

% Now we define our foobar environment
\newenvironment{FOOBAR}{%
  \FOOBAR@env% at \begin{FOOBAR} we just begin FOOBAR@env
}{%
  \endFOOBAR@env% at \end{FOOBAR}, firstly end FOOBAR@env
  \foobar{\FOOBAR@BODY}% perform the command on the stored material
  \global\let\FOOBAR@BODY\@undefined% free the resources
}%

% \makeatother as the counterpart of \makeatletter
\makeatother
yo'
  • 51,322
  • What's wrong with \NewEnviron{FOOBAR}{\foobar{\BODY}}? – egreg Jan 21 '12 at 23:23
  • It simply doesn't work in some cases. There happened an error when I made something like \NewEnviron{FOOBAR}{\sbox{\mybox}{\vbox{\BODY}} ... \smash{\usebox{\mybox}}} (I don't remember the exact thing, because once I solved it, I forgot the details.) – yo' Jan 23 '12 at 13:34