Skip to content

Commit

Permalink
Kpse file search
Browse files Browse the repository at this point in the history
When looking for files, GregorioTeX will now employ kpse.find_file if it does not find the file is not in the expected location.  This allows for TEXINPUTS to specify paths to scores and addresses the bug part of gregorio-project#1395.
  • Loading branch information
rpspringuel committed Dec 5, 2018
1 parent 1357ea0 commit c75f2a6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ All notable changes to this project will be documented in this file.
As of v3.0.0 this project adheres to [Semantic Versioning](http://semver.org/). It follows [some conventions](http://keepachangelog.com/).

## [Unreleased][CTAN]
### Added
- GregorioTeX will now look for scores using kpse if it does not find them directly. See [#1395](https://github.com/gregorio-project/gregorio/issues/1395).


## [5.1.1] - 2018-03-25
Expand Down
34 changes: 26 additions & 8 deletions tex/gregoriotex.lua
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,22 @@ local function compile_gabc(gabc_file, gtex_file, glog_file, allow_deprecated)
end
end

local function locate_file(filename)
local result
if lfs.isfile(filename) then
result = filename
log("Found %s directly", filename)
else
result = kpse.find_file(filename)
if result then
log("Found %s using kpsewhich", filename)
else
log("Cannot find %s", filename)
end
end
return result
end

local function include_score(input_file, force_gabccompile, allow_deprecated)
if string.match(input_file, "[#%%]") then
err("GABC filename contains invalid character(s): # %%\n"
Expand All @@ -872,27 +888,29 @@ local function include_score(input_file, force_gabccompile, allow_deprecated)
end

local cleaned_filename = input_name:gsub("[%s%+%&%*%?$@:;!\"\'`]", "-")
local gabc_file = string.format("%s%s.gabc", file_dir, input_name)
local gtex_file = string.format("%s%s-%s.gtex", file_dir, cleaned_filename,
local gabc_filename = string.format("%s%s.gabc", file_dir, input_name)
local gabc_file = locate_file(gabc_filename)
local gtex_filename = string.format("%s%s-%s.gtex", file_dir, cleaned_filename,
internalversion:gsub("%.", "_"))
local gtex_file = locate_file(gtex_filename)
local glog_file = string.format("%s%s-%s.glog", file_dir, cleaned_filename,
internalversion:gsub("%.", "_"))
if not lfs.isfile(gtex_file) then
if not gtex_file then
clean_old_gtex_files(file_dir..cleaned_filename)
log("The file %s does not exist. Searching for a gabc file", gtex_file)
if lfs.isfile(gabc_file) then
log("The file %s does not exist. Will use gabc file", gtex_filename)
if gabc_file then
local gabc = io.open(gabc_file, 'r')
if gabc == nil then
err("\n Unable to open %s", gabc_file)
return
else
gabc:close()
end
compile_gabc(gabc_file, gtex_file, glog_file, allow_deprecated)
tex.print(string.format([[\input %s\relax]], gtex_file))
compile_gabc(gabc_file, gtex_filename, glog_file, allow_deprecated)
tex.print(string.format([[\input %s\relax]], gtex_filename))
return
else
err("The file %s does not exist.", gabc_file)
err("The file %s does not exist", gabc_filename)
return
end
end
Expand Down

0 comments on commit c75f2a6

Please sign in to comment.