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
This commit is contained in:
Ihor Radchenko 2024-01-15 13:50:32 +01:00
parent 59238cfa82
commit 38c6eb2b72
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
3 changed files with 39 additions and 11 deletions

View File

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

View File

@ -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))))))))

View File

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