From dde9af3c60b2bc71cff7f164627656d46f387306 Mon Sep 17 00:00:00 2001 From: Miguel de Benito Delgado Date: Sun, 16 May 2021 23:13:53 +0200 Subject: [PATCH 1/5] WIP: marginal figures. Quite a mess. --- progs/markdownout.scm | 55 +++++++++++++++++++++++++++++++------------ progs/tmmarkdown.scm | 17 +++++++++++-- 2 files changed, 55 insertions(+), 17 deletions(-) diff --git a/progs/markdownout.scm b/progs/markdownout.scm index f2fcde7..c5dfade 100644 --- a/progs/markdownout.scm +++ b/progs/markdownout.scm @@ -430,18 +430,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) @@ -501,15 +514,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)))))) @@ -641,9 +659,16 @@ (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 + 'numbered "numberered")) + (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 d50e4b7..9419fe5 100644 --- a/progs/tmmarkdown.scm +++ b/progs/tmmarkdown.scm @@ -159,7 +159,7 @@ (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")) @@ -174,7 +174,15 @@ (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 @@ -363,10 +371,15 @@ (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) From 8716138c66840ad0fbcc5585c56cb6715c02feea Mon Sep 17 00:00:00 2001 From: Miguel de Benito Delgado Date: Sun, 16 May 2021 23:20:43 +0200 Subject: [PATCH 2/5] WIP: hugo shortcode for marginal figures. --- .../hugo/shortcodes/sidefigure.html.html | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 extensions/hugo/shortcodes/sidefigure.html.html diff --git a/extensions/hugo/shortcodes/sidefigure.html.html b/extensions/hugo/shortcodes/sidefigure.html.html new file mode 100644 index 0000000..5160142 --- /dev/null +++ b/extensions/hugo/shortcodes/sidefigure.html.html @@ -0,0 +1,70 @@ +{{/* 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. + 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 "[%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 }} + {{ . }} + {{ end }} + + + {{ end }} + +
+{{- /**/ -}} From 6268a0fa62d990a6fbe3795d538cb0abeaafa7c2 Mon Sep 17 00:00:00 2001 From: Miguel de Benito Delgado Date: Mon, 17 May 2021 14:06:28 +0200 Subject: [PATCH 3/5] Test marginal figure (incomplete) --- tests/hugo/marginal-figure.md | 10 ++++++++++ tests/hugo/marginal-figure.tm | 15 +++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 tests/hugo/marginal-figure.md create mode 100644 tests/hugo/marginal-figure.tm 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 From 8c06dd2d28e4e078034c9cf3ec0246e2145455e3 Mon Sep 17 00:00:00 2001 From: Miguel de Benito Delgado Date: Mon, 17 May 2021 14:07:00 +0200 Subject: [PATCH 4/5] Avoid unnecessary whitespace --- progs/markdownout.scm | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/progs/markdownout.scm b/progs/markdownout.scm index c5dfade..9e6ac06 100644 --- a/progs/markdownout.scm +++ b/progs/markdownout.scm @@ -501,8 +501,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?) From c48382fa03a69fa594cffef206a2a3ab35fc623d Mon Sep 17 00:00:00 2001 From: Miguel de Benito Delgado Date: Fri, 21 May 2021 01:03:22 +0200 Subject: [PATCH 5/5] Don't use shortcode numbering for figures. --- extensions/hugo/shortcodes/sidefigure.html.html | 14 ++++++++++---- progs/markdownout.scm | 5 ++--- progs/tmmarkdown.scm | 7 +++++-- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/extensions/hugo/shortcodes/sidefigure.html.html b/extensions/hugo/shortcodes/sidefigure.html.html index 5160142..e2ed243 100644 --- a/extensions/hugo/shortcodes/sidefigure.html.html +++ b/extensions/hugo/shortcodes/sidefigure.html.html @@ -16,6 +16,8 @@ "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 */}} @@ -36,18 +38,18 @@ {{- $anchor := "" -}} {{- with .Get "numbered" -}} {{- $this.Page.Scratch.Add "sidenote-counter" 1 -}} - {{- $refText = printf "[%d]" ($this.Page.Scratch.Get "sidenote-counter") -}} + {{- $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" -}} {{.}} @@ -60,7 +62,11 @@ {{ . | markdownify }} {{ end }} {{ with .Inner }} - {{ . }} + {{ if $.Get "markdownify" }} + {{ . | markdownify }} + {{ else }} + {{ . }} + {{ end }} {{ end }} diff --git a/progs/markdownout.scm b/progs/markdownout.scm index 9e6ac06..6c0a02a 100644 --- a/progs/markdownout.scm +++ b/progs/markdownout.scm @@ -525,7 +525,7 @@ (define (md-sidenote-sub x numbered?) (if (hugo-extensions?) - (let ((numbered (if numbered? '(numbered "numbered") '())) + (let ((numbered (if numbered? '((numbered "numbered")) '())) (args (cdr x))) (md-hugo-shortcode (append `(sidenote (halign ,(marginal-style (first args))) @@ -668,8 +668,7 @@ (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 - 'numbered "numberered")) + (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) diff --git a/progs/tmmarkdown.scm b/progs/tmmarkdown.scm index 9419fe5..d1be5c3 100644 --- a/progs/tmmarkdown.scm +++ b/progs/tmmarkdown.scm @@ -64,7 +64,7 @@ (counter-new 'h3 'h2) (counter-new 'environment 'h3 'h2 'h1) (counter-new 'equation) - (counter-new 'figure 'h3 'h2 'h1)) + (counter-new 'figure)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Helper functions for the transformation of strees and dispatcher @@ -170,7 +170,10 @@ ; 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"))))