Hi,

thanks for the patience. I hope to have implemented all suggestions by now.

BR,/PA

On Tue, 13 Dec 2022 at 10:24, Ihor Radchenko <yanta...@posteo.net> wrote:

> Pedro Andres Aranda Gutierrez <paag...@gmail.com> writes:
>
> > I've (finally) followed the procedure and broken up the patch in two. One
> > for the labels= ,caption=  and one for the language= control.
>
> Thanks!
> You also need to provide etc/ORG-NEWS entry since we are adding a new
> feature here.
>
> > FYI, I have already cleared the FSF paperwork for an emacs patch.
>
> Bastien, could you kindly confirm?
>
> > Subject: [PATCH 2/2] Allow to suppress language= in SRC blocks
>
> Please also provide changelog entries. See
> https://orgmode.org/worg/org-contribute.html#commit-messages
>
> > +(defcustom org-latex-listings-src-omit-language nil
> > +  "Set this option to t to omit the
> > +\"language=\"
> > +in the parameters to \\begin{lstlisting} when exporting a src block"
>
> Please describe in the docstring when this kind of setting is needed.
>
> > +  :group 'org-export-latex
> > +  :version "30.0"
>
> :version is not necessary. See 15.1 Common Item Keywords section of
> Elisp manual:
>
>     ‘:version VERSION’
>          This keyword specifies that the item was first introduced in Emacs
>          version VERSION, or that its default value was changed in that
>          version.  The value VERSION must be a string.
>
>     ‘:package-version '(PACKAGE . VERSION)’
>          This keyword specifies that the item was first introduced in
>          PACKAGE version VERSION, or that its meaning or default value was
>          changed in that version.  This keyword takes priority over
>                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>          ‘:version’.
>          ^^^^^^^^^^^
>
> --
> Ihor Radchenko // yantar92,
> Org mode contributor,
> 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

Headaches with a Juju log:
unit-basic-16: 09:17:36 WARNING juju.worker.uniter.operation we should run
a leader-deposed hook here, but we can't yet
From 3bc08d0ccabb2d3f4a0ea09bec5bc6a896c351ac Mon Sep 17 00:00:00 2001
From: "Pedro A. Aranda Gutierrez" <paag...@gmail.com>
Date: Mon, 12 Dec 2022 13:49:35 +0100
Subject: [PATCH 1/4] Don't emit empty labels and captions in SRC blocks

---
 lisp/ox-latex.el | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index a2d60d5db..f03903605 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -3594,11 +3594,14 @@ and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
           ((and float (not (assoc "float" lst-opt)))
            `(("float" ,(plist-get info :latex-default-figure-position)))))
          `(("language" ,lst-lang))
-         (if label
-             `(("label" ,(org-latex--label src-block info)))
-           '(("label" " ")))
-         (if caption-str `(("caption" ,caption-str)) '(("caption" " ")))
-         `(("captionpos" ,(if caption-above-p "t" "b")))
+         (when label
+             `(("label" ,(org-latex--label src-block info))))
+         (when caption-str
+           `(("caption" ,caption-str)))
+         (when caption-str
+           ;; caption-above-p means captionpos is t(op)
+           ;; else b(ottom)
+           `(("captionpos" ,(if caption-above-p "t" "b"))))
          (cond ((assoc "numbers" lst-opt) nil)
                ((not num-start) '(("numbers" "none")))
                (t `(("firstnumber" ,(number-to-string (1+ num-start)))
-- 
2.25.1

From 33d2ca63e749da8f1faacb66ece636df66464416 Mon Sep 17 00:00:00 2001
From: "Pedro A. Aranda Gutierrez" <paag...@gmail.com>
Date: Tue, 13 Dec 2022 12:07:09 +0100
Subject: [PATCH 4/4] Add entries to ORG-NEWS for changes and
 org-latex-listings-src-omit-language

---
 etc/ORG-NEWS | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 5d5e726e0..7fa9122ee 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -432,6 +432,20 @@ following properties: ~:hook~, ~:prepare-finalize~,
 ~:before-finalize~, ~:after-finalize~.  These nullary functions run
 prior to their global counterparts for the selected template.
 
+
+*** New =org-latex-listings-src-omit-language= variable for LaTeX export
+
+The =org-latex-listings-src-omit-language= customization variable
+allows you to omit the =language= parameter in the exported
+=lstlisting= environment. This is necessary when the =listings= backend
+forwards the actual listing generation to another package like
+=fancyvrb= using the following setup in the document header:
+#+BEGIN_example
+#+LATEX_HEADER: \\RequirePackage{fancyvrb}
+#+LATEX_HEADER: \\DefineVerbatimEnvironment{verbatim}{Verbatim}{...whatever...}
+#+LATEX_HEADER: \\DefineVerbatimEnvironment{lstlisting}{Verbatim}{...whatever...}
+#+END_example
+
 ** New options
 *** A new option for custom setting ~org-refile-use-outline-path~ to show document title in refile targets
 
@@ -747,6 +761,18 @@ following snippet to allow multiple different ID formats in Org files.
         org-attach-id-uuid-folder-format
         org-attach-id-ts-folder-format))
 #+end_src
+*** The LaTeX export backend only emits =label= and =caption= when they are not empty
+
+When exporting a SRC block and using the listings backend , =label==
+and =caption== parameters for the =lstlisting= environment will be
+only generated when they are not empty. Things like
+
+#+BEGIN_src latex
+\begin{lstlisting}[label= ,caption= ,captionpos=b]
+\end{lstlisting}
+#+END_src
+
+will no more appear.
 
 * Version 9.5
 
-- 
2.25.1

From 3a4705f454ed5f692ce9d04f81d3ae9bc2efad56 Mon Sep 17 00:00:00 2001
From: "Pedro A. Aranda Gutierrez" <paag...@gmail.com>
Date: Mon, 12 Dec 2022 13:51:49 +0100
Subject: [PATCH 2/4] Allow to suppress language= in SRC blocks

---
 lisp/ox-latex.el | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index f03903605..924afb399 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -1021,6 +1021,15 @@ in this list - but it does not hurt if it is present."
 	   (symbol :tag "Major mode       ")
 	   (string :tag "Listings language"))))
 
+(defcustom org-latex-listings-src-omit-language nil
+  "Set this option to t to omit the
+\"language=\"
+in the parameters to \\begin{lstlisting} when exporting a src block"
+  :group 'org-export-latex
+  :version "30.0"
+  :package-version '(Org . "9.7")
+  :type 'boolean)
+
 (defcustom org-latex-listings-options nil
   "Association list of options for the latex listings package.
 
@@ -3593,7 +3602,8 @@ and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
           ((string= "multicolumn" float) '(("float" "*")))
           ((and float (not (assoc "float" lst-opt)))
            `(("float" ,(plist-get info :latex-default-figure-position)))))
-         `(("language" ,lst-lang))
+         (unless org-latex-listings-src-omit-language
+           `(("language" ,lst-lang)))
          (when label
              `(("label" ,(org-latex--label src-block info))))
          (when caption-str
-- 
2.25.1

From 57eef55b0e903f880a1693d51b1e123220cfce78 Mon Sep 17 00:00:00 2001
From: "Pedro A. Aranda Gutierrez" <paag...@gmail.com>
Date: Tue, 13 Dec 2022 12:06:26 +0100
Subject: [PATCH 3/4] Refine DOCSTRING for org-latex-listings-src-omit-language

---
 lisp/ox-latex.el | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 924afb399..f18c2a068 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -1024,9 +1024,18 @@ in this list - but it does not hurt if it is present."
 (defcustom org-latex-listings-src-omit-language nil
   "Set this option to t to omit the
 \"language=\"
-in the parameters to \\begin{lstlisting} when exporting a src block"
+in the parameters to \\begin{lstlisting} when exporting a src block.
+
+This is necessary, for example, when the `fancyvrb' package is used
+instead of `listings' by including the following in the doc header:
+
+#+LATEX_HEADER: \\RequirePackage{fancyvrb}
+#+LATEX_HEADER: \\DefineVerbatimEnvironment{verbatim}{Verbatim}{...}
+#+LATEX_HEADER: \\DefineVerbatimEnvironment{lstlisting}{Verbatim}{...}
+
+{...} is whatever default parameters you need to pass to either environment.
+"
   :group 'org-export-latex
-  :version "30.0"
   :package-version '(Org . "9.7")
   :type 'boolean)
 
-- 
2.25.1

Reply via email to