4 Typesetting Racket Code
procedure
(typeset-code stx) → pict?
stx : syntax?
Beware that if you use read-syntax on a file port, you may have to turn on line counting via port-count-lines! for the code to typeset properly. Also beware that when a source file containing a syntax or quote-syntax form is compiled, source location information is omitted from the compiled syntax object.
Normally, typeset-code is used through the code syntactic form, which works properly with compilation, and that escapes to pict-producing code via unsyntax. See also define-code.
Embedded picts within stx are used directly. Row elements are combined using and operator like htl-append, so use code-align (see below) as necessary to add an ascent to ascentless picts. More precisely, creation of a line of code uses pict-last to determine the end point of the element most recently added to a line; the main effect is that closing parentheses are attached in the right place when a multi-line pict is embedded in stx.
An identifier that starts with _ is italicized in the pict, and the _ is dropped, unless the code-italic-underscore-enabled parameter is set to #f. Also, unless code-scripts-enabled is set to #f, _ and ^ in the middle of a word create superscripts and subscripts, respectively (like TeX); for example foo^4_ok is displayed as the identifier foo with a 4 superscript and an ok subscript.
Further, uses of certain identifiers in stx typeset specially:
(code:comment s ...) —
produces a comment block, with each s on its own line, where each s must be a string or a pict. (code:line datum ...) —
typesets the datum sequence, which is mostly useful for the top-level sequence, since typeset-code accepts only one argument. (code:contract datum ...) —
like code:line, but every datum is colored as a comment, and a ; is prefixed to every line. (code:template datum ...) —
like code:line, but a ; is prefixed to every line. $ —
typesets as a vertical bar (for no particularly good reason).
syntax
(code datum ...)
For more information, see typeset-code and define-code, since code is defined as
parameter
(current-code-font style) → void? style : text-style/c
parameter
(current-code-tt) → (string? . -> . pict?)
(current-code-tt proc) → void? proc : (string? . -> . pict?)
(lambda (s) (text s (current-code-font) (current-font-size)))
This procedure is not used to typeset subscripts or other items that require font changes, where current-code-font is used directly.
parameter
(current-code-line-sep amt) → void? amt : real?
parameter
(current-comment-color) → (or/c string? (is-a?/c color%))
(current-comment-color color) → void? color : (or/c string? (is-a?/c color%))
parameter
(current-keyword-color) → (or/c string? (is-a?/c color%))
(current-keyword-color color) → void? color : (or/c string? (is-a?/c color%))
parameter
(current-id-color) → (or/c string? (is-a?/c color%))
(current-id-color color) → void? color : (or/c string? (is-a?/c color%))
parameter
(current-literal-color) → (or/c string? (is-a?/c color%))
(current-literal-color color) → void? color : (or/c string? (is-a?/c color%))
parameter
(current-const-color) → (or/c string? (is-a?/c color%))
(current-const-color color) → void? color : (or/c string? (is-a?/c color%))
parameter
(current-base-color) → (or/c string? (is-a?/c color%))
(current-base-color color) → void? color : (or/c string? (is-a?/c color%))
parameter
(current-reader-forms syms) → void? syms : (listof symbol?)
procedure
(code-align pict) → pict?
pict : pict?
parameter
(current-keyword-list names) → void? names : (listof string?)
parameter
(current-const-list) → (listof string?)
(current-const-list names) → void? names : (listof string?)
parameter
(current-literal-list names) → void? names : (listof string?)
value
value
parameter
(code-colorize-enabled on?) → void? on? : any/c
parameter
(code-colorize-quote-enabled on?) → void? on? : any/c
parameter
(code-italic-underscore-enabled on?) → void? on? : any/c
parameter
(code-scripts-enabled on?) → void? on? : any/c
syntax
(define-code code-id typeset-code-id)
(define-code code-id typeset-code-id escape-id)
The resulting code-id syntactic form takes a sequence of datums:
(code-id datum ...)
It produces a pict that typesets the sequence. Source-location information for the datum determines the layout of code in the resulting pict. The code-id is expanded in such a way that source location is preserved during compilation (so typeset-code-id receives a syntax object with source locations intact).
If a datum contains (escape-id expr)—
syntax
(define-exec-code (pict-id runnable-id string-id) datum ...)
Meanwhile, runnable-id is bound to a syntax object that wraps the datums in a begin. In this case, _s are removed from the datums, but not the following expression. Thus, an _ identifier is used to comment out an expression from the pict, but have it present in the syntax object for evaluation.
The string-id is bound to a string representation of the code that is in the pict. This string is useful for copying to the clipboard with (send the-clipboard set-clipboard-string string-id 0).
syntax
(define-exec-code/scale scale-expr (pict-id runnable-id string-id) datum ...)
value
comment-color : (or/c string? (is-a?/c color%))
value
keyword-color : (or/c string? (is-a?/c color%))
value
value
literal-color : (or/c string? (is-a?/c color%))
procedure
(code-pict-bottom-line-pict pict) → (or/c pict? #f)
pict : pict?
procedure
(pict->code-pict pict bl-pict) → pict?
pict : pict? bl-pict : (or/c pict? #f)