summaryrefslogtreecommitdiff
path: root/Master/texmf-dist
diff options
context:
space:
mode:
authorManuel Pégourié-Gonnard <mpg@elzevir.fr>2011-06-15 22:01:52 +0000
committerManuel Pégourié-Gonnard <mpg@elzevir.fr>2011-06-15 22:01:52 +0000
commit09e10390fb69feee4980866963ec8338e6c145a4 (patch)
tree1118adec8f6be46a058b97e70b030c2c0923451d /Master/texmf-dist
parent8514e9d43bde2d06fd57c794e2fde4ba4c1102a0 (diff)
lualatex cleverer jobname quoting: now in TeX too
git-svn-id: svn://tug.org/texlive/trunk@22997 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist')
-rw-r--r--Master/texmf-dist/tex/latex/latexconfig/lualatexquotejobname.lua11
-rw-r--r--Master/texmf-dist/tex/latex/latexconfig/lualatexquotejobname.tex59
2 files changed, 45 insertions, 25 deletions
diff --git a/Master/texmf-dist/tex/latex/latexconfig/lualatexquotejobname.lua b/Master/texmf-dist/tex/latex/latexconfig/lualatexquotejobname.lua
index 9009864e52c..1809a67874d 100644
--- a/Master/texmf-dist/tex/latex/latexconfig/lualatexquotejobname.lua
+++ b/Master/texmf-dist/tex/latex/latexconfig/lualatexquotejobname.lua
@@ -1,11 +1,7 @@
-- $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).
+-- 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.
@@ -18,12 +14,9 @@ callback.register('process_jobname', function(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
+ -- add quotes around the cleaned up jobname if necessary
if jobname:find(' ') then
clean = '"' .. clean .. '"'
end
diff --git a/Master/texmf-dist/tex/latex/latexconfig/lualatexquotejobname.tex b/Master/texmf-dist/tex/latex/latexconfig/lualatexquotejobname.tex
index 79b8b4bdba9..779ea32b5cb 100644
--- a/Master/texmf-dist/tex/latex/latexconfig/lualatexquotejobname.tex
+++ b/Master/texmf-dist/tex/latex/latexconfig/lualatexquotejobname.tex
@@ -1,34 +1,61 @@
% $Id$
% Manuel Pegourie-Gonnard, originally written 2010. WTFPL v2.
%
-% Quote \jobname if it contains spaces, similarly to what pdfTeX does.
+% Quote \jobname if it contains spaces, similarly to what other engines do.
%
% Recent versions of luatex kindly provide a process_jobname callback for
% this. Detect if it is available and use a fallback in pure TeX otherwise.
% If using the callback, register it at \everyjob time since callbacks are not
% dumped in formats currently.
%
-% The TeX version fails with "luatex '\input foo'" invocations, but it can
-% either support that or spaces in filenames, not both. This one is kept for
-% historical reasons.
+% The TeX version fails (jobname is set to texput) with invocations like
+% luatex '\input foo'
+% but work correctly with the following:
+% luatex foo\ bar
+% luatex -jobname foo\ bar '\input "foo bar"'
+% It is is not possible to support all this case without the callback. It is
+% debatable if supporting another set cases would be better, but this is the
+% historical (TL 2010) behaviour, so just keep it.
+%
+% \jobname quoting is normalized in the same way as in web2c's
+% normalize_quotes() function (see lib/texmfmp.c, non-XeTeX case), that is:
+% - remove quotes
+% - complain if quotes are not "balanced" (ie not in even number)
+% - enclose the result in quotes iff it contains spaces
%
% This file is inputed after latex.ltx.
%
\everyjob\expandafter{\the\everyjob
\ifcase\directlua{
tex.sprint(callback.list().process_jobname == nil and 0 or 1)}\relax
- % no callback, do what we can in TeX
- \begingroup
- \def\testsp#1 #2\relax{%
- \ifx\relax#2\relax
- \let\fixjobname\empty
- \else
- \edef\fixjobname{\def\noexpand\jobname{"\jobname"}}%
- \fi}%
- \edef\dotest{\noexpand\testsp\jobname\space\relax}\dotest
- \expandafter\endgroup\fixjobname
+ % no callback, do what we can in TeX
+ \begingroup \makeatletter
+ % strip quotes from job name and count them
+ \def\stripquotes#1"#2\@nil{%
+ \edef\clean{\clean#1}%
+ \ifx\empty#2\empty \else
+ \advance\count@\@ne
+ \stripquotes#2\@nil
+ \fi}%
+ \count@\z@
+ \def\clean{}%
+ \expandafter\stripquotes\jobname"\@nil
+ % complain if their was not an even ("balanced") number of quotes
+ \ifodd\count@
+ \errmessage{Unbalanced quotes in jobname: \jobname}%
+ \fi
+ % now check if their are spaces and quote if necessary
+ \def\testsp#1 #2\@nil{%
+ \ifx\empty#2\empty
+ \edef\fixjobname{\def\noexpand\jobname{\clean}}%
+ \else
+ \edef\fixjobname{\def\noexpand\jobname{"\clean"}}%
+ \fi}%
+ \edef\dotest{\noexpand\testsp\clean\space\relax}\dotest
+ % do it after closing the group
+ \expandafter\endgroup\fixjobname
\or % callback available, use it
- % put the function in a separate file for convenience (uses %, ~, etc)
- \directlua{dofile(assert(kpse.find_file("lualatexquotejobname.lua")))}
+ % function in a separate file for convenience (uses %, ~, etc)
+ \directlua{dofile(assert(kpse.find_file("lualatexquotejobname.lua")))}
\fi}
\endinput