Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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 }.

share|improve this question
1  
There is a space after #1 that shouldn't be there. –  egreg Jan 20 '12 at 11:49
    
@egreg Thankyou so much! I hadn't realised that could cause a problem. It's all working perfectly now. –  Simon StJohn-Green Jan 20 '12 at 11:53
add comment

2 Answers 2

up vote 5 down vote accepted

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}
share|improve this answer
add comment

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
share|improve this answer
    
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.) –  tohecz Jan 23 '12 at 13:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.