summaryrefslogtreecommitdiff
path: root/Master
diff options
context:
space:
mode:
Diffstat (limited to 'Master')
-rw-r--r--Master/texmf-dist/tex/latex/latexconfig/lualatexquotejobname.lua33
-rw-r--r--Master/texmf-dist/tex/latex/latexconfig/lualatexquotejobname.tex10
2 files changed, 35 insertions, 8 deletions
diff --git a/Master/texmf-dist/tex/latex/latexconfig/lualatexquotejobname.lua b/Master/texmf-dist/tex/latex/latexconfig/lualatexquotejobname.lua
new file mode 100644
index 00000000000..9009864e52c
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/latexconfig/lualatexquotejobname.lua
@@ -0,0 +1,33 @@
+-- $Id: lualatexquotejobname.tex 22957 2011-06-13 20:49:26Z mpg $
+-- Manuel Pegourie-Gonnard, originally written 2010. WTFPL v2.
+--
+-- Used in lualatexquotejobname.tex
+--
+-- Try to replicate web2c's function normalize_quotes() (in lib/texmfmp.c,
+-- non-XeTeX version) as closely as possible (that is, exactly except error
+-- handling).
+--
+-- 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
+ -- this code is executed when jobname is first expanded, which is
+ -- probably too late for an early exit as in web2c's normalize_quotes()
+ -- so, just throw an error without exiting
+ texio.write_nl('! Unbalanced quotes in jobname: ' .. jobname )
+ end
+ -- add quotes around the clean up jobname if necessary
+ if jobname:find(' ') then
+ clean = '"' .. clean .. '"'
+ end
+ -- remember the result before returning
+ jobname_cache[jobname] = clean
+ return clean
+end)
diff --git a/Master/texmf-dist/tex/latex/latexconfig/lualatexquotejobname.tex b/Master/texmf-dist/tex/latex/latexconfig/lualatexquotejobname.tex
index bf70bad24ca..79b8b4bdba9 100644
--- a/Master/texmf-dist/tex/latex/latexconfig/lualatexquotejobname.tex
+++ b/Master/texmf-dist/tex/latex/latexconfig/lualatexquotejobname.tex
@@ -28,13 +28,7 @@
\edef\dotest{\noexpand\testsp\jobname\space\relax}\dotest
\expandafter\endgroup\fixjobname
\or % callback available, use it
- \directlua{
- callback.register('process_jobname', function(jobname)
- if jobname:find(' ') then
- return '"' .. jobname .. '"'
- else
- return jobname
- end
- end)}
+ % put the function in a separate file for convenience (uses %, ~, etc)
+ \directlua{dofile(assert(kpse.find_file("lualatexquotejobname.lua")))}
\fi}
\endinput