emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Jason Ross <jasonross1024@gmail.com>
To: "Juan Manuel Macías" <maciaschain@posteo.net>
Cc: orgmode <emacs-orgmode@gnu.org>
Subject: Re: Sub-figures in Org Mode
Date: Tue, 26 Oct 2021 10:46:42 -0700	[thread overview]
Message-ID: <9e59a818-7a92-c244-f6ba-9677cbdf6768@gmail.com> (raw)
In-Reply-To: <87tuh87gp3.fsf@posteo.net>

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 
                (links (org-element-map special-block 'link #'identity))
                  (org-context--get-placefigure-options special-block 
                  (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))))
                  (lambda (link)
                    (let ((figure-string 
(org-context--get-link-figure-string link info)))
                      (if captionp
                        (let ((caption
                                 (org-export-get-parent-element link) 
                          (format "{%s}\n{%s}"
                                  figure-string (or caption "")))
                      (format "{%s}" figure-string)))

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

(advice-add 'org-context-special-block :around 


  reply	other threads:[~2021-10-26 17:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-22 23:27 Sub-figures in Org Mode Jason Ross
2021-10-23  0:00 ` Juan Manuel Macías
2021-10-26 17:46   ` Jason Ross [this message]
2021-10-30 14:28     ` Juan Manuel Macías
2021-10-25 10:44 ` Eric S Fraga
2021-10-25 10:48 ` Eric S Fraga

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9e59a818-7a92-c244-f6ba-9677cbdf6768@gmail.com \
    --to=jasonross1024@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=maciaschain@posteo.net \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).