2
$\begingroup$

I often want to output a mathematical equation in a text environment, and I find it very cumbersome and often the result is also not satisfactory.

This example out of the "Advanced Manipulate Functionality" help page illustrates this quite well:

Manipulate[
 Row[{"(", Column[{n, m}, Center], ") = ", Binomial[n, m]}],
 {n, 1, 10, 1}, {m, 1, n, 1}]

With "cumbersome" I mean the way it is entered as Row[{"(", Column[{n, m}, Center], ") = ", Binomial[n, m]}].

With "not satisfactory" I mean, that math content is often not formatted nicely. In this example the parentheses are too small.

Isn't there a better way to display mathematical equations?

Thanks for help!

$\endgroup$
1
$\begingroup$
Manipulate[Row[{TraditionalForm @ Defer @ Binomial[##] &[n, m], " = ", Binomial[n, m]}], 
  {n, 1, 10, 1}, {m, 1, n, 1}]

enter image description here

| improve this answer | |
$\endgroup$
1
$\begingroup$

Isn't there a better way to display mathematical equations?

Nothing beats $\LaTeX$ (Sorry Wolfram :)

so that is what I would do, thanks to MaTeX package.

enter image description here

Manipulate[
 If[m > n, m = n];
 MaTeX["{" <> ToString@n <> "\\choose" <> ToString@m <> "}=" <> 
   ToString@Binomial[n, m], Magnification -> 2]
 ,
 {{n, 5, "n"}, 1, 10, 1, Appearance -> "Labeled"},
 {{m, 2, "m"}, 1, 10, 1, Appearance -> "Labeled"},
 TrackedSymbols :> {n, m}]

You can extend this to much more complicated math

enter image description here

Manipulate[
 If[from > to, from = to];
 Module[{int, int0},
  int0 = NIntegrate[integrand, {x, from, to}];

  MaTeX["
    \\begin{aligned}
    \\int_{" <> ToString@N@from <> "}^{" <> ToString@N@to <> "} " <> 
    integrandTeX
    <> " &= \\left[" <> antiTeX <> "\\right]_{" <> ToString@N@from <> 
    "}^{" <> ToString@N@to <> "}\\\\"
    <> " &= " <> ToString@int0
    <> "\\end{aligned}"
   , Magnification -> 1.2]
  ]
 ,
 {{from, 0, "from"}, 0, 10, 0.1, Appearance -> "Labeled"},
 {{to, 5.3, "to"}, 0, 10, 0.1, Appearance -> "Labeled"},
 {{antiTeX, ""}, None},
 {{integrandTeX, ""}, None},
 TrackedSymbols :> {from, to},
 Initialization :> (
   integrand = Cos[x]^2/Sqrt[Cos[x]^4 + Cos[x]^2 + 1];
   anti = Integrate[integrand, x];
   antiTeX = ToString@TeXForm@anti;
   integrandTeX = ToString@TeXForm@integrand
   )]
| improve this answer | |
$\endgroup$

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.