pandoc / lua-filters

A collection of lua filters for pandoc
MIT License
611 stars 166 forks source link

Possibility to hide lilypond figure captions #168

Closed tilleule closed 3 years ago

tilleule commented 3 years ago

Is there a possibility to remove the "Figure: ..." caption from the lilypond images? I'm planning to write worksheets (markdown -> pdflatex) with many single line notation examples an the captions are unnecessarily wasting space then. I tried using the pandoc option -fmarkdown-implicit_figures but that didn't work.

tarleb commented 3 years ago

The -f option controls the reader, while we want to modify the writer behavior. Can you try with --to=markdown-implicit_figures?

tilleule commented 3 years ago

Thank you for your answer. I tried that in different ways, but it doesn't work. The error always is cannot produce pdf output from implicit_figures. My guess is that --to expects a format and not an option.

I also played around with adding a non-breakable space \ around the lilypond block in the source file (because pandoc documentation suggests this under "Extension: implicit-figures" but that throws errors every time.

The perfect solution for me would be that if ly-caption="" the caption was simply left away. Is that possible?

tarleb commented 3 years ago

Can you give the exact command that you tried? Note that --to takes a format together with the enabled/disabled extensions.

pandoc --to=markdown-implicit_figures ...

The perfect solution for me would be that if ly-caption="" the caption was simply left away. Is that possible?

Looking at the code, I believe that it should already work that way.

tilleule commented 3 years ago

OK, maybe I just don't get it: I'm trying to create a pdf. I'm coming from markdown. If I use pandoc -o appo2.pdf --lua-filter=lilypond.lua --to=markdown-implicit_figures -f markdown appo.md the result is cannot produce pdf output from markdown-implicit_figures.

pandoc -o appo2.pdf --lua-filter=lilypond.lua --to=pdf-implicit_figures -f markdown appo.md' throws the same error:cannot produce pdf output from pdf-implicit_figures'

I can go this way: pandoc -o appo2.md --lua-filter=lilypond.lua --to=markdown-implicit_figures -f markdown appo.md to create a markdown file, which includes both the generated markdown for the images plus the lilypond code, but how to get to a pdf from there? pandoc -o appo2.pdf --lua-filter=lilypond.lua -f markdown appo2.mdthrows out Error producing PDF. ! Undefined control sequence. l.69 ``\layout as does using it without the filter.

BTW, if I use ly-caption="" in the source, it defaults to "Figure X: Musical notation".

tarleb commented 3 years ago

Ah, I see. Pandoc doesn't accept pdf as output format, one needs to give the format via which the PDF is created. That's usually LaTeX, so try with --to=latex-implicit_figures.

You are right, passing ly-caption="" doesn't work. I had missed something. I'm not sure how I feel about the proposed solution. How about adding a class ly-no-figure to suppress figure creation?

It's also possible to define everything inline, like so

`
<lilypond code goes here>
`{.lilypond .ly-fragment ly-caption="The range of the oboe" ly-name="oboe"}

The above will not create a figure.

tilleule commented 3 years ago

Defining everything inline did the trick! The only thing I needed to figure out additionally was that my layout definitions needed to go into one line, i.e.

`\layout {\context {\Staff \remove "Time_signature_engraver" \remove "Clef_engraver" \remove "Bar_engraver"}}
    \relative c'' {\chordmode { f1:maj7 g:7 b,:9} <e, fis a> <es g c> <d fis g a> <a cis e gis> <c d e g>}
    \addlyrics { "_____" "_____" "_____" "_____" "_____" "_____" "_____" "_____" }
`{.lilypond .ly-fragment ly-caption="hello" ly-name="chords"}

works, whereas

`<\layout {
    \context {  
    \Staff
    \remove "Time_signature_engraver"
    \remove "Bar_engraver"
       }
    }
    \relative c'' {\chordmode { f1:maj7 g:7 b,:9} <e, fis a> <es g c> <d fis g a> <a cis e gis> <c d e g>}
    \addlyrics { "_____" "_____" "_____" "_____" "_____" "_____" "_____" "_____" }
 `{.lilypond .ly-fragment ly-caption="hello" ly-name="chords"}

does not work.

For the record, using -to=latex-implicit_captions threw the error "The extension implicit_figures is not supported for latex".

This workaround is great for me, having an optional class ly-no-figure(this would be used like {.lilypond .ly-fragment ly-no caption ly-name="chords"}, right?) would be quite elegant, too.

Thank you very much for your help, tarleb!