Pref::output

Modify the screen output of objects

MuPAD® notebooks will be removed in a future release. 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.

Syntax

Pref::output(f)
Pref::output(NIL)

Description

Pref::output allows to modify the screen output of objects returned by the MuPAD® kernel.

When the MuPAD kernel returns a result x, say, of a computation, the function f is called before the result is printed to the screen. Instead of x, the return value f(x) is used as screen output of the computation.

Make sure that a user-defined output function f processes arbitrary MuPAD objects.

The call Pref::output(NIL) resets the output function to the identity map: the screen output coincides with the object returned by the computation. NIL is the default value of the output function.

Examples

Example 1

All numbers of type Type::Numeric shall be displayed as floating point numbers. Since the kernel may return sequences of objects, the output function may be called with an unknown number of parameters. It uses map to apply its functionality to all of its arguments. Whenever a numerical object of type Type::Numeric is encountered, it is replaced by a floating-point approximation:

f := proc(x) 
begin
  if args(0) > 1 then
       return(map(args(), f))
  end_if;
  if testtype(x, Type::Numeric) then
       return(float(x))
  else return(x)
  end_if;
end_proc:
Pref::output(f):
4/9; sin(3); 4/9, sin(3), 1/2 + 17*I

We restore the standard mode:

Pref::output(NIL): delete f:

Example 2

The procedure generate::TeX is applied to the result of a computation. The corresponding TeX code (a string) is displayed:

Pref::output(generate::TeX):
sqrt(x^2 - 1/x)

We restore the standard mode:

Pref::output(NIL):

Parameters

f

The “output function”: a procedure

Return Values

Previously defined “output function”, or NIL.