Re: PATCH: don't emit empty attributes for lstlistings in LaTeX listings backend

2022-12-11 Thread Ihor Radchenko
Pedro Andres Aranda Gutierrez  writes:

> attached is a small patch for the Latex export backend that suppresses
> emitting empty labels and captions when exporting src blocks using
> 'listings. This cleans up the emitted LaTeX.

For record.
There is a new version of this patch in 
https://orgmode.org/list/CAO48Bk9rjGXZMkuPNyXLeRYow95PfBB=+o0s0uucmtw_pja...@mail.gmail.com

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



PATCH: don't emit empty attributes for lstlistings in LaTeX listings backend

2022-12-10 Thread Pedro Andres Aranda Gutierrez
Hi,

attached is a small patch for the Latex export backend that suppresses
emitting empty labels and captions when exporting src blocks using
'listings. This cleans up the emitted LaTeX.

BR,/PA
-- 
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
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 5b29a284c..1291aff95 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -3594,11 +3594,11 @@ 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= w/o label makes little sense
+ `(("label" ,(org-latex--label src-block info
+ (when caption-str  ; caption= w/o caption makes little sense
+   `(("caption" ,caption-str))
+   `(("captionpos" ,(if caption-above-p "t" "b" ; as does captionpos w/o caption
  (cond ((assoc "numbers" lst-opt) nil)
((not num-start) '(("numbers" "none")))
(t `(("firstnumber" ,(number-to-string (1+ num-start)))