emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* latex export R code syntax highlighting with minted
@ 2012-03-16 20:36 Ista Zahn
  2012-03-16 21:13 ` Christophe Pouzat
  2012-03-16 21:47 ` Nick Dokos
  0 siblings, 2 replies; 4+ messages in thread
From: Ista Zahn @ 2012-03-16 20:36 UTC (permalink / raw)
  To: emacs-orgmode Mailinglist

Hi all,

I'm having trouble modifying the example at
http://orgmode.org/worg/org-tutorials/org-latex-export.html#sec-12-3
to highlight R code blocks. The trouble seems to be that org-mode
identifies R blocks using uppercase R, while pygments looks for
lowercase r.

For example, org exports

\begin{minted}{R}
 2+2
\end{minted}

but pygments doesn't know how to highlight R. If I change to

\begin{minted}{r}
 2+2
\end{minted}

(note the lower case r) then it works, but of course I don't want to
have to perform a find-and-replace every time.

Do you know how to either a) make org-mode identify R blocks with a
lowercase r, or b) make pygments recognize uppercase R, or c) some
other solution I've overlooked?

Thanks!
Ista

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: latex export R code syntax highlighting with minted
  2012-03-16 20:36 latex export R code syntax highlighting with minted Ista Zahn
@ 2012-03-16 21:13 ` Christophe Pouzat
  2012-03-16 21:39   ` Ista Zahn
  2012-03-16 21:47 ` Nick Dokos
  1 sibling, 1 reply; 4+ messages in thread
From: Christophe Pouzat @ 2012-03-16 21:13 UTC (permalink / raw)
  To: Ista Zahn; +Cc: emacs-orgmode Mailinglist

Ista Zahn <istazahn@gmail.com> writes:

> Hi all,
>
> I'm having trouble modifying the example at
> http://orgmode.org/worg/org-tutorials/org-latex-export.html#sec-12-3
> to highlight R code blocks. The trouble seems to be that org-mode
> identifies R blocks using uppercase R, while pygments looks for
> lowercase r.
>
> For example, org exports
>
> \begin{minted}{R}
>  2+2
> \end{minted}
>
> but pygments doesn't know how to highlight R. If I change to
>
> \begin{minted}{r}
>  2+2
> \end{minted}
>
> (note the lower case r) then it works, but of course I don't want to
> have to perform a find-and-replace every time.
>
> Do you know how to either a) make org-mode identify R blocks with a
> lowercase r, or b) make pygments recognize uppercase R, or c) some
> other solution I've overlooked?
>
> Thanks!
> Ista
>
>

Hi Ista,

Put the following expression:

(add-to-list 'org-export-latex-minted-langs '(R "r"))  

in an emacs-lisp code block at the beginning of your org file (or in the
*scratch* buffer) and evaluate it.

Christophe
  
-- 

Président, Nicolas Sarkozy représente une sorte de triomphe bouffon de l'égalitarisme français ; pour la première fois de notre histoire, nous avons un chef de l'État qui se comporte comme s'il ne valait pas mieux que les citoyens. C'est en réalité toujours le cas, mais cette vérité doit être cachée pour que les institutions et le système social tournent de façon, si ce n'est harmonieuse, du moins raisonnable.

E. Todd, Après la démocratie. 
--

Christophe Pouzat
MAP5 - Mathématiques Appliquées à Paris 5
CNRS UMR 8145
45, rue des Saints-Pères
75006 PARIS
France

tel: +33142863828
mobile: +33662941034
web: http://www.biomedicale.univ-paris5.fr/physcerv/C_Pouzat.html

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: latex export R code syntax highlighting with minted
  2012-03-16 21:13 ` Christophe Pouzat
@ 2012-03-16 21:39   ` Ista Zahn
  0 siblings, 0 replies; 4+ messages in thread
From: Ista Zahn @ 2012-03-16 21:39 UTC (permalink / raw)
  To: Christophe Pouzat; +Cc: emacs-orgmode Mailinglist

Ah, perfect! Thank you.

On Fri, Mar 16, 2012 at 5:13 PM, Christophe Pouzat
<christophe.pouzat@gmail.com> wrote:
> (add-to-list 'org-export-latex-minted-langs '(R "r"))

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: latex export R code syntax highlighting with minted
  2012-03-16 20:36 latex export R code syntax highlighting with minted Ista Zahn
  2012-03-16 21:13 ` Christophe Pouzat
@ 2012-03-16 21:47 ` Nick Dokos
  1 sibling, 0 replies; 4+ messages in thread
From: Nick Dokos @ 2012-03-16 21:47 UTC (permalink / raw)
  To: Ista Zahn; +Cc: nicholas.dokos, emacs-orgmode Mailinglist

Ista Zahn <istazahn@gmail.com> wrote:

> Hi all,
> 
> I'm having trouble modifying the example at
> http://orgmode.org/worg/org-tutorials/org-latex-export.html#sec-12-3
> to highlight R code blocks. The trouble seems to be that org-mode
> identifies R blocks using uppercase R, while pygments looks for
> lowercase r.
> 
> For example, org exports
> 
> \begin{minted}{R}
>  2+2
> \end{minted}
> 
> but pygments doesn't know how to highlight R. If I change to
> 
> \begin{minted}{r}
>  2+2
> \end{minted}
> 
> (note the lower case r) then it works, but of course I don't want to
> have to perform a find-and-replace every time.
> 
> Do you know how to either a) make org-mode identify R blocks with a
> lowercase r, or b) make pygments recognize uppercase R, or c) some
> other solution I've overlooked?
> 

Christophe provided the org solution a) and obviously that's the way to go
(maybe one of you could provide a patch to change the default value of
org-export-latex-minted-langs to add the R setting?)

For completeness, and of theoretical interest only, here's how to do b).

o Find the directory where pygments is installed. I just started python
  imported pygments and asked for help:

,----
| $ python
| Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) 
| [GCC 4.5.2] on linux2
| Type "help", "copyright", "credits" or "license" for more information.
| >>> import pygments
| >>> help(pygments)
| Help on package pygments:
| 
| NAME
|     pygments
| 
| FILE
|     /usr/lib/python2.7/dist-packages/pygments/__init__.py
| ...  
`----

o cd /path/to/pygments/lexers, edit the file math.py (you probably have
  to be root) and add the 'R' alias for 'S':

,----
|     ...
|     name = 'S'
|     aliases = ['splus', 's', 'r', 'R']
|     filenames = ['*.S', '*.R']
|     mimetypes = ['text/S-plus', 'text/S', 'text/R']
|     ...
`----

o run (as root) the _mapping.py script to regenerate stuff:

,----
| $ sudo python _mapping.py
`----

Nick





  

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-03-16 21:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-16 20:36 latex export R code syntax highlighting with minted Ista Zahn
2012-03-16 21:13 ` Christophe Pouzat
2012-03-16 21:39   ` Ista Zahn
2012-03-16 21:47 ` Nick Dokos

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).