▼ |  | Redex: Practical Semantics Engineering

1 | Patterns
2 | Terms
3 | Languages
4 | Reduction Relations
5 | Metafunctions and Relations
6 | Testing
7 | GUI
8 | Typesetting
9 | Removing the pink background from PLT Redex rendered picts and ps files
| Index

► | 8 | Typesetting

8.1 | Picts & Post Script
8.2 | Customization

On this page:

8.1`` Picts & Post Script
render-term
term->pict
render-language
language->pict
render-reduction-relation
reduction-relation->pict
render-metafunction
render-metafunctions
metafunction->pict
metafunctions->pict
8.2`` Customization
render-language-nts
extend-language-show-union
render-reduction-relation-rules
rule-pict-style
reduction-rule-style/ c
arrow-space
horizontal-label-space
metafunction-pict-style
delimit-ellipsis-arguments?
linebreaks
metafunction-cases
label-style
grammar-style
paren-style
literal-style
metafunction-style
non-terminal-style
non-terminal-subscript-style
non-terminal-superscript-style
default-style
label-font-size
metafunction-font-size
default-font-size
reduction-relation-rule-separation
curly-quotes-for-strings
current-text
set-arrow-pict!
white-bracket-sizing

top ← prev up next →

### 8`` Typesetting

( require redex/pict )

The redex/pict library provides functions designed to automatically typeset grammars, reduction relations, and metafunction written with plt redex.

Each grammar, reduction relation, and metafunction can be saved in a .ps file (as encapsulated postscript), or can be turned into a pict for viewing in the REPL or using with Slideshow (see Slideshow: Racket Figure and Presentation Tools).

#### 8.1`` Picts & PostScript

This section documents two classes of operations, one for direct use of creating postscript figures for use in papers and for use in DrRacket to easily adjust the typesetting: render-term, render-language, render-reduction-relation, render-metafunctions, and render-lw, and one for use in combination with other libraries that operate on picts term->pict, language->pict, reduction-relation->pict, metafunction->pict, and lw->pict. The primary difference between these functions is that the former list sets dc-for-text-size and the latter does not.

( render-term lang term file) → ( if file void? pict? )
lang : compiled-lang?
term : any/c
file : ( or/c #f path-string? )

Renders the term term. If file is #f, it produces a pict; if file is a path, it saves Encapsulated PostScript in the provided filename. See render-language for details on the construction of the pict.

( term->pict lang term) → pict?
lang : compiled-lang?
term : any/c

Produces a pict like render-term, but without adjusting dc-for-text-size.

This function is primarily designed to be used with Slideshow or with other tools that combine picts together.

( render-language lang [file #:nts nts]) → ( if file void? pict? )
lang : compiled-lang?
file : ( or/c false/c path-string? ) = #f

| nts |  | : |  | ( or/c false/c ( listof ( or/c string? symbol? )))
|  |  | = |  | ( render-language-nts )

Renders a language. If file is #f, it produces a pict; if file is a path, it saves Encapsulated PostScript in the provided filename. See render-language-nts for information on the nts argument.

This function parameterizes dc-for-text-size to install a relevant dc: a bitmap-dc% or a post-script-dc%, depending on whether file is a path.

See language->pict if you are using Slideshow or are otherwise setting dc-for-text-size.

( language->pict lang [#:nts nts]) → pict?
lang : compiled-lang?

| nts |  | : |  | ( or/c false/c ( listof ( or/c string? symbol? )))
|  |  | = |  | ( render-language-nts )

Produce a pict like render-language, but without adjusting dc-for-text-size.

This function is primarily designed to be used with Slideshow or with other tools that combine picts together.

( render-reduction-relation |  | rel |
| [ | file |
|  | #:style style]) |

→ ( if file void? pict? )
rel : reduction-relation?
file : ( or/c false/c path-string? ) = #f
style : reduction-rule-style/c = ( rule-pict-style )

Renders a reduction relation. If file is #f, it produces a pict; if file is a path, it saves Encapsulated PostScript in the provided filename. See rule-pict-style for information on the style argument.

This function parameterizes dc-for-text-size to install a relevant dc: a bitmap-dc% or a post-script-dc%, depending on whether file is a path. See also reduction-relation->pict.

The following forms of arrows can be typeset:

> --> -+> ==> -> => ..> >-> ~~> ~> :-> :–> c-> –>> >– –< >>– –<<

( reduction-relation->pict r [#:style style]) → pict?
r : reduction-relation?
style : reduction-rule-style/c = ( rule-pict-style )

Produces a pict like render-reduction-relation, but without setting dc-for-text-size.

This function is primarily designed to be used with Slideshow or with other tools that combine picts together.

( render-metafunction metafunction-name)

( render-metafunction metafunction-name filename)

( render-metafunctions metafunction-name ...)

( render-metafunctions metafunction-name ... #:file filename)

If provided with one argument, render-metafunction produces a pict that renders properly in the definitions window in DrRacket. If given two arguments, it writes postscript into the file named by filename (which may be either a string or bytes).

Similarly, render-metafunctions accepts multiple metafunctions and renders them together, lining up all of the clauses together.

This function sets dc-for-text-size. See also metafunction->pict and metafunctions->pict.

( metafunction->pict metafunction-name)

This produces a pict, but without setting dc-for-text-size. It is suitable for use in Slideshow or other libraries that combine picts.

( metafunctions->pict metafunction-name ...)

Like metafunction->pict, this produces a pict, but without setting dc-for-text-size and is suitable for use in Slideshow or other libraries that combine picts. Like render-metafunctions, it accepts multiple metafunctions and renders them together.

#### 8.2`` Customization

( render-language-nts ) → ( or/c false/c ( listof symbol? ))
( render-language-nts nts) → void?
nts : ( or/c false/c ( listof symbol? ))

The value of this parameter controls which non-terminals render-language and language->pict render by default. If it is #f (the default), all non-terminals are rendered. If it is a list of symbols, only the listed symbols are rendered.

See also language-nts.

( extend-language-show-union ) → boolean?
( extend-language-show-union show?) → void?
show? : boolean?

If this is #t, then a language constructed with extend-language is shown as if the language had been constructed directly with language. If it is #f, then only the last extension to the language is shown (with four-period ellipses, just like in the concrete syntax).

Defaultly #f.

Note that the #t variant can look a little bit strange if .... are used and the original version of the language has multi-line right-hand sides.

( render-reduction-relation-rules )
→ ( or/c false/c ( listof ( or/c symbol? string? )))
( render-reduction-relation-rules rules) → void?
rules : ( or/c false/c ( listof ( or/c symbol? string? )))

This parameter controls which rules in a reduction relation will be rendered.

( rule-pict-style ) → reduction-rule-style/c
( rule-pict-style style) → void?
style : reduction-rule-style/c

This parameter controls the style used by default for the reduction relation. It can be 'horizontal, where the left and right-hand sides of the reduction rule are beside each other or 'vertical, where the left and right-hand sides of the reduction rule are above each other. The 'compact-vertical style moves the reduction arrow to the second line and uses less space between lines. The 'vertical-overlapping-side-conditions variant, the side-conditions don’t contribute to the width of the pict, but are just overlaid on the second line of each rule. The 'horizontal-left-align style is like the 'horizontal style, but the left-hand sides of the rules are aligned on the left, instead of on the right.

reduction-rule-style/c : flat-contract?

A contract equivalent to

( symbols 'vertical
'compact-vertical
'vertical-overlapping-side-conditions
'horizontal)

( arrow-space ) → natural-number/c
( arrow-space space) → void?
space : natural-number/c

This parameter controls the amount of extra horizontal space around the reduction relation arrow. Defaults to 0.

(horizontal-label-space) → natural-number/c
(horizontal-label-space space) → void?
space : natural-number/c

This parameter controls the amount of extra space before the label on each rule, but only in horizontal mode. Defaults to 0.

( metafunction-pict-style )

→

( or/c 'left-right
'up-down
'left-right/vertical-side-conditions
'up-down/vertical-side-conditions
'left-right/compact-side-conditions
'up-down/compact-side-conditions
'left-right/beside-side-conditions)

( metafunction-pict-style style) → void?

style

:

( or/c 'left-right
'up-down
'left-right/vertical-side-conditions
'up-down/vertical-side-conditions
'left-right/compact-side-conditions
'up-down/compact-side-conditions
'left-right/beside-side-conditions)

This parameter controls the style used for typesetting metafunctions. The 'left-right style means that the results of calling the metafunction are displayed to the right of the arguments and the 'up-down style means that the results are displayed below the arguments.

The 'left-right/vertical-side-conditions and 'up-down/vertical-side-conditions variants format side conditions each on a separate line, instead of all on the same line.

The 'left-right/compact-side-conditions and 'up-down/compact-side-conditions variants move side conditions to separate lines to avoid making the rendered form wider than it would be otherwise.

The 'left-right/beside-side-conditions variant is like 'left-right, except it puts the side-conditions on the same line, instead of on a new line below the case.

( delimit-ellipsis-arguments? ) → any/c
( delimit-ellipsis-arguments? delimit?) → void?
delimit? : any/c

This parameter controls the typesetting of metafunction definitions and applications. When it is non-#f (the default), commas precede ellipses that represent argument sequences; when it is #f no commas appear in those positions.

( linebreaks ) → ( or/c #f ( listof boolean? ))
( linebreaks breaks) → void?
breaks : ( or/c #f ( listof boolean? ))

This parameter controls which cases in the metafunction are rendered on two lines and which are rendered on one.

If its value is a list, the length of the list must match the number of cases and each boolean indicates if that case has a linebreak or not.

This influences the 'left/right styles only.

( metafunction-cases )

→

( or/c #f ( and/c ( listof ( and/c integer?
( or/c zero? positive? )))
pair? ))

( metafunction-cases cases) → void?

cases

:

( or/c #f ( and/c ( listof ( and/c integer?
( or/c zero? positive? )))
pair? ))

This parameter controls which cases in a metafunction are rendered. If it is #f (the default), then all of the cases appear. If it is a list of numbers, then only the selected cases appear (counting from 0).

( label-style ) → text-style/c
( label-style style) → void?
style : text-style/c

( grammar-style ) → text-style/c
( grammar-style style) → void?
style : text-style/c

( paren-style ) → text-style/c
( paren-style style) → void?
style : text-style/c

( literal-style ) → text-style/c
( literal-style style) → void?
style : text-style/c

( metafunction-style ) → text-style/c
( metafunction-style style) → void?
style : text-style/c

( non-terminal-style ) → text-style/c
( non-terminal-style style) → void?
style : text-style/c

( non-terminal-subscript-style ) → text-style/c
( non-terminal-subscript-style style) → void?
style : text-style/c

( non-terminal-superscript-style ) → text-style/c
( non-terminal-superscript-style style) → void?
style : text-style/c

( default-style ) → text-style/c
( default-style style) → void?
style : text-style/c

These parameters determine the font used for various text in the picts. See text in the texpict collection for documentation explaining text-style/c. One of the more useful things it can be is one of the symbols 'roman, 'swiss, or 'modern, which are a serif, sans-serif, and monospaced font, respectively. (It can also encode style information, too.)

The label-style is used for the reduction rule label names. The literal-style is used for names that aren’t non-terminals that appear in patterns. The metafunction-style is used for the names of metafunctions. The paren-style is used for the parentheses (including “[”, “]”, “{”, and “}”, as well as “(” and “)”), but not for the square brackets used for in-hole decompositions, which use the default-style. The grammar-style is used for the “::=” and “|” in grammars.

The non-terminal-style is used for the names of non-terminals. Two parameters style the text in the (optional) "underscore" component of a non-terminal reference. The first, non-terminal-subscript-style, applies to the segment between the underscore and the first caret (^) to follow it; the second, non-terminal-superscript-style, applies to the segment following that caret. For example, in the non-terminal reference x_y_z, x has style non-terminal-style, y has style non-terminal-subscript-style, and z has style non-terminal-superscript-style.

The non-terminal-subscript-style is used for the portion after the underscore in non-terminal references.

The default-style is used for parenthesis, the dot in dotted lists, spaces, the "where" and "fresh" in side-conditions, and other places where the other parameters aren’t used.

( label-font-size ) → ( and/c ( between/c 1 255) integer? )
( label-font-size size) → void?
size : ( and/c ( between/c 1 255) integer? )

( metafunction-font-size ) → ( and/c ( between/c 1 255) integer? )
( metafunction-font-size size) → void?
size : ( and/c ( between/c 1 255) integer? )

( default-font-size ) → ( and/c ( between/c 1 255) integer? )
( default-font-size size) → void?
size : ( and/c ( between/c 1 255) integer? )

These parameters control the various font sizes. The default-font-size is used for all of the font sizes except labels and metafunctions.

( reduction-relation-rule-separation )
→ ( parameter/c ( and/c integer? positive? exact? ))
( reduction-relation-rule-separation sep) → void?
sep : ( parameter/c ( and/c integer? positive? exact? ))

Controls the amount of space between clauses in a reduction relation. Defaults to 4.

( curly-quotes-for-strings ) → boolean?
( curly-quotes-for-strings on?) → void?
on? : boolean?

Controls if the open and close quotes for strings are turned into “ and ” or are left as merely ".

Defaults to #t.

( current-text ) → ( -> string? text-style/c number? pict? )
( current-text proc) → void?
proc : ( -> string? text-style/c number? pict? )

This parameter’s function is called whenever Redex typesets some part of a grammar, reduction relation, or metafunction. It defaults to slideshow’s text function.

( set-arrow-pict! arrow proc) → void?
arrow : symbol?
proc : ( -> pict? )

This functions sets the pict for a given reduction-relation symbol. When typesetting a reduction relation that uses the symbol, the thunk will be invoked to get a pict to render it. The thunk may be invoked multiple times when rendering a single reduction relation.

( white-bracket-sizing )
→ ( -> string? number? ( values number? number? number? number? ))
( white-bracket-sizing proc) → void?
proc : ( -> string? number? ( values number? number? number? number? ))

This parameter is used when typesetting metafunctions to determine how to create the 〚〛 characters. Rather than using those characters directly (since glyphs tend not to be available in PostScript fonts), they are created by combining two ‘[’ characters or two ‘]’ characters together.

The procedure accepts a string that is either "[" or "]", and returns four numbers. The first two numbers determine the offset (from the left and from the right respectively) for the second square bracket, and the second two two numbers determine the extra space added (to the left and to the right respectively).

The default value of the parameter is:

( λ (str size)
( let ([inset-amt (floor/even ( max 4 ( * size 1/2)))])
( cond
[( equal? str "[")
( values inset-amt
0
0
( / inset-amt 2))]
[ else
( values 0
inset-amt
( / inset-amt 2)
0)])))

where floor/even returns the nearest even number below its argument. This means that for sizes 9, 10, and 11, inset-amt will be 4, and for 12, 13, 14, and 15, inset-amt will be 6.

top ← prev up next →