### The Maxima on-line user's manual

Algebra Calculator

#### Printf

Function: printf (<dest>, <string>)

Function: printf (<dest>, <string>, <expr_1>, ..., <expr_n>) Makes the Common Lisp function FORMAT available in Maxima. (From gcl.info: "format produces formatted output by outputting the characters of control-string string and observing that a tilde introduces a directive. The character after the tilde, possibly preceded by prefix parameters and modifiers, specifies what kind of formatting is desired. Most directives use one or more elements of args to create their output.")

The following description and the examples may give an idea of using `printf`. See a Lisp reference for more information.

~% new line ~& fresh line ~t tab ~\$ monetary ~d decimal integer ~b binary integer ~o octal integer ~x hexadecimal integer ~br base-b integer ~r spell an integer ~p plural ~f floating point ~e scientific notation ~g ~f or ~e, depending upon magnitude ~h bigfloat ~a uses Maxima function string ~s like ~a, but output enclosed in "double quotes" ~~ ~ ~< justification, ~> terminates ~( case conversion, ~) terminates ~[ selection, ~] terminates ~{ iteration, ~} terminates

Note that the selection directive `~[` is zero-indexed. Also note that the directive ~* is not supported.

```          (%i1) printf( false, "~a ~a ~4f ~a ~@r",
"String",sym,bound,sqrt(12),144), bound = 1.234;
(%o1)                 String sym 1.23 2*sqrt(3) CXLIV
(%i2) printf( false,"~{~a ~}",["one",2,"THREE"] );
(%o2)                          one 2 THREE
(%i3) printf(true,"~{~{~9,1f ~}~%~}",mat ),
mat = args(matrix([1.1,2,3.33],[4,5,6],[7,8.88,9]))\$
1.1       2.0       3.3
4.0       5.0       6.0
7.0       8.9       9.0
(%i4) control: "~:(~r~) bird~p ~[is~;are~] singing."\$
(%i5) printf( false,control, n,n,if n=1 then 0 else 1 ), n=2;
(%o5)                    Two birds are singing.```

If <dest> is a stream or `true`, then `printf` returns `false`. Otherwise, `printf` returns a string containing the output.

There are also some inexact matches for `printf`. Try `?? printf` to see them.

```(%o1)                                true
(%i2) ```

### Related Examples

##### printf

printf(false,"~4f",50...

Calculate

##### printf

/* Definintion von zw...

b:[false,false,true,t...

/* Definition einer V...

Calculate

##### printf

printf(false,"~e",51/...

Calculate

##### printf

printf(false,"~3f",50...

printf(false,"~,2h",5...

Calculate

##### printf

printf(false, "~x", 1...

Calculate

##### printf

x:123.4567;

printf(false,"~1f",x);

printf(false,"~2f",x);

Calculate

##### printf

printf(false,"~6g",51...

Calculate

##### printf

printf(false,"~g",50/...

Calculate

##### printf

x:123.4567;

printf(false,"~1f",x);

printf(false,"~2f",x);

Calculate

##### printf

printf(false,"~g",51/...

Calculate