From 962840188681e1d6f4aec0ebf07e05a70609325d Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sun, 29 Apr 2018 23:01:08 +0000 Subject: lwarp (26apr18) git-svn-id: svn://tug.org/texlive/trunk@47491 c570f23f-e606-0410-a88d-b1316a301751 --- .../texk/texlive/linked_scripts/lwarp/lwarpmk.lua | 155 ++++++++++++++++----- 1 file changed, 121 insertions(+), 34 deletions(-) (limited to 'Build') diff --git a/Build/source/texk/texlive/linked_scripts/lwarp/lwarpmk.lua b/Build/source/texk/texlive/linked_scripts/lwarp/lwarpmk.lua index c372f67f629..4baee4dd05e 100755 --- a/Build/source/texk/texlive/linked_scripts/lwarp/lwarpmk.lua +++ b/Build/source/texk/texlive/linked_scripts/lwarp/lwarpmk.lua @@ -4,7 +4,7 @@ -- Print the usage of the lwarpmk command: -printversion = "v0.53" +printversion = "v0.55" function printhelp () print ("lwarpmk: Use lwarpmk -h or lwarpmk --help for help.") ; @@ -49,8 +49,10 @@ sourcename = "projectname" (the source-code filename w/o .tex) homehtmlfilename = "index" (or perhaps the project name) htmlfilename = "" (or "projectname" - filename prefix) latexmk = "false" (or "true" to use latexmk to build PDFs) -languge = "english" (use a language supported by xindy) -xdyfile = "lwarp.xdy" (or a custom file based on lwarp.xdy) +xindylanguge = "english" (use a language supported by xindy) +xindycodepage = "utf8" (use a codepage supported by xindy) +xindystyle = "lwarp.xdy" (or a custom file based on lwarp.xdy) +pdftotextenc = "UTF-8" (use an encoding supported by pdftotext) -- Filenames must contain only letters, numbers, underscore, or dash. Values must be in "quotes". @@ -97,17 +99,24 @@ function loadconf () local conffile = "lwarpmk.conf" -- Optional configuration filename: if ( arg[2] ~= nil ) then conffile = arg[2]..".lwarpmkconf" end --- Default language: -language = "english" --- Default xdyfile: -xdyfile = "lwarp.xdy" +-- Default xindy language: +xindylanguage = "english" +-- Default xindy codepage: +xindycodepage = "utf8" +-- Default xindystyle: +xindystyle = "lwarp.xdy" +-- Default pdftotext encoding: +pdftotextenc = "UTF-8" -- Verify the file exists: if (lfs.attributes(conffile,"mode")==nil) then -- file not exists print ("lwarpmk: ===") - print ("lwarpmk: " .. conffile .." does not exist.") + print ("lwarpmk: File \"" .. conffile .."\" does not exist.") + print ("lwarpmk: Move to the project's source directory,") + print ("lwarpmk: recompile using pdflatex, xelatex, or lualatex,") + print ("lwarpmk: then try using lwarpmk again.") if ( arg[2] ~= nil ) then - print ("lwarpmk: " .. arg[2] .. " does not appear to be a project name.\n") + print ("lwarpmk: (\"" .. arg[2] .. "\" does not appear to be a project name.)") end print ("lwarpmk: ===") printhelp () ; @@ -152,8 +161,10 @@ elseif ( cvarname == "sourcename" ) then sourcename = cvalue elseif ( cvarname == "homehtmlfilename" ) then homehtmlfilename = cvalue elseif ( cvarname == "htmlfilename" ) then htmlfilename = cvalue elseif ( cvarname == "latexmk" ) then latexmk = cvalue -elseif ( cvarname == "language" ) then language = cvalue -elseif ( cvarname == "xdyfile" ) then xdyfile = cvalue +elseif ( cvarname == "xindylanguage" ) then xindylanguage = cvalue +elseif ( cvarname == "xindycodepage" ) then xindycodepage = cvalue +elseif ( cvarname == "xindystyle" ) then xindystyle = cvalue +elseif ( cvarname == "pdftotextenc" ) then pdftotextenc = cvalue else print ("lwarpmk: ===") print ("lwarpmk: " .. linenum .. " : " .. line ) ; @@ -207,13 +218,13 @@ elseif opsystem=="Windows" then -- For Windows else print ( "lwarpmk: Select Unix or Windows for opsystem" ) end --- for Windows --- set xindycmd according to pdflatex vs xelatex/lualatex: +-- set xindycmd, glossarycmd according to pdflatex vs xelatex/lualatex: if ( latexname == "pdflatex" ) then - xindycmd = "texindy -C utf8" - glossarycmd = "xindy -C utf8" + xindycmd = "texindy " + glossarycmd = "xindy " else - xindycmd = "xindy -M texindy -C utf8" - glossarycmd = "xindy -C utf8" + xindycmd = "xindy -M texindy " + glossarycmd = "xindy " end end -- loadconf @@ -282,7 +293,7 @@ function pdftohtml () -- Convert to text: print ("lwarpmk: Converting " .. sourcename .."_html.pdf to " .. sourcename .. "_html.html") -os.execute("pdftotext -enc UTF-8 -nopgbrk -layout " +os.execute("pdftotext -enc " .. pdftotextenc .. " -nopgbrk -layout " .. sourcename .. "_html.pdf " .. sourcename .. "_html.html") -- Split the result into individual HTML files: splitfile (homehtmlfilename .. ".html" , sourcename .. "_html.html") @@ -303,33 +314,96 @@ os.execute ( rmname .. " *.aux " .. ) end --- Create lateximages based on lateximages.txt: -function createlateximages () -print ("lwarpmk: Creating lateximages.") -local limagesfile = io.open("lateximages.txt", "r") -if ( limagesfile == nil ) then +-- Error if the HTML document does not exist. +-- The lateximages are drawn from the HTML PDF verison of the document, +-- so "lwarpmk html" must be done before "lwarpmk limages". +function checkhtmlpdfexists () +local htmlpdffile = io.open(sourcename .. "_html.pdf", "r") +if ( htmlpdffile == nil ) then + print ("") + print ("lwarpmk: ===") + print ("lwarpmk: The HTML version of the document does not exist.") + print ("lwarpmk: Enter \"lwarpmk html\" to compile the HTML version.") + print ("lwarpmk: ===") + os.exit(1) +end +io.close (htmlpdffile) +end -- checkhtmlpdfexists + +-- Warning of a missing lateximages.txt file: +function warnlimages () print ("lwarpmk: ===") print ("lwarpmk: \"lateximages.txt\" does not exist.") print ("lwarpmk: Your project does not use SVG math or other lateximages,") print ("lwarpmk: or the file has been deleted somehow.") - print ("lwarpmk: Use \"lwarpmk html\" to recompile your project,") + print ("lwarpmk: Use \"lwarpmk html\" to recompile your project") print ("lwarpmk: and recreate \"lateximages.txt\".") print ("lwarpmk: If your project does not use SVG math or other lateximages,") print ("lwarpmk: then \"lateximages.txt\" will never exist, and") print ("lwarpmk: \"lwarpmk limages\" will not be necessary.") print ("lwarpmk: ===") +end -- warnlimages + +-- Check lateximages.txt to see if need to recompile first. +-- If any entry has a page number of zero, then there were incorrect images. +function checklimages () +print ("lwarpmk: Checking for a valid lateximages.txt file.") +local limagesfile = io.open("lateximages.txt", "r") +if ( limagesfile == nil ) then + warnlimages () + os.exit(1) +end +-- Track warning to recompile if find a page 0 +local pagezerowarning = false +-- Scan lateximages.txt +for line in limagesfile:lines() do + -- lwimgpage is the page number in the PDF which has the image + -- lwimghash is true if this filename is a hash + -- lwimgname is the lateximage filename root to assign for the image + i,j,lwimgpage,lwimghash,lwimgname = string.find (line,"|(.*)|(.*)|(.*)|") + -- For each entry: + if ( (i~=nil) ) then + -- If the page number is 0, image references are incorrect + -- and must recompile the soure document: + if ( lwimgpage == "0" ) then + pagezerowarning = true + end + end -- if i~=nil +end -- do +if ( pagezerowarning ) then + print ("") + print ("lwarpmk: ===") + print ("lwarpmk: The document must be recompiled before creating the lateximages.") + print ("lwarpmk: Enter \"lwarpmk html\" again, then try \"lwarpmk limages\" again.") + print ("lwarpmk: ===") + os.exit(1) ; +end -- pagezerowarning +end -- checklateximages + +-- Create lateximages based on lateximages.txt: +function createlateximages () +-- See if the document must be recompiled first: +checklimages () +-- See if the print version exists: +checkhtmlpdfexists () +-- Attempt to create the lateximages: +print ("lwarpmk: Creating lateximages.") +local limagesfile = io.open("lateximages.txt", "r") +if ( limagesfile == nil ) then + warnlateximages () os.exit(1) end -- Create the lateximages directory, ignore error if already exists err = os.execute("mkdir lateximages") --- For Windows, create lwarp_one_limage.cmd: +-- For Windows, create lwarp_one_limage.cmd from lwarp_one_limage.txt: if opsystem=="Windows" then err = os.execute ( cpname .. " lwarp_one_limage.txt lwarp_one_limage.cmd" ) if ( err ~= 0 ) then print ("lwarpmk: ===") - print ("lwarpmk: File error trying to copy to lwarp_one_limage.cmd") + print ("lwarpmk: File error trying to copy") + print (" lwarp_one_limage.txt to lwarp_one_limage.cmd") print ("lwarpmk: ===") os.exit(1) ; end @@ -429,6 +503,10 @@ end -- not page 0 end -- not nil end -- do io.close(limagesfile) +print ( "lwarpmk limages: ===") +print ( "lwarpmk limages: Wait a moment for the images to complete" ) +print ( "lwarpmk limages: before reloading the page." ) +print ( "lwarpmk limages: ===") print ( "lwarpmk limages: done" ) if ( pagezerowarning == true ) then print ( "lwarpmk limages: WARNING: Images will be incorrect." ) @@ -448,8 +526,9 @@ err=os.execute ( "latexmk -pdf -dvi- -ps- -recorder " .. opquote .. "$makeindex = q/" -- $ .. xindycmd - .. " -M " .. xdyfile - .. " -L " .. language .. " /" + .. " -M " .. xindystyle + .. " -C " .. xindycodepage + .. " -L " .. xindylanguage .. " /" .. opquote .. " -pdflatex=\"" .. latexname .." %O %S\" " .. sourcename..fsuffix ..".tex" ) ; @@ -512,8 +591,9 @@ loadconf () print ("lwarpmk: Processing the index.") os.execute( xindycmd - .. " -M " .. xdyfile - .. " -L " .. language + .. " -M " .. xindystyle + .. " -C " .. xindycodepage + .. " -L " .. xindylanguage .. " " .. sourcename .. ".idx") print ("lwarpmk: Forcing an update of " .. sourcename ..".tex.") refreshdate () @@ -528,7 +608,10 @@ elseif arg[1] == "printglossary" then loadconf () print ("lwarpmk: Processing the glossary.") -os.execute(glossarycmd .. " -L " .. language .. " -I xindy -M " .. sourcename .. +os.execute(glossarycmd .. + " -L " .. xindylanguage .. + " -C " .. xindycodepage .. + " -I xindy -M " .. sourcename .. " -t " .. sourcename .. ".glg -o " .. sourcename .. ".gls " .. sourcename .. ".glo") print ("lwarpmk: Forcing an update of " .. sourcename ..".tex.") @@ -583,8 +666,9 @@ loadconf () print ("lwarpmk: Processing the index.") os.execute( xindycmd - .. " -M " .. xdyfile - .. " -L " .. language + .. " -M " .. xindystyle + .. " -L " .. xindylanguage + .. " -C " .. xindycodepage .. " " .. sourcename .. "_html.idx" ) print ("lwarpmk: Forcing an update of " .. sourcename ..".tex.") @@ -600,7 +684,10 @@ elseif arg[1] == "htmlglossary" then loadconf () print ("lwarpmk: Processing the glossary.") -os.execute(glossarycmd .. " -L " .. language .. " -I xindy -M " ..sourcename .. +os.execute(glossarycmd .. + " -L " .. xindylanguage .. + " -C " .. xindycodepage .. + " -I xindy -M " ..sourcename .. "_html -t " .. sourcename .. "_html.glg -o " ..sourcename .. "_html.gls " ..sourcename .. "_html.glo") @@ -668,8 +755,8 @@ elseif (arg[1] == "-h" ) or (arg[1] == "--help") then printusage () else -print ("lwarpmk: Unknown command \""..arg[1].."\".\n") printhelp () +print ("\nlwarpmk: ****** Unknown command \""..arg[1].."\". ******\n") end end -- not --version -- cgit v1.2.3