commit a26a7322a54dc0d6dc898a60828a17cf4b082980
parent 558a8a5c64912de2a205c402a50c3062bf3b287c
Author: Leif Andersen <leif@leifandersen.net>
Date: Wed, 22 Mar 2017 19:42:21 -0400
Latex macros _can_ actually have multiple optional args.
While done as a tex hack, macros in latex can have multiple optional
arguments. As such, we should support it with command-optional.
Meaning that the type of command-optional-arguments is now (Listof String)
Diffstat:
4 files changed, 17 insertions(+), 12 deletions(-)
diff --git a/scribble-doc/scribblings/scribble/core.scrbl b/scribble-doc/scribblings/scribble/core.scrbl
@@ -1800,10 +1800,10 @@ See also @racketmodname[scribble/latex-prefix].}
Used as a @tech{style property} on an @racket[element] to add extra
arguments to the element's command in Latex output.}
-@defstruct[command-optional ([argument string?])]{
+@defstruct[command-optional ([arguments (listof string?)])]{
Used as a @tech{style property} on a @racket[element] to add
- an optional argument to the element's command in Latex output.
+ a optional arguments to the element's command in Latex output.
@history[#:added "1.20"]
}
diff --git a/scribble-lib/scribble/acmart.rkt b/scribble-lib/scribble/acmart.rkt
@@ -307,13 +307,13 @@
[(#f) (make-element (make-style "institution" command-props)
(decode-content name))]
[(sub) (make-element (make-style "department"
- (cons (command-optional (number->string level))
+ (cons (command-optional (list (number->string level)))
command-props))
(decode-content name))]
[else (make-element (make-style "department"
(append
(if (> level 0)
- (list (command-optional (number->string level)))
+ (list (command-optional (list (number->string level))))
(list))
command-props))
(decode-content name))]))
diff --git a/scribble-lib/scribble/latex-properties.rkt b/scribble-lib/scribble/latex-properties.rkt
@@ -11,5 +11,5 @@
[(latex-defaults+replacements latex-defaults)
([replacements (hash/c string? (or/c bytes? path-string? (cons/c 'collects (listof bytes?))))])]
[command-extras ([arguments (listof string?)])]
- [command-optional ([argument string?])]
+ [command-optional ([arguments (listof string?)])]
[short-title ([text (or/c string? #f)])])
diff --git a/scribble-lib/scribble/latex-render.rkt b/scribble-lib/scribble/latex-render.rkt
@@ -486,9 +486,11 @@
[(multiarg-element? e)
(check-render)
(printf "\\~a" style-name)
- (define maybe-optional
+ (define maybe-optional-args
(findf command-optional? (if style (style-properties style) '())))
- (and maybe-optional (printf "[~a]" maybe-optional))
+ (when maybe-optional-args
+ (for ([i (in-list (command-optional-arguments maybe-optional-args))])
+ (printf "[~a]" i)))
(if (null? (multiarg-element-contents e))
(printf "{}")
(for ([i (in-list (multiarg-element-contents e))])
@@ -499,11 +501,14 @@
[else
(define maybe-optional
(findf command-optional? (if style (style-properties style) '())))
- (wrap e
- (if maybe-optional
- (format "~a[~a]" style-name (command-optional-argument maybe-optional))
- style-name)
- tt?)]))]
+ (if maybe-optional
+ (wrap e
+ (string-join #:before-first (format "~a[" style-name)
+ #:after-last "]"
+ (command-optional-arguments maybe-optional)
+ "][")
+ tt?)
+ (wrap e style-name tt?))]))]
[(and (not style-name)
style
(memq 'exact-chars (style-properties style)))