jperon / lyluatex

Alternative à lilypond-book pour lualatex
MIT License
56 stars 11 forks source link

Lilypond snippet to every environment #275

Closed clxt closed 2 years ago

clxt commented 4 years ago

Maybe I don't understand something, but is it possible to add a snippet to every lilypond environment of the document ? Let's say I want to remove bar numbers, can I add something like:

\context {
    \Score
    \remove "Bar_number_engraver"
}

to every lilypond instance? Thanks a lot!

uliska commented 4 years ago

I I don't have it off the top of my head, but I think that's not supported. But it's a good idea that should be added.

rpspringuel commented 4 years ago

I'd love an option like this, especially if, like the other options, it was controllable at all levels.

jperon commented 4 years ago

@clxt @rpspringuel Could you please tell me wether the "Wrapping Commands" section of the manual, especially the part about lysavefrag environment, answers that ? If not, could you elaborate a bit more, so that I understand better what I'd have to implement ?

rpspringuel commented 4 years ago

First off, I hadn't noticed that before, so this may be redundant now. My one question to see if it is is whether include-header, include_footer, include_before_body, and include_after_body are controllable at an option level.

I.e. Instead of:

\begin{ly}[
  include_before_body={head,mymark,head},
  include_after_body=foot,
]
d e f
\end{ly}

Can I have:

\setluaoption{ly}{include_before_body}{head,mymark,head}
\setluaoption{ly}{include_after_body}{foot}
\begin{ly}
d e f
\end{ly}

With the obvious added effect that all subsequent invocations of the ly environment will also have those headers and footers applied?

jperon commented 4 years ago

Yes, you can. You may even define the fragment after defining the option, as soon as the fragment is defined before first call to \begin{ly}. For example:

\documentclass{article}
\usepackage[include_before_body=preamble]{lyluatex}

\begin{lysavefrag}{preamble}
\override Staff.NoteHead.style = #'neomensural
\end{lysavefrag}

\begin{document}

\begin{ly}
d e f
\end{ly}

\end{document}

You may even (though it's IMHO a bad idea, as it may make things less clear) redefine a fragment in the middle of the document, without changing the option:

\documentclass{article}
\usepackage[include_before_body=preamble]{lyluatex}

\begin{lysavefrag}{preamble}
\override Staff.NoteHead.style = #'cross
\end{lysavefrag}

\begin{document}

\begin{lilypond}
  d e f
\end{lilypond}

\begin{lysavefrag}{preamble}
\override Staff.NoteHead.style = #'neomensural
\end{lysavefrag}

\begin{lilypond}
  d e f
\end{lilypond}

\end{document}
rpspringuel commented 4 years ago

Okay, I've tested this and it does exactly what I need. If @clxt needs something different, I'll let him determine.