emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Adding export option for babel language
@ 2014-05-08  2:46 Ken Mankoff
  2014-05-08 16:17 ` Charles Berry
  0 siblings, 1 reply; 4+ messages in thread
From: Ken Mankoff @ 2014-05-08  2:46 UTC (permalink / raw)
  To: Org-mode mailing list


I'd like to add support for PythonTeX to Org Babel 
https://github.com/gpoore/pythontex

The motivation is that PythonTeX is a better literate environment than
just Org + Babel, because it can print results inline just like an
interactive Python session, instead of all the code followed by all the
results. 

This is just a modification to the existing LaTeX export for python, it
is not support for a new language. I'm new to Org development and seek
advice how to begin approaching the solution.

I'd like the python code blocks to behave just as they do now, but if I
have set (setq org-latex-listings 'pythontex) instead of (setq
org-latex-listings 'minted), then instead of wrapping python code blocks
with:

\begin{minted}[]{python}
x+2
print x
\end{minted}

It should wrap them with

\begin{pyconsole}
x+2
print x
\end{pyconsole}

I found out that the minted export is handled in ox-latex.el, and I
assume I could get pythontex support by going through that file and
tearing it down and building it back up with pythontex in place of
minted, but I also noticed this:

       ;; Case 2.  Custom environment.
       (custom-env (format "\\begin{%s}\n%s\\end{%s}\n"
			   custom-env
			   (org-export-format-code-default src-block info)
			   custom-env))

Can I take advantage of this code? It seems like this might be the
support for Special Blocks
http://orgmode.org/worg/org-contrib/org-special-blocks.html But that
page says that the code is obsolete. And a special block won't be
treated as a python org babel block in the Org file, which is important.

Any advice where I should start digging to add pythontex support will be
much appreciated.

Thanks,

  -k.

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

* Re: Adding export option for babel language
  2014-05-08  2:46 Adding export option for babel language Ken Mankoff
@ 2014-05-08 16:17 ` Charles Berry
  2014-05-08 19:53   ` Ken Mankoff
  0 siblings, 1 reply; 4+ messages in thread
From: Charles Berry @ 2014-05-08 16:17 UTC (permalink / raw)
  To: emacs-orgmode

Ken Mankoff <mankoff <at> gmail.com> writes:

> 
> 
> I'd like to add support for PythonTeX to Org Babel 
> https://github.com/gpoore/pythontex
> 
> The motivation is that PythonTeX is a better literate environment than
> just Org + Babel, because it can print results inline just like an
> interactive Python session, instead of all the code followed by all the
> results. 
> 
> This is just a modification to the existing LaTeX export for python, it
> is not support for a new language. I'm new to Org development and seek
> advice how to begin approaching the solution.
> 
> I'd like the python code blocks to behave just as they do now, but if I
> have set (setq org-latex-listings 'pythontex) instead of (setq
> org-latex-listings 'minted), then instead of wrapping python code blocks
> with:
> 
> \begin{minted}[]{python}
> x+2
> print x
> \end{minted}
> 
> It should wrap them with
> 
> \begin{pyconsole}
> x+2
> print x
> \end{pyconsole}
> 

A quick-and-dirty approach to do just that much would be to write an export
filter for `src-block' and maybe `inline-src-block', see

   (info "(org) Advanced configuration")

   http://orgmode.org/worg/dev/org-export-reference.html#filter-system

and 

    http://orgmode.org/worg/exporters/filter-markup.html


Also, `C-h f org--filter TAB' should give you a buffer of such filter
functions (and a couple of false positives) that you might browse.


HTH,

Chuck 

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

* Re: Adding export option for babel language
  2014-05-08 16:17 ` Charles Berry
@ 2014-05-08 19:53   ` Ken Mankoff
  2014-05-08 20:09     ` Ken Mankoff
  0 siblings, 1 reply; 4+ messages in thread
From: Ken Mankoff @ 2014-05-08 19:53 UTC (permalink / raw)
  To: Charles Berry; +Cc: emacs-orgmode

Hi Chuck,

On 2014-05-08 at 12:17, Charles Berry <ccberry@ucsd.edu> wrote:
>> I'd like the python code blocks to behave just as they do now, but if I
>> have set (setq org-latex-listings 'pythontex) instead of (setq
>> org-latex-listings 'minted), then instead of wrapping python code blocks
>> with:
>> 
>> \begin{minted}[]{python}
>> x+2
>> print x
>> \end{minted}
>> 
>> It should wrap them with
>> 
>> \begin{pyconsole}
>> x+2
>> print x
>> \end{pyconsole}
>> 
>
> A quick-and-dirty approach to do just that much would be to write an export
> filter for `src-block' and maybe `inline-src-block', see
>
>    (info "(org) Advanced configuration")
>
>    http://orgmode.org/worg/dev/org-export-reference.html#filter-system
>
> and 
>
>     http://orgmode.org/worg/exporters/filter-markup.html
>
>
> Also, `C-h f org--filter TAB' should give you a buffer of such filter
> functions (and a couple of false positives) that you might browse.

I've briefly looked at the filters. Yes, it seems like that might be one
way to do this. But I have a hunch it is already implemented, and that I
just don't know how to access it or what variable to set.

See:
http://orgmode.org/cgit.cgi/org-mode.git/tree/lisp/ox-latex.el#n2280

Where Case 1 is no fontification, Case 3 is minted, and Case 2 is
custom. I can see that if `custom-env` is set correctly, it wraps the
code exactly as I want above:

       (custom-env (format "\\begin{%s}\n%s\\end{%s}\n"
			   custom-env
			   (org-export-format-code-default src-block info)
			   custom-env))

But I'm not sure where to set custom-env, although I know I want to set
it to `pyconsole`.

  -k.

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

* Re: Adding export option for babel language
  2014-05-08 19:53   ` Ken Mankoff
@ 2014-05-08 20:09     ` Ken Mankoff
  0 siblings, 0 replies; 4+ messages in thread
From: Ken Mankoff @ 2014-05-08 20:09 UTC (permalink / raw)
  To: Charles Berry; +Cc: emacs-orgmode


I figured it out:

(setq org-latex-custom-lang-environments
         '((python "pyconsole")))

And of course \usepackage{pythontex} somewhere.

This is really nice. Now the Org buffer behaves as before, but the
exported LaTeX has the python code appear as if it were run right there
in an interactive session. I set ":export code" so the Org results are
not shown in the PDF, and PythonTeX re-generates the results and puts
them inline!

  -k.


On 2014-05-08 at 15:53, Ken Mankoff <mankoff@gmail.com> wrote:
> Hi Chuck,
>
> On 2014-05-08 at 12:17, Charles Berry <ccberry@ucsd.edu> wrote:
>>> I'd like the python code blocks to behave just as they do now, but if I
>>> have set (setq org-latex-listings 'pythontex) instead of (setq
>>> org-latex-listings 'minted), then instead of wrapping python code blocks
>>> with:
>>> 
>>> \begin{minted}[]{python}
>>> x+2
>>> print x
>>> \end{minted}
>>> 
>>> It should wrap them with
>>> 
>>> \begin{pyconsole}
>>> x+2
>>> print x
>>> \end{pyconsole}
>>> 
>>
>> A quick-and-dirty approach to do just that much would be to write an export
>> filter for `src-block' and maybe `inline-src-block', see
>>
>>    (info "(org) Advanced configuration")
>>
>>    http://orgmode.org/worg/dev/org-export-reference.html#filter-system
>>
>> and 
>>
>>     http://orgmode.org/worg/exporters/filter-markup.html
>>
>>
>> Also, `C-h f org--filter TAB' should give you a buffer of such filter
>> functions (and a couple of false positives) that you might browse.
>
> I've briefly looked at the filters. Yes, it seems like that might be one
> way to do this. But I have a hunch it is already implemented, and that I
> just don't know how to access it or what variable to set.
>
> See:
> http://orgmode.org/cgit.cgi/org-mode.git/tree/lisp/ox-latex.el#n2280
>
> Where Case 1 is no fontification, Case 3 is minted, and Case 2 is
> custom. I can see that if `custom-env` is set correctly, it wraps the
> code exactly as I want above:
>
>        (custom-env (format "\\begin{%s}\n%s\\end{%s}\n"
> 			   custom-env
> 			   (org-export-format-code-default src-block info)
> 			   custom-env))
>
> But I'm not sure where to set custom-env, although I know I want to set
> it to `pyconsole`.
>
>   -k.

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

end of thread, other threads:[~2014-05-08 20:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-08  2:46 Adding export option for babel language Ken Mankoff
2014-05-08 16:17 ` Charles Berry
2014-05-08 19:53   ` Ken Mankoff
2014-05-08 20:09     ` Ken Mankoff

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).