Search code examples
ralignmentmarkdownr-markdowntext-alignment

How to create interlinear gloss in R markdown?


I would like to create an interlinear gloss in R markdown, in which glosses are aligned with the words that they are providing information about.

In the following example, I want the left edge of each character string in the German sentence on top to be aligned with the left edge of each character string of the English beneath it:

  1. Ich habe den Bub gesehen

    1sg.NOM have.1sg.PRES DEF.ACC.SG boy.ACC.SG see.PERF.PART

So the left edge of "boy.ACC.SG" should be aligned right beneath the left edge of "Bub."

Packages like gb4e do this in TeX, but I don't know how to align text this way in markdown.


Solution

  • There are some pandoc filters available that might actually help, e.g. pangloss, which is python-based and can be installed via pip. To use it in an rmarkdown document, specify in yaml that pangloss should be used as a filter:

    ---
    title: My title
    author: Somebody
    output:
      pdf_document: 
        pandoc_args:
          - --filter
          - pangloss
    ---
    

    Pangloss actually seems to use the gb4e package for pdf outputting, so you may have to include it in your preamble, so that the whole thing becomes

    ---
    title: My title
    author: Somebody
    output:
      pdf_document: 
        pandoc_args:
          - --filter
          - pangloss
        includes:
            in_header: add_to_preamble.tex
    ---
    

    and add_to_preamble.tex must contain the line

    \usepackage{gb4e}
    

    The actual examples are included in markdown the following way (this is the example given at pangloss's github page)

    As you can see in the following examples, pangloss is really easy to use:
    
    (@) Jorge  llama             a  Maria.
        George calls-3s.PRES.IND to Maria
        'George calls Maria.'
    (@ex-french) Aussi, vous pouvez          avoir    de multiples   exemples.
        also   you  can-2p.PRES.IND have.INF of multiple-PL example-PL
        'You can also have multiple examples.'
    
    You can even refer to examples, as in (@ex-french).
    

    This seems to be pretty much still a work in progress, though.