From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/30655 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Schroeder Newsgroups: gmane.text.pandoc Subject: Re: How to make my latex environment accessible from markdown via short-code? Date: Thu, 2 Jun 2022 01:32:47 -0700 (PDT) Message-ID: <39724faa-16cb-403e-b366-3787bb6d89ben@googlegroups.com> References: <4de0a599-a196-438a-928c-b0895b35afb6n@googlegroups.com> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_512_2120047506.1654158767802" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32086"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBCMMVPMN5MPRBMHL4GKAMGQEKFMRHWQ-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Thu Jun 02 10:32:52 2022 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-oi1-f187.google.com ([209.85.167.187]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nwgGC-0008AM-3T for gtp-pandoc-discuss@m.gmane-mx.org; Thu, 02 Jun 2022 10:32:52 +0200 Original-Received: by mail-oi1-f187.google.com with SMTP id m4-20020aca3f04000000b0032bd8d07161sf1891090oia.13 for ; Thu, 02 Jun 2022 01:32:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=sender:date:from:to:message-id:in-reply-to:references:subject :mime-version:x-original-sender:reply-to:precedence:mailing-list :list-id:list-post:list-help:list-archive:list-subscribe :list-unsubscribe; bh=XvcxgwW/CXJoUsRFPnP1JOAjPIgYc3GM5ZNKce5z2A8=; b=B8OcQ0qIkGCTbQEygpyC9W9rER6MJbfnhQg2o6W6De+ynkSWHPzm7HaoUx0GelYXF1 G/Ilv2IXZ7zWk2YRJcDorHLiPsDVi0zyXWluhh28P12txXvN5A0jm3/NGV5wHMghD8ID tvvSJYXxBgIJKunwVQq6PGB08WLpzbIWRDbCY4l33YZs/r/1AWdSeWg2qn8oIBhAC4kf CHKScpFBiginphU4P9gMrR8BAy2H1CC1uPIRa0IMDUt5isFVafG4BmyW2wuDeQbvlpUk qh5/BqEP6njLTBRUMxvv6rAIyPbgjujaZRLxlNfz2Wur8oyyf5zbZo7Nk6Cn+lIxg4Oq PrDw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:message-id:in-reply-to:references:subject:mime-version :x-original-sender:reply-to:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-subscribe:list-unsubscribe; bh=XvcxgwW/CXJoUsRFPnP1JOAjPIgYc3GM5ZNKce5z2A8=; b=bQob5SZABgy7R4/VruTttLrO5Sop0vixI+Ts9lZ0CibNFRy/YlMlSp7nQ/0YIrPTp/ tc/F98Tak6DBxbSilJB2OhNz6yrOYnoM/F6mT+4hYf+K9EiV2dCpCTDZZWg2LotE8p27 ZVoyp01TBAsWHw93xYLwgQ7IrWcEK4FDQcXewpId0R2Amhk5nbMb/8LT+jzn30W/lMF5 ZTzCHJ/k4H1FoQ8E7q/rMnuB7NrgbavNZxoyPpOwO7aC08bScCytPZWNCbHciMywQFGn Riph0YpL8UQ+0KfTBjNozTICD8WdykCDVS5L05b+fvX3A2TWLlMuZyCFdCsVkHUUkF3J NJGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=sender:x-gm-message-state:date:from:to:message-id:in-reply-to :references:subject:mime-version:x-original-sender:reply-to :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post :list-help:list-archive:list-subscribe:list-unsubscribe; bh=XvcxgwW/CXJoUsRFPnP1JOAjPIgYc3GM5ZNKce5z2A8=; b=wlWhZGRuilpeJ/FzzdY+XuwU3qPNwHTPesK64EWkoJFZZaT3oDanMoTJEBJ1KaE6/6 Qg18tZS/sMkGfe/cZnNstAzGj3LaayNUuT0hkCOHEv01dOAm59SY2B/AgFPZitwRPRgx N7tM0ExJ1wSpLddYIkclkCzTMR9ygKWoSBJs60/wb+6XBDmEvDcwu/P/PgOoWnW1s92V UCTOkI4PhJbZEJrVBKdh0vvFLIqT/Z8gIWGJZTb795eriLkDC/M4QJN2ZLw0P2UymcdY fF84eZQZ6OKuzNw9HQ18lhzGrwW8ElkP2AKZzzjX6hhioiD+xkvJA1dh3H3nbs+Zve9t OYWQ== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AOAM532x72jNBxBmYQaaKTBPOqDCcwg+GlSNJCT4CTrM+fgnvwJlG9pv IikHTC4evJUzcYOPKZSgsJk= X-Google-Smtp-Source: ABdhPJxyYD6mxbXm93OfmaZ0YsGcDkGEnv31EXR95Tt/5qK8uupao3PRrWw1BFZqHxt+gcKDdXbK8Q== X-Received: by 2002:a05:6808:23d3:b0:32c:4460:b19e with SMTP id bq19-20020a05680823d300b0032c4460b19emr7758752oib.100.1654158770972; Thu, 02 Jun 2022 01:32:50 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a05:6808:16a9:b0:32e:4091:d608 with SMTP id bb41-20020a05680816a900b0032e4091d608ls154380oib.4.gmail; Thu, 02 Jun 2022 01:32:48 -0700 (PDT) X-Received: by 2002:a05:6808:14c7:b0:32b:7ca0:292c with SMTP id f7-20020a05680814c700b0032b7ca0292cmr1967661oiw.203.1654158768345; Thu, 02 Jun 2022 01:32:48 -0700 (PDT) In-Reply-To: X-Original-Sender: ondekoza-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Precedence: list Mailing-list: list pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org; contact pandoc-discuss+owners-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org List-ID: X-Google-Group-Id: 1007024079513 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Xref: news.gmane.io gmane.text.pandoc:30655 Archived-At: ------=_Part_512_2120047506.1654158767802 Content-Type: multipart/alternative; boundary="----=_Part_513_1864308320.1654158767802" ------=_Part_513_1864308320.1654158767802 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Whoa! That was quick. Thanks, Denis. I'll try it out and post my result=20 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: > > =20 > > ::: hint > > Whatever > > ::: > > =20 > > Now, you can use a filter like the one below (posted by BPJ at some point= ). > > =20 > > This will check each div whether it has one of the classes defined in=20 > ENV_CLASSES. If yes, it will insert an appropriate raw block. > > =20 > > ```lua > > ENV_CLASSES =3D { 'intro', 'question', 'solution', 'hint', 'definition',= =20 > 'whatever'} > > =20 > > local function latex(s) > > return pandoc.RawBlock('latex', s) > > end > > =20 > > local function get_env_class(elem) > > if elem.classes then > > for i =3D 1, #elem.classes do > > for j =3D 1, #ENV_CLASSES do > > if elem.classes[i] =3D=3D 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 > > =20 > > function Div(el) > > local env_class =3D 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{'..=20 > env_class..'}') } > > end > > end > > =20 > > function Span(el) > > if el.classes[1] =3D=3D 'speaker' then > > return pandoc.RawInline('latex',=20 > '\\speaker{'..el.content..'}') > > end > > end > > ``` > > =20 > > =20 > > *Von:* pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org *Im=20 > Auftrag von *Stefan Schroeder > *Gesendet:* Donnerstag, 2. Juni 2022 10:18 > *An:* pandoc-discuss > *Betreff:* How to make my latex environment accessible from markdown via= =20 > short-code? > > =20 > > 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=20 > like a call-out. > > =20 > > This works: > > --- > > ```{=3Dlatex} > \begin{hint} > ``` > Lorem ipsum dolor sit amet,=20 > ```{=3Dlatex} > \end{hint} > ``` > > --- > > The Lorem text appears in the callout-environment. > > =20 > > I want to make the environment accessible more conveniently via a=20 > short-code. > > =20 > > I have created a new lua-filter, 'hint.lua' that I successfully include: > > return { > { > Str =3D function (elem) > if elem.text =3D=3D "{{hint_end}}" then > return pandoc.Str("```{=3Dlatex}\n\\end{guidehint}\n```\n") > elseif elem.text =3D=3D "{{hint_begin}}" then > return pandoc.Str "```{=3Dlatex}\\begin{guidehint}```" > else > return elem > end > end, > } > } > > =20 > > But when I use it, the macro-text will be included literally: > > =20 > > {{hint_begin}} > Neque porro quisquam est,=20 > {{hint_end}} > > =20 > > The code is not interpreted to end up being proper Latex, but it's escape= d=20 > somehow to become a string literal.=20 > > Thus my output looks like this: > > =20 > > =E2=80=9C=E2=80=98{=3Dlatex}\begin{hint}=E2=80=9C=E2=80=98 Neque porro qu= isquam est, qui dolorem ipsum, quia=20 > dolor sit, amet, consectetur, > adipisci velit =E2=80=9C=E2=80=98{=3Dlatex} \end{hint} =E2=80=9C=E2=80=98 > > =20 > > How do I make the short-code to get access to my own environments? > > =20 > > PS. If there are different apporaches, that'll be nice as well. > > =20 > > Thanks > > Stefan > > =20 > > --=20 > You received this message because you are subscribed to the Google Groups= =20 > "pandoc-discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an= =20 > email to pandoc-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit=20 > https://groups.google.com/d/msgid/pandoc-discuss/4de0a599-a196-438a-928c-= b0895b35afb6n%40googlegroups.com=20 > > . > --=20 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 e= mail 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. ------=_Part_513_1864308320.1654158767802 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Whoa! That was quick. Thanks, Denis. I'll try it out and post my result her= e.

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

Just use divs for that:

=C2=A0

::: hint

Whatever

:::

=C2=A0

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

=C2=A0

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.

=C2=A0

```lua

ENV_CLASSES =3D { 'intro= 9;, 'question', 'solution', 'hint', 'definition= ', 'whatever'}

=C2=A0

local function latex(s)<= u>

=C2=A0 return pandoc.RawBlock(&= #39;latex', s)

end

=C2=A0

local function get_env_class(el= em)

if elem.classes then

=C2=A0 for i =3D 1, #elem.classes do=

=C2=A0=C2=A0=C2=A0 for j =3D 1, #ENV_CLASSES do

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 = if elem.classes[i] =3D=3D ENV_CLASSES[j] then return ENV_CLASSES[j] end<= /u>

=C2=A0 end=

end

else

=C2=A0 error('function has_= class used on an element of type ' ..

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0 elem.t .. ' that cannot have classes.') end end=

=C2=A0

function Div(el)<= /span>

=C2=A0 local env_class =3D get_= env_class(el) -- nil if there is none

=C2=A0 if env_class then -- fal= se if env_class is nil

=C2=A0=C2=A0=C2=A0 return { lat= ex('\\begin{'.. env_class..'}'), el, latex('\\end{'= .. env_class..'}') }

=C2=A0 end=

end

=C2=A0

function Span(el)=

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if el.classes[= 1] =3D=3D 'speaker' then

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= return pandoc.RawInline('latex', '\\speaker{'..el.content.= .'}')

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 end<= /u>

end

```

=C2=A0

=C2=A0

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

=C2=A0

I am converting markdown to pdf via latex using my o= wn template.

In the template I have defined a new environment cal= led 'hint' that is like a call-out.

=C2=A0

This works:

---

```{=3Dlatex}
\begin{hint}
```
Lorem ipsum dolor sit amet,
```{=3Dlatex}
\end{hint}
```

---

The Lorem text appears in the callout-environment.

=C2=A0

I want to make the environment accessible more conve= niently via a short-code.

=C2=A0

I have created a new lua-filter, 'hint.lua' = that I successfully include:

return {
=C2=A0 {
=C2=A0 =C2=A0 Str =3D function (elem)
=C2=A0 =C2=A0 =C2=A0 if elem.text =3D=3D "{{hint_end}}" then
=C2=A0 =C2=A0 =C2=A0 =C2=A0 return pandoc.Str("```{=3Dlatex}\n\\end{gu= idehint}\n```\n")
=C2=A0 =C2=A0 =C2=A0 elseif elem.text =3D=3D "{{hint_begin}}" the= n
=C2=A0 =C2=A0 =C2=A0 =C2=A0 return pandoc.Str "```{=3Dlatex}\\begin{gu= idehint}```"
=C2=A0 =C2=A0 =C2=A0 else
=C2=A0 =C2=A0 =C2=A0 =C2=A0 return elem
=C2=A0 =C2=A0 =C2=A0 end
=C2=A0 =C2=A0 end,
=C2=A0 }
}

=C2=A0

But when I use it, the macro-text will be included l= iterally:

=C2=A0

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

=C2=A0

The code is not interpreted to end up being proper L= atex, but it's escaped somehow to become a string literal.

Thus my output looks like this:

=C2=A0

=E2=80=9C=E2=80=98{=3Dlatex}\begin{hint}=E2=80=9C=E2= =80=98 Neque porro quisquam est, qui dolorem ipsum, quia dolor sit, amet, c= onsectetur,
adipisci velit =E2=80=9C=E2=80=98{=3Dlatex} \end{hint} =E2=80=9C=E2=80=98

=C2=A0

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

=C2=A0

PS. If there are different apporaches, that'll b= e nice as well.

=C2=A0

Thanks

Stefan

=C2=A0

--
You received this message because you are subscribed to the Google Groups &= quot;pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an e= mail to pandoc-discus...-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.org= m.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/4de0a599-a196-438a-928c-b0= 895b35afb6n%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups &= quot;pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an e= mail to pand= oc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@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.
------=_Part_513_1864308320.1654158767802-- ------=_Part_512_2120047506.1654158767802--