Attached is a new version of the patch that needed the package version.
The others don't need changes, right?

/PA

On 06/10/2026 20:41, Ihor Radchenko wrote:
"Pedro A. Aranda" <[email protected]> writes:

Find attached a couple of patches that I'd like you to take a look
before applying on main.

Looks good in general.
Although I have a couple of larger-scope comments.

TINYCHANGE

Nit: The purpose of TINYCHANGE is copyright marking. It is only needed
for commits created by people without copyright assignment.

+#+vindex: org-latex-src-block-backend
+#+vindex: org-latex-listings-env
+#+vindex: org-latex-listings-src-omit-language
+The =listings= export backend generates LaTeX code for the ~listings~
+package by default, but is also compatible with the ~fancyvrb~
+package.  To generate code for the latter, you need to adjust the
+following variables:
+
+#+begin_src emacs-lisp
+(setq org-latex-listings-env "Verbatim"
+      org-latex-src-block-backend 'listings
+      org-latex-listings-src-omit-language t)
+#+end_src
+
+*Note:* if you use ~Verbatim~ to export your source code blocks, add
+~fancyvrb~ to ~org-latex-packages-alist~, or include:
+
+#+BEGIN_SRC org
+,#+LATEX_HEADER: \usepackage{fancyvrb}
+#+END_SRC
+
+in your document header.

A general thought not for this patch, but for future - if we keep adding
more and more special defaults sensible for ltx-talk, it could make
sense to split it into a separate ox-ltx-talk derived from ox-beamer.
Then, we can have ltx-specific defaults for org-latex-listings-env and similar.

      (:latex-link-with-unknown-path-format nil nil 
org-latex-link-with-unknown-path-format)
      (:latex-src-block-backend nil nil org-latex-src-block-backend)
      (:latex-listings-langs nil nil org-latex-listings-langs)
+    (:latex-listings-env nil nil org-latex-listings-env)
      (:latex-listings-options nil nil org-latex-listings-options)
      (:latex-listings-src-omit-language nil nil 
org-latex-listings-src-omit-language)
      (:latex-minted-langs nil nil org-latex-minted-langs)

I think it would be nice (in the future), to allow some of these
ox-latex options to be settable via in-document keywords.
For example, #+LATEX_LISTINGS_ENV: fancyrb would be very natural.

+(defcustom org-latex-listings-env "lstlisting"
+  "The LaTeX environment to use by the listings source code export backend.
+
+Set this variable to \"Verbatim\" and add the fancyvrb LaTeX package to your
+`org-latex-packages-alist' variable, via local variables, customization or in
+your Emacs init code, for example, with:
+
+  (require \\='ox-latex)
+  (add-to-list \\='org-latex-packages-alist \\='(\"\" \"fancyvrb\"))
+
+Note: this is the simplest solution to add code blocks in ltx-talk.
+"
+  :group 'org-export-latex
+  :type '(string :tag "Listings environment")
+  :safe #'stringp)

Please add :package-version.
Also, I am wondering if we should make the type less generic and only
accept lstlisting and fancyrb.


--
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 fd107283f30b1d6c9a1e0183109c27713b4e2003 Mon Sep 17 00:00:00 2001
From: "Pedro A. Aranda" <[email protected]>
Date: Sat, 3 Oct 2026 13:03:29 +0200
Subject: [PATCH] ox-latex: Further control for the listings src backend

* doc/org-manual.org (* An example of a presentation using =ltx-talk=):
Add a reference to source code listing options.
(* Source blocks in LaTeX export): Document `org-latex-listings-env'.
* lisp/ox-latex.el (org-latex-listings-env): New variable to define the
LaTeX block to use when exporting source code with the listings backend.
(org-latex-src-block--listings): break up the environment and use
`org-latex-listings-env' when generating the LaTeX begin/end commands.
* Testing/lisp/test-ox-latex.el (test-ox-latex/fancy-listings): New test
for `org-latex-listings-env'.

This is prompted after further studying the manuals and examples
provided by the ltx-talk authors.  Listings are scarcely discussed and
when they are, fancyvrb is used.
---
 doc/org-manual.org            | 29 +++++++++++++++++++++++++++++
 lisp/ox-latex.el              | 25 +++++++++++++++++++++++--
 testing/lisp/test-ox-latex.el | 26 ++++++++++++++++++++++++++
 3 files changed, 78 insertions(+), 2 deletions(-)

diff --git a/doc/org-manual.org b/doc/org-manual.org
index a3fbae1ac..b15dbd5da 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -13534,6 +13534,12 @@ is the version of the Beamer example above adapted to ~ltx-talk:~
    | =exampleblock=     | No      |                 |
    | =note=             | No      |                 |
    |--------------------+---------+-----------------|
+4. The easiest way to get source code listings in your ~ltx-talk~
+   slides is to use the ~fancyvrb~ package as described in the
+   package's documentation.  To use ~fancyvrb~ in Org you will need to
+   customize some variables, cf.  [[* Source blocks in LaTeX export]].
+   Another possibility is to use the ~minted~ exporter if you need
+   source code decoration.
 
 ** HTML Export
 :PROPERTIES:
@@ -15077,6 +15083,29 @@ file, use the ~org-latex-listings-options~,
 ~org-latex-engraved-options~, and ~org-latex-minted-options~
 variables.
 
+#+vindex: org-latex-src-block-backend
+#+vindex: org-latex-listings-env
+#+vindex: org-latex-listings-src-omit-language
+The =listings= export backend generates LaTeX code for the ~listings~
+package by default, but is also compatible with the ~fancyvrb~
+package.  To generate code for the latter, you need to adjust the
+following variables:
+
+#+begin_src emacs-lisp
+(setq org-latex-listings-env "Verbatim"
+      org-latex-src-block-backend 'listings
+      org-latex-listings-src-omit-language t)
+#+end_src
+
+*Note:* if you use ~Verbatim~ to export your source code blocks, add
+~fancyvrb~ to ~org-latex-packages-alist~, or include:
+
+#+BEGIN_SRC org
+,#+LATEX_HEADER: \usepackage{fancyvrb}
+#+END_SRC
+
+in your document header.
+
 *** Example blocks in LaTeX export
 :PROPERTIES:
 :DESCRIPTION: Attributes specific to example blocks.
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index f9b9981e6..c678f7500 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -156,6 +156,7 @@ (org-export-define-backend 'latex
     (:latex-link-with-unknown-path-format nil nil org-latex-link-with-unknown-path-format)
     (:latex-src-block-backend nil nil org-latex-src-block-backend)
     (:latex-listings-langs nil nil org-latex-listings-langs)
+    (:latex-listings-env nil nil org-latex-listings-env)
     (:latex-listings-options nil nil org-latex-listings-options)
     (:latex-listings-src-omit-language nil nil org-latex-listings-src-omit-language)
     (:latex-minted-langs nil nil org-latex-minted-langs)
@@ -1166,6 +1167,23 @@ (defcustom org-latex-listings-options nil
 	   (string :tag "Listings option value")))
   :safe #'listp)
 
+(defcustom org-latex-listings-env "lstlisting"
+  "The LaTeX environment to use by the listings source code export backend.
+
+Set this variable to \"Verbatim\" and add the fancyvrb LaTeX package to your
+`org-latex-packages-alist' variable, via local variables, customization or in
+your Emacs init code, for example, with:
+
+  (require \\='ox-latex)
+  (add-to-list \\='org-latex-packages-alist \\='(\"\" \"fancyvrb\"))
+
+Note: this is the simplest solution to add code blocks in ltx-talk.
+"
+  :group 'org-export-latex
+  :package-version '(Org . "10.0")
+  :type '(string :tag "Listings environment")
+  :safe #'stringp)
+
 (defcustom org-latex-minted-langs
   '((emacs-lisp "common-lisp")
     (cc "c++")
@@ -4059,6 +4077,7 @@ (cl-defun org-latex-src-block--listings
          (or (cadr (assq (intern lang)
                          (plist-get info :latex-listings-langs)))
              lang))
+        (env (or (plist-get info :latex-listings-env) "lstlisting"))
         (caption-str
          (when caption
            (let ((main (org-export-get-caption src-block))
@@ -4071,7 +4090,8 @@ (cl-defun org-latex-src-block--listings
         (lst-opt (plist-get info :latex-listings-options)))
     (concat
      (format
-      "\\begin{lstlisting}[%s]\n%s\\end{lstlisting}"
+      "\\begin{%s}[%s]\n%s"
+      env
       ;; Options.
       (concat
        (org-latex--make-option-string
@@ -4115,7 +4135,8 @@ (cl-defun org-latex-src-block--listings
                 ;; code
                 (concat (make-string (+ (- max-width (length loc)) 6) ?\s)
                         (format "(%s)" ref)))))
-         nil (and retain-labels (cdr code-info))))))))
+         nil (and retain-labels (cdr code-info)))))
+     (format "\n\\end{%s}" env))))
 
 ;;;; Statistics Cookie
 
diff --git a/testing/lisp/test-ox-latex.el b/testing/lisp/test-ox-latex.el
index b2cf44cae..60dc40739 100644
--- a/testing/lisp/test-ox-latex.el
+++ b/testing/lisp/test-ox-latex.el
@@ -755,5 +755,31 @@ (ert-deftest test-ox-latex/alt-attribute ()
    (should (search-forward "It has a second line!}" nil t))
    (should (search-forward "]{./image.png}" nil t))))
 
+(ert-deftest test-ox-latex/fancy-listings ()
+  "Test that we can define Verbatim as environment for the listings backend."
+  (let ((org-latex-listings-env "Verbatim")
+        (org-latex-src-block-backend 'listings)
+        (org-latex-listings-src-omit-language t)
+        (org-latex-packages-alist '(("" "fancyvrb"))))
+   (org-test-with-exported-text
+    'latex
+    "#+LATEX_COMPILER: pdflatex
+
+* A stupid little listings
+
+#+BEGIN_SRC c
+for (int i=0; i<10; i++)
+    printf(\"i: %d\\n\",i);
+#+END_SRC
+"
+    ;; (message "fancy-listings:\n%s" (buffer-string))
+    (goto-char (point-min))
+    (should (search-forward "\\usepackage{fancyvrb}\n"))
+    (should (search-forward "\\begin{document}\n"))
+    (should (search-forward "\\begin{Verbatim}[numbers=none]\n"))
+    (should (search-forward "\\end{Verbatim}\n"))
+    (should (search-forward "\\end{document}"))
+    )))
+
 (provide 'test-ox-latex)
 ;;; test-ox-latex.el ends here
-- 
2.53.0

Reply via email to