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

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