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 have defined a command as follows

\newsavebox{\textsix}

\newcommand{\bottomr}[1]{\sbox{\textsix}{\parbox{11cm}{\begin{flushright} #1
\end{flushright}}}}

which save the parameter (text) of the command \bottomr to a \sbox, That can be used with \usebox{\textsix}

I would like to convert it to an environment like

\newsavebox{\textsix}
\newenvironment{bottomr}{ }{ }

which capture the text inside bottomr environment and save it to a \sbox Approximate like this

\documentclass[a4paper{article}
\usepackage{lipsum}

\begin{document}
\newsavebox{\textsix}
\newenvironment{bottomr}{?}{?}
\begin{bottomr}
\lipsum[1]
\end{bottomr}

\usebox{\textsix}
\end{document}
share|improve this question
    
Seems that environ package should be able to do what you want. –  A.Ellett Jul 17 at 17:45
1  

2 Answers 2

up vote 8 down vote accepted

The environment form of \sbox is environment lrbox. Environment minipage can be used instead of the command \parbox. Environment flushright is not necessary, because there is the command form \raggedleft.

\documentclass[a4paper]{article}
\usepackage{lipsum}

\begin{document}
\newsavebox{\textsix}

\newenvironment{bottomr}{%
  \begin{lrbox}{\textsix}%
  \begin{minipage}{11cm}%
  \raggedleft
}{%
  \end{minipage}%
  \end{lrbox}%
  % export box register setting outside the scope of the environment
  \global\setbox\textsix=\copy\textsix
}
\begin{bottomr}
\lipsum[1]
\end{bottomr}

\usebox{\textsix}
\end{document}

Result

share|improve this answer

Following some guidelines from How can I collect the contents of a LaTeX environment in a macro without the grouping?, here is an environ approach:

enter image description here

\documentclass{article}
\usepackage{lipsum,environ}

\newsavebox{\textsix}
\NewEnviron{bottomr}[1][11cm]{%
  \expandafter\gdef\expandafter\envBODY\expandafter{\BODY}% Store body
  \gdef\dolaterbottomr{\savebox\textsix{\parbox{#1}{\raggedleft\strut\envBODY\strut}}}
  \aftergroup\dolaterbottomr%
}

\begin{document}
\begin{bottomr}
\lipsum*[2]
\end{bottomr}

\lipsum*[1]\strut

\usebox{\textsix}

\lipsum[3]
\end{document}

I've added an optional argument specifying the width of the \parbox (default is 11cm), as well as some \struts to manage baselines at the start/end of paragraph(s). I don't know whether this is necessary.

share|improve this answer

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.