How to align text using pandoc with lua-filters?
Asked Answered
E

0

0

How to align all h1 headers of the pdf to center using pandoc with lua-filters?

I have the test.md file bellow:

<center>
# Chapter 1
</center>

<right>
## Sub-1-1
</right>

<left>
### Sub-1-2
</left>

<center>
# Chapter 2
</center>

<right>
## Sub-2-1
</right>

<left>
### Sub-2-2
</left>

And I need to align center all "Chapters" to center, all the "Sub--1" to right and all the "Sub--2" to left using tags as above, to stay like:

            Chapter 1
                          Sub-1-1
Sub-1-2
            Chapter 2
                          Sub-2-1
Sub-2-2

I can uppcase the "Chapters" with the follow filter.lua:

local text = require('text')

function Header(el)
    if el.level == 1 then
      return pandoc.walk_block(el, {
        Str = function(el)
            return pandoc.Str(text.upper(el.text))
        end })
    end
end

So I call the pandoc:

pandoc test.md -o test.pdf --pdf-engine=xelatex --lua-filter=./filter.lua

But I don't know how to align the things with lua-filters.

Einhorn answered 21/10, 2020 at 14:41 Comment(2)
This is probably easier when done in LaTeX. Write the necessary LaTeX header snippets to a file and pass it to pandoc via -H. See also tex.stackexchange.com/a/8547Settlement
@Settlement I updated my question, I need with tags, because sometimes I need align, sometimes not, with LaTeX I already can do this, like this answer: https://mcmap.net/q/671647/-how-do-i-convert-a-markdown-file-with-centered-text-in-atom-using-pandoc-convert-to-pdf, but I would like know how to make this with lua-filters yet.Einhorn

© 2022 - 2024 — McMap. All rights reserved.