Generate formatted string from expressions
MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.
MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.
generate::TeX(e
)
generate::TeX(e)
returns a TeX formatted
string representing e
. This string may be printed
to a file using fprint
.
Use the printing option Unquoted
to remove quotes
and to expand special characters like newlines and tabs.
The output string may be used in the mathmode of TeX. Note
that generate::TeX
doesn't break large formulas
into smaller ones.
generate::TeX
generates a string containing
the TeX code:
generate::TeX(hold(int)(exp(x^2)/x, x))
Use print
with
option Unquoted
to get a more readable output:
print(Unquoted, generate::TeX(hold(int)(exp(x^2)/x, x)))
\int \frac{\mathrm{e}^{x^2}}{x} \,d x
This example shows how to write a "TeX"
method
for a domain. The domain elements represent open intervals. The "TeX"
method
makes recursive use of generate::TeX
in order to
TeXformat its operands and concatenates the resulting strings to
a new string containing the TeX output of the interval.
Interval := newDomain("Interval"): Interval::TeX := e > "\\left]".generate::TeX(extop(e, 1)). ", ".generate::TeX(extop(e, 2))."\\right[": print(Unquoted, generate::TeX(new(Interval, 1, x^(a+2)))):
\left]1, x^{a + 2}\right[

An arithmetical expression 
generate::TeX
returns a string containing TeX code.
e
The TeX packages amsmath and amssymb are needed.
A domain overloading generate::TeX
has to
provide a function as its "TeX"
slot which translates
its elements into a TeX formatted string. This function may use generate::TeX
recursively.
See Example 2.