public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* Markdown Fenced Div to LaTeX Environment
@ 2021-01-24 13:47 Chris Diaz
       [not found] ` <8ba84992-d792-4333-aae0-560147ef79d4n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 22+ messages in thread
From: Chris Diaz @ 2021-01-24 13:47 UTC (permalink / raw)
  To: pandoc-discuss


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

Hello,

I'm looking for advice on how to produce HTML and LaTeX from Markdown using 
fenced divs (or something else) to apply custom styles to specific portions 
of the document. 

For example, I'm hoping to write something like this:

::: solution
Solution text here.
:::

in order to produce this when HTML is the output (already works):

<div class="solution">
Solution text here.
</div>

and this when LaTeX/PDF is the output:

\begin{solution}
Solution text here.
\end{solution}

This idea comes from Bookdown's 
<https://bookdown.org/yihui/bookdown/custom-blocks.html> Custom Blocks 
feature, but I'm wondering if there's a way to do this with Pandoc, or if 
this would require a Lua filter. 

Thanks,
Chris

-- 
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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/8ba84992-d792-4333-aae0-560147ef79d4n%40googlegroups.com.

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

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

* Re: Markdown Fenced Div to LaTeX Environment
       [not found] ` <8ba84992-d792-4333-aae0-560147ef79d4n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2021-01-24 14:32   ` Albert Krewinkel
       [not found]     ` <87pn1uwglb.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
  2021-01-24 17:58   ` Markdown Fenced Div to LaTeX Environment John MacFarlane
  1 sibling, 1 reply; 22+ messages in thread
From: Albert Krewinkel @ 2021-01-24 14:32 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

Hi,

you'll need a Lua filter for this, which is what R Markdown, and thereby
Bookdown, is using as well:

https://github.com/rstudio/rmarkdown/blob/master/inst/rmarkdown/lua/latex-div.lua

Cheers,
Albert

Chris Diaz <chris.diaz26-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:

> Hello,
>
> I'm looking for advice on how to produce HTML and LaTeX from Markdown using
> fenced divs (or something else) to apply custom styles to specific portions
> of the document.
>
> For example, I'm hoping to write something like this:
>
> ::: solution
> Solution text here.
> :::
>
> in order to produce this when HTML is the output (already works):
>
> <div class="solution">
> Solution text here.
> </div>
>
> and this when LaTeX/PDF is the output:
>
> \begin{solution}
> Solution text here.
> \end{solution}
>
> This idea comes from Bookdown's
> <https://bookdown.org/yihui/bookdown/custom-blocks.html> Custom Blocks
> feature, but I'm wondering if there's a way to do this with Pandoc, or if
> this would require a Lua filter.
>
> Thanks,
> Chris


--
Albert Krewinkel
GPG: 8eed e3e2 e8c5 6f18 81fe  e836 388d c0b2 1f63 1124


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

* Re: Markdown Fenced Div to LaTeX Environment
       [not found]     ` <87pn1uwglb.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
@ 2021-01-24 17:35       ` Bastien DUMONT
  2021-06-16 14:37       ` Fenced Div to ConTeXt Environment (was: Markdown Fenced Div to LaTeX Environment) 'juh' via pandoc-discuss
  1 sibling, 0 replies; 22+ messages in thread
From: Bastien DUMONT @ 2021-01-24 17:35 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

Hi,

Having an analogous requirement, I turned to PP (http://christophe.delord.free.fr/pp/). It seems to me that PP macro files can be more easy to write and manage than lua filters if your processing doesn't involve much programming. Also, you can easily define macros with more than one argument: for instance, a call to a macro like !century(4)(th) can handle separately the number format (roman or numeral) and of "th" (normal ou superscript).

Cheers,

Bastien

Le Sunday 24 January 2021 à 03:32:32PM, Albert Krewinkel a écrit :
> Hi,
> 
> you'll need a Lua filter for this, which is what R Markdown, and thereby
> Bookdown, is using as well:
> 
> https://github.com/rstudio/rmarkdown/blob/master/inst/rmarkdown/lua/latex-div.lua
> 
> Cheers,
> Albert
> 
> Chris Diaz <chris.diaz26-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
> 
> > Hello,
> >
> > I'm looking for advice on how to produce HTML and LaTeX from Markdown using
> > fenced divs (or something else) to apply custom styles to specific portions
> > of the document.
> >
> > For example, I'm hoping to write something like this:
> >
> > ::: solution
> > Solution text here.
> > :::
> >
> > in order to produce this when HTML is the output (already works):
> >
> > <div class="solution">
> > Solution text here.
> > </div>
> >
> > and this when LaTeX/PDF is the output:
> >
> > \begin{solution}
> > Solution text here.
> > \end{solution}
> >
> > This idea comes from Bookdown's
> > <https://bookdown.org/yihui/bookdown/custom-blocks.html> Custom Blocks
> > feature, but I'm wondering if there's a way to do this with Pandoc, or if
> > this would require a Lua filter.
> >
> > Thanks,
> > Chris
> 
> 
> --
> Albert Krewinkel
> GPG: 8eed e3e2 e8c5 6f18 81fe  e836 388d c0b2 1f63 1124
> 
> -- 
> 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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/87pn1uwglb.fsf%40zeitkraut.de.

-- 
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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/YA2v9NAvdF/J/WWQ%40localhost.


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

* Re: Markdown Fenced Div to LaTeX Environment
       [not found] ` <8ba84992-d792-4333-aae0-560147ef79d4n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  2021-01-24 14:32   ` Albert Krewinkel
@ 2021-01-24 17:58   ` John MacFarlane
       [not found]     ` <m2lfcigqtj.fsf-jF64zX8BO08an7k8zZ43ob9bIa4KchGshsV+eolpW18@public.gmane.org>
  1 sibling, 1 reply; 22+ messages in thread
From: John MacFarlane @ 2021-01-24 17:58 UTC (permalink / raw)
  To: Chris Diaz, pandoc-discuss


You need a filter, but it would be a simple one.

Something like

function latex(s)
  return pandoc.RawBlock('latex', s) 
end

function Div(el)
  if el.classes[1] == 'solution' then
    return { latex('\begin{solution}'), el.content, latex('\end{solution}') }
  end
end

Chris Diaz <chris.diaz26-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:

> Hello,
>
> I'm looking for advice on how to produce HTML and LaTeX from Markdown using 
> fenced divs (or something else) to apply custom styles to specific portions 
> of the document. 
>
> For example, I'm hoping to write something like this:
>
> ::: solution
> Solution text here.
> :::
>
> in order to produce this when HTML is the output (already works):
>
> <div class="solution">
> Solution text here.
> </div>
>
> and this when LaTeX/PDF is the output:
>
> \begin{solution}
> Solution text here.
> \end{solution}
>
> This idea comes from Bookdown's 
> <https://bookdown.org/yihui/bookdown/custom-blocks.html> Custom Blocks 
> feature, but I'm wondering if there's a way to do this with Pandoc, or if 
> this would require a Lua filter. 
>
> Thanks,
> Chris
>
> -- 
> 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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/8ba84992-d792-4333-aae0-560147ef79d4n%40googlegroups.com.


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

* Re: Markdown Fenced Div to LaTeX Environment
       [not found]     ` <m2lfcigqtj.fsf-jF64zX8BO08an7k8zZ43ob9bIa4KchGshsV+eolpW18@public.gmane.org>
@ 2021-01-24 19:50       ` Chris Diaz
       [not found]         ` <CAMkDs=NHev6VHpGEq6qiYGbOMgMr6RqKzu0E9dcsr1kZFXO-Ow-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 22+ messages in thread
From: Chris Diaz @ 2021-01-24 19:50 UTC (permalink / raw)
  To: John MacFarlane; +Cc: pandoc-discuss

[-- Attachment #1: Type: text/plain, Size: 2218 bytes --]

Thanks! Exactly what i needed to know.

-Chris

On Sun, Jan 24, 2021, 11:58 AM John MacFarlane <jgm-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org> wrote:

>
> You need a filter, but it would be a simple one.
>
> Something like
>
> function latex(s)
>   return pandoc.RawBlock('latex', s)
> end
>
> function Div(el)
>   if el.classes[1] == 'solution' then
>     return { latex('\begin{solution}'), el.content,
> latex('\end{solution}') }
>   end
> end
>
> Chris Diaz <chris.diaz26-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
>
> > Hello,
> >
> > I'm looking for advice on how to produce HTML and LaTeX from Markdown
> using
> > fenced divs (or something else) to apply custom styles to specific
> portions
> > of the document.
> >
> > For example, I'm hoping to write something like this:
> >
> > ::: solution
> > Solution text here.
> > :::
> >
> > in order to produce this when HTML is the output (already works):
> >
> > <div class="solution">
> > Solution text here.
> > </div>
> >
> > and this when LaTeX/PDF is the output:
> >
> > \begin{solution}
> > Solution text here.
> > \end{solution}
> >
> > This idea comes from Bookdown's
> > <https://bookdown.org/yihui/bookdown/custom-blocks.html> Custom Blocks
> > feature, but I'm wondering if there's a way to do this with Pandoc, or
> if
> > this would require a Lua filter.
> >
> > Thanks,
> > Chris
> >
> > --
> > 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/pandoc-discuss/8ba84992-d792-4333-aae0-560147ef79d4n%40googlegroups.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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CAMkDs%3DNHev6VHpGEq6qiYGbOMgMr6RqKzu0E9dcsr1kZFXO-Ow%40mail.gmail.com.

[-- Attachment #2: Type: text/html, Size: 3689 bytes --]

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

* Re: Markdown Fenced Div to LaTeX Environment
       [not found]         ` <CAMkDs=NHev6VHpGEq6qiYGbOMgMr6RqKzu0E9dcsr1kZFXO-Ow-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2021-01-28  3:17           ` Bernie Roesler
       [not found]             ` <e6363602-852a-45a1-a199-81553da1966bn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 22+ messages in thread
From: Bernie Roesler @ 2021-01-28  3:17 UTC (permalink / raw)
  To: pandoc-discuss


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

Hi all,

Is there a *reverse* of this solution? I'm trying to go from LaTeX to 
markdown/html for posting to a Jekyll blog, but pandoc parses out much of 
the algorithm/algorithmic environments, and does not put the contents in a 
div like it does for theorems/proofs.

With the input:

\begin{algorithm}
    \Require $x > 0$.
    \Procedure{SquareX}{$x$}
      \State $x \gets x^2$
      \State \Return $x$
    \EndProcedure
\end{algorithm}

Currently the output is:

$x > 0$. $x \gets x^2$ $x$

I'd like to have to something like:

<div class="algorithm">
    <span class="Require">$x > 0$</span>
    <span class="Procedure">SquareX</span>($x$)
    <span class="State">$x \gets x^2$</span>
    <span class="State" class="Return">$x$</span>
    <span class="EndProcedure"></span>
</div>

or something to that effect to allow formatting of the individual elements.

See also my StackOverflow question 
<https://stackoverflow.com/questions/65930404/pandoc-latex-to-markdown-do-not-parse-environment>
 and Jekyll Talk discussion 
<https://talk.jekyllrb.com/t/kramdown-latex-usepackage-algorithm-pseudocode/2861/7?u=broesler>
.

I can do my own wrangling and add a verbatim environment before running it 
through pandoc and then parse that chunk of the markdown file afterwards, 
but I was curious if there was a more elegant solution to dealing with 
unknown environments.

Thanks,
Bernie

On Sunday, January 24, 2021 at 2:51:02 PM UTC-5 chris....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:

> Thanks! Exactly what i needed to know. 
>
> -Chris
>
> On Sun, Jan 24, 2021, 11:58 AM John MacFarlane <j...-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org> wrote:
>
>>
>> You need a filter, but it would be a simple one.
>>
>> Something like
>>
>> function latex(s)
>>   return pandoc.RawBlock('latex', s) 
>> end
>>
>> function Div(el)
>>   if el.classes[1] == 'solution' then
>>     return { latex('\begin{solution}'), el.content, 
>> latex('\end{solution}') }
>>   end
>> end
>>
>> Chris Diaz <chris....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
>>
>> > Hello,
>> >
>> > I'm looking for advice on how to produce HTML and LaTeX from Markdown 
>> using 
>> > fenced divs (or something else) to apply custom styles to specific 
>> portions 
>> > of the document. 
>> >
>> > For example, I'm hoping to write something like this:
>> >
>> > ::: solution
>> > Solution text here.
>> > :::
>> >
>> > in order to produce this when HTML is the output (already works):
>> >
>> > <div class="solution">
>> > Solution text here.
>> > </div>
>> >
>> > and this when LaTeX/PDF is the output:
>> >
>> > \begin{solution}
>> > Solution text here.
>> > \end{solution}
>> >
>> > This idea comes from Bookdown's 
>> > <https://bookdown.org/yihui/bookdown/custom-blocks.html> Custom Blocks 
>> > feature, but I'm wondering if there's a way to do this with Pandoc, or 
>> if 
>> > this would require a Lua filter. 
>> >
>> > Thanks,
>> > Chris
>> >
>> > -- 
>> > 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...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
>> > To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/pandoc-discuss/8ba84992-d792-4333-aae0-560147ef79d4n%40googlegroups.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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/e6363602-852a-45a1-a199-81553da1966bn%40googlegroups.com.

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

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

* Re: Markdown Fenced Div to LaTeX Environment
       [not found]             ` <e6363602-852a-45a1-a199-81553da1966bn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2021-01-28 17:10               ` John MacFarlane
       [not found]                 ` <m2ft2l7zrz.fsf-jF64zX8BO08an7k8zZ43ob9bIa4KchGshsV+eolpW18@public.gmane.org>
  0 siblings, 1 reply; 22+ messages in thread
From: John MacFarlane @ 2021-01-28 17:10 UTC (permalink / raw)
  To: Bernie Roesler, pandoc-discuss


Pandoc's latex reader doesn't know about the algorithm
environment. What package defines it?

With the latest pandoc release, we get this output with
pandoc -f latex -t html --mathjax on your input:

<div class="algorithm">
<p><span class="math inline">\(x &gt; 0\)</span>. <span class="math inline">\(x \gets x^2\)</span> <span class="math inline">\(x\)</span></p>
</div>

Better, though we lose the line breaks and we lose \Require, etc.

If you want to handle this properly, one option would be to use
pandoc -f latex+raw_tex --lua-filter handle_algorithm.lua

You'd have to write handle_algorithm.lua, but what it would do
is find raw latex blocks with algorithm environments and convert
them to some form that works in your Jekyll blog.

You might also try this approach:

Add macro definitions to your latex:

\renewcommand{\Require}{1]{Require #1}

and so on for \State and \Procedure.

Then pandoc will parse them and you'll get better output. That
gets you almost all the way there, except for the newlines and
whitespace, if they're significant in this environment.

For the newlines, you could add a filter that intercepts
SoftBreak.



Bernie Roesler <bernard.roesler-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:

> Hi all,
>
> Is there a *reverse* of this solution? I'm trying to go from LaTeX to 
> markdown/html for posting to a Jekyll blog, but pandoc parses out much of 
> the algorithm/algorithmic environments, and does not put the contents in a 
> div like it does for theorems/proofs.
>
> With the input:
>
> \begin{algorithm}
>     \Require $x > 0$.
>     \Procedure{SquareX}{$x$}
>       \State $x \gets x^2$
>       \State \Return $x$
>     \EndProcedure
> \end{algorithm}
>
> Currently the output is:
>
> $x > 0$. $x \gets x^2$ $x$
>
> I'd like to have to something like:
>
> <div class="algorithm">
>     <span class="Require">$x > 0$</span>
>     <span class="Procedure">SquareX</span>($x$)
>     <span class="State">$x \gets x^2$</span>
>     <span class="State" class="Return">$x$</span>
>     <span class="EndProcedure"></span>
> </div>
>
> or something to that effect to allow formatting of the individual elements.
>
> See also my StackOverflow question 
> <https://stackoverflow.com/questions/65930404/pandoc-latex-to-markdown-do-not-parse-environment>
>  and Jekyll Talk discussion 
> <https://talk.jekyllrb.com/t/kramdown-latex-usepackage-algorithm-pseudocode/2861/7?u=broesler>
> .
>
> I can do my own wrangling and add a verbatim environment before running it 
> through pandoc and then parse that chunk of the markdown file afterwards, 
> but I was curious if there was a more elegant solution to dealing with 
> unknown environments.
>
> Thanks,
> Bernie
>
> On Sunday, January 24, 2021 at 2:51:02 PM UTC-5 chris....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:
>
>> Thanks! Exactly what i needed to know. 
>>
>> -Chris
>>
>> On Sun, Jan 24, 2021, 11:58 AM John MacFarlane <j...-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org> wrote:
>>
>>>
>>> You need a filter, but it would be a simple one.
>>>
>>> Something like
>>>
>>> function latex(s)
>>>   return pandoc.RawBlock('latex', s) 
>>> end
>>>
>>> function Div(el)
>>>   if el.classes[1] == 'solution' then
>>>     return { latex('\begin{solution}'), el.content, 
>>> latex('\end{solution}') }
>>>   end
>>> end
>>>
>>> Chris Diaz <chris....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
>>>
>>> > Hello,
>>> >
>>> > I'm looking for advice on how to produce HTML and LaTeX from Markdown 
>>> using 
>>> > fenced divs (or something else) to apply custom styles to specific 
>>> portions 
>>> > of the document. 
>>> >
>>> > For example, I'm hoping to write something like this:
>>> >
>>> > ::: solution
>>> > Solution text here.
>>> > :::
>>> >
>>> > in order to produce this when HTML is the output (already works):
>>> >
>>> > <div class="solution">
>>> > Solution text here.
>>> > </div>
>>> >
>>> > and this when LaTeX/PDF is the output:
>>> >
>>> > \begin{solution}
>>> > Solution text here.
>>> > \end{solution}
>>> >
>>> > This idea comes from Bookdown's 
>>> > <https://bookdown.org/yihui/bookdown/custom-blocks.html> Custom Blocks 
>>> > feature, but I'm wondering if there's a way to do this with Pandoc, or 
>>> if 
>>> > this would require a Lua filter. 
>>> >
>>> > Thanks,
>>> > Chris
>>> >
>>> > -- 
>>> > 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...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
>>> > To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/pandoc-discuss/8ba84992-d792-4333-aae0-560147ef79d4n%40googlegroups.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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/e6363602-852a-45a1-a199-81553da1966bn%40googlegroups.com.


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

* Re: Markdown Fenced Div to LaTeX Environment
       [not found]                 ` <m2ft2l7zrz.fsf-jF64zX8BO08an7k8zZ43ob9bIa4KchGshsV+eolpW18@public.gmane.org>
@ 2021-01-28 19:24                   ` Bernie Roesler
       [not found]                     ` <0F730DD9-8029-462F-A65E-AD3E618118E4-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 22+ messages in thread
From: Bernie Roesler @ 2021-01-28 19:24 UTC (permalink / raw)
  To: John MacFarlane; +Cc: pandoc-discuss

[-- Attachment #1: Type: text/plain, Size: 7885 bytes --]

Ah, excellent. The additional div makes a big difference in processing.

I realized I over-simplified my example. It's actually:

\begin{algorithm}
	\caption{...}
	\label{alg:my_alg}
	\begin{algorithmic}
	...statements...
	\end{algorithmic}
\end{algorithm}

"algorithm" is just a float like "figure" or "table", and "algorithmic" actually defines the commands "\Require", etc. pandoc now makes divs for both algorithm and algorithmic, but still loses the commands, as you've mentioned.

I've just been using a bash/sed script to pre-process the latex document before processing with pandoc which seems to work well for now.

Thanks for the update!

-Bernie


------------------
for reference, I'm now using:
------------------
$ pandoc --version
pandoc 2.11.4
Compiled with pandoc-types 1.22, texmath 0.12.1, skylighting 0.10.2,
citeproc 0.3.0.5, ipynb 0.1.0.1
User data directory: /Users/bernardroesler/.local/share/pandoc or /Users/bernardroesler/.pandoc
Copyright (C) 2006-2021 John MacFarlane. Web:  https://pandoc.org
This is free software; see the source for copying conditions. There is no
warranty, not even for merchantability or fitness for a particular purpose.


> On Jan 28, 2021, at 12:10, John MacFarlane <jgm-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org> wrote:
> 
> 
> Pandoc's latex reader doesn't know about the algorithm
> environment. What package defines it?
> 
> With the latest pandoc release, we get this output with
> pandoc -f latex -t html --mathjax on your input:
> 
> <div class="algorithm">
> <p><span class="math inline">\(x &gt; 0\)</span>. <span class="math inline">\(x \gets x^2\)</span> <span class="math inline">\(x\)</span></p>
> </div>
> 
> Better, though we lose the line breaks and we lose \Require, etc.
> 
> If you want to handle this properly, one option would be to use
> pandoc -f latex+raw_tex --lua-filter handle_algorithm.lua
> 
> You'd have to write handle_algorithm.lua, but what it would do
> is find raw latex blocks with algorithm environments and convert
> them to some form that works in your Jekyll blog.
> 
> You might also try this approach:
> 
> Add macro definitions to your latex:
> 
> \renewcommand{\Require}{1]{Require #1}
> 
> and so on for \State and \Procedure.
> 
> Then pandoc will parse them and you'll get better output. That
> gets you almost all the way there, except for the newlines and
> whitespace, if they're significant in this environment.
> 
> For the newlines, you could add a filter that intercepts
> SoftBreak.
> 
> 
> 
> Bernie Roesler <bernard.roesler-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <mailto:bernard.roesler@gmail.com>> writes:
> 
>> Hi all,
>> 
>> Is there a *reverse* of this solution? I'm trying to go from LaTeX to 
>> markdown/html for posting to a Jekyll blog, but pandoc parses out much of 
>> the algorithm/algorithmic environments, and does not put the contents in a 
>> div like it does for theorems/proofs.
>> 
>> With the input:
>> 
>> \begin{algorithm}
>>    \Require $x > 0$.
>>    \Procedure{SquareX}{$x$}
>>      \State $x \gets x^2$
>>      \State \Return $x$
>>    \EndProcedure
>> \end{algorithm}
>> 
>> Currently the output is:
>> 
>> $x > 0$. $x \gets x^2$ $x$
>> 
>> I'd like to have to something like:
>> 
>> <div class="algorithm">
>>    <span class="Require">$x > 0$</span>
>>    <span class="Procedure">SquareX</span>($x$)
>>    <span class="State">$x \gets x^2$</span>
>>    <span class="State" class="Return">$x$</span>
>>    <span class="EndProcedure"></span>
>> </div>
>> 
>> or something to that effect to allow formatting of the individual elements.
>> 
>> See also my StackOverflow question 
>> <https://stackoverflow.com/questions/65930404/pandoc-latex-to-markdown-do-not-parse-environment <https://stackoverflow.com/questions/65930404/pandoc-latex-to-markdown-do-not-parse-environment>>
>> and Jekyll Talk discussion 
>> <https://talk.jekyllrb.com/t/kramdown-latex-usepackage-algorithm-pseudocode/2861/7?u=broesler <https://talk.jekyllrb.com/t/kramdown-latex-usepackage-algorithm-pseudocode/2861/7?u=broesler>>
>> .
>> 
>> I can do my own wrangling and add a verbatim environment before running it 
>> through pandoc and then parse that chunk of the markdown file afterwards, 
>> but I was curious if there was a more elegant solution to dealing with 
>> unknown environments.
>> 
>> Thanks,
>> Bernie
>> 
>> On Sunday, January 24, 2021 at 2:51:02 PM UTC-5 chris....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <http://gmail.com/> wrote:
>> 
>>> Thanks! Exactly what i needed to know. 
>>> 
>>> -Chris
>>> 
>>> On Sun, Jan 24, 2021, 11:58 AM John MacFarlane <j...-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org <http://berkeley.edu/>> wrote:
>>> 
>>>> 
>>>> You need a filter, but it would be a simple one.
>>>> 
>>>> Something like
>>>> 
>>>> function latex(s)
>>>>  return pandoc.RawBlock('latex', s) 
>>>> end
>>>> 
>>>> function Div(el)
>>>>  if el.classes[1] == 'solution' then
>>>>    return { latex('\begin{solution}'), el.content, 
>>>> latex('\end{solution}') }
>>>>  end
>>>> end
>>>> 
>>>> Chris Diaz <chris....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <http://gmail.com/>> writes:
>>>> 
>>>>> Hello,
>>>>> 
>>>>> I'm looking for advice on how to produce HTML and LaTeX from Markdown 
>>>> using 
>>>>> fenced divs (or something else) to apply custom styles to specific 
>>>> portions 
>>>>> of the document. 
>>>>> 
>>>>> For example, I'm hoping to write something like this:
>>>>> 
>>>>> ::: solution
>>>>> Solution text here.
>>>>> :::
>>>>> 
>>>>> in order to produce this when HTML is the output (already works):
>>>>> 
>>>>> <div class="solution">
>>>>> Solution text here.
>>>>> </div>
>>>>> 
>>>>> and this when LaTeX/PDF is the output:
>>>>> 
>>>>> \begin{solution}
>>>>> Solution text here.
>>>>> \end{solution}
>>>>> 
>>>>> This idea comes from Bookdown's 
>>>>> <https://bookdown.org/yihui/bookdown/custom-blocks.html <https://bookdown.org/yihui/bookdown/custom-blocks.html>> Custom Blocks 
>>>>> feature, but I'm wondering if there's a way to do this with Pandoc, or 
>>>> if 
>>>>> this would require a Lua filter. 
>>>>> 
>>>>> Thanks,
>>>>> Chris
>>>>> 
>>>>> -- 
>>>>> 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 <http://googlegroups.com/>.
>>>>> To view this discussion on the web visit 
>>>> https://groups.google.com/d/msgid/pandoc-discuss/8ba84992-d792-4333-aae0-560147ef79d4n%40googlegroups.com <https://groups.google.com/d/msgid/pandoc-discuss/8ba84992-d792-4333-aae0-560147ef79d4n%40googlegroups.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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <mailto:pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>.
>> To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/e6363602-852a-45a1-a199-81553da1966bn%40googlegroups.com <https://groups.google.com/d/msgid/pandoc-discuss/e6363602-852a-45a1-a199-81553da1966bn%40googlegroups.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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/0F730DD9-8029-462F-A65E-AD3E618118E4%40gmail.com.

[-- Attachment #2: Type: text/html, Size: 35653 bytes --]

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

* Re: Markdown Fenced Div to LaTeX Environment
       [not found]                     ` <0F730DD9-8029-462F-A65E-AD3E618118E4-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2021-01-28 19:52                       ` Bernie Roesler
  0 siblings, 0 replies; 22+ messages in thread
From: Bernie Roesler @ 2021-01-28 19:52 UTC (permalink / raw)
  To: John MacFarlane; +Cc: pandoc-discuss

[-- Attachment #1: Type: text/plain, Size: 8373 bytes --]

Edit: Reference for algorithm environments <https://tex.stackexchange.com/a/230789>.


> On Jan 28, 2021, at 14:24, Bernie Roesler <bernard.roesler-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> 
> Ah, excellent. The additional div makes a big difference in processing.
> 
> I realized I over-simplified my example. It's actually:
> 
> \begin{algorithm}
> 	\caption{...}
> 	\label{alg:my_alg}
> 	\begin{algorithmic}
> 	...statements...
> 	\end{algorithmic}
> \end{algorithm}
> 
> "algorithm" is just a float like "figure" or "table", and "algorithmic" actually defines the commands "\Require", etc. pandoc now makes divs for both algorithm and algorithmic, but still loses the commands, as you've mentioned.
> 
> I've just been using a bash/sed script to pre-process the latex document before processing with pandoc which seems to work well for now.
> 
> Thanks for the update!
> 
> -Bernie
> 
> 
> ------------------
> for reference, I'm now using:
> ------------------
> $ pandoc --version
> pandoc 2.11.4
> Compiled with pandoc-types 1.22, texmath 0.12.1, skylighting 0.10.2,
> citeproc 0.3.0.5, ipynb 0.1.0.1
> User data directory: /Users/bernardroesler/.local/share/pandoc or /Users/bernardroesler/.pandoc
> Copyright (C) 2006-2021 John MacFarlane. Web:  https://pandoc.org <https://pandoc.org/>
> This is free software; see the source for copying conditions. There is no
> warranty, not even for merchantability or fitness for a particular purpose.
> 
> 
>> On Jan 28, 2021, at 12:10, John MacFarlane <jgm-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org <mailto:jgm@berkeley.edu>> wrote:
>> 
>> 
>> Pandoc's latex reader doesn't know about the algorithm
>> environment. What package defines it?
>> 
>> With the latest pandoc release, we get this output with
>> pandoc -f latex -t html --mathjax on your input:
>> 
>> <div class="algorithm">
>> <p><span class="math inline">\(x &gt; 0\)</span>. <span class="math inline">\(x \gets x^2\)</span> <span class="math inline">\(x\)</span></p>
>> </div>
>> 
>> Better, though we lose the line breaks and we lose \Require, etc.
>> 
>> If you want to handle this properly, one option would be to use
>> pandoc -f latex+raw_tex --lua-filter handle_algorithm.lua
>> 
>> You'd have to write handle_algorithm.lua, but what it would do
>> is find raw latex blocks with algorithm environments and convert
>> them to some form that works in your Jekyll blog.
>> 
>> You might also try this approach:
>> 
>> Add macro definitions to your latex:
>> 
>> \renewcommand{\Require}{1]{Require #1}
>> 
>> and so on for \State and \Procedure.
>> 
>> Then pandoc will parse them and you'll get better output. That
>> gets you almost all the way there, except for the newlines and
>> whitespace, if they're significant in this environment.
>> 
>> For the newlines, you could add a filter that intercepts
>> SoftBreak.
>> 
>> 
>> 
>> Bernie Roesler <bernard.roesler-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <mailto:bernard.roesler@gmail.com>> writes:
>> 
>>> Hi all,
>>> 
>>> Is there a *reverse* of this solution? I'm trying to go from LaTeX to 
>>> markdown/html for posting to a Jekyll blog, but pandoc parses out much of 
>>> the algorithm/algorithmic environments, and does not put the contents in a 
>>> div like it does for theorems/proofs.
>>> 
>>> With the input:
>>> 
>>> \begin{algorithm}
>>>    \Require $x > 0$.
>>>    \Procedure{SquareX}{$x$}
>>>      \State $x \gets x^2$
>>>      \State \Return $x$
>>>    \EndProcedure
>>> \end{algorithm}
>>> 
>>> Currently the output is:
>>> 
>>> $x > 0$. $x \gets x^2$ $x$
>>> 
>>> I'd like to have to something like:
>>> 
>>> <div class="algorithm">
>>>    <span class="Require">$x > 0$</span>
>>>    <span class="Procedure">SquareX</span>($x$)
>>>    <span class="State">$x \gets x^2$</span>
>>>    <span class="State" class="Return">$x$</span>
>>>    <span class="EndProcedure"></span>
>>> </div>
>>> 
>>> or something to that effect to allow formatting of the individual elements.
>>> 
>>> See also my StackOverflow question 
>>> <https://stackoverflow.com/questions/65930404/pandoc-latex-to-markdown-do-not-parse-environment <https://stackoverflow.com/questions/65930404/pandoc-latex-to-markdown-do-not-parse-environment>>
>>> and Jekyll Talk discussion 
>>> <https://talk.jekyllrb.com/t/kramdown-latex-usepackage-algorithm-pseudocode/2861/7?u=broesler <https://talk.jekyllrb.com/t/kramdown-latex-usepackage-algorithm-pseudocode/2861/7?u=broesler>>
>>> .
>>> 
>>> I can do my own wrangling and add a verbatim environment before running it 
>>> through pandoc and then parse that chunk of the markdown file afterwards, 
>>> but I was curious if there was a more elegant solution to dealing with 
>>> unknown environments.
>>> 
>>> Thanks,
>>> Bernie
>>> 
>>> On Sunday, January 24, 2021 at 2:51:02 PM UTC-5 chris....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <http://gmail.com/> wrote:
>>> 
>>>> Thanks! Exactly what i needed to know. 
>>>> 
>>>> -Chris
>>>> 
>>>> On Sun, Jan 24, 2021, 11:58 AM John MacFarlane <j...-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org <http://berkeley.edu/>> wrote:
>>>> 
>>>>> 
>>>>> You need a filter, but it would be a simple one.
>>>>> 
>>>>> Something like
>>>>> 
>>>>> function latex(s)
>>>>>  return pandoc.RawBlock('latex', s) 
>>>>> end
>>>>> 
>>>>> function Div(el)
>>>>>  if el.classes[1] == 'solution' then
>>>>>    return { latex('\begin{solution}'), el.content, 
>>>>> latex('\end{solution}') }
>>>>>  end
>>>>> end
>>>>> 
>>>>> Chris Diaz <chris....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <http://gmail.com/>> writes:
>>>>> 
>>>>>> Hello,
>>>>>> 
>>>>>> I'm looking for advice on how to produce HTML and LaTeX from Markdown 
>>>>> using 
>>>>>> fenced divs (or something else) to apply custom styles to specific 
>>>>> portions 
>>>>>> of the document. 
>>>>>> 
>>>>>> For example, I'm hoping to write something like this:
>>>>>> 
>>>>>> ::: solution
>>>>>> Solution text here.
>>>>>> :::
>>>>>> 
>>>>>> in order to produce this when HTML is the output (already works):
>>>>>> 
>>>>>> <div class="solution">
>>>>>> Solution text here.
>>>>>> </div>
>>>>>> 
>>>>>> and this when LaTeX/PDF is the output:
>>>>>> 
>>>>>> \begin{solution}
>>>>>> Solution text here.
>>>>>> \end{solution}
>>>>>> 
>>>>>> This idea comes from Bookdown's 
>>>>>> <https://bookdown.org/yihui/bookdown/custom-blocks.html <https://bookdown.org/yihui/bookdown/custom-blocks.html>> Custom Blocks 
>>>>>> feature, but I'm wondering if there's a way to do this with Pandoc, or 
>>>>> if 
>>>>>> this would require a Lua filter. 
>>>>>> 
>>>>>> Thanks,
>>>>>> Chris
>>>>>> 
>>>>>> -- 
>>>>>> 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 <http://googlegroups.com/>.
>>>>>> To view this discussion on the web visit 
>>>>> https://groups.google.com/d/msgid/pandoc-discuss/8ba84992-d792-4333-aae0-560147ef79d4n%40googlegroups.com <https://groups.google.com/d/msgid/pandoc-discuss/8ba84992-d792-4333-aae0-560147ef79d4n%40googlegroups.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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <mailto:pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>.
>>> To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/e6363602-852a-45a1-a199-81553da1966bn%40googlegroups.com <https://groups.google.com/d/msgid/pandoc-discuss/e6363602-852a-45a1-a199-81553da1966bn%40googlegroups.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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/B9CE6F77-90D4-4B5A-8EA7-953A11DAFD36%40gmail.com.

[-- Attachment #2: Type: text/html, Size: 36325 bytes --]

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

* Fenced Div to ConTeXt Environment (was: Markdown Fenced Div to LaTeX Environment)
       [not found]     ` <87pn1uwglb.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
  2021-01-24 17:35       ` Bastien DUMONT
@ 2021-06-16 14:37       ` 'juh' via pandoc-discuss
  2021-06-16 15:48         ` AW: " denis.maier-NSENcxR/0n0
  1 sibling, 1 reply; 22+ messages in thread
From: 'juh' via pandoc-discuss @ 2021-06-16 14:37 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

[-- Attachment #1: Type: text/plain, Size: 1048 bytes --]

Hi Albert,
hi John,
hi all,

sorry for hijacking the thread.

I want to insert special context markup like

\startparagraph[intro]
...
\stopparagraph

via

::: intro :::
...
:::

The solution for latex was this:

Am Sun, Jan 24, 2021 at 03:32:32PM +0100 schrieb Albert Krewinkel:
> Hi,
> 
> you'll need a Lua filter for this, which is what R Markdown, and thereby
> Bookdown, is using as well:
> 
> https://github.com/rstudio/rmarkdown/blob/master/inst/rmarkdown/lua/latex-div.lua

There also was a short snippet from John MacFarlane:

function latex(s)
  return pandoc.RawBlock('latex', s)
end

function Div(el)
  if el.classes[1] == 'solution' then
    return { latex('\begin{solution}'), el.content, latex('\end{solution}') }
  end
end


How can I achieve this with context output. Simply changing the string "latex"
to "context" results in this error.

Error running filter filter.lua:
./filter.lua: createProcess: runInteractiveProcess: exec: invalid argument (Exec format error)
make: *** [Makefile:36: pdf] Fehler 83

TIA
Jan Ulrich Hasecke

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

* AW: Fenced Div to ConTeXt Environment (was: Markdown Fenced Div to LaTeX Environment)
  2021-06-16 14:37       ` Fenced Div to ConTeXt Environment (was: Markdown Fenced Div to LaTeX Environment) 'juh' via pandoc-discuss
@ 2021-06-16 15:48         ` denis.maier-NSENcxR/0n0
       [not found]           ` <5db56b4f1d8d4ca2bec612bcebb7a525-NSENcxR/0n0@public.gmane.org>
  0 siblings, 1 reply; 22+ messages in thread
From: denis.maier-NSENcxR/0n0 @ 2021-06-16 15:48 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

Hmm, I cannot even run the latex example. So maybe it has nothing to do with latex vs context.
Denis

> -----Ursprüngliche Nachricht-----
> Von: 'juh' via pandoc-discuss <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
> Gesendet: Mittwoch, 16. Juni 2021 16:38
> An: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> Betreff: Fenced Div to ConTeXt Environment (was: Markdown Fenced Div to
> LaTeX Environment)
> 
> Hi Albert,
> hi John,
> hi all,
> 
> sorry for hijacking the thread.
> 
> I want to insert special context markup like
> 
> \startparagraph[intro]
> ...
> \stopparagraph
> 
> via
> 
> ::: intro :::
> ...
> :::
> 
> The solution for latex was this:
> 
> Am Sun, Jan 24, 2021 at 03:32:32PM +0100 schrieb Albert Krewinkel:
> > Hi,
> >
> > you'll need a Lua filter for this, which is what R Markdown, and
> > thereby Bookdown, is using as well:
> >
> >
> https://github.com/rstudio/rmarkdown/blob/master/inst/rmarkdown/lua/la
> > tex-div.lua
> 
> There also was a short snippet from John MacFarlane:
> 
> function latex(s)
>   return pandoc.RawBlock('latex', s)
> end
> 
> function Div(el)
>   if el.classes[1] == 'solution' then
>     return { latex('\begin{solution}'), el.content, latex('\end{solution}') }
>   end
> end
> 
> 
> How can I achieve this with context output. Simply changing the string "latex"
> to "context" results in this error.
> 
> Error running filter filter.lua:
> ./filter.lua: createProcess: runInteractiveProcess: exec: invalid argument
> (Exec format error)
> make: *** [Makefile:36: pdf] Fehler 83
> 
> TIA
> Jan Ulrich Hasecke
> 
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/pandoc-
> discuss/20210616143731.GA29446%40sokrates.

-- 
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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/5db56b4f1d8d4ca2bec612bcebb7a525%40unibe.ch.


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

* Re: Fenced Div to ConTeXt Environment (was: Markdown Fenced Div to LaTeX Environment)
       [not found]           ` <5db56b4f1d8d4ca2bec612bcebb7a525-NSENcxR/0n0@public.gmane.org>
@ 2021-06-16 21:59             ` Bastien DUMONT
  2021-06-17  6:27               ` 'juh' via pandoc-discuss
  0 siblings, 1 reply; 22+ messages in thread
From: Bastien DUMONT @ 2021-06-16 21:59 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

Maybe it's only part of the solution, but backslashes should be escaped:

return { latex('\\begin{solution}'), el.content, latex('\\end{solution}') }

Le Wednesday 16 June 2021 à 03:48:59PM, denis.maier-NSENcxR/0n0@public.gmane.org a écrit :
> Hmm, I cannot even run the latex example. So maybe it has nothing to do with latex vs context.
> Denis
> 
> > -----Ursprüngliche Nachricht-----
> > Von: 'juh' via pandoc-discuss <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
> > Gesendet: Mittwoch, 16. Juni 2021 16:38
> > An: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> > Betreff: Fenced Div to ConTeXt Environment (was: Markdown Fenced Div to
> > LaTeX Environment)
> > 
> > Hi Albert,
> > hi John,
> > hi all,
> > 
> > sorry for hijacking the thread.
> > 
> > I want to insert special context markup like
> > 
> > \startparagraph[intro]
> > ...
> > \stopparagraph
> > 
> > via
> > 
> > ::: intro :::
> > ...
> > :::
> > 
> > The solution for latex was this:
> > 
> > Am Sun, Jan 24, 2021 at 03:32:32PM +0100 schrieb Albert Krewinkel:
> > > Hi,
> > >
> > > you'll need a Lua filter for this, which is what R Markdown, and
> > > thereby Bookdown, is using as well:
> > >
> > >
> > https://github.com/rstudio/rmarkdown/blob/master/inst/rmarkdown/lua/la
> > > tex-div.lua
> > 
> > There also was a short snippet from John MacFarlane:
> > 
> > function latex(s)
> >   return pandoc.RawBlock('latex', s)
> > end
> > 
> > function Div(el)
> >   if el.classes[1] == 'solution' then
> >     return { latex('\begin{solution}'), el.content, latex('\end{solution}') }
> >   end
> > end
> > 
> > 
> > How can I achieve this with context output. Simply changing the string "latex"
> > to "context" results in this error.
> > 
> > Error running filter filter.lua:
> > ./filter.lua: createProcess: runInteractiveProcess: exec: invalid argument
> > (Exec format error)
> > make: *** [Makefile:36: pdf] Fehler 83
> > 
> > TIA
> > Jan Ulrich Hasecke
> > 
> > --
> > 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 view this discussion on the web visit
> > https://groups.google.com/d/msgid/pandoc-
> > discuss/20210616143731.GA29446%40sokrates.
> 
> -- 
> 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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/5db56b4f1d8d4ca2bec612bcebb7a525%40unibe.ch.

-- 
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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/YMp0KUjIO6VXhYu2%40localhost.


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

* Re: Fenced Div to ConTeXt Environment (was: Markdown Fenced Div to LaTeX Environment)
  2021-06-16 21:59             ` Bastien DUMONT
@ 2021-06-17  6:27               ` 'juh' via pandoc-discuss
       [not found]                 ` <493d0aa9-47f5-ca8d-2ef5-8e63f965c529-cl+VPiYnx/1AfugRpC6u6w@public.gmane.org>
  0 siblings, 1 reply; 22+ messages in thread
From: 'juh' via pandoc-discuss @ 2021-06-17  6:27 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw


Thanks Bastien,

Am 16.06.21 um 23:59 schrieb Bastien DUMONT:
> Maybe it's only part of the solution, but backslashes should be escaped:
> 
> return { latex('\\begin{solution}'), el.content, latex('\\end{solution}') }

while this sounds familiar, it does not change the error message.

I guess that I miss something fundamental with applying filters.

The filter is called with --filter filter.lua.

I also tried the filter cited in the original thread with the same error:
https://github.com/rstudio/rmarkdown/blob/master/inst/rmarkdown/lua/latex-div.lua

Any other idea how I can achieve this?

\startparagraph[intro]
...
\stopparagraph

by using this in the md-file?


::: intro :::
...
:::


TIA
juh


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

* Re: Fenced Div to ConTeXt Environment (was: Markdown Fenced Div to LaTeX Environment)
       [not found]                 ` <493d0aa9-47f5-ca8d-2ef5-8e63f965c529-cl+VPiYnx/1AfugRpC6u6w@public.gmane.org>
@ 2021-06-17  6:54                   ` BPJ
       [not found]                     ` <CADAJKhDmtv1iLv8GsKzjxSzmvHzuOfpP6qrc21TUEYturw_xTQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 22+ messages in thread
From: BPJ @ 2021-06-17  6:54 UTC (permalink / raw)
  To: pandoc-discuss

[-- Attachment #1: Type: text/plain, Size: 1794 bytes --]

--filter/-F is for JSON filters. Lua filters need --lua-filter/-L


Den tors 17 juni 2021 08:27'juh' via pandoc-discuss <
pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> skrev:

>
> Thanks Bastien,
>
> Am 16.06.21 um 23:59 schrieb Bastien DUMONT:
> > Maybe it's only part of the solution, but backslashes should be escaped:
> >
> > return { latex('\\begin{solution}'), el.content,
> latex('\\end{solution}') }
>
> while this sounds familiar, it does not change the error message.
>
> I guess that I miss something fundamental with applying filters.
>
> The filter is called with --filter filter.lua.
>
> I also tried the filter cited in the original thread with the same error:
>
> https://github.com/rstudio/rmarkdown/blob/master/inst/rmarkdown/lua/latex-div.lua
>
> Any other idea how I can achieve this?
>
> \startparagraph[intro]
> ...
> \stopparagraph
>
> by using this in the md-file?
>
>
> ::: intro :::
> ...
> :::
>
>
> TIA
> juh
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/pandoc-discuss/493d0aa9-47f5-ca8d-2ef5-8e63f965c529%40mailbox.org
> .
>

-- 
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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CADAJKhDmtv1iLv8GsKzjxSzmvHzuOfpP6qrc21TUEYturw_xTQ%40mail.gmail.com.

[-- Attachment #2: Type: text/html, Size: 2961 bytes --]

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

* Re: Fenced Div to ConTeXt Environment (was: Markdown Fenced Div to LaTeX Environment)
       [not found]                     ` <CADAJKhDmtv1iLv8GsKzjxSzmvHzuOfpP6qrc21TUEYturw_xTQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2021-06-17  7:55                       ` 'juh' via pandoc-discuss
       [not found]                         ` <dc8ef20b-4a8b-c385-704c-28c85a5b6820-cl+VPiYnx/1AfugRpC6u6w@public.gmane.org>
  0 siblings, 1 reply; 22+ messages in thread
From: 'juh' via pandoc-discuss @ 2021-06-17  7:55 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw


Am 17.06.21 um 08:54 schrieb BPJ:
> --filter/-F is for JSON filters. Lua filters need --lua-filter/-L

Thanks a lot! Now the error message is much more informative.

This is my filter:

function context(s)
   return pandoc.RawBlock('context', s)
end

function Div(el)
   if el.classes[1] == 'intro' then
     return { context('\\startparagraph{intro}'), el.content, 
context('\\stopparagraph') }
   end
end


This is the error message

Error running filter filter.lua:
Could not read list: Could not get Block value: untagged value

Any hints?
juh


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

* AW: Fenced Div to ConTeXt Environment (was: Markdown Fenced Div to LaTeX Environment)
       [not found]                         ` <dc8ef20b-4a8b-c385-704c-28c85a5b6820-cl+VPiYnx/1AfugRpC6u6w@public.gmane.org>
@ 2021-06-17  8:12                           ` denis.maier-NSENcxR/0n0
       [not found]                             ` <4396a9133ab74e4fbff486f09e22d254-NSENcxR/0n0@public.gmane.org>
  2021-06-17  8:18                           ` Bastien DUMONT
  1 sibling, 1 reply; 22+ messages in thread
From: denis.maier-NSENcxR/0n0 @ 2021-06-17  8:12 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

Yep, this is also what I was getting. 

But this minimal shows how to make it work:

```lua -- works
function Div(el)
    return {pandoc.RawBlock('context', "\\start"), el, pandoc.RawBlock('context', "\\stop")}
end
```

vs.

```lua -- does not work!
function Div(el)
    return {pandoc.RawBlock('context', "\\start"), el.content, pandoc.RawBlock('context', "\\stop")}
end
```

So, this here works:

```lua
function context(s)
  return pandoc.RawBlock('context', s)
end

function Div(el)
	if el.classes[1] == 'intro' then
		return { context('\\startintro'), el, context('\\stopintro') }
	end
end
```

Maybe this should be a bit more generic though?

```
function context(s)
  return pandoc.RawBlock('context', s)
end

function Div(el)
	if el.classes[1] == 'intro' or 'question' or 'solution' then
		return { context('\\start'..el.classes[1]), el, context('\\stop'..el.classes[1]) }
	end
end
```

As my lua skills are far below mediocre I bet there ways to make this nicer, e.g. by putting the relevant classes into a table and referring to that. And you may also want to pass arguments from your divs to the context \start...\stop construct. Think of this:

\startquestion[difficulty=easy]

How to build pandoc filters using lua?

\stopquestion?

Denis

> -----Ursprüngliche Nachricht-----
> Von: 'juh' via pandoc-discuss <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
> Gesendet: Donnerstag, 17. Juni 2021 09:56
> An: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> Betreff: Re: Fenced Div to ConTeXt Environment (was: Markdown Fenced Div
> to LaTeX Environment)
> 
> 
> Am 17.06.21 um 08:54 schrieb BPJ:
> > --filter/-F is for JSON filters. Lua filters need --lua-filter/-L
> 
> Thanks a lot! Now the error message is much more informative.
> 
> This is my filter:
> 
> function context(s)
>    return pandoc.RawBlock('context', s)
> end
> 
> function Div(el)
>    if el.classes[1] == 'intro' then
>      return { context('\\startparagraph{intro}'), el.content,
> context('\\stopparagraph') }
>    end
> end
> 
> 
> This is the error message
> 
> Error running filter filter.lua:
> Could not read list: Could not get Block value: untagged value
> 
> Any hints?
> juh
> 
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/pandoc-discuss/dc8ef20b-4a8b-c385-
> 704c-28c85a5b6820%40mailbox.org.

-- 
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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/4396a9133ab74e4fbff486f09e22d254%40unibe.ch.


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

* Re: Fenced Div to ConTeXt Environment (was: Markdown Fenced Div to LaTeX Environment)
       [not found]                         ` <dc8ef20b-4a8b-c385-704c-28c85a5b6820-cl+VPiYnx/1AfugRpC6u6w@public.gmane.org>
  2021-06-17  8:12                           ` AW: " denis.maier-NSENcxR/0n0
@ 2021-06-17  8:18                           ` Bastien DUMONT
  1 sibling, 0 replies; 22+ messages in thread
From: Bastien DUMONT @ 2021-06-17  8:18 UTC (permalink / raw)
  To: 'juh' via pandoc-discuss

The problem is that el.content is a List, and the Div function must return a Block or a list of Blocks. The error means that Pandoc doesn't recognize the List provided by el.content as a Block, which is normal.

I see two solutions:

  – The simplest one: replace el.content by el (so that it returns two RawBlocks and a Div, which is a kind of Block);
  – If you really want the content of the Div to be extracted from the Div and the Div to be removed from the output:

function context(s)
  return pandoc.RawBlock('context', s)
end

function Div(el)
  if el.classes[1] == 'intro' then
    local intro = {}
    table.insert(intro, context('\\startparagraph{intro}'))
    for i = 1, #el.content do
      table.insert(intro, el.content[i])
    end
    table.insert(intro, context('\\stopparagraph'))
    return intro
  end
end

I guess that the first solution should satisfy your needs, but the second one is worth mentionning for other applications.

Le Thursday 17 June 2021 à 09:55:40AM, 'juh' via pandoc-discuss a écrit :
> 
> Am 17.06.21 um 08:54 schrieb BPJ:
> > --filter/-F is for JSON filters. Lua filters need --lua-filter/-L
> 
> Thanks a lot! Now the error message is much more informative.
> 
> This is my filter:
> 
> function context(s)
>   return pandoc.RawBlock('context', s)
> end
> 
> function Div(el)
>   if el.classes[1] == 'intro' then
>     return { context('\\startparagraph{intro}'), el.content,
> context('\\stopparagraph') }
>   end
> end
> 
> 
> This is the error message
> 
> Error running filter filter.lua:
> Could not read list: Could not get Block value: untagged value
> 
> Any hints?
> juh
> 
> -- 
> 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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/dc8ef20b-4a8b-c385-704c-28c85a5b6820%40mailbox.org.

-- 
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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/YMsFbs5tYl1pZsZq%40localhost.


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

* Re: Fenced Div to ConTeXt Environment (was: Markdown Fenced Div to LaTeX Environment)
       [not found]                             ` <4396a9133ab74e4fbff486f09e22d254-NSENcxR/0n0@public.gmane.org>
@ 2021-06-17  8:36                               ` Bastien DUMONT
  2021-06-17  8:51                                 ` AW: " denis.maier-NSENcxR/0n0
  2021-06-17 10:20                                 ` 'juh' via pandoc-discuss
  0 siblings, 2 replies; 22+ messages in thread
From: Bastien DUMONT @ 2021-06-17  8:36 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

One possible solution:

```lua
ENV_CLASSES = { 'intro', 'question', 'solution' }

local function context(s)
  return pandoc.RawBlock('context', s)
end

local function get_env_class(elem)
if elem.classes then
  for i = 1, #elem.classes do
    for j = 1, #ENV_CLASSES do
      if elem.classes[i] == ENV_CLASSES[j] then return ENV_CLASSES[j] end
  end
end
else
  error('function has_class used on an element of type ' ..
        elem.t .. ' that cannot have classes.')
end
end

function Div(el)
  local env_class = get_env_class(el) -- nil if there is none
  if env_class then -- false if env_class is nil
    return { context('\\start'.. env_class), el, context('\\stop'.. env_class) }
  end
end
```

Notice that the intro, question or solution class need not be the first one, so that this would be recognized:

::: {.my-class .intro}

blabla

:::

Le Thursday 17 June 2021 à 08:12:06AM, denis.maier-NSENcxR/0n0@public.gmane.org a écrit :
> Yep, this is also what I was getting. 
> 
> But this minimal shows how to make it work:
> 
> ```lua -- works
> function Div(el)
>     return {pandoc.RawBlock('context', "\\start"), el, pandoc.RawBlock('context', "\\stop")}
> end
> ```
> 
> vs.
> 
> ```lua -- does not work!
> function Div(el)
>     return {pandoc.RawBlock('context', "\\start"), el.content, pandoc.RawBlock('context', "\\stop")}
> end
> ```
> 
> So, this here works:
> 
> ```lua
> function context(s)
>   return pandoc.RawBlock('context', s)
> end
> 
> function Div(el)
> 	if el.classes[1] == 'intro' then
> 		return { context('\\startintro'), el, context('\\stopintro') }
> 	end
> end
> ```
> 
> Maybe this should be a bit more generic though?
> 
> ```
> function context(s)
>   return pandoc.RawBlock('context', s)
> end
> 
> function Div(el)
> 	if el.classes[1] == 'intro' or 'question' or 'solution' then
> 		return { context('\\start'..el.classes[1]), el, context('\\stop'..el.classes[1]) }
> 	end
> end
> ```
> 
> As my lua skills are far below mediocre I bet there ways to make this nicer, e.g. by putting the relevant classes into a table and referring to that. And you may also want to pass arguments from your divs to the context \start...\stop construct. Think of this:
> 
> \startquestion[difficulty=easy]
> 
> How to build pandoc filters using lua?
> 
> \stopquestion?
> 
> Denis
> 
> > -----Ursprüngliche Nachricht-----
> > Von: 'juh' via pandoc-discuss <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
> > Gesendet: Donnerstag, 17. Juni 2021 09:56
> > An: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> > Betreff: Re: Fenced Div to ConTeXt Environment (was: Markdown Fenced Div
> > to LaTeX Environment)
> > 
> > 
> > Am 17.06.21 um 08:54 schrieb BPJ:
> > > --filter/-F is for JSON filters. Lua filters need --lua-filter/-L
> > 
> > Thanks a lot! Now the error message is much more informative.
> > 
> > This is my filter:
> > 
> > function context(s)
> >    return pandoc.RawBlock('context', s)
> > end
> > 
> > function Div(el)
> >    if el.classes[1] == 'intro' then
> >      return { context('\\startparagraph{intro}'), el.content,
> > context('\\stopparagraph') }
> >    end
> > end
> > 
> > 
> > This is the error message
> > 
> > Error running filter filter.lua:
> > Could not read list: Could not get Block value: untagged value
> > 
> > Any hints?
> > juh
> > 
> > --
> > 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 view this discussion on the web visit
> > https://groups.google.com/d/msgid/pandoc-discuss/dc8ef20b-4a8b-c385-
> > 704c-28c85a5b6820%40mailbox.org.
> 
> -- 
> 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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/4396a9133ab74e4fbff486f09e22d254%40unibe.ch.

-- 
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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/YMsJgXv77qqiw7au%40localhost.


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

* AW: Fenced Div to ConTeXt Environment (was: Markdown Fenced Div to LaTeX Environment)
  2021-06-17  8:36                               ` Bastien DUMONT
@ 2021-06-17  8:51                                 ` denis.maier-NSENcxR/0n0
  2021-06-17 10:20                                 ` 'juh' via pandoc-discuss
  1 sibling, 0 replies; 22+ messages in thread
From: denis.maier-NSENcxR/0n0 @ 2021-06-17  8:51 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

Thanks, that looks nice!

> -----Ursprüngliche Nachricht-----
> Von: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <pandoc-
> discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> Im Auftrag von Bastien DUMONT
> Gesendet: Donnerstag, 17. Juni 2021 10:36
> An: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> Betreff: Re: Fenced Div to ConTeXt Environment (was: Markdown Fenced Div
> to LaTeX Environment)
> 
> One possible solution:
> 
> ```lua
> ENV_CLASSES = { 'intro', 'question', 'solution' }
> 
> local function context(s)
>   return pandoc.RawBlock('context', s)
> end
> 
> local function get_env_class(elem)
> if elem.classes then
>   for i = 1, #elem.classes do
>     for j = 1, #ENV_CLASSES do
>       if elem.classes[i] == ENV_CLASSES[j] then return ENV_CLASSES[j] end
>   end
> end
> else
>   error('function has_class used on an element of type ' ..
>         elem.t .. ' that cannot have classes.') end end
> 
> function Div(el)
>   local env_class = get_env_class(el) -- nil if there is none
>   if env_class then -- false if env_class is nil
>     return { context('\\start'.. env_class), el, context('\\stop'.. env_class) }
>   end
> end
> ```
> 
> Notice that the intro, question or solution class need not be the first one, so
> that this would be recognized:
> 
> ::: {.my-class .intro}
> 
> blabla
> 
> :::
> 

Just to note this that in this case 

::: {.my-class .intro. solution}
blabla
:::

the filter will pick up the first class it knows about, while silently ignoring the rest.

Denis


> Le Thursday 17 June 2021 à 08:12:06AM, denis.maier-NSENcxR/0n0@public.gmane.org a écrit :
> > Yep, this is also what I was getting.
> >
> > But this minimal shows how to make it work:
> >
> > ```lua -- works
> > function Div(el)
> >     return {pandoc.RawBlock('context', "\\start"), el,
> > pandoc.RawBlock('context', "\\stop")} end ```
> >
> > vs.
> >
> > ```lua -- does not work!
> > function Div(el)
> >     return {pandoc.RawBlock('context', "\\start"), el.content,
> > pandoc.RawBlock('context', "\\stop")} end ```
> >
> > So, this here works:
> >
> > ```lua
> > function context(s)
> >   return pandoc.RawBlock('context', s) end
> >
> > function Div(el)
> > 	if el.classes[1] == 'intro' then
> > 		return { context('\\startintro'), el, context('\\stopintro') }
> > 	end
> > end
> > ```
> >
> > Maybe this should be a bit more generic though?
> >
> > ```
> > function context(s)
> >   return pandoc.RawBlock('context', s) end
> >
> > function Div(el)
> > 	if el.classes[1] == 'intro' or 'question' or 'solution' then
> > 		return { context('\\start'..el.classes[1]), el,
> context('\\stop'..el.classes[1]) }
> > 	end
> > end
> > ```
> >
> > As my lua skills are far below mediocre I bet there ways to make this nicer,
> e.g. by putting the relevant classes into a table and referring to that. And you
> may also want to pass arguments from your divs to the context \start...\stop
> construct. Think of this:
> >
> > \startquestion[difficulty=easy]
> >
> > How to build pandoc filters using lua?
> >
> > \stopquestion?
> >
> > Denis
> >
> > > -----Ursprüngliche Nachricht-----
> > > Von: 'juh' via pandoc-discuss <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
> > > Gesendet: Donnerstag, 17. Juni 2021 09:56
> > > An: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> > > Betreff: Re: Fenced Div to ConTeXt Environment (was: Markdown Fenced
> > > Div to LaTeX Environment)
> > >
> > >
> > > Am 17.06.21 um 08:54 schrieb BPJ:
> > > > --filter/-F is for JSON filters. Lua filters need --lua-filter/-L
> > >
> > > Thanks a lot! Now the error message is much more informative.
> > >
> > > This is my filter:
> > >
> > > function context(s)
> > >    return pandoc.RawBlock('context', s) end
> > >
> > > function Div(el)
> > >    if el.classes[1] == 'intro' then
> > >      return { context('\\startparagraph{intro}'), el.content,
> > > context('\\stopparagraph') }
> > >    end
> > > end
> > >
> > >
> > > This is the error message
> > >
> > > Error running filter filter.lua:
> > > Could not read list: Could not get Block value: untagged value
> > >
> > > Any hints?
> > > juh
> > >
> > > --
> > > 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 view this discussion on the web visit
> > > https://groups.google.com/d/msgid/pandoc-discuss/dc8ef20b-4a8b-
> c385-
> > > 704c-28c85a5b6820%40mailbox.org.
> >
> > --
> > 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/pandoc-
> discuss/4396a9133ab74e4fbff486f09e22d254%40unibe.ch.
> 
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/pandoc-
> discuss/YMsJgXv77qqiw7au%40localhost.

-- 
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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/2570133387e64394bf205ca351294873%40unibe.ch.


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

* Re: Fenced Div to ConTeXt Environment (was: Markdown Fenced Div to LaTeX Environment)
  2021-06-17  8:36                               ` Bastien DUMONT
  2021-06-17  8:51                                 ` AW: " denis.maier-NSENcxR/0n0
@ 2021-06-17 10:20                                 ` 'juh' via pandoc-discuss
       [not found]                                   ` <af60ed15-0d8c-5c51-5a34-a9c082e7fc89-cl+VPiYnx/1AfugRpC6u6w@public.gmane.org>
  1 sibling, 1 reply; 22+ messages in thread
From: 'juh' via pandoc-discuss @ 2021-06-17 10:20 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

Thanks a lot Bastien and Denis,

I go with this one:

```lua
ENV_CLASSES = { 'intro', 'zitat', 'solution' }

local function context(s)
   return pandoc.RawBlock('context', s)
end

local function get_env_class(elem)
if elem.classes then
   for i = 1, #elem.classes do
     for j = 1, #ENV_CLASSES do
       if elem.classes[i] == ENV_CLASSES[j] then return ENV_CLASSES[j] end
   end
end
else
   error('function has_class used on an element of type ' ..
         elem.t .. ' that cannot have classes.')
end
end

function Div(el)
   local env_class = get_env_class(el) -- nil if there is none
   if env_class then -- false if env_class is nil
     return { context('\\startparagraph['.. env_class ..']'), el, 
context('\\stopparagraph') }
   end
end
```

ConTeXt is amazingly flexible in many ways and it is fun to create 
individually designed documents. But I have to deploy it to an 
organization were people want to write content in Markdown. I am 
currently working on a proof of concept that we can meet all of our 
style ideas with ConTeXt while writing in markdown using pandoc.

I think that in the long run I will need some more filters. Eg. it is 
quite easy to have a default width of images with

\setupexternalfigure[width=\textwidth]

so that the default image markup

\placefigure{My caption}{\externalfigure[image.jpg]}

works perfectly fine.

But I can imaging situations where I want to pass an argument to it like 
this.

\placefigure{My caption}{\externalfigure[image.jpg][textwidth=6em]}

I'll try to figure out how to do this in a lua filter. A co-worker of 
mine has some programming skills and might help.

But in fact there might be another solution, if I put the image in an 
special paragraph environment and redefine setupexternalfigure.

For now, thanks a lot!

juh

-- 
Soziale Plastik. Die Kunst der Allmende
Essay zum 30. Todestag von Joseph Beuys
http://www.amazon.de/dp/1523458763/
Taschenbuch, 130 Seiten, EUR 9,90


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

* Re: Fenced Div to ConTeXt Environment (was: Markdown Fenced Div to LaTeX Environment)
       [not found]                                   ` <af60ed15-0d8c-5c51-5a34-a9c082e7fc89-cl+VPiYnx/1AfugRpC6u6w@public.gmane.org>
@ 2021-06-17 11:44                                     ` Bastien DUMONT
  2021-06-17 12:23                                     ` AW: " denis.maier-NSENcxR/0n0
  1 sibling, 0 replies; 22+ messages in thread
From: Bastien DUMONT @ 2021-06-17 11:44 UTC (permalink / raw)
  To: 'juh' via pandoc-discuss

I can't help you with this particular point, but as some people here use Markdown+Pandoc more or less as a frontend to TeX, don't hesitate to share your needs and thoughts. Someone may already have a solution, or something approaching. Moreover it could prompt to the creation or publication of filters that extend Pandoc's capabilities. I wrote myself a filter that enables references to spans of text by page or note number in a variety of formats, would you be interested in testing it?

Le Thursday 17 June 2021 à 12:20:05PM, 'juh' via pandoc-discuss a écrit :
> Thanks a lot Bastien and Denis,
> 
> I go with this one:
> 
> ```lua
> ENV_CLASSES = { 'intro', 'zitat', 'solution' }
> 
> local function context(s)
>   return pandoc.RawBlock('context', s)
> end
> 
> local function get_env_class(elem)
> if elem.classes then
>   for i = 1, #elem.classes do
>     for j = 1, #ENV_CLASSES do
>       if elem.classes[i] == ENV_CLASSES[j] then return ENV_CLASSES[j] end
>   end
> end
> else
>   error('function has_class used on an element of type ' ..
>         elem.t .. ' that cannot have classes.')
> end
> end
> 
> function Div(el)
>   local env_class = get_env_class(el) -- nil if there is none
>   if env_class then -- false if env_class is nil
>     return { context('\\startparagraph['.. env_class ..']'), el,
> context('\\stopparagraph') }
>   end
> end
> ```
> 
> ConTeXt is amazingly flexible in many ways and it is fun to create
> individually designed documents. But I have to deploy it to an organization
> were people want to write content in Markdown. I am currently working on a
> proof of concept that we can meet all of our style ideas with ConTeXt while
> writing in markdown using pandoc.
> 
> I think that in the long run I will need some more filters. Eg. it is quite
> easy to have a default width of images with
> 
> \setupexternalfigure[width=\textwidth]
> 
> so that the default image markup
> 
> \placefigure{My caption}{\externalfigure[image.jpg]}
> 
> works perfectly fine.
> 
> But I can imaging situations where I want to pass an argument to it like
> this.
> 
> \placefigure{My caption}{\externalfigure[image.jpg][textwidth=6em]}
> 
> I'll try to figure out how to do this in a lua filter. A co-worker of mine
> has some programming skills and might help.
> 
> But in fact there might be another solution, if I put the image in an
> special paragraph environment and redefine setupexternalfigure.
> 
> For now, thanks a lot!
> 
> juh
> 
> -- 
> Soziale Plastik. Die Kunst der Allmende
> Essay zum 30. Todestag von Joseph Beuys
> http://www.amazon.de/dp/1523458763/
> Taschenbuch, 130 Seiten, EUR 9,90
> 
> -- 
> 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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/af60ed15-0d8c-5c51-5a34-a9c082e7fc89%40mailbox.org.

-- 
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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/YMs1jE5/RfL9h/Op%40localhost.


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

* AW: Fenced Div to ConTeXt Environment (was: Markdown Fenced Div to LaTeX Environment)
       [not found]                                   ` <af60ed15-0d8c-5c51-5a34-a9c082e7fc89-cl+VPiYnx/1AfugRpC6u6w@public.gmane.org>
  2021-06-17 11:44                                     ` Bastien DUMONT
@ 2021-06-17 12:23                                     ` denis.maier-NSENcxR/0n0
  1 sibling, 0 replies; 22+ messages in thread
From: denis.maier-NSENcxR/0n0 @ 2021-06-17 12:23 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

> -----Ursprüngliche Nachricht-----
> Von: 'juh' via pandoc-discuss <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
> Gesendet: Donnerstag, 17. Juni 2021 12:20
> An: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> Betreff: Re: Fenced Div to ConTeXt Environment (was: Markdown Fenced Div
> to LaTeX Environment)
> 
> Thanks a lot Bastien and Denis,
> [...]
> 
> 
> ConTeXt is amazingly flexible in many ways and it is fun to create individually
> designed documents. But I have to deploy it to an organization were people
> want to write content in Markdown. I am currently working on a proof of
> concept that we can meet all of our style ideas with ConTeXt while writing in
> markdown using pandoc.

Well, if that's your use case I'd think that using Markdown->Pandoc->XHTML is probably the better option and will save you from having to write a lot of filters. Styling a div with a certain class is almost as easy as with CSS.

As I think you know that option, I'd be interested to hear if there's something that speaks against that approach.

Denis

-- 
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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/a687fa37b33e4ecb89529cc9bc105ce8%40unibe.ch.


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

end of thread, other threads:[~2021-06-17 12:23 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-24 13:47 Markdown Fenced Div to LaTeX Environment Chris Diaz
     [not found] ` <8ba84992-d792-4333-aae0-560147ef79d4n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2021-01-24 14:32   ` Albert Krewinkel
     [not found]     ` <87pn1uwglb.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2021-01-24 17:35       ` Bastien DUMONT
2021-06-16 14:37       ` Fenced Div to ConTeXt Environment (was: Markdown Fenced Div to LaTeX Environment) 'juh' via pandoc-discuss
2021-06-16 15:48         ` AW: " denis.maier-NSENcxR/0n0
     [not found]           ` <5db56b4f1d8d4ca2bec612bcebb7a525-NSENcxR/0n0@public.gmane.org>
2021-06-16 21:59             ` Bastien DUMONT
2021-06-17  6:27               ` 'juh' via pandoc-discuss
     [not found]                 ` <493d0aa9-47f5-ca8d-2ef5-8e63f965c529-cl+VPiYnx/1AfugRpC6u6w@public.gmane.org>
2021-06-17  6:54                   ` BPJ
     [not found]                     ` <CADAJKhDmtv1iLv8GsKzjxSzmvHzuOfpP6qrc21TUEYturw_xTQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2021-06-17  7:55                       ` 'juh' via pandoc-discuss
     [not found]                         ` <dc8ef20b-4a8b-c385-704c-28c85a5b6820-cl+VPiYnx/1AfugRpC6u6w@public.gmane.org>
2021-06-17  8:12                           ` AW: " denis.maier-NSENcxR/0n0
     [not found]                             ` <4396a9133ab74e4fbff486f09e22d254-NSENcxR/0n0@public.gmane.org>
2021-06-17  8:36                               ` Bastien DUMONT
2021-06-17  8:51                                 ` AW: " denis.maier-NSENcxR/0n0
2021-06-17 10:20                                 ` 'juh' via pandoc-discuss
     [not found]                                   ` <af60ed15-0d8c-5c51-5a34-a9c082e7fc89-cl+VPiYnx/1AfugRpC6u6w@public.gmane.org>
2021-06-17 11:44                                     ` Bastien DUMONT
2021-06-17 12:23                                     ` AW: " denis.maier-NSENcxR/0n0
2021-06-17  8:18                           ` Bastien DUMONT
2021-01-24 17:58   ` Markdown Fenced Div to LaTeX Environment John MacFarlane
     [not found]     ` <m2lfcigqtj.fsf-jF64zX8BO08an7k8zZ43ob9bIa4KchGshsV+eolpW18@public.gmane.org>
2021-01-24 19:50       ` Chris Diaz
     [not found]         ` <CAMkDs=NHev6VHpGEq6qiYGbOMgMr6RqKzu0E9dcsr1kZFXO-Ow-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2021-01-28  3:17           ` Bernie Roesler
     [not found]             ` <e6363602-852a-45a1-a199-81553da1966bn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2021-01-28 17:10               ` John MacFarlane
     [not found]                 ` <m2ft2l7zrz.fsf-jF64zX8BO08an7k8zZ43ob9bIa4KchGshsV+eolpW18@public.gmane.org>
2021-01-28 19:24                   ` Bernie Roesler
     [not found]                     ` <0F730DD9-8029-462F-A65E-AD3E618118E4-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2021-01-28 19:52                       ` Bernie Roesler

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