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.

I want to create an environment that wraps the content in a command so that I can write this:

\begin{mybox}
  content
\end{mybox}

and get this:

\psshadowbox{content}

When doing it as a custom command it's no problem because everything is defined in the same block, but since custom environments are defined over two blocks I'd have to put the closing brace for the command in another block than the starting brace which obviously doesn't work:

\newenvironment{mybox}
{ \psshadowbox{ }
{ }             }

The reason I don't want to use a command for this is mainly readability, because the content can get quite long and a mere closing brace just isn't very expressive.

share|improve this question

3 Answers 3

up vote 6 down vote accepted

You need to store the content first into a box and then use the box with the command:

\newenvironment{mybox}{%
   \begin{lrbox}{0}%
}{%
   \end{lrbox}%
   \psshadowbox{\usebox0}%
}

You can also use the adjustbox package/environment for this:

\begin{adjustbox}{precode=\psshadowbox}
 ...
\end{adjustbox}
share|improve this answer

You can also use the package framed to allow page breaks:

\documentclass[a4paper,12pt]{article} 
\usepackage{xcolor}
\usepackage{framed}
\usepackage{pstricks}
\newenvironment{mybox}{%
  \def\FrameCommand{\psshadowbox}%
  \MakeFramed {\FrameRestore}}%
 {\endMakeFramed}
\usepackage{lipsum}
\begin{document}
\begin{mybox}
\lipsum
\end{mybox}
\end{document}
share|improve this answer

In general you can also use the environ package which provides the content of the environment in \BODY, which can be passe to a macro:

enter image description here

\documentclass{article}
\usepackage{environ}

\newcommand{\MyMacro}[1]{MyMacro = #1}%

\NewEnviron{mybox}{%
    \MyMacro{\BODY}%
}{}%

\begin{document}
\begin{mybox}
  content
\end{mybox}
\end{document}

For your specific application with \psshadow:

enter image description here

% !TEX program = xelatex
\documentclass{article}
\usepackage{pstricks}
\usepackage{environ}

\newcommand{\MyMacro}[1]{\psshadowbox{#1}}%

\NewEnviron{mybox}{%
    \MyMacro{\BODY}%
}{}%

\begin{document}
\begin{mybox}
  content
\end{mybox}
\end{document}
share|improve this answer
    
ah now that's how environment definitions should've worked to begin with! only problem is it doesn't seem to support line breaks and lists. fixed it by wrapping the \BODY in a minipage though. –  estolua Jun 4 '12 at 10:30

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.