[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals-release/org ec7c16a 08/22: ox-latex: Allow percent sign
From: |
ELPA Syncer |
Subject: |
[elpa] externals-release/org ec7c16a 08/22: ox-latex: Allow percent sign in 'src-block' caption |
Date: |
Mon, 27 Sep 2021 15:57:33 -0400 (EDT) |
branch: externals-release/org
commit ec7c16a060f25bfdc3f30b6d2295cf3631e733df
Author: Max Nikulin <manikulin@gmail.com>
Commit: Bastien <bzg@gnu.org>
ox-latex: Allow percent sign in 'src-block' caption
* lisp/ox-latex.el (org-latex-src-block): Prevent leak of percent sign
from caption to `format' first argument causing export failure due to
insufficient argument number. The fix covers only the case of verbatim
environment.
* testing/lisp/test-ox.el
(test-org-export/latex-src-block-verbatim-caption): New test for src
block LaTeX export with cases of various formatting of caption and
verbatim environment. Check that percent signs in caption and source
block body do not lead to errors.
Reported-by: Charest, Luc <charest.luc@hydroquebec.com>
<https://lists.gnu.org/archive/html/emacs-orgmode/2021-08/msg00017.html>
---
lisp/ox-latex.el | 30 +++++++--------
testing/lisp/test-ox.el | 97 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 111 insertions(+), 16 deletions(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index af79c7a..28484dc 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -2942,22 +2942,20 @@ contextual information."
(cond
;; Case 1. No source fontification.
((or (not lang) (not listings))
- (let* ((caption-str (org-latex--caption/label-string src-block info))
- (float-env
- (cond ((string= "multicolumn" float)
- (format "\\begin{figure*}[%s]\n%s%%s\n%s\\end{figure*}"
- (plist-get info :latex-default-figure-position)
- (if caption-above-p caption-str "")
- (if caption-above-p "" caption-str)))
- (caption (concat
- (if caption-above-p caption-str "")
- "%s"
- (if caption-above-p "" (concat "\n"
caption-str))))
- (t "%s"))))
- (format
- float-env
- (concat (format "\\begin{verbatim}\n%s\\end{verbatim}"
- (org-export-format-code-default src-block info))))))
+ (let ((caption-str (org-latex--caption/label-string src-block info))
+ (verbatim (format "\\begin{verbatim}\n%s\\end{verbatim}"
+ (org-export-format-code-default src-block
info))))
+ (cond ((string= "multicolumn" float)
+ (format "\\begin{figure*}[%s]\n%s%s\n%s\\end{figure*}"
+ (plist-get info :latex-default-figure-position)
+ (if caption-above-p caption-str "")
+ verbatim
+ (if caption-above-p "" caption-str)))
+ (caption (concat
+ (if caption-above-p caption-str "")
+ verbatim
+ (if caption-above-p "" (concat "\n" caption-str))))
+ (t verbatim))))
;; Case 2. Custom environment.
(custom-env
(let ((caption-str (org-latex--caption/label-string src-block info))
diff --git a/testing/lisp/test-ox.el b/testing/lisp/test-ox.el
index 206b887..8b24ddd 100644
--- a/testing/lisp/test-ox.el
+++ b/testing/lisp/test-ox.el
@@ -3896,6 +3896,103 @@ Another text. (ref:text)
(org-export-format-code-default
(org-element-map tree 'src-block #'identity info t) info))))))
+(ert-deftest test-org-export/latex-src-block-verbatim-caption ()
+ "Test `org-latex-src-block' caption for verbatim environment.
+Check that percent sign does not become a part of format.
+This test does not cover listings and custom environments."
+ (let ((export
+ (lambda (buffer-text)
+ (org-test-with-parsed-data
+ buffer-text
+ (let* ((backend (org-export-get-backend 'latex))
+ (info (org-combine-plists
+ (org-export--get-export-attributes backend)
+ (org-export-get-environment backend)))
+ (result (org-latex-src-block
+ (org-element-map tree 'src-block #'identity info t)
+ t info)))
+ ;; Remove properties to make failure reports more clear.
+ (set-text-properties 0 (length result) nil result)
+ result)))))
+
+ (should (equal
+ "\
+\\begin{verbatim}
+\"No float, no listings, 20%S\"
+\\end{verbatim}
+\\captionof{figure}{Caption of verbatim is below, 20\\%s}
+"
+ (funcall export
+ "\
+#+CAPTION: Caption of verbatim is below, 20%s
+#+BEGIN_SRC emacs-lisp
+ \"No float, no listings, 20%S\"
+#+END_SRC")))
+
+ ;; `org-latex-caption-above' has no associated property or keyword.
+ (should (equal
+ "\
+\\captionof{figure}{Caption of verbatim is above, 40\\%s}
+\\begin{verbatim}
+\"No float, no listings, 40%S\"
+\\end{verbatim}"
+ (let ((org-latex-caption-above t))
+ (funcall export
+ "\
+#+CAPTION: Caption of verbatim is above, 40%s
+#+BEGIN_SRC emacs-lisp
+ \"No float, no listings, 40%S\"
+#+END_SRC"))))
+
+ (should (equal
+ "\
+\\begin{figure*}[tp]
+\\caption{Caption is above, 60\\%s}
+\\begin{verbatim}
+\"Float, no listings, 60%S\"
+\\end{verbatim}
+\\end{figure*}"
+ (let ((org-latex-caption-above t)
+ (org-latex-default-figure-position "tp"))
+ (funcall export
+ "\
+#+CAPTION: Caption is above, 60%s
+#+ATTR_LATEX: :float multicolumn
+#+BEGIN_SRC emacs-lisp
+ \"Float, no listings, 60%S\"
+#+END_SRC"))))
+
+ (should (equal
+ "\
+\\begin{figure*}[tp]
+\\begin{verbatim}
+\"Float, no lang, listings, 80%S\"
+\\end{verbatim}
+\\caption{Caption is below, 60\\%s}
+\\end{figure*}"
+ (let ((org-latex-listings 'minted) ; inactive due to missing lang
+ (org-latex-default-figure-position "tp"))
+ ;; Namely "multicolumn" value to get just figure environment
+ ;; looks like a bug.
+ (funcall export
+ "\
+#+CAPTION: Caption is below, 60%s
+#+ATTR_LATEX: :float multicolumn
+#+BEGIN_SRC
+ \"Float, no lang, listings, 80%S\"
+#+END_SRC"))))
+
+ (should (equal
+ "\
+\\begin{verbatim}
+\"No caption, no float, no listings, 100%S\"
+\\end{verbatim}"
+ (funcall export
+ "\
+#+BEGIN_SRC emacs-lisp
+ \"No caption, no float, no listings, 100%S\"
+#+END_SRC")))))
+
;;; Smart Quotes
- [elpa] externals-release/org updated (4be129f -> 14fb761), ELPA Syncer, 2021/09/27
- [elpa] externals-release/org 268a433 01/22: mk/server.mk: Use a new path, ELPA Syncer, 2021/09/27
- [elpa] externals-release/org bf22d98 10/22: CONTRIBUTE: Update to follow the new structure of doc/, ELPA Syncer, 2021/09/27
- [elpa] externals-release/org 413060b 05/22: CONTRIBUTE: Fix merge leftover, ELPA Syncer, 2021/09/27
- [elpa] externals-release/org 399481b 09/22: Do not ignore user-defined display-buffer-alist in org-insert-link, ELPA Syncer, 2021/09/27
- [elpa] externals-release/org 3f5605e 06/22: org-agenda.el: Avoid dependency on subr-x, ELPA Syncer, 2021/09/27
- [elpa] externals-release/org 05ee1e6 18/22: Do not rely on M-q binding for filling src-block, ELPA Syncer, 2021/09/27
- [elpa] externals-release/org ec7c16a 08/22: ox-latex: Allow percent sign in 'src-block' caption,
ELPA Syncer <=
- [elpa] externals-release/org 6a2c487 07/22: Avoid infinite loop in org-agenda-dim-blocked-tasks, ELPA Syncer, 2021/09/27
- [elpa] externals-release/org 97de19f 12/22: Fix not updating org-clock-marker after refiling from indirect buffer, ELPA Syncer, 2021/09/27
- [elpa] externals-release/org d8b9bd0 11/22: Fix byte-comp function warnings, ELPA Syncer, 2021/09/27
- [elpa] externals-release/org 6a558fc 19/22: org: Fix potential modified src match-data issue, ELPA Syncer, 2021/09/27
- [elpa] externals-release/org 14fb761 22/22: Do not use mark-whole-buffer noninteractively, ELPA Syncer, 2021/09/27
- [elpa] externals-release/org bea172a 02/22: mk/default.mk: Use the Emacs manual css, ELPA Syncer, 2021/09/27
- [elpa] externals-release/org a33ad98 04/22: CONTRIBUTE: Fix link for cloning as a contributor, ELPA Syncer, 2021/09/27
- [elpa] externals-release/org 4a11766 03/22: docs: Update outdated code.orgmode.org links, ELPA Syncer, 2021/09/27
- [elpa] externals-release/org e23815b 13/22: Correctly handle org-log-note-clock-out non-interactively, ELPA Syncer, 2021/09/27
- [elpa] externals-release/org aea7cab 14/22: Fix duplicate logbook entry for repeated tasks, ELPA Syncer, 2021/09/27