diff --git a/extensions/hugo/shortcodes/sidefigure.html.html b/extensions/hugo/shortcodes/sidefigure.html.html new file mode 100644 index 0000000..e2ed243 --- /dev/null +++ b/extensions/hugo/shortcodes/sidefigure.html.html @@ -0,0 +1,76 @@ +{{/* Figures at the margin. + +Batteries not included. Requires lots of styles. +Some content breaks paragraphs! + +Usage: + +{{< sidefigure class="optional CSS class" valign= + numbered=numbered raw=raw header="Some text" >}} +Content here. +{{< /sidefigure >}} +Parameters: + class: one or more CSS class names + valign: where the bottom of the sidenote will be placed wrt the inline content. + "top" is the default: the sidenote starts at the height it is inserted. + "center" shifts it by 50% upwards. "bottom" by 100%. + numbered: whether to prefix the content with an autoincreased counter and + display it in the main text. + markdownify: whether to process .Inner with the markdown renderer. This is a + HACK, remove it. Will break nested shortcodes. + raw: set to true if there are nested shortcodes, e.g. {{
}} or {{}} + header: This will be rendered bold and centered above the content +*/}} +{{- $this := . -}} +{{- $class := "sidenote" -}} +{{- with .Get "valign" -}} + {{- if (eq . "center") -}} + {{- $class = printf "%s %s" $class (safeHTMLAttr "sidenote-center") -}} + {{- end -}} + {{- if (eq . "bottom") -}} + {{- $class = printf "%s %s" $class (safeHTMLAttr "sidenote-bottom") -}} + {{- end -}} +{{- end -}} +{{- with .Get "class" -}} + {{- $class = printf "%s %s" $class (safeHTMLAttr .) -}} +{{- end -}} +{{- $refText := "" -}} +{{- $anchor := "" -}} +{{- with .Get "numbered" -}} + {{- $this.Page.Scratch.Add "sidenote-counter" 1 -}} + {{- $refText = printf "Figure %d. " ($this.Page.Scratch.Get "sidenote-counter") -}} + {{- $anchor = printf "%s" $refText -}} +{{- end -}} +{{- $anchor | safeHTML -}} + + + {{ $src := .Get "src"}} + {{- with .Page.Resources.GetMatch $src }} + {{- $src = .RelPermalink }} + {{- end }} + {{.Get + + + {{- with .Get "title" -}} + {{.}} + {{- end -}} + {{ if or (.Get "caption") .Inner }} + + {{- $anchor | safeHTML -}} + + {{ with .Get "caption"}} + {{ . | markdownify }} + {{ end }} + {{ with .Inner }} + {{ if $.Get "markdownify" }} + {{ . | markdownify }} + {{ else }} + {{ . }} + {{ end }} + {{ end }} + + + {{ end }} + + +{{- /**/ -}} diff --git a/progs/markdownout.scm b/progs/markdownout.scm index b660b27..10de366 100644 --- a/progs/markdownout.scm +++ b/progs/markdownout.scm @@ -429,18 +429,31 @@ (alt (if (list-2? payload) (second payload) ""))) (string-append "![" alt "](" (force-string src) ")"))) -(define (md-figure-sub x type . args) - (let* ((payload (cdr x)) - (src (force-string (car payload))) +; FIXME: clear this mess with figures, don't expect img as content, etc. +(define (md-figure-sub payload) + (let* ((src (force-string (car payload))) (title (with-globals 'num-line-breaks 0 ; Don't break lines in 'document (string-concatenate (map serialize-markdown* (cdr payload)))))) - (if (hugo-extensions?) - (md-hugo-shortcode `(,type (src ,src) ,@args) title) - (md-image (list 'image src title))))) + (list src title))) (define (md-figure type . args) - (lambda (x) (md-figure-sub x type args))) + (lambda (x) + (with params (md-figure-sub (cdr x)) + (if (hugo-extensions?) + (md-hugo-shortcode `(,type (src ,(car params)) ,args) (cadr params)) + (md-image (list 'image (car params) (cadr params))))))) + +(define (md-marginal-figure type . args) + (lambda (x) + (let ((params (md-figure-sub (cddr x))) + (vpos (cadr x))) + (if (hugo-extensions?) + (md-hugo-shortcode `(,type (valign ,(marginal-style vpos)) + (src ,(car params)) + ,args) + (cadr params)) + (md-image (list 'image (car params) (cadr params))))))) (define (md-footnote x) @@ -487,8 +500,10 @@ (string-append (serialize-markdown* inner) "{{string (car x)) ">}}")))) (string-trim-both - (string-recompose-space - `("{{<" ,shortcode ,@(map process-one arguments) ">}}" ,content)))))) + (string-append + (string-recompose-space + `("{{<" ,shortcode ,@(map process-one arguments) ">}}")) + content))))) (define (md-toc x) (if (hugo-extensions?) @@ -500,15 +515,20 @@ (md-hugo-shortcode '(references)) (md-style '(strong "Bibliography not implemented for raw Markdown")))) +(define marginal-styles-table + (list->ahash-table '(("b" . "bottom") ("c" . "center") + ("t" . "top") ("normal" . "right")))) + +(define (marginal-style s) + (ahash-ref marginal-styles-table s)) + (define (md-sidenote-sub x numbered?) (if (hugo-extensions?) - (let ((styles (list->ahash-table '(("b" . "bottom") ("c" . "center") - ("t" . "top") ("normal" . "right")))) - (numbered (if numbered? '(numbered "numbered") '())) + (let ((numbered (if numbered? '((numbered "numbered")) '())) (args (cdr x))) (md-hugo-shortcode - (append `(sidenote (halign ,(ahash-ref styles (first args))) - (valign ,(ahash-ref styles (second args)))) + (append `(sidenote (halign ,(marginal-style (first args))) + (valign ,(marginal-style (second args)))) numbered) (third args))) (md-footnote (list 'footnote (third (cdr x)))))) @@ -640,9 +660,15 @@ (list 'footnote md-footnote) (list 'todo md-todo) (list 'image md-image) - (list 'small-figure (md-figure 'tmfigure)) - (list 'big-figure (md-figure 'tmfigure)) - (list 'wide-figure (md-figure 'tmfigure 'class "wide-figure")) + (list 'small-figure (md-figure 'tmfigure 'numbered "numbered")) + (list 'small-figure* (md-figure 'tmfigure)) + (list 'big-figure (md-figure 'tmfigure 'numbered "numbered")) + (list 'big-figure* (md-figure 'tmfigure)) + (list 'wide-figure (md-figure 'tmfigure 'class "wide-figure" + 'numbered "numbered")) + (list 'wide-figure* (md-figure 'tmfigure 'class "wide-figure")) + (list 'marginal-figure (md-marginal-figure 'sidefigure)) + (list 'marginal-figure* (md-marginal-figure 'sidefigure)) (list 'hlink md-hlink) (list 'tags md-hugo-tags) ; Hugo extension (DEPRECATED) (list 'hugo-short md-hugo-shortcode) ; Hugo extension diff --git a/progs/tmmarkdown.scm b/progs/tmmarkdown.scm index 193f687..264aad8 100644 --- a/progs/tmmarkdown.scm +++ b/progs/tmmarkdown.scm @@ -87,7 +87,6 @@ first empty label" (counter-new 'equation) (counter-new 'figure)) - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Helper functions for the transformation of strees and dispatcher ;; TODO: use TeXmacs' logic-dispatch, export sessions, bibliography @@ -187,7 +186,7 @@ first empty label" (numbered-unnumbered-append (figure-tag-list))) (not (string-contains? (symbol->string (car x)) "table")))) -(define (parse-figure x) +(define (parse-figure-sub x) ; Example input: ; (big-figure (image "path-to.jpeg" "251px" "251px" "" "") ; (document "caption")) @@ -198,11 +197,22 @@ first empty label" ; implementing Figure text as TeXmacs. (let* ((offset (if (is-figure? x) 0 2)) (img (tm-ref x offset)) - (caption (texmacs->markdown* (tm-ref x (+ 1 offset)))) + (caption `(concat (strong "Figure " + ,(counter-label current-counter) + ". ") + ,(texmacs->markdown* (tm-ref x (+ 1 offset))))) (src (if (tm-is? img 'image) (tm-ref (parse-image img) 0) '(document "Wrong image src")))) - (list (car x) src caption))) + (list src caption))) + +(define (parse-figure x) + `(,(car x) ,@(parse-figure-sub x))) + +(define (parse-marginal-figure x) + (let* ((vpos (first (cdr x))) + (args (parse-figure-sub `(small-figure ,@(cddr x))))) + `(,(car x) ,vpos ,@args))) (define (parse-with x) ; HACK: we end up calling ourselves with (with "stuff"), which @@ -400,10 +410,15 @@ first empty label" (list 'reference parse-reference) (list 'image parse-image) (list 'small-figure (count parse-figure 'figure)) + (list 'small-figure* parse-figure) (list 'render-small-figure parse-figure) (list 'big-figure (count parse-figure 'figure)) + (list 'big-figure* parse-figure) (list 'render-big-figure parse-figure) (list 'wide-figure (count parse-figure 'figure)) + (list 'wide-figure* parse-figure) + (list 'marginal-figure (count parse-marginal-figure 'figure)) + (list 'marginal-figure* parse-marginal-figure) (list 'footnote keep) (list 'marginal-note keep) (list 'marginal-note* keep) diff --git a/tests/hugo/marginal-figure.md b/tests/hugo/marginal-figure.md new file mode 100644 index 0000000..621f080 --- /dev/null +++ b/tests/hugo/marginal-figure.md @@ -0,0 +1,10 @@ +--- + +--- + +Is it possible to characterize ultra-universal, pseudo-unique, partially +regular measure spaces? Recently, there has been much interest in the +computation of partially empty arrows. In [14], the authors address the +surjectivity{{< sidefigure valign="top" src="NaiveMCShapley1000itersBoston.png" +numbered="numberered" >}}This is a numbered margin figure with +caption{{}} of unconditionally regular functors. \ No newline at end of file diff --git a/tests/hugo/marginal-figure.tm b/tests/hugo/marginal-figure.tm new file mode 100644 index 0000000..ecd11a7 --- /dev/null +++ b/tests/hugo/marginal-figure.tm @@ -0,0 +1,15 @@ + + +> + +<\body> + Is it possible to characterize ultra-universal, pseudo-unique, partially + regular measure spaces? Recently, there has been much interest in the + computation of partially empty arrows. In [14], the authors address the + surjectivity|This + is a numbered margin figure with caption> of unconditionally regular + functors. + + + +> \ No newline at end of file