public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* jupyter markdown to latex?
@ 2016-11-24  9:55 Dominic Steinitz
       [not found] ` <B684A512-D28B-47CB-BA7F-B5EB72C4E56B-yV5wzPaMHOBg9hUCZPvPmw@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: Dominic Steinitz @ 2016-11-24  9:55 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

Hi,

I have exported a jupyter notebook to markdown. The problem is that has encoded its generated latex as html like this example (which I think is mathjax).

> <html><script type="math/tex; mode=display">\newcommand{\Bold}[1]{\mathbf{#1}}\left\{\begin{array}{lcl} r & = & \sqrt{x^{2} + y^{2}} \\ \theta & = & \arctan\left(\frac{y}{x}\right) \end{array}\right.</script></html>

I really want it to be something like

> $$\begin{array}{lcl} r & = & \sqrt{x^{2} + y^{2}} \\ \theta & = & \arctan\left(\frac{y}{x}\right) \end{array}$$

Is there an easy way of doing this and / or has someone written a filter to do something like this? I’d rather avoid having to write a filter myself if possible. NB I do *not* want latex as I need to convert this into something that WordPress likes. In this example, it would be something like

> $latex \begin{array}{lcl} r & = & \sqrt{x^{2} + y^{2}} \\ \theta & = & \arctan\left(\frac{y}{x}\right) \end{array}$


Many thanks,

Dominic Steinitz
dominic-yV5wzPaMHOBg9hUCZPvPmw@public.gmane.org
http://idontgetoutmuch.wordpress.com

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/B684A512-D28B-47CB-BA7F-B5EB72C4E56B%40steinitz.org.
For more options, visit https://groups.google.com/d/optout.


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

* Re: jupyter markdown to latex?
       [not found] ` <B684A512-D28B-47CB-BA7F-B5EB72C4E56B-yV5wzPaMHOBg9hUCZPvPmw@public.gmane.org>
@ 2016-11-24 11:12   ` Matthias Geier
       [not found]     ` <CAFesC-d-6ifOHhdw+5fDohy6ABZSYp_5nA2r4TWEdeSuJXUjpg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: Matthias Geier @ 2016-11-24 11:12 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

Hi Dominic.

How did you export your Jupyter notebook to Markdown?

I just tried it both via the menu ("File" -> "Download as" ->
"Markdown") and via nbconvert (python3 -m nbconvert --to markdown
mynotebook.ipynb). In both cases, the LaTeX math was unchanged, no
HTML stuff was added.

I've created a pandoc filter to convert "raw LaTeX" nodes to "math"
nodes, this might give some pointers how to add "$latex ... $":
https://github.com/spatialaudio/nbsphinx/blob/18a4a32bd98e8bfa92612f9ab9d5fce212eff205/nbsphinx.py#L713

BTW, from a LaTeX point of view it doesn't make sense to put dollar
signs around a math environment, this would make more sense (just
remove the dollar signs):

\begin{array}{lcl}
r & = & \sqrt{x^{2} + y^{2}} \\ \theta & = & \arctan\left(\frac{y}{x}\right)
\end{array}

... and it is actually supported by Jupyter (and by pandoc).

You could use nbconvert to convert your notebooks to Markdown, and
then run pandoc on them with a custom filter that adds the "$latex ...
$".

cheers,
Matthias

On Thu, Nov 24, 2016 at 10:55 AM, Dominic Steinitz <dominic-yV5wzPaMHOBg9hUCZPvPmw@public.gmane.org> wrote:
> Hi,
>
> I have exported a jupyter notebook to markdown. The problem is that has encoded its generated latex as html like this example (which I think is mathjax).
>
>> <html><script type="math/tex; mode=display">\newcommand{\Bold}[1]{\mathbf{#1}}\left\{\begin{array}{lcl} r & = & \sqrt{x^{2} + y^{2}} \\ \theta & = & \arctan\left(\frac{y}{x}\right) \end{array}\right.</script></html>
>
> I really want it to be something like
>
>> $$\begin{array}{lcl} r & = & \sqrt{x^{2} + y^{2}} \\ \theta & = & \arctan\left(\frac{y}{x}\right) \end{array}$$
>
> Is there an easy way of doing this and / or has someone written a filter to do something like this? I’d rather avoid having to write a filter myself if possible. NB I do *not* want latex as I need to convert this into something that WordPress likes. In this example, it would be something like
>
>> $latex \begin{array}{lcl} r & = & \sqrt{x^{2} + y^{2}} \\ \theta & = & \arctan\left(\frac{y}{x}\right) \end{array}$
>
>
> Many thanks,
>
> Dominic Steinitz
> dominic-yV5wzPaMHOBg9hUCZPvPmw@public.gmane.org
> http://idontgetoutmuch.wordpress.com
>
> --
> You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/B684A512-D28B-47CB-BA7F-B5EB72C4E56B%40steinitz.org.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CAFesC-d-6ifOHhdw%2B5fDohy6ABZSYp_5nA2r4TWEdeSuJXUjpg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


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

* Re: jupyter markdown to latex?
       [not found]     ` <CAFesC-d-6ifOHhdw+5fDohy6ABZSYp_5nA2r4TWEdeSuJXUjpg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2016-11-24 12:23       ` Dom
  2016-11-24 14:10       ` Dom
  1 sibling, 0 replies; 5+ messages in thread
From: Dom @ 2016-11-24 12:23 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 3970 bytes --]

The LaTeX I write myself is fine but the output from the notebook is the 
problem. I am using sagemath to do symbolic manipulations. Hmmm maybe I can 
coax jupyter / sagemath into producing latex. Let me try.

On Thursday, 24 November 2016 11:12:42 UTC, Matthias Geier wrote:
>
> Hi Dominic. 
>
> How did you export your Jupyter notebook to Markdown? 
>
> I just tried it both via the menu ("File" -> "Download as" -> 
> "Markdown") and via nbconvert (python3 -m nbconvert --to markdown 
> mynotebook.ipynb). In both cases, the LaTeX math was unchanged, no 
> HTML stuff was added. 
>
> I've created a pandoc filter to convert "raw LaTeX" nodes to "math" 
> nodes, this might give some pointers how to add "$latex ... $": 
>
> https://github.com/spatialaudio/nbsphinx/blob/18a4a32bd98e8bfa92612f9ab9d5fce212eff205/nbsphinx.py#L713 
>
> BTW, from a LaTeX point of view it doesn't make sense to put dollar 
> signs around a math environment, this would make more sense (just 
> remove the dollar signs): 
>
> \begin{array}{lcl} 
> r & = & \sqrt{x^{2} + y^{2}} \\ \theta & = & 
> \arctan\left(\frac{y}{x}\right) 
> \end{array} 
>
> ... and it is actually supported by Jupyter (and by pandoc). 
>
> You could use nbconvert to convert your notebooks to Markdown, and 
> then run pandoc on them with a custom filter that adds the "$latex ... 
> $". 
>
> cheers, 
> Matthias 
>
> On Thu, Nov 24, 2016 at 10:55 AM, Dominic Steinitz <dom...-yV5wzPaMHOBg9hUCZPvPmw@public.gmane.org 
> <javascript:>> wrote: 
> > Hi, 
> > 
> > I have exported a jupyter notebook to markdown. The problem is that has 
> encoded its generated latex as html like this example (which I think is 
> mathjax). 
> > 
> >> <html><script type="math/tex; 
> mode=display">\newcommand{\Bold}[1]{\mathbf{#1}}\left\{\begin{array}{lcl} r 
> & = & \sqrt{x^{2} + y^{2}} \\ \theta & = & \arctan\left(\frac{y}{x}\right) 
> \end{array}\right.</script></html> 
> > 
> > I really want it to be something like 
> > 
> >> $$\begin{array}{lcl} r & = & \sqrt{x^{2} + y^{2}} \\ \theta & = & 
> \arctan\left(\frac{y}{x}\right) \end{array}$$ 
> > 
> > Is there an easy way of doing this and / or has someone written a filter 
> to do something like this? I’d rather avoid having to write a filter myself 
> if possible. NB I do *not* want latex as I need to convert this into 
> something that WordPress likes. In this example, it would be something like 
> > 
> >> $latex \begin{array}{lcl} r & = & \sqrt{x^{2} + y^{2}} \\ \theta & = & 
> \arctan\left(\frac{y}{x}\right) \end{array}$ 
> > 
> > 
> > Many thanks, 
> > 
> > Dominic Steinitz 
> > dom...-yV5wzPaMHOBg9hUCZPvPmw@public.gmane.org <javascript:> 
> > http://idontgetoutmuch.wordpress.com 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> Groups "pandoc-discuss" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an email to pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <javascript:>. 
> > To post to this group, send email to pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org 
> <javascript:>. 
> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/pandoc-discuss/B684A512-D28B-47CB-BA7F-B5EB72C4E56B%40steinitz.org. 
>
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/96c79bc5-8346-42e1-ac19-59760848e1a5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 7428 bytes --]

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

* Re: jupyter markdown to latex?
       [not found]     ` <CAFesC-d-6ifOHhdw+5fDohy6ABZSYp_5nA2r4TWEdeSuJXUjpg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  2016-11-24 12:23       ` Dom
@ 2016-11-24 14:10       ` Dom
       [not found]         ` <fb7e06d7-e268-4e45-ad2e-7cf0e610ffdb-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  1 sibling, 1 reply; 5+ messages in thread
From: Dom @ 2016-11-24 14:10 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 4717 bytes --]

Ok I am making progress. In my .ipynb file I now have

print(latex(cartesianToPolar.display()))

and after processing with

 jupyter-nbconvert --to markdown Mercator.ipynb


I can see

\left\{\begin{array}{lcl} r & = & \sqrt{x^{2} + y^{2}} \\ \theta & = & \
arctan\left(\frac{y}{x}\right) \end{array}\right.


I have written a filter as suggested

> #!/usr/bin/env runhaskell
> > import Text.Pandoc.JSON
> > import Text.Pandoc.Walk (walkM)
> > 
> > wordpressify :: Inline -> Inline
> > wordpressify (Math x y) = Math x ("LaTeX " ++ y)
> > wordpressify x = x
> > 
> > myFilter :: Pandoc -> IO Pandoc
> > myFilter = walkM (return . wordpressify)
> > 
> > main :: IO ()
> > main = toJSONFilter myFilter
>

But no joy :( I still have

\left\{\begin{array}{lcl} r & = & \sqrt{x^{2} + y^{2}} \\ \theta & = & 
\arctan\left(\frac{y}{x}\right)\end{array}\right.

I am not sure what I should pattern match on.

Thanks, Dominic. 

On Thursday, 24 November 2016 11:12:42 UTC, Matthias Geier wrote:
>
> Hi Dominic. 
>
> How did you export your Jupyter notebook to Markdown? 
>
> I just tried it both via the menu ("File" -> "Download as" -> 
> "Markdown") and via nbconvert (python3 -m nbconvert --to markdown 
> mynotebook.ipynb). In both cases, the LaTeX math was unchanged, no 
> HTML stuff was added. 
>
> I've created a pandoc filter to convert "raw LaTeX" nodes to "math" 
> nodes, this might give some pointers how to add "$latex ... $": 
>
> https://github.com/spatialaudio/nbsphinx/blob/18a4a32bd98e8bfa92612f9ab9d5fce212eff205/nbsphinx.py#L713 
>
> BTW, from a LaTeX point of view it doesn't make sense to put dollar 
> signs around a math environment, this would make more sense (just 
> remove the dollar signs): 
>
> \begin{array}{lcl} 
> r & = & \sqrt{x^{2} + y^{2}} \\ \theta & = & 
> \arctan\left(\frac{y}{x}\right) 
> \end{array} 
>
> ... and it is actually supported by Jupyter (and by pandoc). 
>
> You could use nbconvert to convert your notebooks to Markdown, and 
> then run pandoc on them with a custom filter that adds the "$latex ... 
> $". 
>
> cheers, 
> Matthias 
>
> On Thu, Nov 24, 2016 at 10:55 AM, Dominic Steinitz <dom...-yV5wzPaMHOBg9hUCZPvPmw@public.gmane.org 
> <javascript:>> wrote: 
> > Hi, 
> > 
> > I have exported a jupyter notebook to markdown. The problem is that has 
> encoded its generated latex as html like this example (which I think is 
> mathjax). 
> > 
> >> <html><script type="math/tex; 
> mode=display">\newcommand{\Bold}[1]{\mathbf{#1}}\left\{\begin{array}{lcl} r 
> & = & \sqrt{x^{2} + y^{2}} \\ \theta & = & \arctan\left(\frac{y}{x}\right) 
> \end{array}\right.</script></html> 
> > 
> > I really want it to be something like 
> > 
> >> $$\begin{array}{lcl} r & = & \sqrt{x^{2} + y^{2}} \\ \theta & = & 
> \arctan\left(\frac{y}{x}\right) \end{array}$$ 
> > 
> > Is there an easy way of doing this and / or has someone written a filter 
> to do something like this? I’d rather avoid having to write a filter myself 
> if possible. NB I do *not* want latex as I need to convert this into 
> something that WordPress likes. In this example, it would be something like 
> > 
> >> $latex \begin{array}{lcl} r & = & \sqrt{x^{2} + y^{2}} \\ \theta & = & 
> \arctan\left(\frac{y}{x}\right) \end{array}$ 
> > 
> > 
> > Many thanks, 
> > 
> > Dominic Steinitz 
> > dom...-yV5wzPaMHOBg9hUCZPvPmw@public.gmane.org <javascript:> 
> > http://idontgetoutmuch.wordpress.com 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> Groups "pandoc-discuss" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an email to pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <javascript:>. 
> > To post to this group, send email to pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org 
> <javascript:>. 
> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/pandoc-discuss/B684A512-D28B-47CB-BA7F-B5EB72C4E56B%40steinitz.org. 
>
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/fb7e06d7-e268-4e45-ad2e-7cf0e610ffdb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 21424 bytes --]

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

* Re: jupyter markdown to latex?
       [not found]         ` <fb7e06d7-e268-4e45-ad2e-7cf0e610ffdb-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2016-11-25 10:25           ` John MacFarlane
  0 siblings, 0 replies; 5+ messages in thread
From: John MacFarlane @ 2016-11-25 10:25 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

+++ Dom [Nov 24 16 06:10 ]:
>   I have written a filter as suggested

This has some unnecessary steps.  Try the simpler:

    #!/usr/bin/env runhaskell
    import Text.Pandoc.JSON

    wordpressify :: Inline -> Inline
    wordpressify (Math x y) = Math x ("LaTeX " ++ y)
    wordpressify x = x

    main :: IO ()
    main = toJSONFilter wordpressify

toJSONFilter does all the work of lifting wordpressify
into a transformation Pandoc -> Pandoc -- and there's
no need to involve IO.

Try your filter with some simple math first:

    $x=y$

and see if it works. Then see if it works for your
intended application.


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

end of thread, other threads:[~2016-11-25 10:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-24  9:55 jupyter markdown to latex? Dominic Steinitz
     [not found] ` <B684A512-D28B-47CB-BA7F-B5EB72C4E56B-yV5wzPaMHOBg9hUCZPvPmw@public.gmane.org>
2016-11-24 11:12   ` Matthias Geier
     [not found]     ` <CAFesC-d-6ifOHhdw+5fDohy6ABZSYp_5nA2r4TWEdeSuJXUjpg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-11-24 12:23       ` Dom
2016-11-24 14:10       ` Dom
     [not found]         ` <fb7e06d7-e268-4e45-ad2e-7cf0e610ffdb-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2016-11-25 10:25           ` John MacFarlane

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 NNTP newsgroup(s).