summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/luatex/gregoriotex/gregoriotex.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/luatex/gregoriotex/gregoriotex.lua')
-rw-r--r--Master/texmf-dist/tex/luatex/gregoriotex/gregoriotex.lua331
1 files changed, 100 insertions, 231 deletions
diff --git a/Master/texmf-dist/tex/luatex/gregoriotex/gregoriotex.lua b/Master/texmf-dist/tex/luatex/gregoriotex/gregoriotex.lua
index e00885a3ca5..72775a0a8c1 100644
--- a/Master/texmf-dist/tex/luatex/gregoriotex/gregoriotex.lua
+++ b/Master/texmf-dist/tex/luatex/gregoriotex/gregoriotex.lua
@@ -24,13 +24,13 @@ local hpack, traverse, traverse_id, has_attribute, count, remove, insert_after,
gregoriotex = gregoriotex or {}
local gregoriotex = gregoriotex
-local internalversion = '4.2.0-beta1' -- GREGORIO_VERSION (comment used by VersionManager.py)
+local internalversion = '4.1.2' -- GREGORIO_VERSION (comment used by VersionManager.py)
local err, warn, info, log = luatexbase.provides_module({
name = "gregoriotex",
- version = '4.2.0-beta1', -- GREGORIO_VERSION
+ version = '4.1.2', -- GREGORIO_VERSION
greinternalversion = internalversion,
- date = "2016/04/27", -- GREGORIO_DATE_LTX
+ date = "2016/05/08", -- GREGORIO_DATE_LTX
description = "GregorioTeX module.",
author = "The Gregorio Project (see CONTRIBUTORS.md)",
copyright = "2008-2015 - The Gregorio Project",
@@ -68,14 +68,11 @@ local line_heights = nil
local new_line_heights = nil
local score_heights = nil
local new_score_heights = nil
-local saved_positions = nil
-local saved_lengths = nil
-local new_saved_lengths = nil
-local saved_newline_before_euouae = nil
-local new_saved_newline_before_euouae = nil
+local var_brace_positions = nil
+local new_var_brace_positions = nil
+local pos_saves = nil
+local new_pos_saves = nil
local auxname = nil
-local snippet_filename = nil
-local snippet_logname = nil
local space_below_staff = 5
local space_above_staff = 13
@@ -137,35 +134,7 @@ local function keys_changed(tab1, tab2)
return false
end
-local function saved_computations_changed(tab1, tab2)
- local score_ids = {}
- local id,_
- for id,_ in pairs(tab1) do
- score_ids[id] = true
- end
- for id,_ in pairs(tab2) do
- score_ids[id] = true
- end
- for id,_ in pairs(score_ids) do
- local inner1 = tab1[id]
- local inner2 = tab2[id]
- if inner1 == nil or inner2 == nil then return true end
- local keys = {}
- local index
- for index,_ in pairs(inner1) do
- keys[index] = true
- end
- for index,_ in pairs(inner2) do
- keys[index] = true
- end
- for index,_ in pairs(keys) do
- if inner1[index] ~= inner2[index] then return true end
- end
- end
- return false
-end
-
-local function is_greaux_write_needed()
+local function heights_changed()
local id, tab
for id, tab in pairs(new_line_heights) do
if keys_changed(tab, line_heights[id]) then return true end
@@ -173,24 +142,30 @@ local function is_greaux_write_needed()
for id, tab in pairs(line_heights) do
if keys_changed(tab, new_line_heights[id]) then return true end
end
- if saved_computations_changed(saved_lengths, new_saved_lengths) then
- return true
+ for id, tab in pairs(new_var_brace_positions) do
+ if keys_changed(tab, var_brace_positions[id]) then return true end
end
- if saved_computations_changed(saved_newline_before_euouae, new_saved_newline_before_euouae) then
- return true
+ for id, tab in pairs(var_brace_positions) do
+ if keys_changed(tab, new_var_brace_positions[id]) then return true end
+ end
+ for id, tab in pairs(new_pos_saves) do
+ if keys_changed(tab, pos_saves[id]) then return true end
+ end
+ for id, tab in pairs(pos_saves) do
+ if keys_changed(tab, new_pos_saves[id]) then return true end
end
return false
end
local function write_greaux()
- if is_greaux_write_needed() then
+ if heights_changed() then
-- only write this if heights change; since table ordering is not
-- predictable, this ensures a steady state if the heights are unchanged.
local aux = io.open(auxname, 'w')
if aux then
log("Writing %s", auxname)
aux:write('return {\n ["line_heights"]={\n')
- local id, tab, id2, line, value
+ local id, tab, id2, line
for id, tab in pairs(new_line_heights) do
aux:write(string.format(' ["%s"]={\n', id))
for id2, line in pairs(tab) do
@@ -199,26 +174,25 @@ local function write_greaux()
end
aux:write(' },\n')
end
- aux:write(' },\n ["saved_lengths"]={\n')
- for id, tab in pairs(new_saved_lengths) do
+ aux:write(' },\n ["var_brace_positions"]={\n')
+ for id, tab in pairs(new_var_brace_positions) do
aux:write(string.format(' ["%s"]={\n', id))
- for id2, value in pairs(tab) do
- if value ~= nil then
- aux:write(string.format(' [%d]=%d,\n', id2, value))
+ for id2, line in pairs(tab) do
+ if line[1] ~= nil and line[2] ~= nil then
+ aux:write(string.format(' [%d]={%d,%d},\n', id2, line[1],
+ line[2]))
end
end
aux:write(' },\n')
end
- aux:write(' },\n ["saved_newline_before_euouae"]={\n')
- for id, tab in pairs(new_saved_newline_before_euouae) do
+ aux:write(' },\n ["pos_saves"]={\n')
+ for id, tab in pairs(new_pos_saves) do
aux:write(string.format(' ["%s"]={\n', id))
- for id2, value in pairs(tab) do
- if value ~= nil then
- if value then
- aux:write(string.format(' [%d]=true,\n', id2))
- else
- aux:write(string.format(' [%d]=false,\n', id2))
- end
+ for id2, line in pairs(tab) do
+ if line[1] ~= nil and line[2] ~= nil and line[3] ~= nil and
+ line[4] ~= nil then
+ aux:write(string.format(' [%d]={%d,%d,%d,%d},\n', id2, line[1],
+ line[2], line[3], line[4]))
end
end
aux:write(' },\n')
@@ -247,12 +221,8 @@ local function init(arg, enable_height_computation)
end
if outputdir and lfs.isdir(outputdir) then
auxname = outputdir..'/'..tex.jobname..'.gaux'
- snippet_filename = outputdir..'/'..tex.jobname..'.gsnippet'
- snippet_logname = outputdir..'/'..tex.jobname..'.gsniplog'
else
auxname = tex.jobname..'.gaux'
- snippet_filename = tex.jobname..'.gsnippet'
- snippet_logname = tex.jobname..'.gsniplog'
end
-- to get latexmk to realize the aux file is a dependency
@@ -261,12 +231,12 @@ local function init(arg, enable_height_computation)
log("Reading %s", auxname)
local score_info = dofile(auxname)
line_heights = score_info.line_heights or {}
- saved_lengths = score_info.saved_lengths or {}
- saved_newline_before_euouae = score_info.saved_newline_before_euouae or {}
+ var_brace_positions = score_info.var_brace_positions or {}
+ pos_saves = score_info.pos_saves or {}
else
line_heights = {}
- saved_lengths = {}
- saved_newline_before_euouae = {}
+ var_brace_positions = {}
+ pos_saves = {}
end
if enable_height_computation then
@@ -292,9 +262,8 @@ local function init(arg, enable_height_computation)
'line heights. Remove or undefine \\greskipheightcomputation to '..
'resume height computation.')
end
- saved_positions = {}
- new_saved_lengths = {}
- new_saved_newline_before_euouae = {}
+ new_var_brace_positions = {}
+ new_pos_saves = {}
end
-- node factory
@@ -558,43 +527,19 @@ local function clean_old_gtex_files(file_withdir)
end
end
-local function compile_gabc(gabc_file, gtex_file, glog_file, allow_deprecated)
+local function compile_gabc(gabc_file, gtex_file)
info("compiling the score %s...", gabc_file)
local extra_args = ''
if tex.count['gre@generate@pointandclick'] == 1 then
- extra_args = extra_args..' -p'
- end
- if not allow_deprecated then
- extra_args = extra_args..' -D'
+ extra_args = ' -p'
end
- local cmd = string.format("gregorio %s -W -o %s -l %s %s",
- extra_args, gtex_file, glog_file, gabc_file)
- res = os.execute(cmd)
+ res = os.execute(string.format("gregorio %s -o %s %s", extra_args, gtex_file, gabc_file))
if res == nil then
- err("\nSomething went wrong when executing\n '%s'.\n"
- .."shell-escape mode may not be activated. Try\n\n"
- .."%s --shell-escape %s.tex\n\n"
- .."See the documentation of gregorio or your TeX\n"
- .."distribution to automatize it.",
- cmd, tex.formatname, tex.jobname)
+ err("\nSomething went wrong when executing\n 'gregorio -o %s %s'.\n"
+ .."shell-escape mode may not be activated. Try\n\n%s --shell-escape %s.tex\n\nSee the documentation of gregorio or your TeX\ndistribution to automatize it.", gtex_file, gabc_file, tex.formatname, tex.jobname)
elseif res ~= 0 then
- local glog = io.open(glog_file, 'a+')
- if glog == nil then
- err("\n Unable to open %s", glog_file)
- else
- local size = glog:seek('end')
- if size > 0 then
- glog:seek('set')
- local line
- for line in glog:lines() do
- warn(line)
- end
- end
- glog:close()
- end
- err("\nAn error occured when compiling the score file\n"
- .."'%s' with gregorio.\nPlease check your score file.", gabc_file)
+ err("\nAn error occured when compiling the score file\n'%s' with gregorio.\nPlease check your score file.", gabc_file)
else
-- open the gtex file for writing so that LuaTeX records output to it
-- when the -recorder option is used
@@ -604,25 +549,10 @@ local function compile_gabc(gabc_file, gtex_file, glog_file, allow_deprecated)
else
gtex:close()
end
- local glog = io.open(glog_file, 'a+')
- if glog == nil then
- err("\n Unable to open %s", glog_file)
- else
- local size = glog:seek('end')
- if size > 0 then
- glog:seek('set')
- local line
- for line in glog:lines() do
- warn(line)
- end
- warn("*** end of warnings for %s ***", gabc_file)
- end
- glog:close()
- end
end
end
-local function include_score(input_file, force_gabccompile, allow_deprecated)
+local function include_score(input_file, force_gabccompile)
local file_root
if string.match(input_file:sub(-5), '%.gtex') then
file_root = input_file:sub(1,-6)
@@ -634,7 +564,6 @@ local function include_score(input_file, force_gabccompile, allow_deprecated)
file_root = input_file
end
local gtex_file = file_root.."-"..internalversion:gsub("%.", "_")..".gtex"
- local glog_file = file_root.."-"..internalversion:gsub("%.", "_")..".glog"
local gabc_file = file_root..".gabc"
if not lfs.isfile(gtex_file) then
clean_old_gtex_files(file_root)
@@ -647,7 +576,7 @@ local function include_score(input_file, force_gabccompile, allow_deprecated)
else
gabc:close()
end
- compile_gabc(gabc_file, gtex_file, glog_file, allow_deprecated)
+ compile_gabc(gabc_file, gtex_file)
tex.print(string.format([[\input %s\relax]], gtex_file))
return
else
@@ -668,57 +597,29 @@ local function include_score(input_file, force_gabccompile, allow_deprecated)
end
if gtex_timestamp < gabc_timestamp then
log("%s has been modified and %s needs to be updated. Recompiling the gabc file.", gabc_file, gtex_file)
- compile_gabc(gabc_file, gtex_file, glog_file, allow_deprecated)
+ compile_gabc(gabc_file, gtex_file)
elseif force_gabccompile then
- compile_gabc(gabc_file, gtex_file, glog_file)
+ compile_gabc(gabc_file, gtex_file)
end
tex.print(string.format([[\input %s\relax]], gtex_file))
return
end
-local function direct_gabc(gabc, header, allow_deprecated)
- info('Processing gabc snippet...')
- local deprecated
- if allow_deprecated then
- deprecated = ''
- else
- deprecated = '-D '
- end
- local f = io.open(snippet_filename, 'w')
+local function direct_gabc(gabc, header)
+ tmpname = os.tmpname()
+ local f = io.open(tmpname, 'w')
-- trims spaces on both ends (trim6 from http://lua-users.org/wiki/StringTrim)
gabc = gabc:match('^()%s*$') and '' or gabc:match('^%s*(.*%S)')
f:write('name:direct-gabc;\n'..(header or '')..'\n%%\n'..gabc:gsub('\\par ', '\n'))
f:close()
- local cmd = string.format('gregorio -W %s-S -l %s %s', deprecated, snippet_logname,
- snippet_filename)
- local p = io.popen(cmd, 'r')
+ local p = io.popen('gregorio -S '..tmpname, 'r')
if p == nil then
- err("\nSomething went wrong when executing\n %s\n"
- .."shell-escape mode may not be activated. Try\n\n"
- .."%s --shell-escape %s.tex\n\n"
- .."See the documentation of gregorio or your TeX\n"
- .."distribution to automatize it.", cmd, tex.formatname, tex.jobname)
- else
- tex.print(p:read("*a"):explode('\n'))
- p:close()
+ err("\nSomething went wrong when executing\n gregorio -S "..tmpname..".\n"
+ .."shell-escape mode may not be activated. Try\n\n%s --shell-escape %s.tex\n\nSee the documentation of gregorio or your TeX\ndistribution to automatize it.", tex.formatname, tex.jobname)
end
- local glog = io.open(snippet_logname, 'a+')
- if glog == nil then
- err("\n Unable to open %s", snippet_logname)
- else
- local size = glog:seek('end')
- if size > 0 then
- glog:seek('set')
- local line
- for line in glog:lines() do
- warn(line)
- end
- warn("*** end of warnings/errors processing snippet ***")
- end
- glog:close()
- end
- os.remove(snippet_filename)
- os.remove(snippet_logname)
+ tex.print(p:read("*a"):explode('\n'))
+ p:close()
+ os.remove(tmpname)
end
local function get_gregorioversion()
@@ -978,97 +879,64 @@ local function adjust_line_height(inside_discretionary)
end
end
-local function prep_save_position(index, fn)
- if saved_positions[cur_score_id] == nil then
- saved_positions[cur_score_id] = {}
- end
- saved_positions[cur_score_id][index] = { fn = fn }
-end
-
-local function save_position(index, which)
- tex.print(catcode_at_letter, string.format([[\luatexlatelua{gregoriotex.late_save_position('%s', %d, %d, \number\gre@lastxpos, \number\gre@lastypos)}]], cur_score_id, index, which))
+local function var_brace_note_pos(brace, start_end)
+ tex.print(catcode_at_letter, string.format([[\luatexlatelua{gregoriotex.late_brace_note_pos('%s', %d, %d, \number\gre@lastxpos)}]], cur_score_id, brace, start_end))
end
-local function late_save_position(score_id, index, which, xpos, ypos)
- info('saving %s, %d [%d] (%d,%d)', score_id, index, which, xpos, ypos)
- local pos = saved_positions[score_id][index]
- if pos == nil then
- err('Attempting to use unprepared position save slot %d', index)
- return
- end
- --[[
- if pos.fn == nil then
- err('Attempting to reuse position save slot %d', index)
- return
+local function late_brace_note_pos(score_id, brace, start_end, pos)
+ if new_var_brace_positions[score_id] == nil then
+ new_var_brace_positions[score_id] = {}
end
- --]]
- pos['x'..which] = xpos
- pos['y'..which] = ypos
- if pos.x1 ~= nil and pos.y1 ~= nil and pos.x2 ~= nil and pos.y2 ~= nil then
- pos.fn(score_id, index, pos)
- --pos.fn = nil
+ if new_var_brace_positions[score_id][brace] == nil then
+ new_var_brace_positions[score_id][brace] = {}
end
+ new_var_brace_positions[score_id][brace][start_end] = pos
end
-local function compute_saved_length(score_id, index, pos)
- if new_saved_lengths[score_id] == nil then
- new_saved_lengths[score_id] = {}
- end
- new_saved_lengths[score_id][index] = pos.x2 - pos.x1
- info('computed length for %s, %d: %d', score_id, index,
- new_saved_lengths[score_id][index])
-end
-
-local function save_length(index, which)
- if which == 1 then
- prep_save_position(index, compute_saved_length)
+local function var_brace_len(brace)
+ if var_brace_positions[cur_score_id] ~= nil then
+ if var_brace_positions[cur_score_id][brace] ~= nil then
+ local posend = var_brace_positions[cur_score_id][brace][2]
+ local posstart = var_brace_positions[cur_score_id][brace][1]
+ if posend > posstart then
+ tex.print(string.format('%dsp', posend - posstart))
+ else
+ warn('Dynamically sized braces spanning multiple lines unsupported, using length 2mm.')
+ tex.print('2mm')
+ end
+ return
+ end
end
- save_position(index, which)
+ tex.print('2mm')
end
-local function compute_saved_newline_before_euouae(score_id, index, pos)
- if new_saved_newline_before_euouae[score_id] == nil then
- new_saved_newline_before_euouae[score_id] = {}
- end
- new_saved_newline_before_euouae[score_id][index] = pos.y2 ~= pos.y1
- info('computed euouae for %s, %d: %s', score_id, index,
- new_saved_newline_before_euouae[score_id][index])
+local function save_pos(index, which)
+ tex.print(catcode_at_letter, string.format([[\gre@savepos\luatexlatelua{gregoriotex.late_save_pos('%s', %d, %d, \number\gre@lastxpos, \number\gre@lastypos)}]], cur_score_id, index, which))
end
-local function save_euouae(index, which)
- if which == 1 then
- prep_save_position(index, compute_saved_newline_before_euouae)
+local function late_save_pos(score_id, index, which, xpos, ypos)
+ if new_pos_saves[score_id] == nil then
+ new_pos_saves[score_id] = {}
end
- tex.sprint(catcode_at_letter, [[\gre@savepos]])
- save_position(index, which)
-end
-
-local function var_brace_len(brace)
- if saved_lengths[cur_score_id] ~= nil then
- local length = saved_lengths[cur_score_id][brace]
- if saved_lengths[cur_score_id][brace] ~= nil then
- if length > 0 then
- tex.print(string.format('%dsp', length))
- return
- else
- warn('Dynamically sized signs spanning multiple lines unsupported, using length 2mm.')
- end
- end
+ if new_pos_saves[score_id][index] == nil then
+ new_pos_saves[score_id][index] = {}
end
- tex.print('2mm')
+ new_pos_saves[score_id][index][(2 * which) - 1] = xpos
+ new_pos_saves[score_id][index][2 * which] = ypos
end
-- this function is meant to be used from \ifcase; prints 0 for true and 1 for false
local function is_ypos_different(index)
- if saved_newline_before_euouae[cur_score_id] ~= nil then
- local newline_before_euouae =
- saved_newline_before_euouae[cur_score_id][index]
- if newline_before_euouae then
+ if pos_saves[cur_score_id] ~= nil then
+ local saved_pos = pos_saves[cur_score_id][index]
+ if saved_pos == nil or saved_pos[2] == saved_pos[4] then
+ tex.sprint([[\number1\relax ]])
+ else
tex.sprint([[\number0\relax ]])
- return
end
+ else
+ tex.sprint([[\number1\relax ]])
end
- tex.sprint([[\number1\relax ]])
end
local function width_to_bp(width, value_if_star)
@@ -1162,7 +1030,8 @@ gregoriotex.font_size = font_size
gregoriotex.direct_gabc = direct_gabc
gregoriotex.adjust_line_height = adjust_line_height
gregoriotex.var_brace_len = var_brace_len
-gregoriotex.save_length = save_length
+gregoriotex.var_brace_note_pos = var_brace_note_pos
+gregoriotex.late_brace_note_pos = late_brace_note_pos
gregoriotex.mark_translation = mark_translation
gregoriotex.mark_abovelinestext = mark_abovelinestext
gregoriotex.width_to_bp = width_to_bp
@@ -1171,11 +1040,11 @@ gregoriotex.rotation = rotation
gregoriotex.scale_space = scale_space
gregoriotex.set_header_capture = set_header_capture
gregoriotex.capture_header = capture_header
+gregoriotex.save_pos = save_pos
+gregoriotex.late_save_pos = late_save_pos
gregoriotex.is_ypos_different = is_ypos_different
-gregoriotex.save_euouae = save_euouae
gregoriotex.mode_part = mode_part
gregoriotex.set_debug_string = set_debug_string
-gregoriotex.late_save_position = late_save_position
dofile(kpse.find_file('gregoriotex-nabc.lua', 'lua'))
dofile(kpse.find_file('gregoriotex-signs.lua', 'lua'))