[racket] Making a section optional in Scribble
On Tue, Dec 16, 2014 at 9:27 PM, Matthias Felleisen
<matthias at ccs.neu.edu> wrote:
>
> A 'when' expression returns the value of the last expression, in your
> case the content of the section. By lifting the when out, you get both
> pieces: [...]
After I complained about it a few times, Matthew made it possible to use
lists, as well as some other other scribble/text-isms (like ignoring #f
and void):
#lang scribble/base
@(define some-condition #true)
@title{Use Lists}
@section{Section one}
Section one is for everyone.
@(when some-condition
(list @section{Section two}
"Section two is for some, but not all."
"This is more satisfactory."))
But it's more convenient to use the text syntax, and it works better in
that you don't get the hard-to-find formatting bug that the above
produced:
#lang scribble/base
@(define some-condition #true)
@title{Use Lists}
@section{Section one}
Section one is for everyone.
@(when some-condition
@list{@section{Section two}
Section two is for some, but not all.
This is more satisfactory.})
> This is clearly unsatisfactory but I am sure you can make this look
> decent with a bit of macrology
A tiny bit of very simple macrology that can still be useful here is:
#lang scribble/base
@(define some-condition #true)
@(define-syntax-rule (when* C E ...) (and C (list E ...)))
@title{Use Lists}
@section{Section one}
Section one is for everyone.
@when*[some-condition]{
@section{Section two}
Section two is for some, but not all.
This is more satisfactory.}
[In my fantasies I get to redefine a #%begin[*] macro to `list'
(actually, `begin/text') and that makes everything works as people
usually expect.]
And since lists have no rendering meaning (= they're just flattened) (at
least that was how I wanted it, hopefuly it didn't change--?), you don't
need tricks like `append-map' and similar:
#lang scribble/base
@(define some-condition #true)
@(define-syntax-rule (when* C E ...) (and C (list E ...)))
@title{Use Lists}
@section{Section one}
Section one is for everyone.
@(define (triple . x) (build-list 3 (λ(_) (list x "\n" "\n"))))
@when*[some-condition]{
@triple{
@section{Section two}
@triple{Section two is for some, but not all.
This is more satisfactory.}}}
--
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
http://barzilay.org/ Maze is Life!