Hi again, Attached is a new version of the patch. It builds on Ihors refactoring patch. Best. /PA
On Sun, 30 Mar 2025 at 07:24, Pedro Andres Aranda Gutierrez < paag...@gmail.com> wrote: > Thanks! > > Will try out as soon as I have time to. > > /PA > > On Sat, 29 Mar 2025 at 15:44, Ihor Radchenko <yanta...@posteo.net> wrote: > >> Pedro Andres Aranda Gutierrez <paag...@gmail.com> writes: >> >> > after giving ox-html a second (and a third read), there are too many >> > dependencies to make a clean move a simple task. >> > It will take me more time than I have right now. So why not fixing the >> bug >> > now and doing the factoring out later? >> >> See the attached patch. Let me know if the factored out part is not >> sufficient for your needs. >> >> >> -- >> Ihor Radchenko // yantar92, >> Org mode maintainer, >> Learn more about Org mode at <https://orgmode.org/>. >> Support Org development at <https://liberapay.com/org-mode>, >> or support my work at <https://liberapay.com/yantar92> >> > > > -- > Fragen sind nicht da, um beantwortet zu werden, > Fragen sind da um gestellt zu werden > Georg Kreisler > > Sagen's Paradeiser, write BE! > Year 1 of the New Koprocracy > > -- Fragen sind nicht da, um beantwortet zu werden, Fragen sind da um gestellt zu werden Georg Kreisler Sagen's Paradeiser, write BE! Year 1 of the New Koprocracy
From e8c75bfca3a19ece2712c3bf5982f405309dfcce Mon Sep 17 00:00:00 2001 From: "Pedro A. Aranda" <paag...@gmail.com> Date: Sun, 30 Mar 2025 17:51:12 +0200 Subject: [PATCH 2/2] Rewrite image lining in ox-latex.el * lisp/ox-latex.el: New function (ox-latex-standalone-image-p) using the new (org-export-standalone-link-p) function to determine whether an image is standalone or part or a larger paragraph, table, etc. (org-latex--inline-image): Use (ox-latex-standalone-image-p) * testing/lisp/test-ox-latex.el: (test-ox-latex/inline-image) Add the new image in-lining test cases --- etc/ORG-NEWS | 9 +++- lisp/ox-latex.el | 99 +++++++++++++++++++---------------- testing/lisp/test-ox-latex.el | 20 +++++-- 3 files changed, 80 insertions(+), 48 deletions(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index e5da9281b..aaef7e9d9 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -584,7 +584,7 @@ were tangled into a file named =NAME.bibtex=. Now, they are tangled into a file named =FILE.bib=, using the standard extension =.bib=, matching the rest of the ecosystem, including BibTeX and LaTeX. -*** LaTeX export now respects ~org-latex-with...~ options in the PDF matedata +*** LaTeX export now respects ~org-latex-with...~ options in the PDF metadata Previously, the LaTeX exporter handled the PDF metadata =pdfcreator=, =pdfauthor= and =pdftitle= as defined in @@ -593,6 +593,13 @@ will be defined as empty and not produce any metadata if their corresponding ~org-latex-with-author~, ~org-latex-with-title~, or ~org-latex-with-creator~ option is set to ~nil~. +*** Images will be inlined without default attributes. + +Previously, any image reference would be inlined with a default width +of 900px and centered. This has changed and inlined images will be +included *without* any formatting or default width. *Only* images that +are standalone will take a ~#+attr_latex:~ into account. + * Version 9.7 ** Important announcements and breaking changes diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el index af3ac308b..20e866a72 100644 --- a/lisp/ox-latex.el +++ b/lisp/ox-latex.el @@ -33,6 +33,7 @@ (require 'cl-lib) (require 'ox) (require 'ox-publish) +(require 'ox-html) ;;; Function Declarations @@ -1554,6 +1555,13 @@ property to `toc'" ;;; Internal Functions +(defun ox-latex-standalone-image-p (elem info) + "Check whether the image is standalone +to apply latex attributes or not." + (org-export-standalone-link-p + elem info #'(lambda (link _info) + (org-export-inline-image-p link)))) + (defun org-latex--caption-above-p (element info) "Non-nil when caption is expected to be located above ELEMENT. INFO is a plist holding contextual information." @@ -2955,7 +2963,8 @@ used as a communication channel." (setq options (concat options ",page=" search-option)))) (setq image-code (format "\\includegraphics%s{%s}" - (cond ((not (org-string-nw-p options)) "") + (cond ((not (ox-latex-standalone-image-p link info)) "") + ((not (org-string-nw-p options)) "") ((string-prefix-p "," options) (format "[%s]" (substring options 1))) (t (format "[%s]" options))) @@ -2974,66 +2983,68 @@ used as a communication channel." "}" image-code nil t)))) - ;; Return proper string, depending on FLOAT. - (pcase float - ((and (pred stringp) env-string) - (format "\\begin{%s}%s + ;; Return proper string, depending on FLOAT **only if standalone**. + (if (ox-latex-standalone-image-p link info) + (pcase float + ((and (pred stringp) env-string) + (format "\\begin{%s}%s %s%s %s%s %s\\end{%s}" - env-string - placement - (if caption-above-p caption "") - (if center "\\centering" "") - comment-include image-code - (if caption-above-p "" caption) - env-string)) - (`wrap (format "\\begin{wrapfigure}%s + env-string + placement + (if caption-above-p caption "") + (if center "\\centering" "") + comment-include image-code + (if caption-above-p "" caption) + env-string)) + (`wrap (format "\\begin{wrapfigure}%s %s%s %s%s %s\\end{wrapfigure}" - placement - (if caption-above-p caption "") - (if center "\\centering" "") - comment-include image-code - (if caption-above-p "" caption))) - (`sideways (format "\\begin{sidewaysfigure} + placement + (if caption-above-p caption "") + (if center "\\centering" "") + comment-include image-code + (if caption-above-p "" caption))) + (`sideways (format "\\begin{sidewaysfigure} %s%s %s%s %s\\end{sidewaysfigure}" - (if caption-above-p caption "") - (if center "\\centering" "") - comment-include image-code - (if caption-above-p "" caption))) - (`multicolumn (format "\\begin{figure*}%s + (if caption-above-p caption "") + (if center "\\centering" "") + comment-include image-code + (if caption-above-p "" caption))) + (`multicolumn (format "\\begin{figure*}%s %s%s %s%s %s\\end{figure*}" - placement - (if caption-above-p caption "") - (if center "\\centering" "") - comment-include image-code - (if caption-above-p "" caption))) - (`figure (format "\\begin{figure}%s + placement + (if caption-above-p caption "") + (if center "\\centering" "") + comment-include image-code + (if caption-above-p "" caption))) + (`figure (format "\\begin{figure}%s %s%s %s%s %s\\end{figure}" - placement - (if caption-above-p caption "") - (if center "\\centering" "") - comment-include image-code - (if caption-above-p "" caption))) - ((guard center) - (format "\\begin{center} + placement + (if caption-above-p caption "") + (if center "\\centering" "") + comment-include image-code + (if caption-above-p "" caption))) + ((guard center) + (format "\\begin{center} %s%s %s\\end{center}" - (if caption-above-p caption "") - image-code - (if caption-above-p "" caption))) - (_ - (concat (if caption-above-p caption "") - image-code - (if caption-above-p caption "")))))) + (if caption-above-p caption "") + image-code + (if caption-above-p "" caption))) + (_ + (concat (if caption-above-p caption "") + image-code + (if caption-above-p caption "")))) + image-code))) ;; else return just the \includegraphics{} (defun org-latex-link (link desc info) "Transcode a LINK object from Org to LaTeX. diff --git a/testing/lisp/test-ox-latex.el b/testing/lisp/test-ox-latex.el index 04164767c..f4e6a97d1 100644 --- a/testing/lisp/test-ox-latex.el +++ b/testing/lisp/test-ox-latex.el @@ -147,12 +147,26 @@ Column & Column \\\\ "Test inline images." (org-test-with-exported-text 'latex - "#+caption: Schematic -[[https://orgmode.org/worg/images/orgmode/org-mode-unicorn.svg][file:/wallpaper.png]]" + " +This is an inline image [[file:./test.png]]. + +| [[file:./test.png]] | [[file:./test.jpg]] | + +#+attr_latex: :width 300px +file:test-img.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}}")))) + "This is an inline image \\includegraphics{./test.png}" nil t)) + (should + (search-forward + "\\includegraphics{./test.png} & \\includegraphics{./test.jpg}\\\\" nil t)) + (should + (search-forward + "\\includegraphics[width=300px]{test-img.png}" nil t)) + )) (ert-deftest test-ox-latex/num-t () "Test toc treatment for fixed num:t" -- 2.34.1