Browse Source

ox-latex: Introduce :environment attribute for example blocks

* lisp/ox-latex.el (org-latex-example-block): Implement :environment
  attribute, which allows to override "verbatim" environment.
* doc/org.texi (@LaTeX{} specific attributes): Document change.
Nicolas Goaziou 9 năm trước cách đây
mục cha
commit
8ff31bd0cf
2 tập tin đã thay đổi với 29 bổ sung6 xóa
  1. 19 1
      doc/org.texi
  2. 10 5
      lisp/ox-latex.el

+ 19 - 1
doc/org.texi

@@ -12072,7 +12072,8 @@ All lines between these markers are exported literally
 @cindex #+ATTR_LATEX
 
 @LaTeX{} understands attributes specified in an @code{ATTR_LATEX} line.  They
-affect tables, images, plain lists, special blocks and source blocks.
+affect tables, images, plain lists, source blocks, example blocks and special
+blocks.
 
 @subsubheading Tables in @LaTeX{} export
 @cindex tables, in @LaTeX{} export
@@ -12291,6 +12292,23 @@ counterpart to @code{org-latex-listings-options} and
 #+END_SRC
 @end example
 
+@subsubheading Example blocks in @LaTeX{} export
+@cindex example blocks, in @LaTeX{} export
+@cindex verbatim blocks, in @LaTeX{} export
+
+By default, when exporting to @LaTeX{}, example blocks contents are wrapped
+in a @samp{verbatim} environment.  It is possible to use a different
+environment globally using an appropriate export filter (@pxref{Advanced
+configuration}).  You can also change this per block using
+@code{:environment} parameter.
+
+@example
+#+ATTR_LATEX: :environment myverbatim
+#+BEGIN_EXAMPLE
+This sentence is false.
+#+END_EXAMPLE
+@end example
+
 @subsubheading Special blocks in @LaTeX{} export
 @cindex special blocks, in @LaTeX{} export
 @cindex abstract, in @LaTeX{} export

+ 10 - 5
lisp/ox-latex.el

@@ -1488,11 +1488,16 @@ contextual information."
 CONTENTS is nil.  INFO is a plist holding contextual
 information."
   (when (org-string-nw-p (org-element-property :value example-block))
-    (org-latex--wrap-label
-     example-block
-     (format "\\begin{verbatim}\n%s\\end{verbatim}"
-	     (org-export-format-code-default example-block info))
-     info)))
+    (let ((environment (or (org-export-read-attribute
+			    :attr_latex example-block :environment)
+			   "verbatim")))
+      (org-latex--wrap-label
+       example-block
+       (format "\\begin{%s}\n%s\\end{%s}"
+	       environment
+	       (org-export-format-code-default example-block info)
+	       environment)
+       info))))
 
 
 ;;;; Export Block