Ahoi!
As you probably know ;), I’m using the filter module with LilyPond, setup see
below.
Now, I’d like to overwrite "texsettings.ly", containing the setting of
ConTeXt’s text width, each time before I call LilyPond, to adapt its note line
width to the current text width. That would automate the line width adaption to
e.g. columns.
In the module’s documentation under "Dealing with expansion" I found the
example of creating the filter command in a macro.
Can I use this to call a Lua function first and then LilyPond? Or is there a
better way?
-
\usemodule[filter]
\startbuffer[lilypond::settings]
\include "../lilysettings.ly" % file must be in same folder as text, not in
lilytemp
\include "texsettings.ly"
\stopbuffer
\def\LILYTEMP{lilytemp} % name of folder for LilyPond/buffer files
\def\ParseLilypondFile#1% #1 is the name of the output file
{\ctxlua{thirddata.parselilypondfile("#1")}}
\startluacode
thirddata = thirddata or {}
-- create temp folder if missing
if not lfs.isdir("\LILYTEMP") then
lfs.mkdir("\LILYTEMP")
end
-- write text width to include file
io.savedata("\LILYTEMP/texsettings.ly", "\\paper { line-width = " ..
string.gsub(number.topoints(tex.dimen.textwidth),"pt","\\pt") .. " }
\n")
function thirddata.parselilypondfile(name)
-- include all systems (pages)
-- name is like \LILYTEMP/mainfile-temp-lilypond-21.pdf
logs.report("LILYPOND","name='" .. name .. "'")
local scname = string.gsub(name, '%.pdf$', '-systems.count')
local syco = tonumber(io.loaddata(scname)) or 0
for nr = 1, syco do
logs.report("LILYPOND","including system no." .. nr)
context("\\externalfigure[" .. string.gsub(name, '%.pdf$', '-' .. nr) ..
"]")
end
end
\stopluacode
\defineexternalfilter[lilypond]
[continue=yes,
cache=yes,
%purge=no,
readcommand=\ParseLilypondFile,
bufferbefore={lilypond::settings},
directory=\LILYTEMP/,
output={\externalfilterbasefile.pdf},
filtercommand={lilypond -dbackend=eps -dinclude-eps-fonts
-dno-gs-load-fonts -o"\LILYTEMP/\externalfilterbasefile"
"\externalfilterinputfile"}]
\starttext
-
Greetlings, Hraban
---
http://www.fiee.net
http://wiki.contextgarden.net
https://www.cacert.org (I'm an assurer)
GPG Key ID 1C9B22FD
___
If your question is of interest to others as well, please add an entry to the
Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://context.aanhet.net
archive : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___