diff options
Diffstat (limited to 'Master/texmf-dist/tex/latex/latexconfig/lualatexquotejobname.tex')
-rw-r--r-- | Master/texmf-dist/tex/latex/latexconfig/lualatexquotejobname.tex | 59 |
1 files changed, 43 insertions, 16 deletions
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 |