3

When I write notes by hand, if I want to box an equation, I usually do it in the following way. I find the lowest (highest) point of the equation, I go a little bit higher (lower) and take a line, cutting it a little before and after the aforementioned point. If there are more than one extrema of equal height I do it for all of them (pic related). enter image description here

Is there any way to do this in LaTeX? (for example with TikZ I guess)

  • Welcome to TeX.SX! Short answer: Package tcolorbox provides boxes like \tcbhighmath or \tcbboxmath for such thing. And please always add a minimal but working example (MWE) of what you already have. – Schweinebacke May 18 '17 at 12:02
  • @Schweinebacke tcolorbox's boxes you suggested do not do what I asked for. You probably didn't even read the question. I knew about tcolorbox but I also knew it wasn't satisfying. And for MWE; wouldn't it be the same (if not worse, for cluttering the question) to provide a MWE with a simple colorbox around an equation? – Rrose Sélavy May 18 '17 at 12:13
7

EDITED to turn it into a macro. Took Dai's suggestion to add a \strut, to account for squat equations.

\documentclass{article}
\usepackage{xcolor,stackengine}
\newcommand\redbox[1]{%
  \fboxsep=-2pt
  \def\tmp{\displaystyle\strut #1}
  \def\shadow{\makebox[.4pt]{$\tmp$}}
  \stackengine{0pt}{%
    \stackengine{0pt}{%
      \textcolor{red}{\fbox{~~$\phantom{\tmp}$~~}}%
    }{\color{white}\shadow\shadow\shadow\shadow\shadow\shadow\shadow%
      \shadow\shadow\shadow\shadow}{O}{c}{F}{F}{L}%
  }{$\tmp$}{O}{c}{F}{F}{L}
}
\begin{document}
\[
\redbox{z(t) = \int D\vec m e^{-\int d^\alpha x
 \Phi[...]}}
\]
\[
\redbox{y = \int_0^\tau e^t dt}
\]
\[
\redbox{x = y + z}
\]
\end{document}

enter image description here

  • renamed the macro to radbox in my file. Thanks :D – Rrose Sélavy May 18 '17 at 12:20
  • 1
    Possibly using \fbox{~~$\phantom{\strut\tmp}$~~} would be desirable (e.g. \redbox{x=y+z} without the \strut is boxed rather tighter than likely to be preferable). – Dai Bowen May 18 '17 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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