summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/latexconfig/lualatexquotejobname.lua
blob: 1809a67874dedd64e8f78436435bece3ac66393c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
-- $Id: lualatexquotejobname.tex 22957 2011-06-13 20:49:26Z mpg $
-- Manuel Pegourie-Gonnard, originally written 2010. WTFPL v2.
--
-- Goal: see lualatexquotejobname.tex
--
-- Cache the results of previous calls, not so much for the speed gain which
-- probably doesn't matter, but to avoid repeated error messages.
local jobname_cache = {}
callback.register('process_jobname', function(jobname)
    -- use a cached version if available
    local cached = jobname_cache[jobname]
    if cached ~= nil then return cached end
    -- remove the quotes in jobname
    local clean, n_quotes = jobname:gsub([["]], [[]])
    -- complain if they wasn't an even number of quotes (aka unbalanced)
    if n_quotes % 2 ~= 0 then
        texio.write_nl('! Unbalanced quotes in jobname: ' .. jobname )
    end
    -- add quotes around the cleaned up jobname if necessary
    if jobname:find(' ') then
        clean = '"' .. clean .. '"'
    end
    -- remember the result before returning
    jobname_cache[jobname] = clean
    return clean
end)