Skip to content

Commit

Permalink
Fix #25 ; fix #27
Browse files Browse the repository at this point in the history
- remove temporary `.eps` files ;
- add a `tmpdir` package option.
  • Loading branch information
jperon committed Jan 15, 2018
1 parent e56073f commit 33eca91
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
27 changes: 19 additions & 8 deletions lyluatex.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ local err, warn, info, log = luatexbase.provides_module({
local md5 = require 'md5'


LILYPOND = 'lilypond'
TMP = 'tmp_ly'
N = 0


function ly_define_program(lilypond)
if lilypond then LILYPOND = lilypond end
end
Expand Down Expand Up @@ -49,12 +44,18 @@ function extract_size_arguments(line_width, staffsize)
return line_width, staffsize
end

function hash_output_filename(ly_code,line_width, staffsize)
return TMP..'/'..string.gsub(md5.sumhexa(flatten_content(ly_code))..'-'..staffsize..'-'..line_width.n..line_width.u, '%.', '-')
function hash_output_filename(ly_code, line_width, staffsize)
filename = string.gsub(
md5.sumhexa(flatten_content(ly_code))..
'-'..staffsize..'-'..line_width.n..line_width.u, '%.', '-'
)
local f = io.open(FILELIST, 'a')
f:write(filename, '\n')
f:close()
return TMP..'/'..filename
end

function lilypond_fragment(ly_code, line_width, staffsize)
N = N + 1
line_width, staffsize = extract_size_arguments(line_width, staffsize)
ly_code = ly_code:gsub('\\par ', '\n'):gsub('\\([^%s]*) %-([^%s])', '\\%1-%2')
local output = hash_output_filename(ly_code, line_width, staffsize)
Expand Down Expand Up @@ -158,6 +159,14 @@ function write_tex(output, staffsize)
local i = io.open(output..'-systems.tex', 'r')
local content = i:read("*all")
i:close()
i = io.open(output..'-systems.count', 'r')
if i then
local n = tonumber(i:read('*all'))
i:close()
for i = 1, n, 1 do
os.remove(output..'-'..i..'.eps')
end
end
local texoutput, nbre = content:gsub([[\includegraphics{]],
[[\includegraphics{]]..dirname(output))
tex.print(([[\noindent]]..texoutput):explode('\n'))
Expand Down Expand Up @@ -204,3 +213,5 @@ end


mkdirs(TMP)
FILELIST = TMP..'/'..splitext(status.log_name, 'log')..'.list'
os.remove(FILELIST)
8 changes: 6 additions & 2 deletions lyluatex.sty
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@
% Options
\DeclareStringOption[lilypond]{program}[lilypond]
\DeclareStringOption[default]{line-width}[lilypond]
\DeclareStringOption[tmp_ly]{tmpdir}[lilypond]
\newcommand{\pt}{pt}
\newcommand{\mm}{mm}
\newcommand{\cm}{cm}
\ProcessKeyvalOptions*
% Lua Script
\directlua{dofile(kpse.find_file("lyluatex.lua"))}
\directlua{LILYPOND = '\lyluatex@program'}
\directlua{
LILYPOND = '\luatexluaescapestring{\lyluatex@program}'
TMP = '\luatexluaescapestring{\lyluatex@tmpdir}'
dofile(kpse.find_file("lyluatex.lua"))}
\directlua{}
\newcommand{\lilypondCmd}[1]{%
\directlua{ly_define_program("\luatexluaescapestring{#1}")}%
\def\lyluatex@program{#1}
Expand Down
2 changes: 1 addition & 1 deletion test.tex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
\documentclass[a5paper,fontsize=12pt]{scrbook}
\usepackage[program=lilypond]{lyluatex}
\usepackage[program=lilypond,tmpdir=tmp_ly]{lyluatex}
\usepackage{multicol}

\title{}
Expand Down

0 comments on commit 33eca91

Please sign in to comment.