emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sub-figures in Org Mode


From: Jason Ross
Subject: Re: Sub-figures in Org Mode
Date: Tue, 26 Oct 2021 10:46:42 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0

Hi Juan,

On 10/22/21 5:00 PM, Juan Manuel Macías wrote:
Hi Jason,

Jason Ross <jasonross1024@gmail.com> writes:

Are there any workarounds people use to create subfigures in Org Mode
when exporting to LaTeX? Example output:

In this thread I explain a procedure to export images as subfigures
using org links: https://list.orgmode.org/87mty1an66.fsf@posteo.net/

Best regards,

Juan Manuel


Those are some really clever solutions. I hadn't considered using a
dsl for figure options.

I'm looking at declaring a "figure" block the way you are, but
`org-element-map'ing over the links inside the block and processing them
with the "normal" link-handling machinery. That way, image options work
the same way in a subfigure as they do normally.

Here's what I'm messing with for the ConTeXt backend (this relies
on some changes to figure handling I haven't pushed yet):

#+begin_src elisp
(defun org-context--special-block-figure (orig-fun special-block contents info)
  (let ((type (org-element-property :type special-block)))
    (if (string= "figure" (downcase type))
(let* ((attr (org-export-read-attribute :attr_context special-block))
               (links (org-element-map special-block 'link #'identity))
               (placefigure-options
                (org-context--format-arguments
(org-context--get-placefigure-options special-block info)))
               (captionp
                (mapcan
                 (lambda (link)
                   (let* ((parent (org-export-get-parent-element link))
(caption (org-string-nw-p (org-context--caption/label-string parent info))))
                     (and caption (list caption))))
                 links))
               (image-codes
                (mapconcat
                 (lambda (link)
(let ((figure-string (org-context--get-link-figure-string link info)))
                     (if captionp
                       (let ((caption
                              (org-string-nw-p
                               (org-context--caption/label-string
(org-export-get-parent-element link) info))))
                         (format "{%s}\n{%s}"
                                 figure-string (or caption "")))
                     (format "{%s}" figure-string)))

                   )
                 links
                 "\n"))
               (dimensions
                (let* ((rows (plist-get attr :rows))
                       (cols (plist-get attr :cols))
                       (nlinks (length links)))
                  (if
                      (and rows cols)
(cons (string-to-number rows) (string-to-number cols))
                    (cons 1 nlinks))))
               combination-options)
          (if captionp
               (push (cons "alternative" "text") combination-options)
            (push (cons "alternative" "label") combination-options))
(push (cons "nx" (format "%s" (cdr dimensions))) combination-options) (push (cons "ny" (format "%s" (car dimensions))) combination-options)
          (message (format "%S" combination-options))
          (format "\\startplacefigure[%s]
\\startcombination[%s]
%s
\\stopcombination
\\stopplacefigure"
                  placefigure-options
                  (org-context--format-arguments combination-options)
                  image-codes))
      (funcall orig-fun special-block contents info))))

(advice-add 'org-context-special-block :around #'org-context--special-block-figure)

#+end_src




reply via email to

[Prev in Thread] Current Thread [Next in Thread]