[scribble] code:hilite for binders

32 views
Skip to first unread message

Éric Tanter

unread,
Aug 22, 2020, 6:15:17 PM8/22/20
to racket users
Hi,

From the doc: `(code:hilite datum)` typesets like `datum`, but with a background highlight.
However, it does not work to highlight a binder, eg: `(letrec ([(code:hilite self) …]) …)`
Is there another way to highlight a binder?

Thanks,

— Éric




Éric Tanter

unread,
Aug 22, 2020, 6:25:31 PM8/22/20
to racket users
Just to complement: I’m editing some scribble I wrote years ago and I completely forgot why I was doing that, but to be able to use `(code:highlight …)` in code blocks, I had to add the following line (where `ex-eval` is my base evaluator):
```
@interaction-eval[#:eval ex-eval (define (code:hilite v) v) ]
```

sorry if that’s confusing, but I’m confused ;-)

I just want a way to highlight any bits in a code block, in order to bring the reader’s attention to specific places (could be binders, whole expressions, etc.).

Thanks!

— Éric
> --
> You received this message because you are subscribed to the Google Groups "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/32CE30FE-9724-4421-9A8B-63780A403A5A%40dcc.uchile.cl.

Éric Tanter

unread,
Aug 23, 2020, 10:23:31 AM8/23/20
to racket users
Ok, I “solved” my problem.

The `(define (code:hilite v) v)` is a hack to be able to use `code:hilite` in blocks that are executed, not just displayed, but of course that does not work when highlighting binders.

The solution is to separate the display from the execution, with a separate evaluation in the corresponding evaluator.

The downside is that this forces a duplication of the code (once to display with highlight, once to evaluate). I’m still interested in knowing if there’s a duplication-free solution to this, but meanwhile I’ll just live with it.

— Éric
> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/09CDBBC0-8A5B-4573-9CC6-DA41B3DE53C1%40dcc.uchile.cl.

Robby Findler

unread,
Aug 23, 2020, 10:27:06 AM8/23/20
to Éric Tanter, racket users
I think I've run into this too (but my memory is foggy) and what I did was have a macro that expands into `code` and also expands into the actual code but walks over the code and drops things like code:hilite and code:comment.

Robby


Éric Tanter

unread,
Aug 23, 2020, 4:00:48 PM8/23/20
to Robby Findler, racket users
I was expecting (fearing?) such an answer ;-)
If by any chance you have that macro lying around, I would happily reuse it. It might make sense to include such a facility in scribble anyway.

-- Éric

On 23-08-2020, at 10:27, Robby Findler <ro...@cs.northwestern.edu> wrote:



Ryan Kramer

unread,
Aug 23, 2020, 6:37:52 PM8/23/20
to Racket Users
You might also be able to use make-element-id-transformer like this

#lang scribble/manual

@(begin
   (require scribble/racket
            scribble/eval
            (for-syntax racket/base))

   (define-syntax FOO (make-element-id-transformer
                       (lambda arglist #'(racket (code:hilite foo)))))
   (interaction
    (let ([FOO 41])
      (add1 FOO))))

Reply all
Reply to author
Forward
0 new messages