Typesetting Inference Rules
and other MATH formulas
in PARragraph mode
Didier Rémy
(Version v0.92, last modified 2001/23/02)
Abstract:
This package provides macros for displaying lists of formulas that are
typeset in mixed horizontal and vertical modes. The package is two-folded.
The first part is an environment mathpar
that generalizes the math
display mode to allow several formulas on the same line, and several lines
in the same display. The arrangement of the sequence of formulas into lines
is automatic depending on the line width and on a minimum inter-formula
space and line width alike words in a paragraphs (in centerline mode). A
typical application is displaying a set of type inference rules.
The second par is a macro inferrule
to typeset inference rules
themselves. Here again, both premises and conclusions are presented as list
of formulas that should be displayed in almost the same way, except that the
width is not fixed in advance; and the inference rule should use no more
width than necessary so that other inference rules are given a chance to
appear on the same line.
Although mathpar
and inferrule
look similar in their
specification, and are often used in combination, they are in fact
completely different in their implementations.
1 License
Mathpartir is Copyright (C) 2001, 2002 INRIA. Mathpartir has been developed
by Didier Rémy. Mathpartir is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at your
option) any later version. See the GNU General Public License for more
details (http://pauillac.inria.fr/~remy/license/GPL). Mathpartir is
distributed in the hope that it will be useful, but without any
warranty.
2 Note
This HTML version of the documentation can only partially
demonstrate the behavior of this package. Please refer to the
documentation in DVI format to see how the macros of this package
behave when typesetting under width constraints.
3 The mathpar environment
The mathpar environment is a ``paragraph mode for formulas''.
It allows to typeset long list of formulas putting as
many as possible on the same line:
\begin{mathpar}
A-Formula \and
Longer-Formula \and
And \and The-Last-One
\end{mathpar} |
A-Formula
Longer-Formula
And
The-Last-One |
|
Formulas are separated by \and
(or equivalently by a blank line).
To enforce a vertical break it sufficies to replace \and
by
\\
.
The implementation of mathpar
entirely relies on the paragraph mode
for text. It starts a new paragraph, and a math formula within a paragraph,
after adjusting the spacing and penalties for breaks. Then, it simply binds
\and
to something like \goodbreak
.
4 The inferrule macro
The inferrule macro is designed to typeset inference rules. It should
only1 be used in math mode (or display math mode).
The basic use of the rule is
\inferrule
{one \\ two \\ three \\ or \\ more \\ premisses}
{and \\ any \\ number \\ of \\ conclusions \\ as \\ well}
This is the rendering on a large page
one two three or more premisses |
|
|
and any number of conclusions as well |
|
However, the same formula on a narrower page will automatically be typsetted
like that:
one two three or more premisses |
|
|
and any number of conclusions as well |
|
An inference rule is mainly composed of a premisse and a conclusion.
The premisse and the conclusions are both list of formulas where the
elements are separated by \\
.
Note the dissymetry between typesetting of the premisses and of
conclusions where lines closer to the center are fit first.
A newline can be forced by adding an empty line \\\\
\inferrule
{aa \\\\ bb}
{dd \\ ee \\ ff} |
|
4.1 Single rules
Single rules are the default mode.
Rules are aligned on their fraction bar, as illustrated below:
If the premise or the conclusion is empty, then the fraction bar is not
typeset and the premise or the conclusion is centered:
\inferrule {}{aa} +
\inferrule {aa \\\\ aa}{} |
+
|
Use use { }
instead of {}
to get an axiom for instance:
\inferrule { }{aa} +
\inferrule {aa}{ } |
+
|
The macro \inferrule
acceps a label as optional argument, which will
be typeset on the top left corner of the rule:
\inferrule [yop]
{aa \\ bb}
{cc} |
|
See section 5 for changing typesetting of labels.
A label can also be placed next to the rule directly, since the rule is
centered:
\inferrule
{aa \\ bb}
{cc}
\quad (\textsc {Yop}) |
(Yop) |
4.2 Customizing
By default, lines are centerred in inference rules.
However, this can be changed by either \mprset{flushleft}
or \mprset{center}
. For instance,
$$\mprset{flushleft}
\inferrule
{a \\ bbb \\\\ ccc \\ dd}
{dd \\ ee \\ ff}$$ |
|
Note that lines are aligned independently in the premisse and the
conclusion, which are both themselves centered. In particular,
left alignment will not affect a single-line premisse or conclusion.
4.3 Derivation trees
To help writing cascades of rules forming a derivation tree, inference rules
can also be aligned on their bottom line. For this, we use the star-version:
\inferrule*
{\inferrule* {aa \\ bb}{cc}
\\ dd}
{ee} |
|
The star version can also take an optional argument,
but with a different semantics. The optional argument is parsed by the
keyval
package, so as to offer a set of record-like options:
|
key |
Effect for value v |
before |
Execute v before typesetting the rule.
Useful for instance to change the maximal width of the rule. |
width |
Set the width of the rule to v |
narrower |
Set the width of the rule to v times \hsize . |
left |
Put a label v on the left of the rule |
Left |
Idem, but as if the label had zero width. |
Right |
As Left , but on the right of the rule. |
right |
As left , but on the right of the rule. |
leftskip |
Cheat by (skip negative space) v on the left side. |
rightskip |
Cheat by v on the right side of the rule. |
vdots |
Raise the rule by v and insert vertical dots. |
|
Here is an example of a complex derivation:
and its code
\inferrule* [left=Total]
{\inferrule* [Left=Foo]
{\inferrule* [Right=Bar,
leftskip=2em,rightskip=2em,vdots=1.5em]
{a \\ a \\\\ bb \\ cc \\ dd}
{ee}
\\ ff \\ gg}
{hh}
\\
\inferrule* [lab=XX]{uu \\ vv}{ww}}
{(1)}
4.4 Implementation
The main macro in the implementation of inference rules is the one that
either premises and conclusions. The macros uses two box-registers one
hbox
for typesetting each line and one vbox
for collecting
lines. The premise appears as a list with
\\
as separator. Each element is considered in turn typeset in a
hbox
in display math mode. Its width is compare to the space left on
the current line. If the box would not fit, the current horizontal line is
transferred to the vertical box and emptied. Then, the current formula can
safely be added to the horizontal line (if it does not fit, nothing can be
done). When moved to the vertical list, lines are aligned on their center
(as if their left-part was a left overlapped). At the end the vbox is
readjusted on the right.
This description works for conclusions. For premises, the elements must be
processes in reverse order and the vertical list is simply built upside
down.
5 Other Options
The package also defines \infer
as a shortcut for \inferrule
but only if it is not previously defined.
The package uses \TirName
and \RefTirName
to typeset labels,
which can safely be redefined by the user. The former is used for defining
occurrences (ie. in rule \inferrule
) while the latter is used
for referencing (ie. in the star-version).
The vertical space in mathpar
is adjusted by
\MathparLineskip
. To restore the normal paragraph parameters in mathpar
mode (for instance for some inner paragraph), use the command
\MathparNormalpar
.
The environment uses \MathparBindings
to
rebind \\
, and
, and \par
. You can redefine thus command
to change the default bindings or add your own.
6 Examples
See the source of this documentation ---the file mathpartir.tex
---
for full examples.
7 HEVEA compatibility
The package also redefines \hva
to do nothing in mathpar
environment and nor in inference rules.
In HeVeA, \and
will always produce a vertical break in mathpar
environment; to obtain a horizontal break, use \hva \and
instead.
Conversely, \\
will always produce a horizontal break in type
inference rules; to obtain a vertical break, use \hva \\
instead.
For instance, by default the following code,
\begin{mathpar}
\inferrule* [Left=Foo]
{\inferrule* [Right=Bar,width=8em,
leftskip=2em,rightskip=2em,vdots=1.5em]
{a \\ a \\ bb \\ cc \\ dd}
{ee}
\\ ff \\ gg}
{hh}
\and
\inferrule* [lab=XX]{uu \\ vv}{ww}
\end{mathpar}
which typesets in TeX as follows,
would appear as follows with the compatible HEVEA mode:
To obtain (almost) the same rendering as in TeX, it could be typed as
\begin{mathpar}
\inferrule* [Left=Foo]
{\inferrule* [Right=Bar,width=8em,
leftskip=2em,rightskip=2em,vdots=1.5em]
{a \\ a \hva \\ bb \\ cc \\ dd}
{ee}
\\ ff \\ gg}
{hh}
\hva \and
\inferrule* [lab=XX]{uu \\ vv}{ww}
\end{mathpar}
Actually, it would be typeset and follows with the compatible HEVEA mode:
- 1
- Even though the basic version may work in text mode,
we discourage its use in text mode; the star-version cannot be used in
text-mode
This document was translated from LATEX by
HEVEA.