Hi,
a small refinement after testing on ox-beamer and ox-latex directly. We
don't need to put the alt texy between hyphens...
This would be the version to apply to main.
Best, /PA
On 16/09/2026 12:22, Pedro A. Aranda wrote:
Hi
A new version of the patch that describes multiline :alt in the manual
and tests that the descriptive text is generated correctly.
/PA
On 16/09/2026 08:58, Pedro A. Aranda wrote:
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 dcca74702a7b82e169d426e2cbd30e41773d0a63 Mon Sep 17 00:00:00 2001
From: "Pedro A. Aranda" <[email protected]>
Date: Mon, 21 Sep 2026 07:59:13 +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): Test that
the descriptive text is added correctly.
---
doc/org-manual.org | 18 ++++++++++++++++++
etc/ORG-NEWS | 8 +++++++-
lisp/ox-latex.el | 7 +++++--
testing/lisp/test-ox-latex.el | 16 ++++++++++++++++
4 files changed, 46 insertions(+), 3 deletions(-)
diff --git a/doc/org-manual.org b/doc/org-manual.org
index f68de4690..949040d17 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -14885,6 +14885,24 @@ 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. You can make your descriptive
+text span over more that one line. 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.
+,#+ATTR_LATEX: The application process and the socket that is used to
+,#+ATTR_LATEX: connect to other application processes are shown.
+[[./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 24bcac969..95aff02bd 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,
@@ -266,7 +272,7 @@ keywords or with =#+OPTIONS:=.
Option keys can be used like this:
: #+OPTIONS: html-self-link-headlines:t
: #+OPTIONS: html-tag-class-prefix:"myorg-"
-
+
To know which value you can use, find the allowed option values in the
manual or in the default variable documentation.
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 56ca3ada9..d28f9adf6 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 4c65f447d..a9727e435 100644
--- a/testing/lisp/test-ox-latex.el
+++ b/testing/lisp/test-ox-latex.el
@@ -716,5 +716,21 @@ (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.
+#+ATTR_LATEX: It has a second line!
+[[./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 "It has a second line!}" nil t))
+ (should (search-forward "]{./image.png}" nil t))))
+
(provide 'test-ox-latex)
;;; test-ox-latex.el ends here
--
2.43.0