Re: [O] PATCH -- allow user to set minted style

2014-04-05 Thread Nicolas Goaziou
Michael Weylandt michael.weyla...@gmail.com writes:

 On Apr 4, 2014, at 16:24, Nicolas Goaziou n.goaz...@gmail.com wrote:

 You can add a string at the end of `org-latex-packages-alist' that will
 be inserted in the header.

 Didn't know that -- thanks! Perhaps the docstring could include that. 

Indeed. I'll add it in a while.

 Anyway, since there is no reliable way to detect if a package will be
 required at Org level, this patch cannot work properly.

 Not sure I follow: I'm piggy-backing on the same condition Org uses to
 determine whether to insert \minted blocks for source code. 

There's nothing to follow, actually. I misread the code and my sentence
is irrelevant here. Please scratch that.

 For anyone who wants it: 

 (defun org-latex-minted-style-filter (contents backend info)
 (if (string-match \\usepackage{minted} contents)
 (replace-regexp-in-string usepackage{minted}
 (format usepackage{minted}usemintedstyle{%s} 
 org-latex-minted-default-style) contents)))

 (add-to-list 'org-export-filter-final-output-functions
 'org-latex-minted-style-filter)

Thanks for sharing. You may also want to wrap your code within:

  (when (org-export-derived-backend-p backend 'latex) ...)

so your filter kicks in only when exporting to LaTeX and alike.

 Anyways, even if the idea is rejected thanks for taking a look and for
 all your work on Org Mode.

ox-latex.el has support for quite a few packages already. Defining one
variable for every single feature in all of them doesn't seem realistic.
I'd rather do it only for common packages and commonly customized
features. Of course, this is only a guideline.

In this case, I have the feeling that we should avoid creating yet
another minted variable for a simple one-liner.


Regards,

-- 
Nicolas Goaziou



[O] PATCH -- allow user to set minted style

2014-04-04 Thread Michael Weylandt
Here's a small patch which allows the user to set the Minted highlighting style 
for latex export. 

This requires a different mechanism than org-latex-minted-options since it's a 
global/preamble option. 

Apologies for the badly formatted patch. I'm not at my own computer and wanted 
to give Bastien a chance to include it in 8.2.6. I do not have FSF papers 
signed but I believe this falls under the TINYCHANGE rule. 

Patch applies against a6485af3. 

Michael

--- ox-latex.el.orij2014-04-04 10:45:17.530492000 -0400
+++ ox-latex.el2014-04-04 10:51:42.447567000 -0400
@@ -751,6 +751,18 @@
  (string :tag Minted option name )
  (string :tag Minted option value

+(defcustom org-latex-minted-default-style default
+  The default minted style used; will be inserted in a
+ \\usemintedstyle{} block if org-latex-listings is set to
+ 'minted. A list of available styles can be obtained with:
+
+ pygmentize -L styles
+  :group 'org-export-latex
+  :type '(repeat
+  (list
+   (symbol :tag Minted style name)
+   (symbol :tag Minted style value
+
(defvar org-latex-custom-lang-environments nil
  Alist mapping languages to language-specific LaTeX environments.

@@ -1126,6 +1138,9 @@
  (or (plist-get info :description) )
  (if (not (plist-get info :with-creator)) 
(plist-get info :creator
+ ;; Using minted formatting style
+ (when (eq org-latex-listings 'minted)
+   (format \\usemintedstyle{%s}))
 ;; Document start.
 \\begin{document}\n\n
 ;; Title command.





Re: [O] PATCH -- allow user to set minted style

2014-04-04 Thread Nicolas Goaziou
Hello,

Michael Weylandt michael.weyla...@gmail.com writes:

 Here's a small patch which allows the user to set the Minted
 highlighting style for latex export.

Thank you for the patch.

 This requires a different mechanism than org-latex-minted-options
 since it's a global/preamble option. 

Since it's a global/preamble option, you can include it in your header,
buffer wise, or with `org-latex-classes', or with
`org-latex-packages-alist'...

I don't think this variable is needed in this case.


Regards,

-- 
Nicolas Goaziou



Re: [O] PATCH -- allow user to set minted style

2014-04-04 Thread Michael Weylandt


On Apr 4, 2014, at 14:46, Nicolas Goaziou n.goaz...@gmail.com wrote:

 Hello,
 
 Michael Weylandt michael.weyla...@gmail.com writes:
 
 This requires a different mechanism than org-latex-minted-options
 since it's a global/preamble option.
 
 Since it's a global/preamble option, you can include it in your header,
 buffer wise, or with `org-latex-classes', or with
 `org-latex-packages-alist'...

Taking the choices in reverse:

- The minted style isn't passed as a package option so I'm not sure how 
org-latex-packages-alist helps.
 
- Yes, I have been putting it in the headers of my custom classes, but it has 
to follow \usepackage{minted} or I get a LaTeX error, so I wind up loading 
minted even when not using it. Having it as a variable also makes it easier to 
change the style. 

-I'm not sure what you mean by bufferwise

-Yes, #+LATEX_HEADER_EXTRA works but there's still the problem of failing if 
you don't use minted for that particular export.

I think the right analogy if with hyperref/hypersetup, which does have support 
of this style in Org. 

Michael


Re: [O] PATCH -- allow user to set minted style

2014-04-04 Thread Nicolas Goaziou
Michael Weylandt michael.weyla...@gmail.com writes:

 - The minted style isn't passed as a package option so I'm not sure
 how org-latex-packages-alist helps.

You can add a string at the end of `org-latex-packages-alist' that will
be inserted in the header.

 - Yes, I have been putting it in the headers of my custom classes, but
 it has to follow \usepackage{minted} or I get a LaTeX error, so I wind
 up loading minted even when not using it. Having it as a variable also
 makes it easier to change the style.

I don't think it matters much to load minted even if you don't use it.
Even if it did, you could always define classes with and without minted.
It's a bit troublesome, though, so I suggest to
use #+LATEX_HEADER_EXTRA: instead.

 -Yes, #+LATEX_HEADER_EXTRA works but there's still the problem of
 failing if you don't use minted for that particular export.

If you don't use minted for a particular export, you don't write
#+LATEX_HEADER_EXTRA: \usemintedstyle{name} in the first place.

 I think the right analogy if with hyperref/hypersetup, which does have
 support of this style in Org.

Unlike to minted, hyperref is not really optional, as it belongs to
`org-latex-default-packages-alist'. OTOH, minted may not even be
available on the machine. So there's no reason to show the same level of
support.

Anyway, since there is no reliable way to detect if a package will be
required at Org level, this patch cannot work properly.

Note that you can also write a filter that will insert
\usemintedstyle... when \usepackage{minted} is detected in the
output.


Regards,

-- 
Nicolas Goaziou



Re: [O] PATCH -- allow user to set minted style

2014-04-04 Thread Michael Weylandt
On Apr 4, 2014, at 16:24, Nicolas Goaziou n.goaz...@gmail.com wrote:

 Michael Weylandt michael.weyla...@gmail.com writes:
 
 - The minted style isn't passed as a package option so I'm not sure
 how org-latex-packages-alist helps.
 
 You can add a string at the end of `org-latex-packages-alist' that will
 be inserted in the header.
 

Didn't know that -- thanks! Perhaps the docstring could include that. 

 Anyway, since there is no reliable way to detect if a package will be
 required at Org level, this patch cannot work properly.

Not sure I follow: I'm piggy-backing on the same condition Org uses to 
determine whether to insert \minted blocks for source code. 

 
 Note that you can also write a filter that will insert
 \usemintedstyle... when \usepackage{minted} is detected in the
 output.
 

Indeed; I've done that just now. 

For anyone who wants it: 

(defun org-latex-minted-style-filter (contents backend info)
(if (string-match \\usepackage{minted} contents)
(replace-regexp-in-string usepackage{minted}
(format usepackage{minted}usemintedstyle{%s} 
org-latex-minted-default-style) contents)))

(add-to-list 'org-export-filter-final-output-functions 
'org-latex-minted-style-filter)

Anyways, even if the idea is rejected thanks for taking a look and for all your 
work on Org Mode. 

 
 Regards,
 
 -- 
 Nicolas Goaziou