Re: Sub-figures in Org Mode

2021-10-30 Thread Juan Manuel Macías
Hi Jason, sorry for the late reply.

Jason Ross writes:

> 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.

I really like your idea, and it's more consistent with the Org syntax,
since (as you say) the images behave like images and it is not necessary
to enter the options via marks within the link description, which is somewhat
hacky. I think your idea could also be adapted to LaTeX (and HTML)
backends... 

Best regards,

Juan Manuel 



Re: Sub-figures in Org Mode

2021-10-26 Thread Jason Ross

Hi Juan,

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

Hi Jason,

Jason Ross  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@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




Re: Sub-figures in Org Mode

2021-10-25 Thread Eric S Fraga
Updated example attached: forgot the subcaptions...

-- 
: Eric S Fraga via Emacs 28.0.60, Org release_9.5-163-g4eab5b
: Latest paper written in org: https://arxiv.org/abs/2106.05096
#+latex_header: \usepackage[demo]{graphicx}
#+latex_header: \usepackage{subcaption}
* Question
Are there any workarounds people use to create subfigures in Org Mode
when exporting to LaTeX? Example output:
* Attempt
#+name: fig:fig
#+caption: plots of
#+begin_figure

#+name: fig:sfig1
#+attr_latex: :caption \subcaption{1a}
#+attr_latex: :options {0.5\textwidth}
#+begin_subfigure
#+attr_latex: :width 0.8\linewidth
[[~/s/test/mip.png]]
#+end_subfigure

#+name: fig:sfig2
#+attr_latex: :options {0.5\textwidth}
#+attr_latex: :caption \subcaption{1b}
#+begin_subfigure
#+attr_latex: :width 0.8\linewidth
[[~/s/test/mip.png]]
#+end_subfigure

#+end_figure


Re: Sub-figures in Org Mode

2021-10-25 Thread Eric S Fraga
On Friday, 22 Oct 2021 at 16:27, Jason Ross wrote:
> Are there any workarounds people use to create subfigures in Org Mode
> when exporting to LaTeX? Example output:

The attached should do the job?  At least, it seems to export to your
sample LaTeX.  I cannot compile as for some reason subcaption conflicts
with my standard org to LaTeX setup.

-- 
: Eric S Fraga via Emacs 28.0.60, Org release_9.5-163-g4eab5b
: Latest paper written in org: https://arxiv.org/abs/2106.05096
#+latex_header: \usepackage[demo]{graphicx}
#+latex_header: \usepackage{subcaption}
* Question
Are there any workarounds people use to create subfigures in Org Mode
when exporting to LaTeX? Example output:
* Attempt
#+name: fig:fig
#+caption: plots of
#+begin_figure

#+name: fig:sfig1
#+caption: 1a
#+attr_latex: :options {0.5\textwidth}
#+begin_subfigure
#+attr_latex: :width 0.8\linewidth
[[~/s/test/mip.png]]
#+end_subfigure

#+name: fig:sfig2
#+attr_latex: :options {0.5\textwidth}
#+caption: 1a
#+begin_subfigure
#+attr_latex: :width 0.8\linewidth
[[~/s/test/mip.png]]
#+end_subfigure

#+end_figure


Re: Sub-figures in Org Mode

2021-10-22 Thread Juan Manuel Macías
Hi Jason,

Jason Ross  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@posteo.net/

Best regards,

Juan Manuel 



Sub-figures in Org Mode

2021-10-22 Thread Jason Ross

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

#+begin_example latex
\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{subcaption}
\begin{document}
\begin{figure}
\begin{subfigure}{.5\textwidth}
  \centering
  \includegraphics[width=.8\linewidth]{image1}
  \caption{1a}
  \label{fig:sfig1}
\end{subfigure}%
\begin{subfigure}{.5\textwidth}
  \centering
  \includegraphics[width=.8\linewidth]{image2}
  \caption{1b}
  \label{fig:sfig2}
\end{subfigure}
\caption{plots of}
\label{fig:fig}
\end{figure}
\end{document}
#+end_example

Based on how ox-latex.el handles images I don't see how this would be
possible but the people on this list are a lot smarter than I am so
maybe one of you has found a way.