Chapter 5
Pretty Output and Tex Commands

There are 2 ways of producing pretty output. The most practical for a small session is described in the Pretty Output section below. The fancier way is to produce TEX displays. TEX displays can be done in several ways.

One is by using the Mathematica TEX setting features. Just follow their directions; we have installed a few special NCAlgebra features via the files NCTeX.m and NCTeXForm.m. These features are automatically loaded. If you are using a notebook and have trouble it is possibly because you do not have mma’s notebook.sty file in the correct place. That’s not an NCAlgebra problem but is between you and Mma. We did put some suggestions on this in Section 33.7.

The TEX production has been significantly improved and updated in this version of NCAlgebra. Older methods we developed for TEX which we no longer support are in the directory OBSOLETE2009.

5.1 Pretty Output

5.1.1 NCSetOutput[ optionlist,]

Aliases: None
Description: NCSetOutput displays noncommutative expressions in a special format without affecting the internal representation of the expression. For example, SetOutput[ All True] turns on all display beatifications listed below. Options are set by typing,
All True, to use the new format.
opt False, to return to the default format.
Dot True, ’**’ is displayed as ’.’(i.e., a dot)
Dot False, ’**’ defaults as ’**’
aj True, aj[ X ] is displayed as X*
aj False, aj[ X ] is displayed as aj[ X ]
inv True, inv[ X ] is displayed as X-1
inv False, inv[ X ] is displayed as inv[ X ]
tp True, tp[ X ] is displayed as XT
tp False, tp[ X ] is displayed as tp[ X ]

Examples : (Generic) SetOutput[optTrue] turns on all beautifications of the output related to the attribute opt. (One never types opt. The letters “opt” here stand for any of the listed attributes.) So, for example, one might try the command SetOutput[dotTrue, ajTrue]; aj[rt[x ** y]]

Arguments: Options are: all, dot, rt, tp, inv, aj; You may input a comma-separated sequence of options in any order without first forming a Mathematica list.
Comments / Limitations: WARNING: NCSetOutput was called SetOutput in previous versions. This syntax has now been deprecated. BEWARE: do not use with NCSimplifyRational. Also working with parts of a ”pretty output” may not work (since it changes the Head structure of the output). You can turn on or off options individually at any time. The nesting order of the final display is determined first by any NCAlgebra-defined or user-defined functions, and then by any Mathematica specified order. Only after the Out[#] is assigned are the SetOutput options applied to the OutputForm of the expression. So the internal form of the expression is NEVER altered. Nevertheless, the displayed form may be unexpected for several reasons, among them being; 1. f[g[x]] may be defined elsewhere to always display as g[f[x]]. In this case, SetOutput will display the optional forms of g[ f[x] ], not that of the inputed f[ g[x] ]. 2. Mathematica establishes precedences for functions and operations in order to minimize the overall use of parantheses. This can have unusual, but not unmanageable effects on the displayed form of an expression. For example, (x **y)2 displays as x2 **y ,but is represented internally as the equivalent of (x **y)2.

5.2 TEX Typesetting with NCTEXForm

The Mathematica program provides a command called TeXForm which can be used to output your expression generated by Mathematica into TEX format. We provide an alternative command NCTeXForm that performs the same task to basic NC constructs, through the file NCTeXForm.m. Examples of what this accomplishes are

tp[x] will have the TeX’ed form xT

aj[x] will have the TeX’ed form x*

rt[x] will have the TeX’ed form x1 2

inv[x] will have the TeX’ed form x-1.

5.2.1 NCTeXForm[exp]

Aliases: None
Description: NCTeXForm[exp] produces output that can be compiled by LATEX. It assumes the user has the package amsmath installed.
Arguments: exp is any mathematica expression or lists of expressions.
Comments / Limitations: Not available before NCAlgebra 3.9.

As you might guess if you want to add more its easy. To use this NCTeXForm.m must be loaded; thats all. These are used by NCAlgebra and NCGB. See the demos for more information.

5.3 Simple TEX Commands with NCTEX

In this section we describe some handy additional TEX display features we have added to Mathematica. These act in addition to Mathematica’s TEX setting with NCAlgebra, like TeXForm or Format[  , TeXForm]. Mathematica’s TEX conversion however does not need this and is fine with NCAlgebra, since we have added special NCAlgebra and NCGB notation to the Mathematica-to-TEX dictionary. If you are content with that, there is no reason to read this part of the document. Also the NCProcess TEX spreadsheets are automatic and are not related to this section of the document.

These are very useful commands and we recommend using them. You may have must do a little installation work to use our fancier TEX commands depending how TEXis installed in your system. It should work out-of-the box on most Unix based systems. Beware that some versions of Mathematica creates TEX output that uses a specific Mathematica file called a style file (called notebook.sty). Some of the TEX produced needs to know where this file is kept. A description of how to inform TEX where this file is stored is found in Section ??.

5.3.1 NCTeX[]

Aliases: None
Description: NCTeX[exp] creates a file that contains a LATEX version of exp that gets compiled with LATEX and converted into a PDF image file. By default, if you are on a notebook environment, this file will be imported to the current notebook output. Otherwise, if it fails to be imported or if you are in text mode the output will be displayed on a pdf viewer. NCTeX has many options that can be set through the standard Mathematica SetOptions command or as rules appended to the NCTeX. The following are the available options and their default values: Verbose -> False, tells NCTex to display the details of the operations being performed; DisplayPDF -> False, controls whether a separated PDF viewer will be spawed to display the TEXed output; ImportPDF -> True, controls whether the TEXed output will be imported into a notebook; BreakEquations -> True, tells NCTEX to use the style breqn to attempt to break long equations or expressions in multiple lines; TeXProcessor -> NCTeXForm, tells NCTEX to use NCTeXForm as the command to translate exp into LATEX. Other options are PDFViewer, LaTeXCommand, PDFLaTeXCommand, DVIPSCommand, PS2PDFCommand which we try to guess correctly depending on your platform. You may have to customize those if your installation of TEX is not standard.
Arguments: exp is any mathematica expression or lists of expressions.
Comments / Limitations: Not available before NCAlgebra 3.9.

5.4 Deprecated Commands

The following commands are no longer supported in this version of NCAlgebra.

5.4.1 SeeTeX[] or SeeTeX[anInteger]

Aliases: None
Description: SeeTeX[] tells Mathematica that you would always like to have your outputs displayed in TEX. Inputting SeeTeX[] gives you additional displays which accompany the rest of your Mathematica session unless you turn off SeeTeX using the NoTeX[] (see below). Each output in your session causes a seperate window to open on the screen and this window displays the TEX version of the output. When too many TeX displays are present, Mathematica automatically makes the oldest display disappear. One can set the maximum number of TEX windows to be N which appear using SeeTeX[N]. SeeTeX[] is the same as SeeTeX[5] the first time that it is called. See also NoTeX, KillTeX and Keep.
Arguments: anInteger is an integer.
Comments / Limitations: Not available before NCAlgebra 2.1. At this time, SeeTeX is implemented by creating a directory called TeXSession. The directory TeXSession is filled with files as the session continues. The files corresponding to the k-the output are masterk.tex and outk.tex. The file masterk.tex is boring. The file outk.tex contains the TEX for the output Out[k]. See also the command SeeTex. These files are kept until the KillTeX[] command (§5.4.3) is invoked or until you reload NCAlgebra.m. BEWARE LOADING NCAlgebra.m AUTOMATICALLY DELETES THE DIRECTORY Also, the directory contains a few dvi files and the windows are produced automatically by running xdvi on masterk.dvi. When the TeX windows are removed automatically, the corresponding dvi file is automatically removed. The function Keep[k] (§5.4.5) prevents masterk.dvi and the associated window from being deleted.

5.4.2 NoTeX[]

Aliases: None
Description: NoTeX[] tells Mathematica to stop putting windows on the screen.
Arguments: None
Comments / Limitations: Not available before NCAlgebra 2.1. The command NoTeX[] stops TeX files from being added to the directory TeXSession. It does not remove any files from the directory TeXSession. BUG: If one does SeeTeX[4], then puts up 4 windows, then NoTeX[], then SeeTeX[], the program forgets that the 4 windows are there.

5.4.3 KillTeX[]

Aliases: None
Description: KillTeX[] removes all of the files in the directory TeXSession. See also SeeTeX(§5.4.1)
Arguments: No arguments
Comments / Limitations: Not available before NCAlgebra 2.1

5.4.4 See[aListOfIntegers]

Aliases: None
Description: See[aListOfIntegers]
Arguments: See[aListOfIntegers] allows one to create a TEX file which displays multiple Out statements. For example, See[{5,14,9}] creates a window with Out[5]=, followed by the TEX form of Out[5],Out[14]=, followed by the TEX form of Out[14], Out[9]=, followed by the TEX form of Out[9]
Comments / Limitations: aListOfIntegers is a list of integers

Not available before NCAlgebra 2.1 If the See[{5,14,9}] command is invoked as the 19th command (e.g., In[19] := See[{5,14,9}]), then the TeXed formulas Out[5], Out[14] and Out[19] will be in the file master19.tex. This might help a user in writing a paper based on the session, since it can be used to bring together important formulas. This command requires that the SeeTeX be called before the use of See.

5.4.5 Keep[anInteger]

Aliases: None
Description: Keep[anInteger] tells Mathematica that it should not automatically destroy the window corresponding to the anIntegerth output.
Arguments: anInteger is an integer.
Comments / Limitations: Not available before NCAlgebra 2.1. The file masterk.dvi is also kept. The TeX files are always kept whether or not you invoke Keep (WARNING: See KillTeX (§5.4.3)).. This command requires that the SeeTeX be called before the use of “See”.

5.4.6 Kill[anInteger]

Aliases: None
Description: Kill[anInteger]
Arguments: Kill[k] removes the window and the dvi file corresponding to Out[k].
Comments / Limitations: Not available before NCAlgebra 2.1. The file masterk.dvi is deleted. This command requires that the SeeTeX be called before the use of the command “See”.

The following two commmands require the loading of the file Extra.TeXForm.

5.4.7 LookAtMatrix[aMatrix]

Aliases: None
Description: LookAtMatrix[aMatrix] takes the Mathematica matrix aMatrix, converts it to TEX outputs the string and surrounding LATEXto a file, TeXs the file and displays the TeXed output to the screen using the program dvipage (this can be easily changed to other previewers such as xdvi or xpreview).
Arguments: aMatrix is a matrix.
Comments / Limitations: Must have loaded the file Extra.TeXForm

5.4.8 LookAtLongExpression[anExpression]

Aliases: None
Description: LookAtLongExpression[anExpression] takes the Mathematica expression anExpression, converts it to TEX outputs the string and surrounding LATEXto a file, TeXs the file and displays the TeXed output to the screen using the program dvipage (this can be easily changed to other previewers such as xdvi or xpreview).
Arguments: anExpression is an expression
Comments / Limitations: Must have loaded the file Extra.TeXForm