emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/org 38c6eb2b72 2/3: ox-latex: Do not use float for inli


From: ELPA Syncer
Subject: [elpa] externals/org 38c6eb2b72 2/3: ox-latex: Do not use float for inline images inside links
Date: Mon, 15 Jan 2024 09:59:17 -0500 (EST)

branch: externals/org
commit 38c6eb2b72ce68e72afac9e489f3464cbfdb1e83
Author: Ihor Radchenko <yantar92@posteo.net>
Commit: Ihor Radchenko <yantar92@posteo.net>

    ox-latex: Do not use float for inline images inside links
    
    * lisp/ox.el (org-export-insert-image-links): Fix call to
    `org-element-set-contents' - setting "nil" literally would put an
    actual nil element into contents.
    * lisp/ox-latex.el (org-latex--inline-image): Do not use float
    environment unless the inline image is a single image inside
    paragraph.  The code is adapted with simplifications from
    `org-html-standalone-image-p'.
    * testing/lisp/test-ox-latex.el (test-ox-latex/inline-image): New
    test.
    
    Reported-by: Dr. Arne Babenhauserheide <arne_bab@web.de>
    Link: https://orgmode.org/list/878rest3qv.fsf@localhost
---
 lisp/ox-latex.el              | 37 +++++++++++++++++++++++++++----------
 lisp/ox.el                    |  2 +-
 testing/lisp/test-ox-latex.el | 11 +++++++++++
 3 files changed, 39 insertions(+), 11 deletions(-)

diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 57ea66ef16..b36c46f138 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -2741,16 +2741,33 @@ used as a communication channel."
         ;; Retrieve latex attributes from the element around.
         (attr (org-export-read-attribute :attr_latex parent))
         (float (let ((float (plist-get attr :float)))
-                 (cond ((string= float "wrap") 'wrap)
-                       ((string= float "sideways") 'sideways)
-                       ((string= float "multicolumn") 'multicolumn)
-                        ((string= float "t") 'figure)
-                       ((and (plist-member attr :float) (not float)) 'nonfloat)
-                        (float float)
-                       ((or (org-element-property :caption parent)
-                            (org-string-nw-p (plist-get attr :caption)))
-                        'figure)
-                       (t 'nonfloat))))
+                 (cond
+                   ((org-element-map (org-element-contents parent) t
+                      (lambda (node)
+                        (cond
+                         ((and (org-element-type-p node 'plain-text)
+                               (not (org-string-nw-p node)))
+                          nil)
+                         ((eq link node)
+                          ;; Objects inside link description are
+                          ;; allowed.
+                          (throw :org-element-skip nil))
+                         (t 'not-a-float)))
+                      info 'first-match)
+                    ;; Not a single link inside paragraph (spaces
+                    ;; ignored).  Cannot use float environment.  It
+                    ;; would be inside paragraph.
+                    nil)
+                   ((string= float "wrap") 'wrap)
+                  ((string= float "sideways") 'sideways)
+                  ((string= float "multicolumn") 'multicolumn)
+                   ((string= float "t") 'figure)
+                  ((and (plist-member attr :float) (not float)) 'nonfloat)
+                   (float float)
+                  ((or (org-element-property :caption parent)
+                       (org-string-nw-p (plist-get attr :caption)))
+                   'figure)
+                  (t 'nonfloat))))
         (placement
          (let ((place (plist-get attr :placement)))
            (cond
diff --git a/lisp/ox.el b/lisp/ox.el
index 9178d53cd5..34ea32b3bb 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -4360,7 +4360,7 @@ Return modified DATA."
                             (or rules org-export-default-inline-image-rule))
                ;; Replace contents with image link.
                (org-element-adopt
-                   (org-element-set-contents l nil)
+                   (org-element-set-contents l)
                  (with-temp-buffer
                    (save-excursion (insert contents))
                    (org-element-link-parser))))))))
diff --git a/testing/lisp/test-ox-latex.el b/testing/lisp/test-ox-latex.el
index 35e37e46ad..41df1b8234 100644
--- a/testing/lisp/test-ox-latex.el
+++ b/testing/lisp/test-ox-latex.el
@@ -93,5 +93,16 @@ Column & Column \\\\[0pt]
       "\\hline\\multicolumn{2}{r}{Continued on next page} \\\\
 \\endfoot"))))
 
+(ert-deftest test-ox-latex/inline-image ()
+  "Test inline images."
+  (org-test-with-exported-text
+      'latex
+      "#+caption: Schematic
+[[https://orgmode.org/worg/images/orgmode/org-mode-unicorn.svg][file:/wallpaper.png]]";
+    (goto-char (point-min))
+    (should
+     (search-forward
+      
"\\href{https://orgmode.org/worg/images/orgmode/org-mode-unicorn.svg}{\\includegraphics[width=.9\\linewidth]{/wallpaper.png}}";))))
+
 (provide 'test-ox-latex)
 ;;; test-ox-latex.el ends here



reply via email to

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