Hi,

attached is a patch to add descriptive text to latex images with the new attribute :alt.

Best, /PA
--
Pedro A. Aranda
ox-latex & ox-beamer maintainer

Sagen's Paradeiser! (ORF: Als Radiohören gefährlich war) => write BE!
IA: onomatopeya del rebuzno
2nd year of the New Koprocracy
From d06c1ae42fd4e788d4ddb0825eef2a2c7311939c Mon Sep 17 00:00:00 2001
From: "Pedro A. Aranda" <[email protected]>
Date: Wed, 16 Sep 2026 08:55:07 +0200
Subject: [PATCH] ox-latex: add :alt attribute for images

* doc/org-manual.org: Document :alt in image export for LaTeX.
* etc/ORG-NEWS: Announce new :alt attribute for LaTeX images.
* lisp/ox-latex.el (org-latex--inline-image): Append attribute :alt to
the options as alt={<text>} when defined.
* testing/lisp/test-ox-latex.el (test-ox-latex/alt-attribute): New
test to check that the descriptive text is added correctly.  Note:
debug message demonstrates current implementation status.

This should be the first step towards supporting longer descriptive
texts. :alt <text> is more comfortable than adding the full spec
(alt={"<text>"}) to the :options.
---
 doc/org-manual.org            | 14 ++++++++++++++
 etc/ORG-NEWS                  |  6 ++++++
 lisp/ox-latex.el              |  7 +++++--
 testing/lisp/test-ox-latex.el | 14 ++++++++++++++
 4 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/doc/org-manual.org b/doc/org-manual.org
index 2a5ca1fcf..d36edc39e 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -14884,6 +14884,20 @@ set ~org-latex-images-centered~ to =nil=.
 Set the =:comment-include= attribute to non-~nil~ value for the LaTeX
 export backend to comment out the =\includegraphics= macro.
 
+Finally, if you need to supply an alternative text, for example for a
+textual image description when you generate an accessible PDF, you can
+use the =alt= attribute to include it. For example:
+
+#+begin_example
+,#+ATTR_LATEX: :float wrap :width 0.38\textwidth :placement {r}{0.4\textwidth}
+,#+ATTR_LATEX: :alt An end host, showing the IP protocol stack it implements.
+[[./img/hst.png]]
+#+end_example
+
+#+texinfo: @noindent
+would add a the text after =:alt= as a textual description for screen
+reader applications.
+
 *** Plain lists in LaTeX export
 :PROPERTIES:
 :DESCRIPTION: Attributes specific to lists.
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 6598a7850..04e741599 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -183,6 +183,12 @@ Presentations written with Beamer and ltx-talk are mostly portable,
 except that Beamer theme information is ignored when using ltx-talk
 and some environments listed in the manual are not supported.
 
+*** ox-latex.el: new LaTeX attribute to add descriptive text to images
+
+The LaTeX exporter supports the ~:alt~ attribute to add descriptive
+text to images. This text will be used, for example, by screen reader
+applications to describe images.
+
 ** New and changed options
 
 # Changes dealing with changing default values of customizations,
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 0b7a22179..7e808ae45 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -3195,8 +3195,11 @@ (defun org-latex--inline-image (link info)
 		       (t (plist-get info :latex-image-default-height))))
 	 (options (let ((opt (or (plist-get attr :options)
 				 (plist-get info :latex-image-default-option))))
-		    (if (not (string-match "\\`\\[\\(.*\\)\\]\\'" opt)) opt
-		      (match-string 1 opt))))
+                    (concat
+		     (if (not (string-match "\\`\\[\\(.*\\)\\]\\'" opt)) opt
+		       (match-string 1 opt))
+                     (and (plist-get attr :alt)
+                          (format ",alt={\"%s\"}" (plist-get attr :alt))))))
 	 image-code)
     (if (member filetype '("tikz" "pgf"))
 	;; For tikz images:
diff --git a/testing/lisp/test-ox-latex.el b/testing/lisp/test-ox-latex.el
index 9cd83d509..fdaf3aa81 100644
--- a/testing/lisp/test-ox-latex.el
+++ b/testing/lisp/test-ox-latex.el
@@ -684,5 +684,19 @@ (ert-deftest test-ox-latex/back-in-time-cjk-xelatex ()
       (should (search-forward "\\setCJKsansfont{Noto Sans CJK SC}" nil t))
       (should (search-forward "\\setCJKmonofont{Noto Sans Mono CJK SC}" nil t)))))
 
+(ert-deftest test-ox-latex/alt-attribute ()
+  "Test that the :alt attribute is added correctly to an image"
+  (org-test-with-exported-text
+   'latex
+   "#+ATTR_LATEX: :width .9\\textwidth
+#+ATTR_LATEX: :alt This is the descriptive text for the image.
+[[./image.png]]
+"
+   (message "alt-attribute: %s" (buffer-string))
+   (goto-char (point-min))
+   (should (search-forward "\\includegraphics[" nil t))
+   (should (search-forward "alt={\"This is the descriptive text for the image.\"}" nil t))
+   (should (search-forward "]{./image.png}" nil t))))
+
 (provide 'test-ox-latex)
 ;;; test-ox-latex.el ends here
-- 
2.43.0

Reply via email to