### 13.4 Functions and Variables for TeX Output

Note that the built-in TeX output functionality of wxMaxima makes no use of the functions described here but uses its own implementation instead.

Function: tex
`tex` (expr)
`tex` (expr, destination)
`tex` (expr, false)
`tex` (label)
`tex` (label, destination)
`tex` (label, false)

  Prints a representation of an expression suitable for the TeX document preparation system. The result is a fragment of a document, which can be copied into a larger document but not processed by itself.

  `tex (expr)` prints a TeX representation of expr on the console.

  `tex (label)` prints a TeX representation of the expression named by label and assigns it an equation label (to be displayed to the left of the expression). The TeX equation label is the same as the Maxima label.

  destination may be an output stream or file name. When destination is a file name, `tex` appends its output to the file. The functions `openw` and `opena` create output streams.

  `tex (expr, false)` and `tex (label, false)` return their TeX output as a string.

  `tex` evaluates its first argument after testing it to see if it is a label. Quote-quote `''` forces evaluation of the argument, thereby defeating the test and preventing the label.

  See also `tex1` and `texput`.

  Examples:

      (%i1) integrate (1/(1+x^3), x);
                                          2 x - 1
                        2            atan(-------)
                   log(x  - x + 1)        sqrt(3)    log(x + 1)
      (%o1)      - --------------- + ------------- + ----------
                          6             sqrt(3)          3
      (%i2) tex (%o1);
      $$-{{\log \left(x^2-x+1\right)}\over{6}}+{{\arctan \left({{2\,x-1
       }\over{\sqrt{3}}}\right)}\over{\sqrt{3}}}+{{\log \left(x+1\right)
       }\over{3}}\leqno{\tt (\%o1)}$$
      (%o2)                          (\%o1)
      (%i3) tex (integrate (sin(x), x));
      $$-\cos x$$
      (%o3)                           false
      (%i4) tex (%o1, "foo.tex");
      (%o4)                          (\%o1)

  `tex (expr, false)` returns its TeX output as a string.

      (%i1) S : tex (x * y * z, false);
      (%o1) $$x\,y\,z$$
      (%i2) S;
      (%o2) $$x\,y\,z$$

  Categories:TeX output ·File output ·

Function: tex1 (e)

  Returns a string which represents the TeX output for the expressions e. The TeX output is not enclosed in delimiters for an equation or any other environment.

  See also `tex` and `texput`.

  Examples:

      (%i1) tex1 (sin(x) + cos(x));
      (%o1)                     \sin x+\cos x

Function: texput
`texput` (a, s)
`texput` (a, f)
`texput` (a, s, operator_type)
`texput` (a, [s_1, s_2], matchfix)
`texput` (a, [s_1, s_2, s_3], matchfix)

  Assign the TeX output for the atom a, which can be a symbol or the name of an operator.

  `texput (a, s)` causes the `tex` function to interpolate the string s into the TeX output in place of a.

  `texput (a, f)` causes the `tex` function to call the function f to generate TeX output. f must accept one argument, which is an expression which has operator a, and must return a string (the TeX output). f may call `tex1` to generate TeX output for the arguments of the input expression.

  `texput (a, s, operator_type)`, where operator_type is `prefix`, `infix`, `postfix`, `nary`, or `nofix`, causes the `tex` function to interpolate s into the TeX output in place of a, and to place the interpolated text in the appropriate position.

  `texput (a, [s_1, s_2], matchfix)` causes the `tex` function to interpolate s_1 and s_2 into the TeX output on either side of the arguments of a. The arguments (if more than one) are separated by commas.

  `texput (a, [s_1, s_2, s_3], matchfix)` causes the `tex` function to interpolate s_1 and s_2 into the TeX output on either side of the arguments of a, with s_3 separating the arguments.

  See also `tex` and `tex1`.

  Examples:

  Assign TeX output for a variable.

      (%i1) texput (me,"\\mu_e");
      (%o1)                         \mu_e
      (%i2) tex (me);
      $$\mu_e$$
      (%o2)                         false

  Assign TeX output for an ordinary function (not an operator).

      (%i1) texput (lcm, "\\mathrm{lcm}");
      (%o1)                     \mathrm{lcm}
      (%i2) tex (lcm (a, b));
      $$\mathrm{lcm}\left(a , b\right)$$
      (%o2)                         false

  Call a function to generate TeX output.

      (%i1) texfoo (e) := block ([a, b], [a, b] : args (e),
        concat("\\left[\\stackrel{",tex1(b),"}{",tex1(a),"}\\right]"))$
      (%i2) texput (foo, texfoo);
      (%o2)                        texfoo
      (%i3) tex (foo (2^x, %pi));
      $$\left[\stackrel{\pi}{2^{x}}\right]$$
      (%o3)                         false

  Assign TeX output for a prefix operator.

      (%i1) prefix ("grad");
      (%o1)                         grad
      (%i2) texput ("grad", " \\nabla ", prefix);
      (%o2)                        \nabla
      (%i3) tex (grad f);
      $$ \nabla f$$
      (%o3)                         false

  Assign TeX output for an infix operator.

      (%i1) infix ("~");
      (%o1)                           ~
      (%i2) texput ("~", " \\times ", infix);
      (%o2)                        \times
      (%i3) tex (a ~ b);
      $$a \times b$$
      (%o3)                         false

  Assign TeX output for a postfix operator.

      (%i1) postfix ("##");
      (%o1)                          ##
      (%i2) texput ("##", "!!", postfix);
      (%o2)                          !!
      (%i3) tex (x ##);
      $$x!!$$
      (%o3)                         false

  Assign TeX output for a nary operator.

      (%i1) nary ("@@");
      (%o1)                          @@
      (%i2) texput ("@@", " \\circ ", nary);
      (%o2)                         \circ
      (%i3) tex (a @@ b @@ c @@ d);
      $$a \circ b \circ c \circ d$$
      (%o3)                         false

  Assign TeX output for a nofix operator.

      (%i1) nofix ("foo");
      (%o1)                          foo
      (%i2) texput ("foo", "\\mathsc{foo}", nofix);
      (%o2)                     \mathsc{foo}
      (%i3) tex (foo);
      $$\mathsc{foo}$$
      (%o3)                         false

  Assign TeX output for a matchfix operator.

      (%i1) matchfix ("<<", ">>");
      (%o1)                          <<
      (%i2) texput ("<<", [" \\langle ", " \\rangle "], matchfix);
      (%o2)                [ \langle ,  \rangle ]
      (%i3) tex (<<a>>);
      $$ \langle a \rangle $$
      (%o3)                         false
      (%i4) tex (<<a, b>>);
      $$ \langle a , b \rangle $$
      (%o4)                         false
      (%i5) texput ("<<", [" \\langle ", " \\rangle ", " \\, | \\,"],
            matchfix);
      (%o5)           [ \langle ,  \rangle ,  \, | \,]
      (%i6) tex (<<a>>);
      $$ \langle a \rangle $$
      (%o6)                         false
      (%i7) tex (<<a, b>>);
      $$ \langle a \, | \,b \rangle $$
      (%o7)                         false

  Categories:TeX output ·

Function: get_tex_environment (op)
Function: set_tex_environment (op, before, after)

  Customize the TeX environment output by `tex`. As maintained by these functions, the TeX environment comprises two strings: one is printed before any other TeX output, and the other is printed after.

  Only the TeX environment of the top-level operator in an expression is output; TeX environments associated with other operators are ignored.

  `get_tex_environment` returns the TeX environment which is applied to the operator op; returns the default if no other environment has been assigned.

  `set_tex_environment` assigns the TeX environment for the operator op.

  Examples:

      (%i1) get_tex_environment (":=");
      (%o1) [
      \begin{verbatim}
      , ;
      \end{verbatim}
      ]
      (%i2) tex (f (x) := 1 - x);

      \begin{verbatim}
      f(x):=1-x;
      \end{verbatim}

      (%o2)                         false
      (%i3) set_tex_environment (":=", "$$", "$$");
      (%o3)                       [$$, $$]
      (%i4) tex (f (x) := 1 - x);
      $$f(x):=1-x$$
      (%o4)                         false

  Categories:TeX output ·

Function: get_tex_environment_default ()
Function: set_tex_environment_default (before, after)

  Customize the TeX environment output by `tex`. As maintained by these functions, the TeX environment comprises two strings: one is printed before any other TeX output, and the other is printed after.

  `get_tex_environment_default` returns the TeX environment which is applied to expressions for which the top-level operator has no specific TeX environment (as assigned by `set_tex_environment`).

  `set_tex_environment_default` assigns the default TeX environment.

  Examples:

      (%i1) get_tex_environment_default ();
      (%o1)                       [$$, $$]
      (%i2) tex (f(x) + g(x));
      $$g\left(x\right)+f\left(x\right)$$
      (%o2)                         false
      (%i3) set_tex_environment_default ("\\begin{equation}
      ", "
      \\end{equation}");
      (%o3) [\begin{equation}
      ,
      \end{equation}]
      (%i4) tex (f(x) + g(x));
      \begin{equation}
      g\left(x\right)+f\left(x\right)
      \end{equation}
      (%o4)                         false

  Categories:TeX output ·