Formatting text: settings by parameterize around show, or with-fmt*
The Settings section says where a parameterize of a setting works: around show, not around the code that builds a block. For part of an output it shows with-fmt*, which binds several settings as parameterize does. 🤖 Generated with [ECA](https://eca.dev) (anthropic/claude-opus-5-5) Co-Authored-By: eca-agent <git@eca.dev>
This commit is contained in:
parent
5bc42069cd
commit
4f8da92dc2
1 changed files with 17 additions and 6 deletions
|
|
@ -893,14 +893,25 @@ The rows can be spliced, @code{(rows ,scores)}, from a @code{(Vec (Vec TableCell
|
||||||
|
|
||||||
@subsubsection{Settings}
|
@subsubsection{Settings}
|
||||||
|
|
||||||
The pad character, the right margin, the ellipsis and the number formats are parameters. @code{with-fmt} binds one around some blocks while they run, and @code{with-pad} is @code{with-fmt} for @code{current-pad}. Settings nest:
|
The pad character, the right margin, the ellipsis and the number formats are parameters. For a whole output, set them with @code{parameterize} around the @code{show}:
|
||||||
|
|
||||||
@codeblock[#:lang "bjolang"]|{
|
@codeblock[#:lang "bjolang"]|{
|
||||||
(show [(with-fmt current-comma 3
|
(parameterize ((current-width 20))
|
||||||
(with-fmt current-comma-sep #\space
|
(show (wrapped "Bjolang lays text out with blocks, and blocks nest.")))
|
||||||
(with-fmt current-decimal-sep #\,
|
;; Bjolang lays text
|
||||||
(numeric 1234567.5))))
|
;; out with blocks, and
|
||||||
nl])
|
;; blocks nest.
|
||||||
|
}|
|
||||||
|
|
||||||
|
A block reads its settings when it runs, which is in @code{show}, not when it is built. So the @code{parameterize} must be around the @code{show}: around the code that builds the block, it has ended before the block runs, and does nothing. @code{(show (parameterize ((current-width 20)) (wrapped text)))} wraps at the default width, 78.
|
||||||
|
|
||||||
|
For part of an output, such as one paragraph, one cell or the numbers of one column, put the setting in the layout. @code{with-fmt} binds one setting around a block while it runs, @code{with-fmt*} binds several, written as @code{parameterize} is, and @code{with-pad} is @code{with-fmt} for @code{current-pad}:
|
||||||
|
|
||||||
|
@codeblock[#:lang "bjolang"]|{
|
||||||
|
(show (with-fmt* ((current-comma 3)
|
||||||
|
(current-comma-sep #\space)
|
||||||
|
(current-decimal-sep #\,))
|
||||||
|
(numeric 1234567.5) nl))
|
||||||
;; 1 234 567,5
|
;; 1 234 567,5
|
||||||
}|
|
}|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue