public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* How to make my latex environment accessible from markdown via short-code?
@ 2022-06-02  8:17 ` Stefan Schroeder
       [not found]   ` <4de0a599-a196-438a-928c-b0895b35afb6n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: Stefan Schroeder @ 2022-06-02  8:17 UTC (permalink / raw)
  To: pandoc-discuss


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

I am converting markdown to pdf via latex using my own template.
In the template I have defined a new environment called 'hint' that is like 
a call-out.

This works:
---
```{=latex}
\begin{hint}
```
Lorem ipsum dolor sit amet, 
```{=latex}
\end{hint}
```
---
The Lorem text appears in the callout-environment.

I want to make the environment accessible more conveniently via a 
short-code.

I have created a new lua-filter, 'hint.lua' that I successfully include:
return {
  {
    Str = function (elem)
      if elem.text == "{{hint_end}}" then
        return pandoc.Str("```{=latex}\n\\end{guidehint}\n```\n")
      elseif elem.text == "{{hint_begin}}" then
        return pandoc.Str "```{=latex}\\begin{guidehint}```"
      else
        return elem
      end
    end,
  }
}

But when I use it, the macro-text will be included literally:

{{hint_begin}}
Neque porro quisquam est, 
{{hint_end}}

The code is not interpreted to end up being proper Latex, but it's escaped 
somehow to become a string literal. 
Thus my output looks like this:

“‘{=latex}\begin{hint}“‘ Neque porro quisquam est, qui dolorem ipsum, quia 
dolor sit, amet, consectetur,
adipisci velit “‘{=latex} \end{hint} “‘

How do I make the short-code to get access to my own environments?

PS. If there are different apporaches, that'll be nice as well.

Thanks
Stefan

-- 
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/4de0a599-a196-438a-928c-b0895b35afb6n%40googlegroups.com.

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

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

* AW: How to make my latex environment accessible from markdown via short-code?
       [not found]   ` <4de0a599-a196-438a-928c-b0895b35afb6n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2022-06-02  8:28     ` denis.maier-NSENcxR/0n0
       [not found]       ` <cc1c350768424985bb0f5c9380386904-NSENcxR/0n0@public.gmane.org>
  2022-06-02  8:33     ` Bastien DUMONT
  1 sibling, 1 reply; 8+ messages in thread
From: denis.maier-NSENcxR/0n0 @ 2022-06-02  8:28 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

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

Just use divs for that:

::: hint
Whatever
:::

Now, you can use a filter like the one below (posted by BPJ at some point).

This will check each div whether it has one of the classes defined in ENV_CLASSES. If yes, it will insert an appropriate raw block.

```lua
ENV_CLASSES = { 'intro', 'question', 'solution', 'hint', 'definition', 'whatever'}

local function latex(s)
  return pandoc.RawBlock('latex', 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 { latex('\\begin{'.. env_class..'}'), el, latex('\\end{'.. env_class..'}') }
  end
end

function Span(el)
                if el.classes[1] == 'speaker' then
                               return pandoc.RawInline('latex', '\\speaker{'..el.content..'}')
                end
end
```


Von: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> Im Auftrag von Stefan Schroeder
Gesendet: Donnerstag, 2. Juni 2022 10:18
An: pandoc-discuss <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
Betreff: How to make my latex environment accessible from markdown via short-code?

I am converting markdown to pdf via latex using my own template.
In the template I have defined a new environment called 'hint' that is like a call-out.

This works:
---
```{=latex}
\begin{hint}
```
Lorem ipsum dolor sit amet,
```{=latex}
\end{hint}
```
---
The Lorem text appears in the callout-environment.

I want to make the environment accessible more conveniently via a short-code.

I have created a new lua-filter, 'hint.lua' that I successfully include:
return {
  {
    Str = function (elem)
      if elem.text == "{{hint_end}}" then
        return pandoc.Str("```{=latex}\n\\end{guidehint}\n```\n")
      elseif elem.text == "{{hint_begin}}" then
        return pandoc.Str "```{=latex}\\begin{guidehint}```"
      else
        return elem
      end
    end,
  }
}

But when I use it, the macro-text will be included literally:

{{hint_begin}}
Neque porro quisquam est,
{{hint_end}}

The code is not interpreted to end up being proper Latex, but it's escaped somehow to become a string literal.
Thus my output looks like this:

“‘{=latex}\begin{hint}“‘ Neque porro quisquam est, qui dolorem ipsum, quia dolor sit, amet, consectetur,
adipisci velit “‘{=latex} \end{hint} “‘

How do I make the short-code to get access to my own environments?

PS. If there are different apporaches, that'll be nice as well.

Thanks
Stefan

--
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/4de0a599-a196-438a-928c-b0895b35afb6n%40googlegroups.com<https://groups.google.com/d/msgid/pandoc-discuss/4de0a599-a196-438a-928c-b0895b35afb6n%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
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/cc1c350768424985bb0f5c9380386904%40unibe.ch.

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

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

* Re: How to make my latex environment accessible from markdown via short-code?
       [not found]       ` <cc1c350768424985bb0f5c9380386904-NSENcxR/0n0@public.gmane.org>
@ 2022-06-02  8:32         ` Stefan Schroeder
  0 siblings, 0 replies; 8+ messages in thread
From: Stefan Schroeder @ 2022-06-02  8:32 UTC (permalink / raw)
  To: pandoc-discuss


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

Whoa! That was quick. Thanks, Denis. I'll try it out and post my result 
here.

On Thursday, June 2, 2022 at 10:28:53 AM UTC+2 denis...-NSENcxR/0n0@public.gmane.org wrote:

> Just use divs for that:
>
>  
>
> ::: hint
>
> Whatever
>
> :::
>
>  
>
> Now, you can use a filter like the one below (posted by BPJ at some point).
>
>  
>
> This will check each div whether it has one of the classes defined in 
> ENV_CLASSES. If yes, it will insert an appropriate raw block.
>
>  
>
> ```lua
>
> ENV_CLASSES = { 'intro', 'question', 'solution', 'hint', 'definition', 
> 'whatever'}
>
>  
>
> local function latex(s)
>
>   return pandoc.RawBlock('latex', 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 { latex('\\begin{'.. env_class..'}'), el, latex('\\end{'.. 
> env_class..'}') }
>
>   end
>
> end
>
>  
>
> function Span(el)
>
>                 if el.classes[1] == 'speaker' then
>
>                                return pandoc.RawInline('latex', 
> '\\speaker{'..el.content..'}')
>
>                 end
>
> end
>
> ```
>
>  
>
>  
>
> *Von:* pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> *Im 
> Auftrag von *Stefan Schroeder
> *Gesendet:* Donnerstag, 2. Juni 2022 10:18
> *An:* pandoc-discuss <pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
> *Betreff:* How to make my latex environment accessible from markdown via 
> short-code?
>
>  
>
> I am converting markdown to pdf via latex using my own template.
>
> In the template I have defined a new environment called 'hint' that is 
> like a call-out.
>
>  
>
> This works:
>
> ---
>
> ```{=latex}
> \begin{hint}
> ```
> Lorem ipsum dolor sit amet, 
> ```{=latex}
> \end{hint}
> ```
>
> ---
>
> The Lorem text appears in the callout-environment.
>
>  
>
> I want to make the environment accessible more conveniently via a 
> short-code.
>
>  
>
> I have created a new lua-filter, 'hint.lua' that I successfully include:
>
> return {
>   {
>     Str = function (elem)
>       if elem.text == "{{hint_end}}" then
>         return pandoc.Str("```{=latex}\n\\end{guidehint}\n```\n")
>       elseif elem.text == "{{hint_begin}}" then
>         return pandoc.Str "```{=latex}\\begin{guidehint}```"
>       else
>         return elem
>       end
>     end,
>   }
> }
>
>  
>
> But when I use it, the macro-text will be included literally:
>
>  
>
> {{hint_begin}}
> Neque porro quisquam est, 
> {{hint_end}}
>
>  
>
> The code is not interpreted to end up being proper Latex, but it's escaped 
> somehow to become a string literal. 
>
> Thus my output looks like this:
>
>  
>
> “‘{=latex}\begin{hint}“‘ Neque porro quisquam est, qui dolorem ipsum, quia 
> dolor sit, amet, consectetur,
> adipisci velit “‘{=latex} \end{hint} “‘
>
>  
>
> How do I make the short-code to get access to my own environments?
>
>  
>
> PS. If there are different apporaches, that'll be nice as well.
>
>  
>
> Thanks
>
> Stefan
>
>  
>
> -- 
> 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/4de0a599-a196-438a-928c-b0895b35afb6n%40googlegroups.com 
> <https://groups.google.com/d/msgid/pandoc-discuss/4de0a599-a196-438a-928c-b0895b35afb6n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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/39724faa-16cb-403e-b366-3787bb6d89ben%40googlegroups.com.

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

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

* Re: How to make my latex environment accessible from markdown via short-code?
       [not found]   ` <4de0a599-a196-438a-928c-b0895b35afb6n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  2022-06-02  8:28     ` AW: " denis.maier-NSENcxR/0n0
@ 2022-06-02  8:33     ` Bastien DUMONT
  2022-06-02  8:35       ` AW: " denis.maier-NSENcxR/0n0
  2022-06-02  8:46       ` Stefan Schroeder
  1 sibling, 2 replies; 8+ messages in thread
From: Bastien DUMONT @ 2022-06-02  8:33 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

To complement Denis' answer, your Markdown chunks in "hint.lua" are handled like strings because you created them as Str objects. What you want is to return a CodeBlock (https://pandoc.org/lua-filters.html#pandoc.codeblock), e.g. `pandoc.CodeBlock("latex", "\\begin{guidehint}")`.

More generally, Pandoc has already parsed the input file when it applies filters. Filters manipulate objects in the internal representation of the document and should return such objects. In exceptional cases where you really need to parse a Markdown string inside a filter, use pandoc.read.

Le Thursday 02 June 2022 à 01:17:44AM, Stefan Schroeder a écrit :
> I am converting markdown to pdf via latex using my own template.
> In the template I have defined a new environment called 'hint' that is like a
> call-out.
> 
> This works:
> ---
> ```{=latex}
> \begin{hint}
> ```
> Lorem ipsum dolor sit amet,
> ```{=latex}
> \end{hint}
> ```
> ---
> The Lorem text appears in the callout-environment.
> 
> I want to make the environment accessible more conveniently via a short-code.
> 
> I have created a new lua-filter, 'hint.lua' that I successfully include:
> return {
>   {
>     Str = function (elem)
>       if elem.text == "{{hint_end}}" then
>         return pandoc.Str("```{=latex}\n\\end{guidehint}\n```\n")
>       elseif elem.text == "{{hint_begin}}" then
>         return pandoc.Str "```{=latex}\\begin{guidehint}```"
>       else
>         return elem
>       end
>     end,
>   }
> }
> 
> But when I use it, the macro-text will be included literally:
> 
> {{hint_begin}}
> Neque porro quisquam est,
> {{hint_end}}
> 
> The code is not interpreted to end up being proper Latex, but it's escaped
> somehow to become a string literal.
> Thus my output looks like this:
> 
> “‘{=latex}\begin{hint}“‘ Neque porro quisquam est, qui dolorem ipsum, quia
> dolor sit, amet, consectetur,
> adipisci velit “‘{=latex} \end{hint} “‘
> 
> How do I make the short-code to get access to my own environments?
> 
> PS. If there are different apporaches, that'll be nice as well.
> 
> Thanks
> Stefan
> 
> 
> --
> 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 [1]pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To view this discussion on the web visit [2]https://groups.google.com/d/msgid/
> pandoc-discuss/4de0a599-a196-438a-928c-b0895b35afb6n%40googlegroups.com.
> 
> References:
> 
> [1] mailto:pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> [2] https://groups.google.com/d/msgid/pandoc-discuss/4de0a599-a196-438a-928c-b0895b35afb6n%40googlegroups.com?utm_medium=email&utm_source=footer

-- 
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/Yph14Uv3BuicNJi9%40localhost.


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

* AW: How to make my latex environment accessible from markdown via short-code?
  2022-06-02  8:33     ` Bastien DUMONT
@ 2022-06-02  8:35       ` denis.maier-NSENcxR/0n0
       [not found]         ` <2acb8d6c2b3f4042a0e940cbda7899e4-NSENcxR/0n0@public.gmane.org>
  2022-06-02  8:46       ` Stefan Schroeder
  1 sibling, 1 reply; 8+ messages in thread
From: denis.maier-NSENcxR/0n0 @ 2022-06-02  8:35 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

Or, maybe even a RawBlock? Like in that function:
local function latex(s)
  return pandoc.RawBlock('latex', s)
end


> -----Ursprüngliche Nachricht-----
> Von: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <pandoc-
> discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> Im Auftrag von Bastien DUMONT
> Gesendet: Donnerstag, 2. Juni 2022 10:34
> An: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> Betreff: Re: How to make my latex environment accessible from markdown
> via short-code?
> 
> To complement Denis' answer, your Markdown chunks in "hint.lua" are
> handled like strings because you created them as Str objects. What you want
> is to return a CodeBlock (https://pandoc.org/lua-
> filters.html#pandoc.codeblock), e.g. `pandoc.CodeBlock("latex",
> "\\begin{guidehint}")`.
> 
> More generally, Pandoc has already parsed the input file when it applies
> filters. Filters manipulate objects in the internal representation of the
> document and should return such objects. In exceptional cases where you
> really need to parse a Markdown string inside a filter, use pandoc.read.
> 
> Le Thursday 02 June 2022 à 01:17:44AM, Stefan Schroeder a écrit :
> > I am converting markdown to pdf via latex using my own template.
> > In the template I have defined a new environment called 'hint' that is
> > like a call-out.
> >
> > This works:
> > ---
> > ```{=latex}
> > \begin{hint}
> > ```
> > Lorem ipsum dolor sit amet,
> > ```{=latex}
> > \end{hint}
> > ```
> > ---
> > The Lorem text appears in the callout-environment.
> >
> > I want to make the environment accessible more conveniently via a short-
> code.
> >
> > I have created a new lua-filter, 'hint.lua' that I successfully include:
> > return {
> >   {
> >     Str = function (elem)
> >       if elem.text == "{{hint_end}}" then
> >         return pandoc.Str("```{=latex}\n\\end{guidehint}\n```\n")
> >       elseif elem.text == "{{hint_begin}}" then
> >         return pandoc.Str "```{=latex}\\begin{guidehint}```"
> >       else
> >         return elem
> >       end
> >     end,
> >   }
> > }
> >
> > But when I use it, the macro-text will be included literally:
> >
> > {{hint_begin}}
> > Neque porro quisquam est,
> > {{hint_end}}
> >
> > The code is not interpreted to end up being proper Latex, but it's
> > escaped somehow to become a string literal.
> > Thus my output looks like this:
> >
> > “‘{=latex}\begin{hint}“‘ Neque porro quisquam est, qui dolorem ipsum,
> > quia dolor sit, amet, consectetur, adipisci velit “‘{=latex}
> > \end{hint} “‘
> >
> > How do I make the short-code to get access to my own environments?
> >
> > PS. If there are different apporaches, that'll be nice as well.
> >
> > Thanks
> > Stefan
> >
> >
> > --
> > 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 [1]pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> > To view this discussion on the web visit
> > [2]https://groups.google.com/d/msgid/
> > pandoc-discuss/4de0a599-a196-438a-928c-
> b0895b35afb6n%40googlegroups.com.
> >
> > References:
> >
> > [1] mailto:pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> > [2]
> > https://groups.google.com/d/msgid/pandoc-discuss/4de0a599-a196-
> 438a-92
> > 8c-
> b0895b35afb6n%40googlegroups.com?utm_medium=email&utm_source=fo
> oter
> 
> --
> 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/Yph14Uv3BuicNJi9%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/2acb8d6c2b3f4042a0e940cbda7899e4%40unibe.ch.


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

* Re: AW: How to make my latex environment accessible from markdown via short-code?
       [not found]         ` <2acb8d6c2b3f4042a0e940cbda7899e4-NSENcxR/0n0@public.gmane.org>
@ 2022-06-02  8:44           ` Bastien DUMONT
  2022-06-02  8:47             ` Stefan Schroeder
  0 siblings, 1 reply; 8+ messages in thread
From: Bastien DUMONT @ 2022-06-02  8:44 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

Oh yes, you're right, sorry!

Le Thursday 02 June 2022 à 08:35:22AM, denis.maier-NSENcxR/0n0@public.gmane.org a écrit :
> Or, maybe even a RawBlock? Like in that function:
> local function latex(s)
>   return pandoc.RawBlock('latex', s)
> end
> 
> 
> > -----Ursprüngliche Nachricht-----
> > Von: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <pandoc-
> > discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> Im Auftrag von Bastien DUMONT
> > Gesendet: Donnerstag, 2. Juni 2022 10:34
> > An: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> > Betreff: Re: How to make my latex environment accessible from markdown
> > via short-code?
> > 
> > To complement Denis' answer, your Markdown chunks in "hint.lua" are
> > handled like strings because you created them as Str objects. What you want
> > is to return a CodeBlock (https://pandoc.org/lua-
> > filters.html#pandoc.codeblock), e.g. `pandoc.CodeBlock("latex",
> > "\\begin{guidehint}")`.
> > 
> > More generally, Pandoc has already parsed the input file when it applies
> > filters. Filters manipulate objects in the internal representation of the
> > document and should return such objects. In exceptional cases where you
> > really need to parse a Markdown string inside a filter, use pandoc.read.
> > 
> > Le Thursday 02 June 2022 à 01:17:44AM, Stefan Schroeder a écrit :
> > > I am converting markdown to pdf via latex using my own template.
> > > In the template I have defined a new environment called 'hint' that is
> > > like a call-out.
> > >
> > > This works:
> > > ---
> > > ```{=latex}
> > > \begin{hint}
> > > ```
> > > Lorem ipsum dolor sit amet,
> > > ```{=latex}
> > > \end{hint}
> > > ```
> > > ---
> > > The Lorem text appears in the callout-environment.
> > >
> > > I want to make the environment accessible more conveniently via a short-
> > code.
> > >
> > > I have created a new lua-filter, 'hint.lua' that I successfully include:
> > > return {
> > >   {
> > >     Str = function (elem)
> > >       if elem.text == "{{hint_end}}" then
> > >         return pandoc.Str("```{=latex}\n\\end{guidehint}\n```\n")
> > >       elseif elem.text == "{{hint_begin}}" then
> > >         return pandoc.Str "```{=latex}\\begin{guidehint}```"
> > >       else
> > >         return elem
> > >       end
> > >     end,
> > >   }
> > > }
> > >
> > > But when I use it, the macro-text will be included literally:
> > >
> > > {{hint_begin}}
> > > Neque porro quisquam est,
> > > {{hint_end}}
> > >
> > > The code is not interpreted to end up being proper Latex, but it's
> > > escaped somehow to become a string literal.
> > > Thus my output looks like this:
> > >
> > > “‘{=latex}\begin{hint}“‘ Neque porro quisquam est, qui dolorem ipsum,
> > > quia dolor sit, amet, consectetur, adipisci velit “‘{=latex}
> > > \end{hint} “‘
> > >
> > > How do I make the short-code to get access to my own environments?
> > >
> > > PS. If there are different apporaches, that'll be nice as well.
> > >
> > > Thanks
> > > Stefan
> > >
> > >
> > > --
> > > 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 [1]pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> > > To view this discussion on the web visit
> > > [2]https://groups.google.com/d/msgid/
> > > pandoc-discuss/4de0a599-a196-438a-928c-
> > b0895b35afb6n%40googlegroups.com.
> > >
> > > References:
> > >
> > > [1] mailto:pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> > > [2]
> > > https://groups.google.com/d/msgid/pandoc-discuss/4de0a599-a196-
> > 438a-92
> > > 8c-
> > b0895b35afb6n%40googlegroups.com?utm_medium=email&utm_source=fo
> > oter
> > 
> > --
> > 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/Yph14Uv3BuicNJi9%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/2acb8d6c2b3f4042a0e940cbda7899e4%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/Yph4WGXl6CRlFjkC%40localhost.


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

* Re: How to make my latex environment accessible from markdown via short-code?
  2022-06-02  8:33     ` Bastien DUMONT
  2022-06-02  8:35       ` AW: " denis.maier-NSENcxR/0n0
@ 2022-06-02  8:46       ` Stefan Schroeder
  1 sibling, 0 replies; 8+ messages in thread
From: Stefan Schroeder @ 2022-06-02  8:46 UTC (permalink / raw)
  To: pandoc-discuss


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

Denis' suggestion works as advertised. Thanks. You made my day. ☘

On Thursday, June 2, 2022 at 10:33:42 AM UTC+2 Bastien Dumont wrote:

> To complement Denis' answer, your Markdown chunks in "hint.lua" are 
> handled like strings because you created them as Str objects. What you want 
> is to return a CodeBlock (
> https://pandoc.org/lua-filters.html#pandoc.codeblock), 
> e.g. `pandoc.CodeBlock("latex", "\\begin{guidehint}")`.
>
> More generally, Pandoc has already parsed the input file when it applies 
> filters. Filters manipulate objects in the internal representation of the 
> document and should return such objects. In exceptional cases where you 
> really need to parse a Markdown string inside a filter, use pandoc.read.
>
> Le Thursday 02 June 2022 à 01:17:44AM, Stefan Schroeder a écrit :
> > I am converting markdown to pdf via latex using my own template.
> > In the template I have defined a new environment called 'hint' that is 
> like a
> > call-out.
> > 
> > This works:
> > ---
> > ```{=latex}
> > \begin{hint}
> > ```
> > Lorem ipsum dolor sit amet,
> > ```{=latex}
> > \end{hint}
> > ```
> > ---
> > The Lorem text appears in the callout-environment.
> > 
> > I want to make the environment accessible more conveniently via a 
> short-code.
> > 
> > I have created a new lua-filter, 'hint.lua' that I successfully include:
> > return {
> > {
> > Str = function (elem)
> > if elem.text == "{{hint_end}}" then
> > return pandoc.Str("```{=latex}\n\\end{guidehint}\n```\n")
> > elseif elem.text == "{{hint_begin}}" then
> > return pandoc.Str "```{=latex}\\begin{guidehint}```"
> > else
> > return elem
> > end
> > end,
> > }
> > }
> > 
> > But when I use it, the macro-text will be included literally:
> > 
> > {{hint_begin}}
> > Neque porro quisquam est,
> > {{hint_end}}
> > 
> > The code is not interpreted to end up being proper Latex, but it's 
> escaped
> > somehow to become a string literal.
> > Thus my output looks like this:
> > 
> > “‘{=latex}\begin{hint}“‘ Neque porro quisquam est, qui dolorem ipsum, 
> quia
> > dolor sit, amet, consectetur,
> > adipisci velit “‘{=latex} \end{hint} “‘
> > 
> > How do I make the short-code to get access to my own environments?
> > 
> > PS. If there are different apporaches, that'll be nice as well.
> > 
> > Thanks
> > Stefan
> > 
> > 
> > --
> > 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 [1]pandoc-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> > To view this discussion on the web visit [2]
> https://groups.google.com/d/msgid/
> > pandoc-discuss/4de0a599-a196-438a-928c-b0895b35afb6n%40googlegroups.com.
> > 
> > References:
> > 
> > [1] mailto:pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> > [2] 
> https://groups.google.com/d/msgid/pandoc-discuss/4de0a599-a196-438a-928c-b0895b35afb6n%40googlegroups.com?utm_medium=email&utm_source=footer
>
>

-- 
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/2b75bae1-51bc-49fb-84d0-d52139d9a1e3n%40googlegroups.com.

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

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

* Re: AW: How to make my latex environment accessible from markdown via short-code?
  2022-06-02  8:44           ` Bastien DUMONT
@ 2022-06-02  8:47             ` Stefan Schroeder
  0 siblings, 0 replies; 8+ messages in thread
From: Stefan Schroeder @ 2022-06-02  8:47 UTC (permalink / raw)
  To: pandoc-discuss


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

Thank you for your suggestion as well, Bastien. I'll keep a note of what 
you said for reference.

On Thursday, June 2, 2022 at 10:44:14 AM UTC+2 Bastien Dumont wrote:

> Oh yes, you're right, sorry!
>
> Le Thursday 02 June 2022 à 08:35:22AM, denis...-NSENcxR/0n0@public.gmane.org a écrit :
> > Or, maybe even a RawBlock? Like in that function:
> > local function latex(s)
> > return pandoc.RawBlock('latex', s)
> > end
> > 
> > 
> > > -----Ursprüngliche Nachricht-----
> > > Von: pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <pandoc-
> > > dis...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> Im Auftrag von Bastien DUMONT
> > > Gesendet: Donnerstag, 2. Juni 2022 10:34
> > > An: pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> > > Betreff: Re: How to make my latex environment accessible from markdown
> > > via short-code?
> > > 
> > > To complement Denis' answer, your Markdown chunks in "hint.lua" are
> > > handled like strings because you created them as Str objects. What you 
> want
> > > is to return a CodeBlock (https://pandoc.org/lua-
> > > filters.html#pandoc.codeblock), e.g. `pandoc.CodeBlock("latex",
> > > "\\begin{guidehint}")`.
> > > 
> > > More generally, Pandoc has already parsed the input file when it 
> applies
> > > filters. Filters manipulate objects in the internal representation of 
> the
> > > document and should return such objects. In exceptional cases where you
> > > really need to parse a Markdown string inside a filter, use 
> pandoc.read.
> > > 
> > > Le Thursday 02 June 2022 à 01:17:44AM, Stefan Schroeder a écrit :
> > > > I am converting markdown to pdf via latex using my own template.
> > > > In the template I have defined a new environment called 'hint' that 
> is
> > > > like a call-out.
> > > >
> > > > This works:
> > > > ---
> > > > ```{=latex}
> > > > \begin{hint}
> > > > ```
> > > > Lorem ipsum dolor sit amet,
> > > > ```{=latex}
> > > > \end{hint}
> > > > ```
> > > > ---
> > > > The Lorem text appears in the callout-environment.
> > > >
> > > > I want to make the environment accessible more conveniently via a 
> short-
> > > code.
> > > >
> > > > I have created a new lua-filter, 'hint.lua' that I successfully 
> include:
> > > > return {
> > > > {
> > > > Str = function (elem)
> > > > if elem.text == "{{hint_end}}" then
> > > > return pandoc.Str("```{=latex}\n\\end{guidehint}\n```\n")
> > > > elseif elem.text == "{{hint_begin}}" then
> > > > return pandoc.Str "```{=latex}\\begin{guidehint}```"
> > > > else
> > > > return elem
> > > > end
> > > > end,
> > > > }
> > > > }
> > > >
> > > > But when I use it, the macro-text will be included literally:
> > > >
> > > > {{hint_begin}}
> > > > Neque porro quisquam est,
> > > > {{hint_end}}
> > > >
> > > > The code is not interpreted to end up being proper Latex, but it's
> > > > escaped somehow to become a string literal.
> > > > Thus my output looks like this:
> > > >
> > > > “‘{=latex}\begin{hint}“‘ Neque porro quisquam est, qui dolorem ipsum,
> > > > quia dolor sit, amet, consectetur, adipisci velit “‘{=latex}
> > > > \end{hint} “‘
> > > >
> > > > How do I make the short-code to get access to my own environments?
> > > >
> > > > PS. If there are different apporaches, that'll be nice as well.
> > > >
> > > > Thanks
> > > > Stefan
> > > >
> > > >
> > > > --
> > > > 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 [1]pandoc-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> > > > To view this discussion on the web visit
> > > > [2]https://groups.google.com/d/msgid/
> > > > pandoc-discuss/4de0a599-a196-438a-928c-
> > > b0895b35afb6n%40googlegroups.com.
> > > >
> > > > References:
> > > >
> > > > [1] mailto:pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> > > > [2]
> > > > https://groups.google.com/d/msgid/pandoc-discuss/4de0a599-a196-
> > > 438a-92
> > > > 8c-
> > > b0895b35afb6n%40googlegroups.com?utm_medium=email&utm_source=fo
> > > oter
> > > 
> > > --
> > > 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/Yph14Uv3BuicNJi9%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-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/pandoc-discuss/2acb8d6c2b3f4042a0e940cbda7899e4%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/00769f1a-ee10-4fc2-bb22-9cb1ac351450n%40googlegroups.com.

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

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

end of thread, other threads:[~2022-06-02  8:47 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <AQHYdlk/OWfYV7I3oUynfv4PgxHqAa07x2og>
2022-06-02  8:17 ` How to make my latex environment accessible from markdown via short-code? Stefan Schroeder
     [not found]   ` <4de0a599-a196-438a-928c-b0895b35afb6n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2022-06-02  8:28     ` AW: " denis.maier-NSENcxR/0n0
     [not found]       ` <cc1c350768424985bb0f5c9380386904-NSENcxR/0n0@public.gmane.org>
2022-06-02  8:32         ` Stefan Schroeder
2022-06-02  8:33     ` Bastien DUMONT
2022-06-02  8:35       ` AW: " denis.maier-NSENcxR/0n0
     [not found]         ` <2acb8d6c2b3f4042a0e940cbda7899e4-NSENcxR/0n0@public.gmane.org>
2022-06-02  8:44           ` Bastien DUMONT
2022-06-02  8:47             ` Stefan Schroeder
2022-06-02  8:46       ` Stefan Schroeder

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