summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/latexconfig/lualatexquotejobname.tex
blob: bf70bad24caaa8dca4e6b69f47b2608852f1c255 (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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
% $Id$
% Manuel Pegourie-Gonnard, originally written 2010. WTFPL v2.
%
% Quote \jobname if it contains spaces, similarly to what pdfTeX does.
%
% 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.
%
% 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
  \or % callback available, use it
  \directlua{
    callback.register('process_jobname', function(jobname)
      if jobname:find(' ') then
        return '"' .. jobname .. '"'
      else
        return jobname
      end
    end)}
  \fi}
\endinput