* adding options to the minted environment of exported source blocks in latex
@ 2014-02-07 15:19 Alan Schmitt
2014-02-07 20:45 ` Nicolas Goaziou
0 siblings, 1 reply; 10+ messages in thread
From: Alan Schmitt @ 2014-02-07 15:19 UTC (permalink / raw)
To: emacs-orgmode
Hello,
I use and abuse the `org-latex-minted-options' when exporting source
blocks in latex, but I'm stumped by a usage pattern. I need to change
the list of options for one given source block (adding a "belowskip"
option to it). I tried the following, but it did not do anything:
--8<---------------cut here---------------start------------->8---
#+attr_latex: :belowskip 1cm
#+BEGIN_SRC ocaml
#load "graphics.cma";;
Graphics.open_graph "";;
#+END_SRC
--8<---------------cut here---------------end--------------->8---
I guess that I can only put some specific options for "attr_latex". Is
there a way to put arbitrary options in the exported minted environment?
Thanks a lot,
Alan
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: adding options to the minted environment of exported source blocks in latex
2014-02-07 15:19 adding options to the minted environment of exported source blocks in latex Alan Schmitt
@ 2014-02-07 20:45 ` Nicolas Goaziou
2014-02-09 10:16 ` Alan Schmitt
0 siblings, 1 reply; 10+ messages in thread
From: Nicolas Goaziou @ 2014-02-07 20:45 UTC (permalink / raw)
To: Alan Schmitt; +Cc: emacs-orgmode
Hello,
Alan Schmitt <alan.schmitt@polytechnique.org> writes:
> I use and abuse the `org-latex-minted-options' when exporting source
> blocks in latex, but I'm stumped by a usage pattern. I need to change
> the list of options for one given source block (adding a "belowskip"
> option to it). I tried the following, but it did not do anything:
>
> #+attr_latex: :belowskip 1cm
> #+BEGIN_SRC ocaml
> #load "graphics.cma";;
> Graphics.open_graph "";;
> #+END_SRC
>
> I guess that I can only put some specific options for "attr_latex". Is
> there a way to put arbitrary options in the exported minted
> environment?
At the moment, there is no Org way to add arbitrary options to listings
or minted on a per block basis.
There are basically two ways to implement this. Either we add
an :options keyword and stuff options there:
#+attr_latex: :options a=b,c=d
#+begin_src ...
Another option is to turn options into keywords:
#+attr_latex: :a b :c d
#+begin_src ...
The latter is more elegant, but it requires to know about every
minted/listings options.
It is also possible to do something in-between, i.e., tell Org about
a few selected keywords and stuff the others into :options. This is what
is done for images. Org knows about :height and :width and uses :options
for everything else.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: adding options to the minted environment of exported source blocks in latex
2014-02-07 20:45 ` Nicolas Goaziou
@ 2014-02-09 10:16 ` Alan Schmitt
2014-02-10 16:51 ` Nicolas Goaziou
0 siblings, 1 reply; 10+ messages in thread
From: Alan Schmitt @ 2014-02-09 10:16 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: emacs-orgmode
Hi Nicolas,
Nicolas Goaziou <n.goaziou@gmail.com> writes:
> At the moment, there is no Org way to add arbitrary options to listings
> or minted on a per block basis.
>
> There are basically two ways to implement this. Either we add
> an :options keyword and stuff options there:
>
> #+attr_latex: :options a=b,c=d
> #+begin_src ...
>
> Another option is to turn options into keywords:
>
> #+attr_latex: :a b :c d
> #+begin_src ...
>
> The latter is more elegant, but it requires to know about every
> minted/listings options.
>
> It is also possible to do something in-between, i.e., tell Org about
> a few selected keywords and stuff the others into :options. This is what
> is done for images. Org knows about :height and :width and uses :options
> for everything else.
The latter would be great. The option I'm considering does not exist in
minted, I add it in my preamble.
Best,
Alan
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: adding options to the minted environment of exported source blocks in latex
2014-02-09 10:16 ` Alan Schmitt
@ 2014-02-10 16:51 ` Nicolas Goaziou
2014-02-11 15:23 ` Alan Schmitt
0 siblings, 1 reply; 10+ messages in thread
From: Nicolas Goaziou @ 2014-02-10 16:51 UTC (permalink / raw)
To: Alan Schmitt; +Cc: emacs-orgmode
Hello,
Alan Schmitt <alan.schmitt@polytechnique.org> writes:
> Nicolas Goaziou <n.goaziou@gmail.com> writes:
>
>> It is also possible to do something in-between, i.e., tell Org about
>> a few selected keywords and stuff the others into :options. This is what
>> is done for images. Org knows about :height and :width and uses :options
>> for everything else.
>
> The latter would be great. The option I'm considering does not exist in
> minted, I add it in my preamble.
Then the next question is: what would be the blessed keywords known by
Org? They need to be supported in both listings and minted (but not
necessarily under the same name internally).
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: adding options to the minted environment of exported source blocks in latex
2014-02-10 16:51 ` Nicolas Goaziou
@ 2014-02-11 15:23 ` Alan Schmitt
2014-02-11 18:10 ` Nicolas Goaziou
0 siblings, 1 reply; 10+ messages in thread
From: Alan Schmitt @ 2014-02-11 15:23 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: emacs-orgmode
Nicolas Goaziou <n.goaziou@gmail.com> writes:
> Hello,
>
> Alan Schmitt <alan.schmitt@polytechnique.org> writes:
>
>> Nicolas Goaziou <n.goaziou@gmail.com> writes:
>>
>>> It is also possible to do something in-between, i.e., tell Org about
>>> a few selected keywords and stuff the others into :options. This is what
>>> is done for images. Org knows about :height and :width and uses :options
>>> for everything else.
>>
>> The latter would be great. The option I'm considering does not exist in
>> minted, I add it in my preamble.
>
> Then the next question is: what would be the blessed keywords known by
> Org? They need to be supported in both listings and minted (but not
> necessarily under the same name internally).
It is a good questions. I don't use listings, so I cannot comment about
it. I usually tweak the "frame" and "fontsize" options for minted.
Maybe the simplest approach is to have no blessed keyword, and have them
in :latex_options (as these are latex specific, the option name could be
called that).
Alan
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: adding options to the minted environment of exported source blocks in latex
2014-02-11 15:23 ` Alan Schmitt
@ 2014-02-11 18:10 ` Nicolas Goaziou
2014-02-12 10:25 ` Alan Schmitt
0 siblings, 1 reply; 10+ messages in thread
From: Nicolas Goaziou @ 2014-02-11 18:10 UTC (permalink / raw)
To: Alan Schmitt; +Cc: emacs-orgmode
Hello,
Alan Schmitt <alan.schmitt@polytechnique.org> writes:
> Nicolas Goaziou <n.goaziou@gmail.com> writes:
>
>> Alan Schmitt <alan.schmitt@polytechnique.org> writes:
>>
>>> Nicolas Goaziou <n.goaziou@gmail.com> writes:
>>>
>>>> It is also possible to do something in-between, i.e., tell Org about
>>>> a few selected keywords and stuff the others into :options. This is what
>>>> is done for images. Org knows about :height and :width and uses :options
>>>> for everything else.
>>>
>>> The latter would be great. The option I'm considering does not exist in
>>> minted, I add it in my preamble.
>>
>> Then the next question is: what would be the blessed keywords known by
>> Org? They need to be supported in both listings and minted (but not
>> necessarily under the same name internally).
>
> It is a good questions. I don't use listings, so I cannot comment about
> it. I usually tweak the "frame" and "fontsize" options for minted.
>
> Maybe the simplest approach is to have no blessed keyword, and have them
> in :latex_options (as these are latex specific, the option name could be
> called that).
I must have misunderstood your answer then.
Anyway :latex_options would be redundant on an #+attr_latex: line. I'll
have a look at it when I get some spare time.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: adding options to the minted environment of exported source blocks in latex
2014-02-11 18:10 ` Nicolas Goaziou
@ 2014-02-12 10:25 ` Alan Schmitt
2014-03-25 15:04 ` Nicolas Goaziou
0 siblings, 1 reply; 10+ messages in thread
From: Alan Schmitt @ 2014-02-12 10:25 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: emacs-orgmode
Hello Nicolas,
Nicolas Goaziou <n.goaziou@gmail.com> writes:
> Anyway :latex_options would be redundant on an #+attr_latex: line. I'll
> have a look at it when I get some spare time.
Using attr_latex would be great.
Thanks,
Alan
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: adding options to the minted environment of exported source blocks in latex
2014-02-12 10:25 ` Alan Schmitt
@ 2014-03-25 15:04 ` Nicolas Goaziou
2014-03-25 15:48 ` Alan Schmitt
0 siblings, 1 reply; 10+ messages in thread
From: Nicolas Goaziou @ 2014-03-25 15:04 UTC (permalink / raw)
To: Alan Schmitt; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 156 bytes --]
Hello,
Alan Schmitt <alan.schmitt@polytechnique.org> writes:
> Using attr_latex would be great.
Here is the patch. WDYT?
Regards,
--
Nicolas Goaziou
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-latex-Allow-options-in-LaTeX-attributes.patch --]
[-- Type: text/x-diff, Size: 6162 bytes --]
From c56bd2754030fd999d50d349ee5282a6c16ba832 Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <n.goaziou@gmail.com>
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 <LANG>
+ ...
+ #+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]{<LANG>}
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 <LANG>
+ ...
+ #+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
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: adding options to the minted environment of exported source blocks in latex
2014-03-25 15:04 ` Nicolas Goaziou
@ 2014-03-25 15:48 ` Alan Schmitt
2014-03-25 18:10 ` Nicolas Goaziou
0 siblings, 1 reply; 10+ messages in thread
From: Alan Schmitt @ 2014-03-25 15:48 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: emacs-orgmode
Nicolas Goaziou <n.goaziou@gmail.com> writes:
> Hello,
>
> Alan Schmitt <alan.schmitt@polytechnique.org> writes:
>
>> Using attr_latex would be great.
>
> Here is the patch. WDYT?
It's working great, thanks a lot!
Alan
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: adding options to the minted environment of exported source blocks in latex
2014-03-25 15:48 ` Alan Schmitt
@ 2014-03-25 18:10 ` Nicolas Goaziou
0 siblings, 0 replies; 10+ messages in thread
From: Nicolas Goaziou @ 2014-03-25 18:10 UTC (permalink / raw)
To: Alan Schmitt; +Cc: emacs-orgmode
Alan Schmitt <alan.schmitt@polytechnique.org> writes:
> It's working great, thanks a lot!
Applied, then.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2014-03-25 18:10 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-07 15:19 adding options to the minted environment of exported source blocks in latex Alan Schmitt
2014-02-07 20:45 ` Nicolas Goaziou
2014-02-09 10:16 ` Alan Schmitt
2014-02-10 16:51 ` Nicolas Goaziou
2014-02-11 15:23 ` Alan Schmitt
2014-02-11 18:10 ` Nicolas Goaziou
2014-02-12 10:25 ` Alan Schmitt
2014-03-25 15:04 ` Nicolas Goaziou
2014-03-25 15:48 ` Alan Schmitt
2014-03-25 18:10 ` Nicolas Goaziou
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.