* filter module: call function before calling the filter command?
@ 2016-10-12 9:11 Henning Hraban Ramm
2016-10-13 22:41 ` Aditya Mahajan
0 siblings, 1 reply; 2+ messages in thread
From: Henning Hraban Ramm @ 2016-10-12 9:11 UTC (permalink / raw)
To: mailing list for ConTeXt users
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: filter module: call function before calling the filter command?
2016-10-12 9:11 filter module: call function before calling the filter command? Henning Hraban Ramm
@ 2016-10-13 22:41 ` Aditya Mahajan
0 siblings, 0 replies; 2+ messages in thread
From: Aditya Mahajan @ 2016-10-13 22:41 UTC (permalink / raw)
To: mailing list for ConTeXt users
[-- Attachment #1: Type: TEXT/PLAIN, Size: 968 bytes --]
On Wed, 12 Oct 2016, Henning Hraban Ramm wrote:
> 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?
There is an internal option: filtersetups that may be useful for what you
have in mind.
You can create a lua function, say lilypond.initialize(...), that does all
the initializations, and then write
\startsetups lilypond:initialize
\ctxlua{lilypond.initialize()}
\stopsetups
\defineexternalfilter[...]
[ ...
filtersetups=lilypond:initialize,
...
]
This is untested, but it should work.
Aditya
[-- Attachment #2: Type: text/plain, Size: 489 bytes --]
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-10-13 22:41 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-12 9:11 filter module: call function before calling the filter command? Henning Hraban Ramm
2016-10-13 22:41 ` Aditya Mahajan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).