emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Juan Manuel Macías" <maciaschain@posteo.net>
To: orgmode <emacs-orgmode@gnu.org>
Subject: [tip] Export subfigures to LaTeX (and HTML)
Date: Fri, 25 Dec 2020 17:02:57 +0100	[thread overview]
Message-ID: <87mty1an66.fsf@posteo.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 3199 bytes --]


I have come up with a way to export subfigures to LaTeX (with the subfigure package) by
defining a new link type. The 'subcaption' of the subfigure would be the description of
the link. If we want to add parameters such as width, scale, etc., we can put them next
between the marks '>( ... )'

The code:

#+begin_src emacs-lisp
   :follow (lambda (file) (find-file file))
   :face '(:foreground "chocolate" :weight bold :underline t)
   :display 'full
   :export (lambda (file desc backend)
	     (when (eq backend 'latex)
	       (if (string-match ">(\\(.+\\))" desc)
		   (concat "\\subfigure[" (replace-regexp-in-string "\s+>(.+)" "" desc) "]"
			   (match-string 1 desc)
		 (format "\\subfigure[%s]{\\includegraphics{%s}}" desc file)))))


#+begin_src org
  ,#+CAPTION: Lorem impsum dolor
  ,#+ATTR_LaTeX: :options \centering
  [[subfig:img1.jpg][Caption of img1 >(width=.3\textwidth)]]

  [[subfig:img2.jpg][Caption of img2 >(width=.3\textwidth)]]

  [[subfig:img3.jpg][Caption of img3 >(width=.6\textwidth)]]


#+begin_src latex
    \subfigure[Caption of img1]{\includegraphics[width=.3\textwidth]{img1.jpg}}

    \subfigure[Caption of img2]{\includegraphics[width=.3\textwidth]{img2.jpg}}

    \subfigure[Caption of img3]{\includegraphics[width=.6\textwidth]{img3.jpg}}
    \caption{Lorem impsum dolor}

If we want to export to HTML it would be something more tricky. In this case, the export
function could be like this (a width parameter would be enclosed between >{ ... }):

#+begin_src emacs-lisp
  (lambda (file desc backend)
     ((eq backend 'latex)
      (if (string-match ">(\\(.+\\))" desc)
	  (concat "\\subfigure[" (replace-regexp-in-string "\s*>.+" "" desc) "]" "{\\includegraphics" "[" (match-string 1 desc) "]" "{"  file "}}")
	(format "\\subfigure[%s]{\\includegraphics{%s}}" (replace-regexp-in-string "\s*>.+" "" desc) file)))
     ((eq backend 'html)
      (if (string-match "&gt;{\\(.+\\)}" desc)
	  (concat "<td><img src=\"" file "\" alt=\"" file "\"" " style=\"width:"
		  (match-string 1 desc)
		  (replace-regexp-in-string "\s*&gt;.+" "" desc)
	(format "<td><img src=\"%s\" alt=\"%s\"/><br>%s</td>"
		file file
		(replace-regexp-in-string "\s*&gt;.+" "" desc))))))


#+begin_src org
  ,#+CAPTION: Lorem impsum dolor
  ,#+ATTR_LaTeX: :options \centering
  @@html:<div class="org-center"><table style="margin-left:auto;margin-right:auto;"><tr>@@

  [[subfig:img1.jpg][Caption of img1 >(width=.3\textwidth) >{300px}]]

  [[subfig:img2.jpg][Caption of img2 >(width=.3\textwidth) >{300px}]]

  @@html:</tr></table><p> </p><table style="margin-left:auto;margin-right:auto;"><tr>@@

  [[subfig:img3.jpg][Caption of img3 >(width=.6\textwidth) >{600px}]]

  @@html:</tr></table><br>Lorem ipsum dolor</div>@@

As you can see, it is not the panacea, and you have to apply some direct format...

Happy holidays

Juan Manuel 

[-- Attachment #2: Type: text/html, Size: 0 bytes --]

             reply	other threads:[~2020-12-25 16:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-25 16:02 Juan Manuel Macías [this message]
2020-12-28 18:03 ` [tip] Export subfigures to LaTeX (and HTML) John Kitchin
2020-12-29 15:00   ` Juan Manuel Macías

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=87mty1an66.fsf@posteo.net \
    --to=maciaschain@posteo.net \
    --cc=emacs-orgmode@gnu.org \


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