public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* itemization and a custom Lua writer to convert markdown to LaTeX
@ 2022-04-21  8:34 A A
       [not found] ` <80f61224-056c-4c70-9ab5-3ee40553d784n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: A A @ 2022-04-21  8:34 UTC (permalink / raw)
  To: pandoc-discuss


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



I am trying to make my own customized writer for LaTeX. In this writer, I’d 
like to be able to handle itemizations with nesting and write those 
properly to LaTeX’s itemize environment. Here’s what I have so far:
Writer file custom_writer.lua 

function Header(lev, s, attr)
    level_sequences = {
        "section",
        "subsection",
        "subsubsection",
        "subsubsubsection"
    }
    return string.format("\\%s{%s}", level_sequences[lev], s)
end

function Blocksep()
    return "\n\n"
end

function Para(s)
    return s.."\n\n"
end

function Str(s)
    return s
end

function Space()
    return " "
end

function BulletList(items)
    print("entering BulletList function")
    for i, item in pairs(items) do
        print(i, item)
    end
    return " "
end

function Plain(s)
    return s
end

function Doc(body, metadata, variables) 
    return body
end

Markdown file test.md 

# A section

## A subsection

- An item
    - A subitem
    - A subitem
- An item

Question 

Note the print statements in the BulletList function of my Lua file. To my 
surprise, when I compile using pandoc test.md -t custom_writer.lua -o 
test.tex I get the following output:

entering BulletList function
1    A subitem
2    A subitem
entering BulletList function
1    An item


2    An item
`

There are two things that strike me here:

   - The nested list appears to be processed first, before the outer list. 
   This seems counter-intuitive to me. I can’t think of an algorithm which 
   would result in the correct LaTeX nesting if it goes inner to outer. Why 
   does this occur? Can I get it so that it goes the other way round? 
   - Two blank lines are printed out between 1 An item and 2 An item. Where 
   do these come from? I haven’t specified them anywhere in my Lua file. 

​

-- 
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/80f61224-056c-4c70-9ab5-3ee40553d784n%40googlegroups.com.

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

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

* Re: itemization and a custom Lua writer to convert markdown to LaTeX
       [not found] ` <80f61224-056c-4c70-9ab5-3ee40553d784n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2022-04-21 16:17   ` Albert Krewinkel
       [not found]     ` <87wnfibdzg.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: Albert Krewinkel @ 2022-04-21 16:17 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

A A <amine.aboufirass-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:

> I am trying to make my own customized writer for LaTeX.
>
> [...]
>
> There are two things that strike me here:
>   * The nested list appears to be processed first, before the outer
>     list. This seems counter-intuitive to me. I can’t think of an
>     algorithm which would result in the correct LaTeX nesting if it
>     goes inner to outer. Why does this occur? Can I get it so that it
>     goes the other way round?

For an explanation and possible solution of what's happening here, see
https://groups.google.com/g/pandoc-discuss/c/y9jbpQJsU4w/m/HVWxoKNEAgAJ

>   * Two blank lines are printed out between 1 An item and 2 An item.
>     Where do these come from? I haven’t specified them anywhere in my
>     Lua file.

That's the result of the "BlockSep" function.

You might be able to save yourself some work by using a "new style"
writer as described here: https://pandoc.org/custom-writers#new-style
(requires pandoc 2.18).


-- 
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/87wnfibdzg.fsf%40zeitkraut.de.


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

* Re: itemization and a custom Lua writer to convert markdown to LaTeX
       [not found]     ` <87wnfibdzg.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
@ 2022-06-15 11:50       ` A A
       [not found]         ` <CAMwawgMgLab823rHva19HTcHRORNJ81JuLdnX9CkZGDG=cNkTA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: A A @ 2022-06-15 11:50 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

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

Dear Albert,

I had a look at the link you proposed and I’m experimenting with the code
you had provided back then. It seems to identify the nesting properly. I’m
working on adapting that so that it generates LaTeX itemize environments.
This may take me some time because I’m not too familiar with Lua, and the
code you had proposed uses some advanced language features such as
metatables and such.

With regards to BlockSep, I really don’t see where in the markdown file
this occurs. Here’s the native output generated by my test.md file:

pandoc test.md -t native
[ Header
    1
    ( "a-section" , [] , [] )
    [ Str "A" , Space , Str "section" ]
, Header
    2
    ( "a-subsection" , [] , [] )
    [ Str "A" , Space , Str "subsection" ]
, BulletList
    [ [ Plain [ Str "An" , Space , Str "item" ]
      , BulletList
          [ [ Plain [ Str "A" , Space , Str "subitem" ] ]
          , [ Plain [ Str "A" , Space , Str "subitem" ] ]
          ]
      ]
    , [ Plain [ Str "An" , Space , Str "item" ] ]
    , [ Plain [ Str "An" , Space , Str "item" ]
      , BulletList
          [ [ Plain [ Str "A" , Space , Str "subitem" ]
            , BulletList
                [ [ Plain [ Str "A" , Space , Str "subsubitem" ] ]
                , [ Plain [ Str "A" , Space , Str "subsubitem" ] ]
                ]
            ]
          , [ Plain [ Str "A" , Space , Str "subitem" ] ]
          ]
      ]
    ]
]

The BlockSep is nowhere to be seen, and yet it does seem to be part of the
AST and does have an impact on how my Lua writer translates the file to
LaTeX.

With regards to “new style” writers, I would very much appreciate having a
basic example of how it can deal with bulleted lists and why that is easier
than using the “old style” writer.

Regards,

Amine

On Thu, 21 Apr 2022 at 18:25, Albert Krewinkel <albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
wrote:

> A A <amine.aboufirass-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
>
> > I am trying to make my own customized writer for LaTeX.
> >
> > [...]
> >
> > There are two things that strike me here:
> >   * The nested list appears to be processed first, before the outer
> >     list. This seems counter-intuitive to me. I can’t think of an
> >     algorithm which would result in the correct LaTeX nesting if it
> >     goes inner to outer. Why does this occur? Can I get it so that it
> >     goes the other way round?
>
> For an explanation and possible solution of what's happening here, see
> https://groups.google.com/g/pandoc-discuss/c/y9jbpQJsU4w/m/HVWxoKNEAgAJ
>
> >   * Two blank lines are printed out between 1 An item and 2 An item.
> >     Where do these come from? I haven’t specified them anywhere in my
> >     Lua file.
>
> That's the result of the "BlockSep" function.
>
> You might be able to save yourself some work by using a "new style"
> writer as described here: https://pandoc.org/custom-writers#new-style
> (requires pandoc 2.18).
>
>
> --
> 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/87wnfibdzg.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/CAMwawgMgLab823rHva19HTcHRORNJ81JuLdnX9CkZGDG%3DcNkTA%40mail.gmail.com.

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

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

* Re: itemization and a custom Lua writer to convert markdown to LaTeX
       [not found]         ` <CAMwawgMgLab823rHva19HTcHRORNJ81JuLdnX9CkZGDG=cNkTA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2022-06-15 12:45           ` A A
       [not found]             ` <CAMwawgNnfSBua1LAetThwsP+s0d9WdPj2M8zs8ZA7-d5SjPJmQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: A A @ 2022-06-15 12:45 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

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

I guess one fundamental question which I can't seem to wrap my head around
is why BlockSep doesn't come back in the AST. It is also a semantic element
so I don't understand why it is left out.

On Wed, 15 Jun 2022 at 13:50, A A <amine.aboufirass-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:

> Dear Albert,
>
> I had a look at the link you proposed and I’m experimenting with the code
> you had provided back then. It seems to identify the nesting properly. I’m
> working on adapting that so that it generates LaTeX itemize environments.
> This may take me some time because I’m not too familiar with Lua, and the
> code you had proposed uses some advanced language features such as
> metatables and such.
>
> With regards to BlockSep, I really don’t see where in the markdown file
> this occurs. Here’s the native output generated by my test.md file:
>
> pandoc test.md -t native
> [ Header
>     1
>     ( "a-section" , [] , [] )
>     [ Str "A" , Space , Str "section" ]
> , Header
>     2
>     ( "a-subsection" , [] , [] )
>     [ Str "A" , Space , Str "subsection" ]
> , BulletList
>     [ [ Plain [ Str "An" , Space , Str "item" ]
>       , BulletList
>           [ [ Plain [ Str "A" , Space , Str "subitem" ] ]
>           , [ Plain [ Str "A" , Space , Str "subitem" ] ]
>           ]
>       ]
>     , [ Plain [ Str "An" , Space , Str "item" ] ]
>     , [ Plain [ Str "An" , Space , Str "item" ]
>       , BulletList
>           [ [ Plain [ Str "A" , Space , Str "subitem" ]
>             , BulletList
>                 [ [ Plain [ Str "A" , Space , Str "subsubitem" ] ]
>                 , [ Plain [ Str "A" , Space , Str "subsubitem" ] ]
>                 ]
>             ]
>           , [ Plain [ Str "A" , Space , Str "subitem" ] ]
>           ]
>       ]
>     ]
> ]
>
> The BlockSep is nowhere to be seen, and yet it does seem to be part of
> the AST and does have an impact on how my Lua writer translates the file to
> LaTeX.
>
> With regards to “new style” writers, I would very much appreciate having a
> basic example of how it can deal with bulleted lists and why that is easier
> than using the “old style” writer.
>
> Regards,
>
> Amine
>
> On Thu, 21 Apr 2022 at 18:25, Albert Krewinkel <albert+pandoc@zeitkraut.de>
> wrote:
>
>> A A <amine.aboufirass-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
>>
>> > I am trying to make my own customized writer for LaTeX.
>> >
>> > [...]
>> >
>> > There are two things that strike me here:
>> >   * The nested list appears to be processed first, before the outer
>> >     list. This seems counter-intuitive to me. I can’t think of an
>> >     algorithm which would result in the correct LaTeX nesting if it
>> >     goes inner to outer. Why does this occur? Can I get it so that it
>> >     goes the other way round?
>>
>> For an explanation and possible solution of what's happening here, see
>> https://groups.google.com/g/pandoc-discuss/c/y9jbpQJsU4w/m/HVWxoKNEAgAJ
>>
>> >   * Two blank lines are printed out between 1 An item and 2 An item.
>> >     Where do these come from? I haven’t specified them anywhere in my
>> >     Lua file.
>>
>> That's the result of the "BlockSep" function.
>>
>> You might be able to save yourself some work by using a "new style"
>> writer as described here: https://pandoc.org/custom-writers#new-style
>> (requires pandoc 2.18).
>>
>>
>> --
>> 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/87wnfibdzg.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/CAMwawgNnfSBua1LAetThwsP%2Bs0d9WdPj2M8zs8ZA7-d5SjPJmQ%40mail.gmail.com.

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

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

* Re: itemization and a custom Lua writer to convert markdown to LaTeX
       [not found]             ` <CAMwawgNnfSBua1LAetThwsP+s0d9WdPj2M8zs8ZA7-d5SjPJmQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2022-06-16  7:41               ` Albert Krewinkel
  0 siblings, 0 replies; 5+ messages in thread
From: Albert Krewinkel @ 2022-06-16  7:41 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw; +Cc: A A


A A <amine.aboufirass-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:

> I guess one fundamental question which I can't seem to wrap my head
> around is why BlockSep doesn't come back in the AST. It is also a
> semantic element so I don't understand why it is left out.

The Blocksep function doesn't really correspond to any element in the
AST; it just returns the separator between two block elements. Think of
it as representing the gap between two blocks in the AST.

Could you say a bit more about what you want your output to look like?
That would make it easier for me to suggest some code to use as a
starting point.

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


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

end of thread, other threads:[~2022-06-16  7:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-21  8:34 itemization and a custom Lua writer to convert markdown to LaTeX A A
     [not found] ` <80f61224-056c-4c70-9ab5-3ee40553d784n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2022-04-21 16:17   ` Albert Krewinkel
     [not found]     ` <87wnfibdzg.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2022-06-15 11:50       ` A A
     [not found]         ` <CAMwawgMgLab823rHva19HTcHRORNJ81JuLdnX9CkZGDG=cNkTA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2022-06-15 12:45           ` A A
     [not found]             ` <CAMwawgNnfSBua1LAetThwsP+s0d9WdPj2M8zs8ZA7-d5SjPJmQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2022-06-16  7:41               ` Albert Krewinkel

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