GeneralUse unbalanced brackets in /newenvironment

LaTeX specific issues not fitting into one of the other forums of this category.
kostka
Posts: 11
Joined: Tue Sep 15, 2009 3:53 am

Use unbalanced brackets in /newenvironment

Post by kostka »

Okay, this seems to work perfectly:

Code: Select all

\documentclass{minimal}

\usepackage{fancybox}

\newlength{\boxedeqnlen}
\newenvironment{equationbox}{\vspace{1em}\\%
\begin{Sbox}\setlength{\boxedeqnlen}{\linewidth}%
\addtolength{\boxedeqnlen}{-2\fboxsep}%
\addtolength{\boxedeqnlen}{-2\fboxrule}%
\begin{minipage}{\boxedeqnlen}%
\begin{equation}}%
{\end{equation}%
\end{minipage}%
\end{Sbox}\fbox{\TheSbox}\vspace{1em}\\}

\begin{document}
If we find the value of $x$ which solves the equation
\begin{equation}
2x-1=0
\end{equation}
we obtain
\begin{equationbox}
x=\frac{1}{2}
\end{equationbox}
where we employ the use of a \textit{fraction}.

\end{document}
It behaves exactly like the equation environment as far as I can tell regarding indenting (or not indenting) the next line. It also looks good in both single space and 1.5 spaced environments. Thanks everyone! Back to thesis writing. :geek:

Side note: I couldn't get /bgroup or /egroup to work, but I can't recall the exact problem. They seem to only be substitutes for { and } in certain scenarios.

Side note 2: The main problem with lrbox is that, while it does save text, it also formats it according to the currently activated environment, so if you do something like \begin{equation}\usebox{\thebox}\end{equation}, then the text in \thebox will still be formatted in the normal text mode.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Post Reply