[latex3-commits] [git/LaTeX3-latex3-l3build] master: Heavily refactor typesetting functions (6dba1c2)

Joseph Wright joseph.wright at morningstar2.co.uk
Wed Jun 26 14:42:16 CEST 2019


Repository : https://github.com/latex3/l3build
On branch  : master
Link       : https://github.com/latex3/l3build/commit/6dba1c26494c2db678a66b1da59672a7889819e7

>---------------------------------------------------------------

commit 6dba1c26494c2db678a66b1da59672a7889819e7
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Wed Jun 26 13:42:04 2019 +0100

    Heavily refactor typesetting functions
    
    This is driven by #91, as we need a proper table for env vars, but there were wider issues as the code
    was only partly set up for typesetting in trees.
    Mumble
    
    
    Mumble
    
    
    Mumble


>---------------------------------------------------------------

6dba1c26494c2db678a66b1da59672a7889819e7
 CHANGELOG.md            |   4 +
 l3build-typesetting.lua | 194 ++++++++++++++++++++++--------------------------
 2 files changed, 91 insertions(+), 107 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5adace2..332ada9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,10 @@ this project uses date-based 'snapshot' version identifiers.
 
 ## [Unreleased]
 
+### Fixed
+
+- Support for spaces in paths when typesetting (see #91)
+
 ## [2019-06-18]
 
 ### Added
diff --git a/l3build-typesetting.lua b/l3build-typesetting.lua
index 3eb6452..a15b15b 100644
--- a/l3build-typesetting.lua
+++ b/l3build-typesetting.lua
@@ -26,8 +26,14 @@ for those people who are interested.
 -- Auxiliary functions for typesetting: need to be generally available
 --
 
-local gsub             = string.gsub
-local match            = string.match
+local ipairs = ipairs
+local pairs  = pairs
+local print  = print
+
+local gsub  = string.gsub
+local match = string.match
+
+local os_type = os.type
 
 function dvitopdf(name, dir, engine, hide)
   if match(engine, "^u?ptex$") then
@@ -51,37 +57,36 @@ function dvitopdf(name, dir, engine, hide)
 end
 
 -- An auxiliary used to set up the environmental variables
-function runtool(subdir, dir, envvar, command)
-  dir = dir or "."
-  return(
-    run(
-      typesetdir .. "/" .. subdir,
-      (forcedocepoch and setepoch() or "") ..
-      -- Allow for local texmf files
-      os_setenv .. " TEXMFCNF=." .. os_pathsep
-        .. os_concat ..
-      os_setenv .. " " .. envvar .. "=." .. os_pathsep
-        .. abspath(localdir) .. os_pathsep
-        .. abspath(dir .. "/" .. subdir)
-        .. (typesetsearch and os_pathsep or "")
-        .. os_concat ..
-      command
-    )
-  )
+local function runcmd(cmd,dir,vars)
+  local dir = dir or "."
+  local dir = abspath(dir)
+  local vars = vars or {}
+  -- Allow for local texmf files
+  local env = os_setenv .. " TEXMFCNF=." .. os_pathsep
+  local envpaths = "." .. os_pathsep
+    .. abspath(localdir) .. os_pathsep
+    .. dir .. (typesetsearch and os_pathsep or "")
+  -- Deal with spaces in paths
+  if os_type == "windows" and match(envpaths," ") then
+    envpaths = '"' .. gsub(envpaths,'"','') .. '"'
+  end
+  for _,var in pairs(vars) do
+    env = env .. os_concat .. os_setenv .. " " .. var .. "=" .. envpaths
+  end
+  return run(dir,(forcedocepoch and setepoch() or "") .. env .. os_concat . cmd)
 end
 
-function biber(name, dir)
-  if fileexists(typesetdir .. "/" .. name .. ".bcf") then
-    local path, name = splitpath(name)
-    return(
-      runtool(path, dir, "BIBINPUTS",  biberexe .. " " .. biberopts .. " " .. name)
-    )
+function biber(name,dir)
+  if fileexists(dir .. "/" .. name .. ".bcf") then
+    return
+      runcmd(biberexe .. " " .. biberopts .. " " .. name,dir,{"BIBINPUTS"})
   end
   return 0
 end
 
-function bibtex(name, dir)
-  if fileexists(typesetdir .. "/" .. name .. ".aux") then
+function bibtex(name,dir)
+  local dir = dir or "."
+  if fileexists(dir .. "/" .. name .. ".aux") then
     -- LaTeX always generates an .aux file, so there is a need to
     -- look inside it for a \citation line
     local grep
@@ -90,103 +95,76 @@ function bibtex(name, dir)
     else
      grep = "\\\\\\\\"
     end
-    local path, name = splitpath(name)
-    if run(
-        typesetdir,
+    if run(dir,
         os_grepexe .. " \"^" .. grep .. "citation{\" " .. name .. ".aux > "
           .. os_null
-      ) + run(
-        typesetdir,
+      ) + run(dir,
         os_grepexe .. " \"^" .. grep .. "bibdata{\" " .. name .. ".aux > "
           .. os_null
       ) == 0 then
-      return(
-        -- Cheat slightly as we need to set two variables
-        runtool(
-          path, dir,
-          "BIBINPUTS",
-          os_setenv .. " BSTINPUTS=." .. os_pathsep
-            .. abspath(localdir)
-            .. (typesetsearch and os_pathsep or "") ..
-          os_concat ..
-          bibtexexe .. " " .. bibtexopts .. " " .. name
-        )
-      )
+      return runcmd(bibtexexe .. " " .. bibtexopts .. " " .. name,dir,
+        {"BIBINPUTS","BSTINPUTS"})
     end
   end
   return 0
 end
 
-function makeindex(name, dir, inext, outext, logext, style)
-  if fileexists(typesetdir .. "/" .. name .. inext) then
-    local path, name = splitpath(name)
+function makeindex(name,dir,inext,outext,logext,style)
+  local dir = dir or "."
+  if fileexists(dir .. "/" .. name .. inext) then
     if style == "" then style = nil end
-    return(
-      runtool(
-        path, dir,
-        "INDEXSTYLE",
-        makeindexexe .. " " .. makeindexopts
-          .. " -o " .. name .. outext
-          .. (style and (" -s " .. style) or "")
-          .. " -t " .. name .. logext .. " "  .. name .. inext
-      )
-    )
+    return runcmd(makeindexexe .. " " .. makeindexopts
+      .. " -o " .. name .. outext
+      .. (style and (" -s " .. style) or "")
+      .. " -t " .. name .. logext .. " "  .. name .. inext,
+      dir,
+      {"INDEXSTYLE"})
   end
   return 0
 end
 
-function tex(file, dir)
-  local path, name = splitpath(file)
-  return(
-    runtool(
-      path, dir,
-      "TEXINPUTS",
-      typesetexe .. " " .. typesetopts .. " \"" .. typesetcmds
-        .. "\\input " .. name .. "\""
-    )
-  )
+function tex(file,dir)
+  local dir = dir or "."
+  return runcmd(typesetexe .. " " .. typesetopts .. " \"" .. typesetcmds
+    .. "\\input " .. file .. "\"",
+    dir,{"TEXINPUTS"})
 end
 
-function typesetpdf(file, dir)
-  local name = gsub(file, "%.[^.]+$", "")
+local function typesetpdf(file,dir)
+  local dir = dir or "."
+  local name = jobname(file)
   print("Typesetting " .. name)
-  local errorlevel = typeset(file, dir)
-  if errorlevel == 0 then
-    name = name .. ".pdf"
-    rm(docfiledir,name)
-    cp(name, typesetdir, docfiledir)
-  else
+  local errorlevel = typeset(file,dir)
+  if errorlevel ~= 0 then
     print(" ! Compilation failed")
+    return errorlevel
   end
-  return errorlevel
+  pdfname = name .. pdfext
+  rm(docfiledir,pdfname)
+  return cp(pdfname,dir,docfiledir)
 end
 
-typeset = typeset or function(file, dir)
+typeset = typeset or function(file,dir)
   dir = dir or "."
-  local errorlevel = tex(file, dir)
+  local errorlevel = tex(file,dir)
   if errorlevel ~= 0 then
     return errorlevel
-  else
-    local name = jobname(file)
-    errorlevel = biber(name, dir) + bibtex(name, dir)
-    if errorlevel == 0 then
-      local function cycle(name, dir)
-        return(
-          makeindex(name, dir, ".glo", ".gls", ".glg", glossarystyle) +
-          makeindex(name, dir, ".idx", ".ind", ".ilg", indexstyle)    +
-          tex(file, dir)
-        )
-      end
-      for i = 1, typesetruns do
-        errorlevel = cycle(name, dir)
-        if errorlevel ~= 0 then break end
-      end
-    end
+  end
+  local name = jobname(file)
+  errorlevel = biber(name,dir) + bibtex(name,dir)
+  if errorlevel ~= 0 then
     return errorlevel
   end
+  for i = 2,typesetruns do
+    errorlevel =
+      makeindex(name,dir,".glo",".gls",".glg",glossarystyle) +
+      makeindex(name,dir,".idx",".ind",".ilg",indexstyle)    +
+      tex(file,dir)
+    if errorlevel ~= 0 then break end
+  end
+  return errorlevel
 end
 
-
 -- A hook to allow additional typesetting of demos
 typeset_demo_tasks = typeset_demo_tasks or function()
   return 0
@@ -213,34 +191,36 @@ function doc(files)
   depinstall(typesetdeps)
   unpack({sourcefiles, typesetsourcefiles}, {sourcefiledir, docfiledir})
   -- Main loop for doc creation
-  local done = {}
   local errorlevel = typeset_demo_tasks()
   if errorlevel ~= 0 then
     return errorlevel
   end
-  for _, typesetfiles in ipairs({typesetdemofiles, typesetfiles}) do
-    for _,i in ipairs(typesetfiles) do
-      for _, dir in ipairs({unpackdir, typesetdir}) do
-        for j,_ in pairs(tree(dir, i)) do
-          if not done[j] then
-            j = gsub(j, "^%./", "")
-            -- Allow for command line selection of files
+  local done = {}
+  for _,typesetfiles in ipairs({typesetdemofiles,typesetfiles}) do
+    for _,glob in pairs(typesetfiles) do
+      for _,dir in ipairs({typesetdir,unpackdir}) do
+        for _,file in pairs(tree(dir,glob)) do
+          local path,srcname = splitpath(file)
+          local name = jobname(srcname)
+          if not done[name] then
             local typeset = true
+            -- Allow for command line selection of files
             if files and next(files) then
               typeset = false
-              for _,k in ipairs(files) do
-                if k == gsub(j, "%.[^.]+$", "") then
+              for _,file in pairs(files) do
+                if name == file then
                   typeset = true
                   break
                 end
               end
             end
+            -- Now know if we should typeset this source
             if typeset then
-              local errorlevel = typesetpdf(j, dir)
+              local errorlevel = typesetpdf(srcname,path)
               if errorlevel ~= 0 then
                 return errorlevel
               else
-                done[j] = true
+                done[name] = true
               end
             end
           end





More information about the latex3-commits mailing list