On this page:
7.1 Dingbats
cloud
file-icon
standard-fish
jack-o-lantern
angel-wing
desktop-machine
thermometer
standard-cat
7.2 Balloon Annotations
wrap-balloon
pip-wrap-balloon
pin-balloon
balloon
balloon?
make-balloon
balloon-pict
balloon-point-x
balloon-point-y
balloon-color
current-balloon-color
balloon-enable-3d
7.3 Face
default-face-color
face
face*
7.4 Flash
filled-flash
outline-flash
7.5 Typesetting Racket Code
typeset-code
code
current-code-font
current-code-tt
get-current-code-font-size
current-code-line-sep
current-comment-color
current-keyword-color
current-id-color
current-literal-color
current-const-color
current-base-color
current-reader-forms
code-align
current-keyword-list
current-const-list
current-literal-list
racket/  base-const-list
mzscheme-const-list
code-colorize-enabled
code-colorize-quote-enabled
code-italic-underscore-enabled
code-scripts-enabled
define-code
make-code-transformer
prop:  code-transformer
code-transformer?
define-exec-code
define-exec-code/  scale
comment-color
keyword-color
id-color
literal-color
code-pict-bottom-line-pict
pict->code-pict
7.5.1 Codeblocks
codeblock-pict
current-token-class->color

7 More Pict Constructors

7.1 Dingbats

procedure

(cloud w h [color #:style style])  pict?

  w : real?
  h : real?
  color : (or/c string? (is-a?/c color%)) = "gray"
  style : 
(listof (or/c 'square
              'nw 'ne 'sw 'se
               'wide))
 = null
Creates a fluffy cloud.

Supplying 'nw (northwest), 'ne (northeast), 'sw (southwest), or 'se (southeast) in style extends the cloud to better cover the corner within its bounding box in the corresponding direction. The 'square style is a shorthand for all of those combined. The 'wide style increases the number of bumps along the cloud’s top and bottom edges.

Examples:
> (cloud 100 75)

image

> (cloud 100 75 "lavenderblush")

image

> (cloud 100 75 #:style '(square wide))

image

Changed in version 1.6 of package pict-lib: Added style.

procedure

(file-icon w h color [shaded?])  pict?

  w : real?
  h : real?
  color : (or/c string? (is-a?/c color%) any/c)
  shaded? : any/c = #f
Creates a Mac-like file icon, optionally shaded. If color is not a string or color% object, it is treated as a boolean, in which case true means "gray" and false means "white".

Examples:
> (file-icon 50 60 "bisque")

image

> (file-icon 50 60 "honeydew" #t)

image

procedure

(standard-fish w    
  h    
  [#:direction direction    
  #:color color    
  #:eye-color eye-color    
  #:open-mouth open-mouth])  pict?
  w : real?
  h : real?
  direction : (or/c 'left 'right) = 'left
  color : (or/c string? (is-a?/c color%)) = "blue"
  eye-color : (or/c string? (is-a?/c color%) #f) = "black"
  open-mouth : (or/c boolean? real?) = #f
Creates a fish swimming either 'left or 'right. If eye-color is #f, no eye is drawn.

The open-mouth argument can be either #f (mouth closed), #t (mouth fully open), or a number: 0.0 is closed, 1.0 is fully open, and numbers in between are partially open.

Examples:
> (standard-fish 100 50)

image

> (standard-fish 100 50 #:direction 'right #:color "chocolate")

image

> (standard-fish 100 50 #:eye-color "saddlebrown" #:color "salmon")

image

> (standard-fish 100 50 #:open-mouth #t #:color "olive")

image

procedure

(jack-o-lantern size    
  [pumpkin-color    
  face-color    
  stem-color])  pict?
  size : real?
  pumpkin-color : (or/c string? (is-a?/c color%)) = "orange"
  face-color : (or/c string? (is-a?/c color%)) = "black"
  stem-color : (or/c string? (is-a?/c color%)) = "brown"
Creates a jack-o-lantern; use the same pumpkin and face color to get a plain pumpkin. The size determines the width.

Examples:
> (jack-o-lantern 100)

image

> (jack-o-lantern 100 "cadet blue" "khaki" "salmon")

image

procedure

(angel-wing w h left?)  pict?

  w : real?
  h : real?
  left? : any/c
Creates an angel wing, left or right, or any size. The color and pen width for drawing the wing outline is the current one.

Examples:
> (angel-wing 100 40 #f)

image

> (angel-wing 100 40 #t)

image

procedure

(desktop-machine scale [style])  pict?

  scale : real?
  style : (listof symbol?) = null
Produces a picture of ancient desktop computer. The scale argument scales the size relative to the base size of 120 by 115.

The style can include any of the following:

Examples:
> (desktop-machine 1)

image

> (desktop-machine 1 '(devil plt))

image

> (desktop-machine 1 '(plt binary))

image

procedure

(thermometer [#:height-% height-% 
  #:color-% color-% 
  #:ticks ticks 
  #:start-color start-color 
  #:end-color end-color 
  #:top-circle-diameter top-circle-diameter 
  #:bottom-circle-diameter bottom-circle-diameter 
  #:stem-height stem-height 
  #:mercury-inset mercury-inset]) 
  pict?
  height-% : (between/c 0 1) = 1
  color-% : (between/c 0 1) = height-%
  ticks : exact-nonnegative-integer? = 4
  start-color : (or/c string? (is-a?/c color%)) = "lightblue"
  end-color : (or/c string? (is-a?/c color%)) = "lightcoral"
  top-circle-diameter : (>/c 0) = 40
  bottom-circle-diameter : (>/c 0) = 80
  stem-height : (>/c 0) = 180
  mercury-inset : (>/c 0) = 8
Produces a thermometer that consists of a semi-circle on top of a rectangle on top of a circle. The sizes of the three components are controlled via the top-circle-diameter, stem-height, and bottom-circle-diameter arguments.

The mercury is drawn the same way, but by creating the three components inset from the versions that draw the boundary of the thermometer. This inset is controlled by the mercury-inset argument.

The height of the mercury in the thermometer is controlled by the height-% argument. Its color is interpolated between the start-color and end-color, as determined by the color-% argument.

Finally, some number of ticks are drawn, based on the ticks argument.

Example:
> (thermometer #:stem-height 90
               #:bottom-circle-diameter 40
               #:top-circle-diameter 20
               #:mercury-inset 4)

image

procedure

(standard-cat width    
  height    
  #:left-ear-extent left-ear-extent    
  #:left-ear-arc left-ear-arc    
  #:left-ear-angle left-ear-angle    
  #:right-ear-extent right-ear-extent    
  #:right-ear-arc right-ear-arc    
  #:right-ear-angle right-ear-angle    
  #:fur-color fur-color    
  #:fur-border-color fur-border-color    
  #:lip-color lip-color    
  #:lip-border-color lip-border-color    
  #:lip-border-width lip-border-width    
  #:eye-color eye-color    
  #:nose-color nose-color    
  #:nose nose    
  #:happy? happy?    
  #:eyes eyes    
  #:left-eye left-eye    
  #:right-eye right-eye    
  #:whisker-length whisker-length    
  #:whisker-droop whisker-droop    
  #:whisker-width whisker-width    
  #:whisker-color whisker-color    
  #:whisker-inset? whisker-inset?    
  #:border-width border-width)  pict?
  width : positive?
  height : positive?
  left-ear-extent : (>=/c 0)
  left-ear-arc : (real-in 0 (* 2 pi))
  left-ear-angle : (real-in 0 (* 2 pi))
  right-ear-extent : (>=/c 0)
  right-ear-arc : (real-in 0 (* 2 pi))
  right-ear-angle : (real-in 0 (* 2 pi))
  fur-color : (or/c #f string? (is-a?/c color%))
  fur-border-color : (or/c #f string? (is-a?/c color%))
  lip-color : (or/c #f string? (is-a?/c color%))
  lip-border-color : (or/c string? (is-a?/c color%))
  lip-border-width : (or/c #f (real-in 0 255))
  eye-color : (or/c #f string? (is-a?/c color%))
  nose-color : (or/c #f string? (is-a?/c color%))
  nose : pict?
  happy? : any/c
  eyes : (or/c #f pict?)
  left-eye : (if eyes (or/c #f pict?) pict?)
  right-eye : (if eyes (or/c #f pict?) pict?)
  whisker-length : positive?
  whisker-droop : real?
  whisker-width : (or/c #f (real-in 0 255))
  whisker-color : (or/c string? (is-a?/c color%))
  whisker-inset? : any/c
  border-width : (or/c #f (real-in 0 255))
Creates a cat face with customizable whiskers, eyes, ears, and mouth.

The whisker-width argument can be either #f (no whiskers) or a real between 0 and 255 to specify pen width. Similarly for border-width, there can be no border around the cat face or a custom-width border.

Each cat ear can have a custom extent (length), an arc length (width), and angle (position on head). There are constraints on the ear arc lengths and angles to prevent overlap. The default ear angle is dependent on the ear arc length to make the default positioning sensible. The default ear extent is 1/4 the height of the cat face.

Examples:
> (standard-cat 100 90)

image

> (standard-cat 100 90 #:happy? #t)

image

> (standard-cat 100 90 #:left-ear-arc (* pi 1/8) #:right-ear-extent 30)

image

Added in version 1.10 of package pict-lib.

7.2 Balloon Annotations

The pict/balloon library provides functions for creating and placing cartoon-speech balloons.

procedure

(wrap-balloon pict    
  spike    
  dx    
  dy    
  [color    
  corner-radius])  balloon?
  pict : pict?
  spike : (or/c 'n 's 'e 'w 'ne 'se 'sw 'nw)
  dx : real?
  dy : real?
  color : (or/c string? (is-a?/c color%))
   = (current-balloon-color)
  corner-radius : (and/c real? (not/c negative?)) = 32
Superimposes pict on top of a balloon that wraps it.

The spike argument indicates the corner from which a spike protrudes from the balloon (i.e., the spike that points to whatever the balloon is about). For example, 'n means “north,”, which is a spike in the top middle of the balloon.

The dx and dy arguments specify how far the spike should protrude. For a 'w spike, dx should be negative, etc.

The color argument is the background color for the balloon.

The corner-radius argument determines the radius of the circle used to round the balloon’s corners. As usual, if it is less than 1, then it acts as a ratio of the balloon’s width or height.

The result is a balloon, not a pict. The balloon-pict function extracts a pict whose bounding box does not include the spike, but includes the rest of the image, and the balloon-point-x and balloon-point-y functions extract the location of the spike point. More typically, the pin-balloon function is used to add a balloon to a pict.

procedure

(pip-wrap-balloon pict    
  spike    
  dx    
  dy    
  [color    
  corner-radius])  pict?
  pict : pict?
  spike : (or/c 'n 's 'e 'w 'ne 'se 'sw 'nw)
  dx : real?
  dy : real?
  color : (or/c string? (is-a?/c color%))
   = (current-balloon-color)
  corner-radius : (and/c real? (not/c negative?)) = 32
Like wrap-balloon, but produces a zero-sized pict suitable for use with pin-over.

procedure

(pin-balloon balloon base x y)  pict?

  balloon : balloon?
  base : pict?
  x : real?
  y : real?
(pin-balloon balloon base at-pict find)  pict?
  balloon : balloon?
  base : pict?
  at-pict : pict-path?
  find : (pict? pict-path? . -> . (values real? real?))
Superimposes the pict in balloon onto base to produce a new pict. The balloon is positioned so that its spike points to the location specified by either x and y (numbers) or at the position determined by combining base and at-pict with find. The find function uses its arguments like lt-find.

The resulting pict has the same bounding box, descent, and ascent as base, even if the balloon extends beyond the bounding box.

Examples:
> (define a-pict (standard-fish 70 40))
> (pin-balloon (balloon 40 30 5 'se 5 5)
               (cc-superimpose (blank 300 150) a-pict)
               a-pict
               lc-find)

image

> (pin-balloon (wrap-balloon (text "Hello!") 'sw -5 3)
               (cc-superimpose (blank 300 150) a-pict)
               a-pict
               rt-find)

image

procedure

(balloon w h corner-radius spike dx dy [color])  balloon?

  w : real?
  h : real?
  corner-radius : (and/c real? (not/c negative?))
  spike : (or/c 'n 's 'e 'w 'ne 'se 'sw 'nw)
  dx : real?
  dy : real?
  color : (or/c string? (is-a?/c color%))
   = (current-balloon-color)
Creates a balloon, much like wrap-balloon except that the balloon’s width is w and its height is h.

procedure

(balloon? v)  boolean?

  v : any/c
(make-balloon pict x y)  balloon?
  pict : pict?
  x : real?
  y : real?
(balloon-pict balloon)  pict?
  balloon : balloon?
(balloon-point-x balloon)  real?
  balloon : balloon?
(balloon-point-y balloon)  real?
  balloon : balloon?
A balloon encapsulates a pict and the position of the balloon’s spike relative to the balloon’s top-left corner.

The default background color for a balloon.

parameter

(current-balloon-color)  (or/c string? (is-a?/c color%))

(current-balloon-color color)  void?
  color : (or/c string? (is-a?/c color%))
Determines the background color for a balloon as created by functions like wrap-balloon.

Added in version 1.9 of package pict-lib.

parameter

(balloon-enable-3d)  boolean?

(balloon-enable-3d on?)  void?
  on? : any/c
A parameter that determines whether balloons are drawn with 3-D shading. This parameter affects balloons at drawing time, not at construction time.

7.3 Face

 (require pict/face) package: pict-lib
The pict/face library provides functions for a kind of Mr. Potatohead-style face library.

Orange.

procedure

(face mood [color])  pict?

  mood : symbol?
  color : (or/c string (is-a?/c color%)) = default-face-color
Returns a pict for a pre-configured face with the given base color. The built-in configurations, selected by mood-symbol, are as follows:

'unhappy (face* 'none 'plain #t default-face-color 6)

  

image

'sortof-unhappy (face* 'worried 'grimace #t default-face-color 6)

  

image

'sortof-happy (face* 'worried 'medium #f default-face-color 6)

  

image

'happy (face* 'none 'plain #f default-face-color 6)

  

image

'happier (face* 'none 'large #f default-face-color 3)

  

image

'embarrassed (face* 'worried 'medium #f default-face-color 3)

  

image

'badly-embarrassed (face* 'worried 'medium #t default-face-color 3)

  

image

'unhappier (face* 'normal 'large #t default-face-color 3)

  

image

'happiest (face* 'normal 'huge #f default-face-color 0 -3)

  

image

'unhappiest (face* 'normal 'huge #t default-face-color 0 -3)

  

image

'mad (face* 'angry 'grimace #t default-face-color 0)

  

image

'mean (face* 'angry 'narrow #f default-face-color 0)

  

image

'surprised (face* 'worried 'oh #t default-face-color -4 -3 2)

  

image

procedure

(face* eyebrow-kind    
  mouth-kind    
  frown?    
  color    
  eye-inset    
  eyebrow-dy    
  pupil-dx    
  pupil-dy    
  [#:eyebrow-shading? eyebrow-on?    
  #:mouth-shading? mouth-on?    
  #:eye-shading? eye-on?    
  #:tongue-shading? tongue-on?    
  #:face-background-shading? face-bg-on?    
  #:teeth? teeth-on?])  pict?
  eyebrow-kind : (or/c 'none 'normal 'worried 'angry)
  mouth-kind : 
(or/c 'plain 'smaller 'narrow 'medium 'large
      'huge 'grimace 'oh 'tongue)
  frown? : any/c
  color : (or/c string (is-a?/c color%))
  eye-inset : real?
  eyebrow-dy : real?
  pupil-dx : real?
  pupil-dy : real?
  eyebrow-on? : any/c = #t
  mouth-on? : any/c = #t
  eye-on? : any/c = #t
  tongue-on? : any/c = #t
  face-bg-on? : any/c = #t
  teeth-on? : any/c = #t
Returns a pict for a face:

The #:eyebrow-shading? through #:face-background-shading? arguments control whether a shading is used for on a particular feature in the face (shading tends to look worse than just anti-aliasing when the face is small). The #:teeth? argument controls the visibility of the teeth for some mouth shapes.

7.4 Flash

 (require pict/flash) package: pict-lib

procedure

(filled-flash width    
  height    
  [n-points    
  spike-fraction    
  rotation])  pict?
  width : real?
  height : real?
  n-points : exact-positive-integer? = 10
  spike-fraction : (real-in 0 1) = 0.25
  rotation : real? = 0
Returns a pict for a “flash”: a spiky oval, like the yellow background that goes behind a “new!” logo on web pages or a box of cereal.

The height and width arguments determine the size of the oval in which the flash is drawn, prior to rotation. The actual height and width may be smaller if points is not a multiple of 4, and the actual height and width will be different if the flash is rotated.

The n-points argument determines the number of points on the flash.

The spike-fraction argument determines how big the flash spikes are compared to the bounding oval.

The rotation argument specifies an angle in radians for counter-clockwise rotation.

The flash is drawn in the default color.

Examples:
> (filled-flash 100 50)

image

> (filled-flash 100 50 8 0.25 (/ pi 2))

image

procedure

(outline-flash width    
  height    
  [n-points    
  spike-fraction    
  rotation])  pict?
  width : real?
  height : real?
  n-points : exact-positive-integer? = 10
  spike-fraction : (real-in 0 1) = 0.25
  rotation : real? = 0
Like filled-flash, but drawing only the outline.

Examples:
> (outline-flash 100 50)

image

> (outline-flash 100 50 8 0.25 (/ pi 2))

image

7.5 Typesetting Racket Code

 (require pict/code) package: pict-lib
This library is re-provided by slideshow/code, but initializes get-current-code-font-size.

procedure

(typeset-code stx)  pict?

  stx : syntax?
Produces a pict for code in the given syntax object. The source-location information of the syntax object determines the line breaks, line indenting, and space within a row. Empty rows are ignored.

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.

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:

syntax

(code datum ...)

The macro form of typeset-code. Within a datum, unsyntax can be used to escape to an expression, and identifiers bound as syntax to code transformers trigger transformations.

For more information, see typeset-code and define-code, since code is defined as

(define-code code typeset-code)

Examples:
> (code (+ 1 2))

image

> (code (+ 1 #,(+ 1 1)))

image

> (code (+ 1 #,(frame (code 2))))

image

> (define-syntax two (make-code-transformer #'(code 2)))
> (code (+ 1 two))

image

parameter

(current-code-font)  text-style/c

(current-code-font style)  void?
  style : text-style/c
Parameter for a base font used to typeset text. The default is `(bold . modern). For even more control, see current-code-tt.

parameter

(current-code-tt)  (string? . -> . pict?)

(current-code-tt proc)  void?
  proc : (string? . -> . pict?)
Parameter for a one-argument procedure to turn a string into a pict, used to typeset text. The default is

(lambda (s) (text s (current-code-font) ((get-current-code-font-size))))

This procedure is not used to typeset subscripts or other items that require font changes, where current-code-font is used directly.

A parameter used to access the default font size. The slideshow/code library initializes this parameter to current-font-size.

parameter

(current-code-line-sep)  real?

(current-code-line-sep amt)  void?
  amt : real?
A parameter that determines the spacing between lines of typeset code. The default is 2.

parameter

(current-comment-color)  (or/c string? (is-a?/c color%))

(current-comment-color color)  void?
  color : (or/c string? (is-a?/c color%))
A parameter for the color of comments.

parameter

(current-keyword-color)  (or/c string? (is-a?/c color%))

(current-keyword-color color)  void?
  color : (or/c string? (is-a?/c color%))
A parameter for the color of syntactic-form names. See current-keyword-list.

parameter

(current-id-color)  (or/c string? (is-a?/c color%))

(current-id-color color)  void?
  color : (or/c string? (is-a?/c color%))
A parameter for the color of identifiers that are not syntactic form names or constants.

parameter

(current-literal-color)  (or/c string? (is-a?/c color%))

(current-literal-color color)  void?
  color : (or/c string? (is-a?/c color%))
A parameter for the color of literal values, such as strings and numbers. See also current-literal-list

parameter

(current-const-color)  (or/c string? (is-a?/c color%))

(current-const-color color)  void?
  color : (or/c string? (is-a?/c color%))
A parameter for the color of constant names. See current-const-list.

parameter

(current-base-color)  (or/c string? (is-a?/c color%))

(current-base-color color)  void?
  color : (or/c string? (is-a?/c color%))
A parameter for the color of everything else.

parameter

(current-reader-forms)  (listof symbol?)

(current-reader-forms syms)  void?
  syms : (listof symbol?)
Parameter for a list of symbols indicating which built-in reader forms should be used. The default is ''quasiquote. Remove a symbol to suppress the corresponding reader output.

procedure

(code-align pict)  pict?

  pict : pict?
Adjusts the ascent of pict so that its bottom aligns with the baseline for text; use this function when pict has no ascent.

parameter

(current-keyword-list)  (listof string?)

(current-keyword-list names)  void?
  names : (listof string?)
A list of strings to color as syntactic-form names. The default includes all of the forms provided by racket/base and all of the forms provided by mzscheme.

parameter

(current-const-list)  (listof string?)

(current-const-list names)  void?
  names : (listof string?)
A list of strings to color as constant names. The default is null.

parameter

(current-literal-list)  (listof string?)

(current-literal-list names)  void?
  names : (listof string?)
A list of strings to color as literals, in addition to literals such as strings. The default is null.

A list of strings that could be used to initialize the current-const-list parameter.

A list of strings that could be used to initialize the current-const-list parameter.

parameter

(code-colorize-enabled)  boolean?

(code-colorize-enabled on?)  void?
  on? : any/c
A parameter to enable or disable all code coloring. The default is #t.

A parameter to control whether the datum under a quote is colorized as a literal (as in this documentation). The default is #t.

A parameter to control whether _-prefixed identifiers are italicized (dropping the _). The default is #t.

parameter

(code-scripts-enabled)  boolean?

(code-scripts-enabled on?)  void?
  on? : any/c
A parameter to control whether TeX-style subscripts and subscripts are recognized in an identifier.

syntax

(define-code code-id typeset-code-id)

(define-code code-id typeset-code-id escape-id)
Defines code-id as a macro that uses typeset-code-id, which is a function with the same input as typeset-code. The escape-id form defaults to unsyntax.

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)perhaps as #,expr when escape-id is unsyntaxthen the expr is evaluated and the result datum is spliced in place of the escape-id form in datum. If the result is not a syntax object, it is given the source location of the escape-id form. A pict value injected this way as a datum is rendered as itself.

If a datum contains (transform-id datum ...) or transform-id for a transform-id that is bound as syntax to a code transformer, then the (transform-id datum ...) or transform-id may be replaced with an escaped expression, depending on the code transformer’s result.

procedure

(make-code-transformer proc-or-stx)  code-transformer?

  proc-or-stx : 
(or/c (syntax? . -> . (or/c syntax? #f))
      syntax?)

value

prop:code-transformer : struct-type-property?

procedure

(code-transformer? v)  boolean?

  v : any/c
Exported for-syntax for creating code transformers.

For code transformer created with (make-code-transformer proc), proc takes a syntax object representing the use of an identifier bound to the transformer, and it produces an expression whose value replaces the identifier use within a code form or a form defined via define-code. Like a macro transformer, a code transformer is triggered either by a use of the bound identifier in an “application” position, in which case the transformer receives the entire “application” form, or the identifier by itself can also trigger the transformer. The code transformer’s proc can return #f, in which case the use of the identifier is left untransformed; if the identifier was used in an “application” position, the transformer proc will be called again for the identifier use by itself.

A code transformer produced by (make-code-transformer stx) is equivalent to

(make-code-transformer (lambda (use-stx)
                         (if (identifier? use-stx)
                             stx
                             #f)))

A structure type with the prop:code-transformer property implements a code transformer. The property value must be a procedure of one argument, which receives the structure and returns a procedure that is like a proc passed to make-code-transformer, except that the property value takes the structure instance as an argument before the syntax object to transform.

The code-transformer? predicate returns #t for a value produced by make-code-transformer or for an instance of a structure type with the prop:code-transformer property, #f otherwise.

Example:
> (let-syntax ([bag (make-code-transformer #'(code hat))]
               [copy (make-code-transformer (syntax-rules ()
                                             [(_ c) (code (* 2 c))]))])
    (inset (frame (code ((copy cat) in the bag))) 2))

image

syntax

(define-exec-code (pict-id runnable-id string-id)
  datum ...)
Binds pict-id to the result of (code datum ...), except that if an identifier _ appears anywhere in a datum, then the identifier and the following expression are not included for code.

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 ...)
Like define-exec-code, but with a scale to use via scale/improve-new-text when generating the pict.

For backward compatibility, the default values for current-comment-color, etc.

procedure

(code-pict-bottom-line-pict pict)  (or/c pict? #f)

  pict : pict?
The same as pict-last, provided for backward compatibility.

procedure

(pict->code-pict pict bl-pict)  pict?

  pict : pict?
  bl-pict : (or/c pict? #f)
Mainly for backward compatibility: returns (if bl-pict (use-last pict (or (pict-last bl-pict) bl-pict))).

7.5.1 Codeblocks

procedure

(codeblock-pict code-string    
  [#:keep-lang-line? keep?])  pict?
  code-string : string?
  keep? : any/c = #t
Like Scribble’s codeblock but generates picts.

Unlike code, codeblock-pict formats and colors based on the code’s language’s lexer, which makes it suitable for use with code that doesn’t use Racket syntax.

When keep? is #f, the first #lang line is removed from the pict.

Example:
> (codeblock-pict
    #:keep-lang-line? #f
    (string-join
      '("#lang 2d racket"
        "(require 2d/cond)"
        "(define (same? a b)"
        "  #2dcond"
        "  ╔═════════════╦═══════════════════════╦═════════════╗"
        "                      (pair? a)       ║ (number? a) ║"
        "  ╠═════════════╬═══════════════════════╬═════════════╣"
        "  ║ (pair? b)   ║ (and (same? (car a)        #f      ║"
        "                            (car b))               ║"
        "                     (same? (cdr a)                ║"
        "                            (cdr b))) ║             ║"
        "  ╠═════════════╬═══════════════════════╬═════════════╣"
        "  ║ (number? b) ║          #f              (= a b)   ║"
        "  ╚═════════════╩═══════════════════════╩═════════════╝)")
      "\n"))

image

parameter

(current-token-class->color)

  (-> symbol? (or/c string? (is-a?/c color%)))
(current-token-class->color to-color)  void?
  to-color : (-> symbol? (or/c string? (is-a?/c color%)))
A parameter that provides additional control over the colors used by codeblock-pict. The to-color procedure is applied to each token class produced by a language’s lexer to map the class name to a particular color.

The default value maps the standard set of token classes (as recognized by DrRacket) to the corresponding colors used by code. Specifically, it maps

It is usually sufficient to adjust the individual color parameters also used by code, but current-token-class->color allows for more fine-grained control over how codeblock-pict interprets token classes.

Added in version 1.8 of package pict-lib.