From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id F8qhBVUN5l8IWwAA0tVLHw (envelope-from ) for ; Fri, 25 Dec 2020 16:03:33 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id kAoeAVUN5l/CIAAAbx9fmQ (envelope-from ) for ; Fri, 25 Dec 2020 16:03:33 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 5C16B9403CD for ; Fri, 25 Dec 2020 16:03:32 +0000 (UTC) Received: from localhost ([::1]:43122 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kspYx-0003J4-5W for larch@yhetil.org; Fri, 25 Dec 2020 11:03:31 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36110) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kspYX-0003IG-F4 for emacs-orgmode@gnu.org; Fri, 25 Dec 2020 11:03:05 -0500 Received: from mout02.posteo.de ([185.67.36.66]:44707) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kspYU-0003sG-PU for emacs-orgmode@gnu.org; Fri, 25 Dec 2020 11:03:05 -0500 Received: from submission (posteo.de [89.146.220.130]) by mout02.posteo.de (Postfix) with ESMTPS id 493342400FC for ; Fri, 25 Dec 2020 17:02:59 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1608912179; bh=BvejtmnDqhapKqB88YVB76E9iyYf91x0giQdGg/xzkU=; h=From:To:Subject:Date:From; b=KGJSjaI/CE30yMO88MABAEtQwvZkID+gIzMkoCakEgDbY7ZHpltLdg+SeIV2TWt4I lIVs5R/pLeBt9c94FpwVK1yEkt7NTjPWI/eVFkrSmhoGJP9crlL88voD4qDpjVFPPz pm5715WUAmjANV74uM6b7+IGALmqBq+ZfiJ1198Xs8Sr4ap59cIbt7veo+RBYKIn9o Lb/AwxlrzdJQH49MNClUg/oug8cXyf76GGSiFP75naktrifFIBQvB/7cBtc8vf+bYo r74p4ihvc4vrE5Jn5q9SH8G1M8G1S44IMwf/A52eIaX6/PkSsEvwjNNoc11t4OW5qU CyUrsuGF/AX1w== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4D2Wtp4c5vz9rxP for ; Fri, 25 Dec 2020 17:02:58 +0100 (CET) From: =?utf-8?Q?Juan_Manuel_Mac=C3=ADas?= To: orgmode Subject: [tip] Export subfigures to LaTeX (and HTML) Date: Fri, 25 Dec 2020 17:02:57 +0100 Message-ID: <87mty1an66.fsf@posteo.net> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="=-=-=" Received-SPF: pass client-ip=185.67.36.66; envelope-from=maciaschain@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -3.02 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=KGJSjaI/; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: 5C16B9403CD X-Spam-Score: -3.02 X-Migadu-Scanner: scn1.migadu.com X-TUID: 4BM4v6z5PAeA --=-=-= Content-Type: text/plain Hi, 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 (org-link-set-parameters "subfig" :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) "]" "{\\includegraphics" "[" (match-string 1 desc) "]" "{" file "}}") (format "\\subfigure[%s]{\\includegraphics{%s}}" desc file))))) #+end_src Example: #+begin_src org ,#+CAPTION: Lorem impsum dolor ,#+ATTR_LaTeX: :options \centering ,#+begin_figure [[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)]] ,#+end_figure #+end_src Results: #+begin_src latex \begin{figure}\centering \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} \end{figure} #+end_src 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) (cond ((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 ">{\\(.+\\)}" desc) (concat "\""
" (replace-regexp-in-string "\s*>.+" "" desc) "") (format "\"%s\"/
%s" file file (replace-regexp-in-string "\s*>.+" "" desc)))))) #+end_src Example: #+begin_src org ,#+CAPTION: Lorem impsum dolor ,#+ATTR_LaTeX: :options \centering ,#+begin_figure @@html:
@@ [[subfig:img1.jpg][Caption of img1 >(width=.3\textwidth) >{300px}]] [[subfig:img2.jpg][Caption of img2 >(width=.3\textwidth) >{300px}]] @@html:

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

Lorem ipsum dolor
@@ ,#+end_figure #+end_src As you can see, it is not the panacea, and you have to apply some direct format... Happy holidays Juan Manuel --=-=-= Content-Type: text/html --=-=-=--