In this page, we explain how to obtain to display your mathematical formulas with elaborate notations like the ones used in the following figure:
To extend the mathematical notations you use when working with CtCoq you need to define a new pretty printer and tell CtCoq how to use it. To define a new pretty-printer you may have to learn the PPML language that is used to write pretty-printing specifications by reading the reference manual and user guide(a 370k postscript file). However, you may avoid this by simply modifying the example "user notation" file given in the CtCoq distribution. Below, we give a short checklist of the steps to follow to add simple notations using this method. Then, we give a very short tutorial on the capabilities of the PPML language, showing how to perform basic formatting and how to use your own fonts and colors.
To make your own pretty printing specification, we suggest you use the Centaur windows to edit a PPML file starting from the example given in the tape. Follow these instructions:
<ctcoq-directory>/contrib/vernac-v10/pprinters/usernotations/vernac-usernotations.ppmlwhere <ctcoq-directory> is the directory where ctcoq is installed (if you don't know this directory, go in the xterm where you started ctcoq and type (car #:system:app-path) at the prompt
CFHC_PATT1 -> [<IDENT1 ID_NUMBER> ELEM];You can now edit the various holes of this rule to construct the notations you want, the rest of the file will provide you with examples that you can follow. If you want to introduce several rules, just click on the "->" and type <Ctrl>-A to introduce a new rule schema.
When you are happy with your specification it must be compiled and stored on disk for the display machinery to use it. You must decide where the new notation specification will be stored. Let us suppose you want to put this specification in the sub-directory "resources/special" of your home directory. In this case, you must edit your main resource file to add the following resources:
Centaur.vernac.ppml.usernotations.Location: \ resources/usernotations Centaur.vernac.ppml.usernotations.Root: user Centaur.vernac.ppml.usernotations.Mode: compiled
After this, you should save your modified specification as the file
<your-home-directory>/resources/usernotations/vernac-usernotations.ppml,
hit the option "Reset Resources" from the Centaur top menu, and
hit the "Compile" option from the "PPML" pulldown in the
editing window's menubar. You can then test your new notations by hitting the "Redraw"
option from the "Display" menu in CtCoq windows.
The PPML formalism has been in used for more than ten years in the Centaur system to write pretty printers for a variety of programming languages. It makes it possible to parameterize the line breaking policy, to use several colors and fonts, to use several display variants depending on the level of detail requested, to combine several specifications, to put parentheses only when needed, and to adapt the display mechanism to black and white screens. In this section we shall give an overview of these capabilities.
A pretty printing specification is an ordered collection of rules associating tree patterns with formatting patterns. The order in the list is relevant as it resolves the ambiguity that may exist when an expression matches two patterns. We shall see that it also plays a key role to override a old notation with a new one. Here is an instance of a pretty-printing rule for the plus function binary operator:
appc(ident 'plus',formula_ne_list(*x,*y)) -> [<hv> *x "+" *y ];
In this rule the tree pattern is the expression
appc(ident 'plus',formula_ne_list(*x,*y))
The tree patterns refer to the abstract syntax structure of the commands and expressions. For this reason, they are not written in the "regular" syntax of Coq expressions. This tree pattern matches any expression where a function is applied to two arguments. It is possible to write more complex tree patterns, like the following one that ranges over a finite case of variants:
appc(*f,formula_ne_list(*x,*y)) where *f in {ident 'plus', ident 'mult'}
To know more about the capabilities of the pattern language in PPML, you are invited to consult the PPML documentation.
The right hand side of pretty-printing rules describes boxes. a box has the form
[<hv> ...]
The brackets delimit the contents of the box, the first element of the box, <hv> denotes a separator, indicating how the various elements will be placed with respect to each other. The various possible separators are the following ones:
For any separator it is possible to omit the the arguments, thus <h>, <v>, <hv>, and <hov> are acceptable separators.
The elements of the box can be of several kinds, of which we describe only three:
in class = symbol : "\222"
in class = myclass : "\223"
Then, in the file ~/.centaur.rdb, you insert the following lines:
Centaur.formalism-vernac.Pprinter.Format.class-myclass.Foreground:\ cyan Centaur.formalism-vernac.Pprinter.Format.class-myclass.Font:\ -adobe-new century schoolbook-medium-r-normal--34-*-*-*-*-*-*-*
appc(*op,formula_ne_list(*x, *y)) where *op in {ident 'plus', ident 'mult'} -> [<hv> *x infixop::*op *y]; infixop::ident 'plus' -> [<h> "+" ]; infixop::ident 'mult' -> [<h> "*" ];
The two main sources of special characters are the "symbol" family of fonts and the characters whose codes are outside the ascii range in all other fonts. When you want to introduce a special character in your notations, you should first check what is available in these fonts. This is done by typing the following command to the Unix shell prompt:
xfd -fn -*-symbol-*-r-*-*-*-*-*-*-*-*-*
This will open a new window with the following aspect.:
By clicking on this window, you can get the octal code of the character of your choice. To choose a special character in a regular font, just type
xfd -fn -*-helvetica-*-r-*-*-*-*-*-*-*-*-*
You can also choose the size of the fonts you use by replacing the fifth star by a pixel size. To see the available pixel sizes for a given font on your X server, type the command xlsfonts at the Unix shell prompt. Once you have chosen a font, you can tell CtCoq to use it by a resource class, as described above.