jperon / lyluatex

Alternative à lilypond-book pour lualatex
MIT License
58 stars 12 forks source link

Handling \include correctly #7

Closed mhohl closed 9 years ago

mhohl commented 9 years ago

Hello,

I am using lyluatex for my latest project, and I like it! One drawback (that lyluatex shares with lilypond-book so far): if I include a lilypond file in my lualatex document that has one or more \include directives, chances in these included files do not cause lyluatex to recompile the music.

What about taking these include files into account? Something along the lines of [snip]

local md5 = require 'md5'

function file_exists(name)
   local f=io.open(name,"r")
   if f~=nil then io.close(f) return true else return false end
end

function replaceIncludes(file)
   local content =""
   for Line in io.lines(file) do
       if Line:find("^%s*[^%%]*\\include") then
          local inclfile = Line:gsub("%s*\\include%s*\"(.*)\"", "%1")
          if file_exists(inclfile) then
             content = content .. replaceIncludes(inclfile)
          else
             content = content .. Line .. "\n"
          end
       else
          content = content .. Line .. "\n"
       end
   end
   return content
end

lyincl = replaceIncludes('test.txt')

print(md5.sumhexa(lyincl)) 

[snip]

This is not yet tested in real life situations, but a) recursively checks for \include calls b) ignores commented out lines c) ignores nonexistent include files (mainly because lilypond will spot the error)

What do you think?

Best regards,

Marc

jperon commented 9 years ago

Hello,

Thank you for your report ! Could you please send me (cataclop at hotmail dot com) a mwe showing the problem ? I must confess I don't really understand the case : as temporary files are named after file name and line width, they should be recompiled if necessary, even in included files.

jperon commented 9 years ago

I think commit 5dcb34b62234d5edfcde9748ba33a635a9c9f398 should fix that. Could you test it, please ?

mhohl commented 9 years ago

Am 01.09.2015 um 11:20 schrieb jperon:

I think commit 5dcb34b https://github.com/jperon/lyluatex/commit/5dcb34b62234d5edfcde9748ba33a635a9c9f398 should fix that. Could you test it, please ?

A short real-life test on my current project works as expected.

Thanks a lot for the quick fix!

Cheers,

Marc

— Reply to this email directly or view it on GitHub https://github.com/jperon/lyluatex/issues/7#issuecomment-136646524.

jperon commented 9 years ago

Thank you for reporting !