Guy Rutenberg

Keeping track of what I do

Add Explanation to LaTeX Formulas (Equations)

with 4 comments

When writing a document that contains mathematics, many time the need to add an explanation (e.g. stating the theorem used) is raised. To answer this need I wrote two short LaTeX macros: \explain and \explainup.

\newcommand{\explain}[2]{\underset{\mathclap{\overset{\uparrow}{#2}}}{#1}}
\newcommand{\explainup}[2]{\overset{\mathclap{\underset{\downarrow}{#2}}}{#1}}

This macros add the explanation below and above the formula.
The first argument is the relation (actually it can be anything) that needs be explained, for example =. The second argument is the actual explanation.

The macros depend on the mathtools package by

Example

\documentclass{article}
\usepackage{mathtools}
\makeatletter
 
\newcommand{\explain}[2]{\underset{\mathclap{\overset{\uparrow}{#2}}}{#1}}
\newcommand{\explainup}[2]{\overset{\mathclap{\underset{\downarrow}{#2}}}{#1}}
 
\makeatother
\begin{document}
 
\[
	U_x\explain{=}{\textrm{C.-R.}}V_y\explainup{\geq}{V(x,y)=ye^x}0
\]
 
\end{document}

Will result in

explain-macro.png

Written by Guy

January 4th, 2008 at 8:28 pm

Posted in LaTeX

Tagged with

4 Responses to 'Add Explanation to LaTeX Formulas (Equations)'

Subscribe to comments with RSS or TrackBack to 'Add Explanation to LaTeX Formulas (Equations)'.

  1. Nice one, txs for this.

    Kiran SIngh

    17 Apr 08 at 02:15

  2. That’s grate, Thanks!

    But, do you know how I do the following:
    \left(\explain{\frac{a}{b}}{\mbox{{\rm The brace wont expand!}}}+c\right)

    Here, the () Don’t take the width of the “math” part (without the text in the “explain”) but.. the hight of the explain block (the arrow and the text). Except the ugliness, it make the text unreadable – He intersect with the ( ).
    Do you know how I prevent the () to raise?

    Thanks,
    Ronen.

    Ronen

    15 Feb 09 at 09:26

  3. Hi Ronen,

    A quick solution would be to use manual brace size

    \bigg(\explain{\frac{a}{b}}{\mbox{{\rm The brace wont expand!}}}+c\bigg)

    I currently don’t have a better solution, as the explain environment must be have its full size (or else multiple lines will be clamped together), but the width of the description must be declared as zero (so no extra space will be introduced).

    Guy

    15 Feb 09 at 10:02

  4. Thanks.

    Ronen

    16 Feb 09 at 22:14

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>