scribble icon indicating copy to clipboard operation
scribble copied to clipboard

Use of macros can ruin typesetting in racketblock and similar

Open default-kramer opened this issue 7 years ago • 3 comments
trafficstars

Consider this simple scribble document

#lang scribble/manual

@(define-syntax-rule (show-rb x)
   (racketblock
    (if (= 1 x)
        'yes
        'no)))

@(show-rb 2)
@(show-rb 3)
@(show-rb 4)

You can see that the "external" pieces of syntax cause extra whitespace in the rendered HTML.

I haven't found a built-in way to avoid this problem. Have I overlooked something, or is this a known issue?

default-kramer avatar Oct 02 '18 18:10 default-kramer

On Oct 2, 2018, at 2:21 PM, Ryan Kramer [email protected] wrote:

Consider this simple scribble document

#lang scribble/manual

@(define-syntax-rule (show-rb x) (racketblock (if (= 1 x) 'yes 'no)))

@(show-rb 2) @(show-rb 3) @(show-rb 4)

You can see that the "external" pieces of syntax cause extra whitespace in the rendered HTML.

I haven't found a built-in way to avoid this problem. Have I overlooked something, or is this a known issue?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

@(define (show-rb x) (racketblock (if (= 1 #,x) 'yes 'no)))

@(show-rb 2) @(show-rb 3) @(show-rb 4)

mfelleisen avatar Oct 02 '18 21:10 mfelleisen

Oops, I guess I simplified my example too much! Here is a better example:

#lang scribble/manual

@(define-syntax-rule (show-rb x)
   (racketblock (if (= 1 x)
                    'yes
                    'no)))

@(show-rb (cond
            [(= f g) 99]
            [else 98]))

Is there a simple workaround for this one?

FWIW - I did manage to find a workaround, but it's not ideal. I have a macro that generates the racketblock by doing something like this:

#`(racketblock
   (println "hi")
   #,(move #'here #'x -10)
   (println "bye"))

Which changes the line+column of #'x to match #'here (with an offset of -10 to move it 10 columns to the left). This causes scribble to render it exactly how I want it to look. But, my implementation of move is probably pretty shaky. Plus, it seems to be relying on an implementation detail in scribble. Maybe the ideal solution is some special escape similar to code:hilite which would allow me to say (code:move x) which would tell scribble that x is an "external" piece of syntax, and its line+column numbers need to be tweaked.

default-kramer avatar Oct 02 '18 21:10 default-kramer

On Oct 2, 2018, at 5:26 PM, Ryan Kramer [email protected] wrote:

FWIW - I did manage to find a workaround, but it's not ideal. I have a macro that generates the racketblock by doing something like this:

#`(racketblock (println "hi") #,(move #'here #'x -10) (println "bye"))

Which changes the line+column of #'x to match #'here (with an offset of -10 to move it 10 columns to the left). This causes scribble to render it exactly how I want it to look.

That’s probably what you want in this case

mfelleisen avatar Oct 02 '18 22:10 mfelleisen