racket / redex

Other
93 stars 36 forks source link

Reduce space between rendered rules of a judgement form #264

Open o6po5fcs opened 1 year ago

o6po5fcs commented 1 year ago

I have quite a large judgment form to be rendered for a paper, and I would like to somewhat compact it by reducing the space between the different rules. A standalone excerpt of the judgment form can be found below. To demonstrate, I set all of the "spacing" parameters that I could find to 0, even when they do not affect the rendering of judgment forms.

As a sidenote, I have noticed that, in some cases, the parameter horizontal-bar-spacing reduces only the space above a horizontal bar, and not below. In the screenshot below the code I highlighted one such instance with a red arrow. Possibly related to the inclusion of a unicode union character in the bottom line?

#lang racket

(require redex
         redex/pict)
(define-language CommonLang
  (k ::= number i)
  (p ::= (k ...)) 
  (p-exp ::= k * [script-op (~ k ...)] [script-op k] [⋃ k ...]))

(define-judgment-form
  CommonLang
  #:mode     (matches-in-env I I I)
  #:contract (matches-in-env ps p env)

  [--------------------------------- "empty-selector"
   (matches-in-env () () env)]
  [(matches-in-env (p-exp ...) (k_2 ...) env)
   --------------------------------- "literal-key"
   (matches-in-env (k_1 p-exp ...) (k_1 k_2 ...) env)]
  [(matches-in-env (k_1 p-exp ...) (k_2 ...) env)
   --------------------------------- "union-first"
   (matches-in-env ([⋃ k_1 k_3 ...] p-exp ...) (k_2 ...) env)])

(define (render-matches-in-env . filepath)
  (arrow-space 0)
  (label-space 0)
  (reduction-relation-rule-separation 0) 
  (reduction-relation-rule-extra-separation 0)
  (reduction-relation-rule-line-separation 0)
  (horizontal-bar-spacing 0)
  (metafunction-gap-space 0)
  (metafunction-rule-gap-space 0)
  (metafunction-line-gap-space 0)

  (if (empty? filepath)
      (render-judgment-form matches-in-env)
      (render-judgment-form matches-in-env (car filepath))))

The space that I wish to somewhat reduce highlighted with a red bar, and an instance of horizontal-bar-spacing not respecting being set to 0 is highlighted with a red arrow.

annotated-space

rfindler commented 1 year ago

The best way I have found to handle placement of individual rules in a judgment form is to make them each into independent picts and then put them manually into a larger pict with the precise layout to fit the page well.

That said, I could add more parameters to control some of the spaces you're seeing below (later on).

Robby

On Thu, Jun 29, 2023 at 8:00 AM o6po5fcs @.***> wrote:

I have quite a large judgment form to be rendered for a paper, and I would like to somewhat compact it by reducing the space between the different rules. A standalone excerpt of the judgment form can be found below. To demonstrate, I set all of the "spacing" parameters that I could find to 0, even when they do not affect the rendering of judgment forms.

As a sidenote, I have noticed that, in some cases, the parameter horizontal-bar-spacing reduces only the space above a horizontal bar, and not below. In the screenshot below the code I highlighted one such instance with a red arrow.

lang racket

(require redex redex/pict) (define-language CommonLang (k ::= number i) (p ::= (k ...)) (p-exp ::= k * [script-op (~ k ...)] [script-op k] [⋃ k ...]))

(define-judgment-form CommonLang

:mode (matches-in-env I I I)

:contract (matches-in-env ps p env)

[--------------------------------- "empty-selector" (matches-in-env () () env)] [(matches-in-env (p-exp ...) (k_2 ...) env) --------------------------------- "literal-key" (matches-in-env (k_1 p-exp ...) (k_1 k_2 ...) env)] [(matches-in-env (k_1 p-exp ...) (k_2 ...) env) --------------------------------- "union-first" (matches-in-env ([⋃ k_1 k_3 ...] p-exp ...) (k_2 ...) env)])

(define (render-matches-in-env . filepath) (arrow-space 0) (label-space 0) (reduction-relation-rule-separation 0) (reduction-relation-rule-extra-separation 0) (reduction-relation-rule-line-separation 0) (horizontal-bar-spacing 0) (metafunction-gap-space 0) (metafunction-rule-gap-space 0) (metafunction-line-gap-space 0)

(if (empty? filepath) (render-judgment-form matches-in-env) (render-judgment-form matches-in-env (car filepath))))

The space that I wish to somewhat reduce highlighted with a red bar, and an instance of horizontal-bar-spacing not respecting being set to 0 is highlighted with a red arrow.

[image: annotated-space] https://user-images.githubusercontent.com/115168139/249812038-6dfdd514-f612-4e99-a96d-cc70e4d78a8b.jpg

— Reply to this email directly, view it on GitHub https://github.com/racket/redex/issues/264, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADBNMDMAZWOEPZ7QX7RXILXNWJ65ANCNFSM6AAAAAAZYUPY4U . You are receiving this because you are subscribed to this thread.Message ID: @.***>

o6po5fcs commented 1 year ago

Alright, thank you for the quick response! I had hoped to (as much as possible) make the figures easy to reproduce in code, but in this specific instance it is probably much faster to edit the pdf in Adobe Illustrator to reposition the rules.

For my part the issue can be closed, but I will keep it open for now in case the horizontal-bar-spacing thing is something someone wants to address.

rfindler commented 1 year ago

The disadvantage to using adobe is that you'll have to redo that work when the rules change and it can be easy to forget to do. If you're using scribble to write the document itself, you can just drop picts in anywhere (eg in a figure) and then building the paper will always just use the latest version of the redex code. Here's how you can eliminate the blank space between the clauses, for example.

#lang racket
(require redex pict)
(define-language L
  (e ::= (e e) (λ (x) e) x)
  (x ::= variable-not-otherwise-mentioned))

(define-judgment-form L
  #:mode (fv I O)
  #:contract (fv e (x ...))

  [(fv e_1 (x_1 ...)) (fv e_2 (x_2 ...))
   ------------------------------- "app"
   (fv (e_1 e_2) (x_1 ... x_2 ...))]

  [------------------------------- "var"
   (fv x (x))]

  [(fv e (x_2 ...))
   ------------------------------- "lam"
   (fv (λ (x_1) e) (rm (x_2 ...) x_1))])

(define-metafunction L
  rm : (x ...) x -> (x ...)
  [(rm () x) ()]
  [(rm (x_1 x_2 ...) x_1) (rm (x_2 ...) x_1)]
  [(rm (x_1 x_2 ...) x_3)
   (x_1 x_4 ...)
   (where (x_4 ...) (rm (x_2 ...) x_3))])

(define (render-fv-case name)
  (parameterize ([judgment-form-cases
                  (list name)])
    (render-judgment-form fv)))

(render-judgment-form fv)

(vc-append
 (render-fv-case "app")
 (render-fv-case "var")
 (render-fv-case "lam"))