From a26a7322a54dc0d6dc898a60828a17cf4b082980 Mon Sep 17 00:00:00 2001 From: Leif Andersen Date: Wed, 22 Mar 2017 19:42:21 -0400 Subject: [PATCH] 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) --- scribble-doc/scribblings/scribble/core.scrbl | 4 ++-- scribble-lib/scribble/acmart.rkt | 4 ++-- scribble-lib/scribble/latex-properties.rkt | 2 +- scribble-lib/scribble/latex-render.rkt | 19 ++++++++++++------- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/scribble-doc/scribblings/scribble/core.scrbl b/scribble-doc/scribblings/scribble/core.scrbl index 50300dfe..361d120a 100644 --- 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 index f29ee562..a590d5d3 100644 --- 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 index 4a234a93..3160a473 100644 --- 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 index 68dfac79..e022c920 100644 --- 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)))