How to print out equations in Mathematica
How do I define that a formula should not be computed, but rather di开发者_C百科splayed in Traditional format? Here are 2 examples, where the first one is displayed like I want it, but the second one is simplified.
Print["5. ", Limit[f[x]/g[x], x -> a], "=", Limit[f[x], x -> a]/Limit[g[x], x -> a], ", where ", Limit[g[x], x -> a] != 0];
Print["7. ", Limit[c, x -> a], "=", c]
Use HoldForm to print an expression without evaluating it.
Print["7. ", HoldForm[Limit[c, x -> a]], "=", c]
(* /* ^^^^^^^^ */ *)
It depends a little bit on exactly what you want to do, but if you're just writing text, don't use Print
. Instead, enter the text directly, making sure you are using a Text
cell and not an Input
cell. In the menu, select:
Format -> Style -> Text
Then type out what you want, like:
5. Limit[f[x]/g[x], x -> a] == Limit[f[x], x->a]/Limit[g[x], x -> a] where ...
Select the expression you want to convert to TraditionalForm
and then in the menu again, select:
Cell -> ConvertTo -> TraditionalForm
... and you should get something like this:
You might also find the screencast on typesetting useful: http://www.wolfram.com/broadcast/screencasts/howtoentermathematicaltypesetting/
If you're actually trying to produce TraditionalForm output programmatically (e.g., with Print
) you might consider using Row
and TraditionalForm
with HoldForm
:
Print[Row[{
"5. ",
TraditionalForm[HoldForm[
Limit[f[x]/g[x], x -> a] == Limit[f[x], x -> a]/Limit[g[x], x -> a]]],
" where ..."
}]]
If I undestand you correctly -- you don't want Limit[c, x -> a] to be evaluated. Standart way to stop something from evaluation is to use "Hold".
Print["7. ", Hold[Limit[c, x -> a]], "=", c]
But the result is not good:
7. Hold[Limit[c, x -> a]] = c
The HoldForm command does the trick -- it holds evaluation but doesn't show up:
Print["7. ", HoldForm[Limit[c, x -> a]], "=", c]
7. Limit[c, x -> a] = c
精彩评论