public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* reST writer: export raw LaTeX as “math” directive?
@ 2016-04-01  7:53 Matthias Geier
       [not found] ` <CAFesC-dj8iaoT2+PK+zTjTbft_Rs8g1YE15qTaGr5SmwgyeNBw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Matthias Geier @ 2016-04-01  7:53 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

Dear group.

Is there an option (or some other way) to make pandoc convert raw
LaTeX blocks to the reStructuredText directive "math::" instead of
"raw:: latex"?

I would like to convert Markdown text with raw LaTeX blocks to
reStructuredText. This, in turn, should be used as Sphinx source to
generate both HTML and LaTeX documents.

A little example:

    some *Markdown* text

    \begin{equation}
    \int_{-\infty}^\infty f(x) \delta(x - x_0) dx = f(x_0)
    \end{equation}

    more text

Converted --to rst, this looks like:

    some *Markdown* text

    .. raw:: latex

       \begin{equation}
       \int_{-\infty}^\infty f(x) \delta(x - x_0) dx = f(x_0)
       \end{equation}

    more text

... which of course works fine for LaTeX output, but not for HTML.

Is there a way to get the following output instead?

    some *Markdown* text

    .. math::

       \begin{equation}
       \int_{-\infty}^\infty f(x) \delta(x - x_0) dx = f(x_0)
       \end{equation}

    more text

I'm aware that this won't make sense for arbitrary LaTeX code, but I'm
only interested in (and will be only using) LaTeX math environments.

cheers,
Matthias


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

* Re: reST writer: export raw LaTeX as “math” directive?
       [not found] ` <CAFesC-dj8iaoT2+PK+zTjTbft_Rs8g1YE15qTaGr5SmwgyeNBw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2016-04-03 16:00   ` Daniel Bergey
       [not found]     ` <87r3emznqw.fsf-/RJW9vzmE8ypXNIQCVAXCG0Lkn3mC4nZ0tOlhedn3YvkypF1WZHjJXhe7Zk3YmMvjmZSf7Nhrd8@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Bergey @ 2016-04-03 16:00 UTC (permalink / raw)
  To: Matthias Geier, pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

You can use the following pandoc filter, which converts "latex" blocks
and leaves all others unchanged.  This version is in Haskell; I haven't
used the pandoc libraries for other languages.

module Main where

import           Text.Pandoc.JSON
import           Text.Pandoc.Definition

main :: IO ()
main = toJSONFilter $ \block -> case block of
  RawBlock (Format "latex") math -> Plain [Math DisplayMath math]
  anyOtherBlock -> anyOtherBlock


On 2016-04-01 at 03:53, Matthias Geier <matthias.geier-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> Dear group.
>
> Is there an option (or some other way) to make pandoc convert raw
> LaTeX blocks to the reStructuredText directive "math::" instead of
> "raw:: latex"?
>
> I would like to convert Markdown text with raw LaTeX blocks to
> reStructuredText. This, in turn, should be used as Sphinx source to
> generate both HTML and LaTeX documents.
>
> A little example:
>
>     some *Markdown* text
>
>     \begin{equation}
>     \int_{-\infty}^\infty f(x) \delta(x - x_0) dx = f(x_0)
>     \end{equation}
>
>     more text
>
> Converted --to rst, this looks like:
>
>     some *Markdown* text
>
>     .. raw:: latex
>
>        \begin{equation}
>        \int_{-\infty}^\infty f(x) \delta(x - x_0) dx = f(x_0)
>        \end{equation}
>
>     more text
>
> ... which of course works fine for LaTeX output, but not for HTML.
>
> Is there a way to get the following output instead?
>
>     some *Markdown* text
>
>     .. math::
>
>        \begin{equation}
>        \int_{-\infty}^\infty f(x) \delta(x - x_0) dx = f(x_0)
>        \end{equation}
>
>     more text
>
> I'm aware that this won't make sense for arbitrary LaTeX code, but I'm
> only interested in (and will be only using) LaTeX math environments.
>
> cheers,
> Matthias
>
> -- 
> 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-dj8iaoT2%2BPK%2BzTjTbft_Rs8g1YE15qTaGr5SmwgyeNBw%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.


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

* Re: reST writer: export raw LaTeX as “math” directive?
       [not found]     ` <87r3emznqw.fsf-/RJW9vzmE8ypXNIQCVAXCG0Lkn3mC4nZ0tOlhedn3YvkypF1WZHjJXhe7Zk3YmMvjmZSf7Nhrd8@public.gmane.org>
@ 2016-04-04 17:23       ` Matthias Geier
  0 siblings, 0 replies; 3+ messages in thread
From: Matthias Geier @ 2016-04-04 17:23 UTC (permalink / raw)
  To: Daniel Bergey; +Cc: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

Hi Daniel.

Thanks a lot for your answer, this was very helpful!

If you're interested, I've implemented it in Python there:
https://github.com/spatialaudio/nbsphinx/pull/35

I didn't use the "pandocfilters" module but instead used this as
"object_hook" to json.loads():

    def rawlatex2math_hook(obj):
        if obj.get('t') == 'RawBlock' and obj['c'][0] == 'latex':
            obj['t'] = 'Para'
            obj['c'] = [{
                't': 'Math',
                'c': [
                    {'t': 'DisplayMath', 'c': []},
                    obj['c'][1],
                ]
            }]
        return obj

... and it works perfectly!

cheers,
Matthias

On Sun, Apr 3, 2016 at 6:00 PM, Daniel Bergey wrote:
> You can use the following pandoc filter, which converts "latex" blocks
> and leaves all others unchanged.  This version is in Haskell; I haven't
> used the pandoc libraries for other languages.
>
> module Main where
>
> import           Text.Pandoc.JSON
> import           Text.Pandoc.Definition
>
> main :: IO ()
> main = toJSONFilter $ \block -> case block of
>   RawBlock (Format "latex") math -> Plain [Math DisplayMath math]
>   anyOtherBlock -> anyOtherBlock
>
>
> On 2016-04-01 at 03:53, Matthias Geier <matthias.geier-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>> Dear group.
>>
>> Is there an option (or some other way) to make pandoc convert raw
>> LaTeX blocks to the reStructuredText directive "math::" instead of
>> "raw:: latex"?
>>
>> I would like to convert Markdown text with raw LaTeX blocks to
>> reStructuredText. This, in turn, should be used as Sphinx source to
>> generate both HTML and LaTeX documents.
>>
>> A little example:
>>
>>     some *Markdown* text
>>
>>     \begin{equation}
>>     \int_{-\infty}^\infty f(x) \delta(x - x_0) dx = f(x_0)
>>     \end{equation}
>>
>>     more text
>>
>> Converted --to rst, this looks like:
>>
>>     some *Markdown* text
>>
>>     .. raw:: latex
>>
>>        \begin{equation}
>>        \int_{-\infty}^\infty f(x) \delta(x - x_0) dx = f(x_0)
>>        \end{equation}
>>
>>     more text
>>
>> ... which of course works fine for LaTeX output, but not for HTML.
>>
>> Is there a way to get the following output instead?
>>
>>     some *Markdown* text
>>
>>     .. math::
>>
>>        \begin{equation}
>>        \int_{-\infty}^\infty f(x) \delta(x - x_0) dx = f(x_0)
>>        \end{equation}
>>
>>     more text
>>
>> I'm aware that this won't make sense for arbitrary LaTeX code, but I'm
>> only interested in (and will be only using) LaTeX math environments.
>>
>> cheers,
>> Matthias
>>
>> --
>> 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-dj8iaoT2%2BPK%2BzTjTbft_Rs8g1YE15qTaGr5SmwgyeNBw%40mail.gmail.com.
>> For more options, visit https://groups.google.com/d/optout.


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

end of thread, other threads:[~2016-04-04 17:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-01  7:53 reST writer: export raw LaTeX as “math” directive? Matthias Geier
     [not found] ` <CAFesC-dj8iaoT2+PK+zTjTbft_Rs8g1YE15qTaGr5SmwgyeNBw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-04-03 16:00   ` Daniel Bergey
     [not found]     ` <87r3emznqw.fsf-/RJW9vzmE8ypXNIQCVAXCG0Lkn3mC4nZ0tOlhedn3YvkypF1WZHjJXhe7Zk3YmMvjmZSf7Nhrd8@public.gmane.org>
2016-04-04 17:23       ` Matthias Geier

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