From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: adding options to the minted environment of exported source blocks in latex Date: Tue, 25 Mar 2014 16:04:36 +0100 Message-ID: <87a9cewc8r.fsf@gmail.com> References: <87lhxmzm78.fsf@gmail.com> <87zjlylxmy.fsf@gmail.com> <87vbwlldu7.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:49803) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WSStk-0004F9-TF for emacs-orgmode@gnu.org; Tue, 25 Mar 2014 11:04:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WSStd-0003cy-KZ for emacs-orgmode@gnu.org; Tue, 25 Mar 2014 11:04:16 -0400 Received: from mail-wi0-x232.google.com ([2a00:1450:400c:c05::232]:33368) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WSStd-0003ci-9K for emacs-orgmode@gnu.org; Tue, 25 Mar 2014 11:04:09 -0400 Received: by mail-wi0-f178.google.com with SMTP id bs8so704239wib.17 for ; Tue, 25 Mar 2014 08:04:08 -0700 (PDT) In-Reply-To: (Alan Schmitt's message of "Wed, 12 Feb 2014 11:25:35 +0100") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Alan Schmitt Cc: emacs-orgmode --=-=-= Content-Type: text/plain Hello, Alan Schmitt writes: > Using attr_latex would be great. Here is the patch. WDYT? Regards, -- Nicolas Goaziou --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-ox-latex-Allow-options-in-LaTeX-attributes.patch >From c56bd2754030fd999d50d349ee5282a6c16ba832 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Tue, 25 Mar 2014 15:58:41 +0100 Subject: [PATCH] ox-latex: Allow :options in LaTeX attributes * lisp/ox-latex.el (org-latex-src-block): Allow to add options to listings or minted block-wise. (org-latex-listings-options, org-latex-minted-options): Update docstring. * doc/org.texi (@LaTeX{} specific attributes): Document feature. --- doc/org.texi | 22 +++++++++++++++-- lisp/ox-latex.el | 72 +++++++++++++++++++++++++++++++++++--------------------- 2 files changed, 65 insertions(+), 29 deletions(-) diff --git a/doc/org.texi b/doc/org.texi index 2abfa66..2330835 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -9842,6 +9842,7 @@ Here is an example @end example @cindex formatting source code, markup rules +@vindex org-latex-listings If the example is source code from a programming language, or any other text that can be marked up by font-lock in Emacs, you can ask for the example to look like the fontified Emacs buffer@footnote{This works automatically for @@ -11833,8 +11834,10 @@ that environment. @cindex source blocks, in @LaTeX{} export In addition to syntax defined in @ref{Literal examples}, names and captions -(@pxref{Images and tables}), source blocks also accept a @code{:float} -attribute. You may set it to: +(@pxref{Images and tables}), source blocks also accept two additional +attributes: @code{:float} and @code{:options}. + +You may set the former to @itemize @minus @item @code{t}: if you want to make the source block a float. It is the default @@ -11854,6 +11857,21 @@ Code that may not fit in a single page. #+END_SRC @end example +@vindex org-latex-listings-options +@vindex org-latex-minted-options +The latter allows to specify options relative to the package used to +highlight code in the output (e.g., @code{listings}). This is the local +counterpart to @code{org-latex-listings-options} and +@code{org-latex-minted-options} variables, which see. + +@example +#+ATTR_LATEX: :options commentstyle=\bfseries +#+BEGIN_SRC emacs-lisp + (defun Fib (n) ; Count rabbits. + (if (< n 2) n (+ (Fib (- n 1)) (Fib (- n 2))))) +#+END_SRC +@end example + @subsubheading Special blocks in @LaTeX{} export @cindex special blocks, in @LaTeX{} export @cindex abstract, in @LaTeX{} export diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el index 4616574..fdf1008 100644 --- a/lisp/ox-latex.el +++ b/lisp/ox-latex.el @@ -770,7 +770,13 @@ will typeset the code in a small size font with underlined, bold black keywords. Note that the same options will be applied to blocks of all -languages." +languages. If you need block-specific options, you may use the +following syntax: + + #+ATTR_LATEX: :options key1=value1,key2=value2 + #+BEGIN_SRC + ... + #+END_SRC" :group 'org-export-latex :type '(repeat (list @@ -817,7 +823,13 @@ will result in src blocks being exported with \\begin{minted}[bgcolor=bg,frame=lines]{} as the start of the minted environment. Note that the same -options will be applied to blocks of all languages." +options will be applied to blocks of all languages. If you need +block-specific options, you may use the following syntax: + + #+ATTR_LATEX: :options key1=value1,key2=value2 + #+BEGIN_SRC + ... + #+END_SRC" :group 'org-export-latex :type '(repeat (list @@ -2279,14 +2291,17 @@ contextual information." (format "\\begin{minted}[%s]{%s}\n%s\\end{minted}" ;; Options. - (org-latex--make-option-string - (if (or (not num-start) - (assoc "linenos" org-latex-minted-options)) - org-latex-minted-options - (append - `(("linenos") - ("firstnumber" ,(number-to-string (1+ num-start)))) - org-latex-minted-options))) + (concat + (org-latex--make-option-string + (if (or (not num-start) + (assoc "linenos" org-latex-minted-options)) + org-latex-minted-options + (append + `(("linenos") + ("firstnumber" ,(number-to-string (1+ num-start)))) + org-latex-minted-options))) + (let ((local-options (plist-get attributes :options))) + (and local-options (concat "," local-options)))) ;; Language. (or (cadr (assq (intern lang) org-latex-minted-langs)) lang) ;; Source code. @@ -2328,23 +2343,26 @@ contextual information." ;; Options. (format "\\lstset{%s}\n" - (org-latex--make-option-string - (append - org-latex-listings-options - (cond - ((and (not float) (plist-member attributes :float)) nil) - ((string= "multicolumn" float) '(("float" "*"))) - ((and float (not (assoc "float" org-latex-listings-options))) - `(("float" ,org-latex-default-figure-position)))) - `(("language" ,lst-lang)) - (when label `(("label" ,label))) - (when caption-str `(("caption" ,caption-str))) - (cond ((assoc "numbers" org-latex-listings-options) nil) - ((not num-start) '(("numbers" "none"))) - ((zerop num-start) '(("numbers" "left"))) - (t `(("numbers" "left") - ("firstnumber" - ,(number-to-string (1+ num-start))))))))) + (concat + (org-latex--make-option-string + (append + org-latex-listings-options + (cond + ((and (not float) (plist-member attributes :float)) nil) + ((string= "multicolumn" float) '(("float" "*"))) + ((and float (not (assoc "float" org-latex-listings-options))) + `(("float" ,org-latex-default-figure-position)))) + `(("language" ,lst-lang)) + (when label `(("label" ,label))) + (when caption-str `(("caption" ,caption-str))) + (cond ((assoc "numbers" org-latex-listings-options) nil) + ((not num-start) '(("numbers" "none"))) + ((zerop num-start) '(("numbers" "left"))) + (t `(("numbers" "left") + ("firstnumber" + ,(number-to-string (1+ num-start)))))))) + (let ((local-options (plist-get attributes :options))) + (and local-options (concat "," local-options))))) ;; Source code. (format "\\begin{lstlisting}\n%s\\end{lstlisting}" -- 1.9.1 --=-=-=--