Debian Codegraph @

texk/texlive/linked_scripts/lwarp/lwarpmk.lua

raw symbols SCIP
1 #!/usr/bin/env texlua
2
3 -- Copyright 2016-2026 Brian Dunn
4
5 printversion = "v0.921"
6 requiredconfversion = "2" -- also at *lwarpmk.conf
7
8 function printhelp ()
9 print ("lwarpmk: Use lwarpmk -h or lwarpmk --help for help.") ;
10 end
11
12 function printusage ()
13 --
14 -- Print the usage of the lwarpmk command:
15 --
16 print ( [[
17
18 lwarpmk print [-p project]: Compile the print version if necessary.
19 lwarpmk print1 [-p project]: Forced single compile of the print version.
20 lwarpmk printindex [-p project]: Process print indexes.
21 lwarpmk printglossary [-p project]: Process the glossary for the print version.
22 lwarpmk html [-p project]: Compile the HTML version if necessary.
23 lwarpmk html1 [-p project]: Forced single compile of the HTML version.
24 lwarpmk htmlindex [-p project]: Process HTML indexes.
25 lwarpmk htmlglossary [-p project]: Process the glossary for the html version.
26 lwarpmk again [-p project]: Touch the source code to trigger recompiles.
27 lwarpmk limages [-p project]: Process the "lateximages" created by lwarp.sty.
28 lwarpmk pdftohtml [-p project]:
29 For use with latexmk or a Makefile:
30 Converts project_html.pdf to project_html.html and individual HTML files.
31 Finishes the HTML conversion even if there was a compile error.
32 lwarpmk pdftosvg <list of file names>: Converts each PDF file to SVG.
33 lwarpmk epstopdf <list of file names>: Converts each EPS file to PDF.
34 lwarpmk clean [-p project]: Remove *.aux, *.toc, *.lof/t,
35 *.idx, *.ind, *.bbl, *.log, *_html_inc.*, .gl*,
36 *_html.pdf, *_html.html, *_html.sidetoc
37 lwarpmk cleanall [-p project]: Remove auxiliary files, project.pdf, *.html
38 lwarpmk cleanlimages: Removes all images from the "lateximages" directory.
39 lwarpmk -v: Print the version number.
40 lwarpmk -h: Print this help message.
41 lwarpmk --help: Print this help message.
42
43 ]] )
44 -- printconf ()
45 end
46
47 function splitfilename ( pathandfilename )
48 --
49 -- Separates out the path and extension from a filename.
50 -- Returns path, filename with extension, and extension.
51 -- Ex: thispath, thisfilename, thisextension = splitfilename ("path/to/filename.ext")
52 --
53 -- https://www.fhug.org.uk/wiki/wiki/doku.php?id=plugins:code_snippets:
54 -- split_filename_in_to_path_filename_and_extension
55 --
56 if lfs.attributes(pathandfilename,"mode") == "directory" then
57 local strPath = pathandfilename:gsub("[\\/]$","") -- $ (syntax highlighting)
58 return strPath.."\\","",""
59 end
60 pathandfilename = pathandfilename.."."
61 return pathandfilename:match("^(.-)([^\\/]-)%.([^\\/%.]-)%.?$")
62 end
63
64 function splitfile (destfile,sourcefile)
65 --
66 -- Split one large sourcefile into a number of files,
67 -- starting with destfile.
68 -- The file is split at each occurance of <!--|Start file|newfilename|*
69 -- If lwarp is in use, sets usinglwarp.
70 --
71 usinglwarp = false ;
72 print ("lwarpmk: Splitting " .. sourcefile .. " into " .. destfile) ;
73 local sfile = io.open(sourcefile)
74 io.output(destfile)
75 for line in sfile:lines() do
76 i,j,copen,cstart,newfilename = string.find (line,"(.*)|(.*)|(.*)|") ;
77 if ( (i~= nil) and (copen == "<!--") and (cstart == "Start file")) then
78 -- split the file
79 io.output(newfilename) ;
80 else
81 if ( (i~= nil) and (copen == "<!--") and (cstart == "Using lwarp")) then
82 -- verified the use of \usepackage{lwarp}
83 usinglwarp = true ;
84 else
85 -- not a splitpoint
86 io.write (line .. "\n") ;
87 end end
88 end -- do
89 io.close(sfile)
90 if ( usinglwarp == false ) then
91 print ("lwarpmk: ===")
92 print ("lwarpmk: \\usepackage{lwarp} was not detected,")
93 print ("lwarpmk: or option warpdisable was used.")
94 print ("lwarpmk: The HTML output will not be correct,")
95 print ("lwarpmk: and references may be undefined.")
96 print ("lwarpmk: Ensured that \\usepackage{lwarp} is enabled,")
97 print ("lwarpmk: then lwarpmk print and lwarpmk html again.")
98 print ("lwarpmk: ===")
99 end
100 end -- function
101
102 function cvalueerror ( line, linenum , cvalue )
103 --
104 -- Incorrect value, so print an error and exit.
105 --
106 print ("lwarpmk: ===")
107 print ("lwarpmk: " .. linenum .. " : " .. line ) ;
108 print (
109 "lwarpmk: incorrect variable value \"" .. cvalue ..
110 "\" in lwarpmk.conf.\n"
111 ) ;
112 print ("lwarpmk: ===")
113 -- printconf () ;
114 os.exit(1) ;
115 end
116
117 function printhowtorecompile ()
118 -- Tells the user how to recompile to regenerate the configuration files.
119 print ("lwarpmk: The configuration files lwarpmk.conf and "..sourcename..".lwarpmkconf" )
120 print ("lwarpmk: must be updated. To do so, recompile" )
121 print ("lwarpmk: " , sourcename..".tex" )
122 if ( printlatexcmd == "" ) then
123 print ("lwarpmk: using xe/lua/pdflatex," )
124 else
125 print ("lwarpmk: using the command:")
126 print ("lwarpmk: " , printlatexcmd )
127 end
128 print ("lwarpmk: then use lwarpmk again.")
129 end -- printhowtorecompile
130
131 function ignoreconf ()
132 -- Global argument index
133 argindex = 2
134 end
135
136 function loadconf ()
137 --
138 -- Load settings from the project's "lwarpmk.conf" file:
139 --
140 -- Default configuration filename:
141 local conffile = "lwarpmk.conf"
142 local confroot = "lwarpmk"
143 -- Global argument index
144 argindex = 2
145 -- Optional configuration filename:
146 if ( arg[argindex] == "-p" ) then
147 argindex = argindex + 1
148 confroot = arg[argindex]
149 conffile = confroot..".lwarpmkconf"
150 argindex = argindex + 1
151 end
152 -- Additional defaults:
153 confversion = "0"
154 opsystem = "Unix"
155 imagesdirectory = "lateximages"
156 imagesname = "image-"
157 latexmk = "false"
158 printlatexcmd = ""
159 HTMLlatexcmd = ""
160 printindexcmd = ""
161 HTMLindexcmd = ""
162 latexmkindexcmd = ""
163 -- to be removed:
164 -- indexprog = "makeindex"
165 -- makeindexstyle = "lwarp.ist"
166 -- xindylanguage = "english"
167 -- xindycodepage = "utf8"
168 -- xindystyle = "lwarp.xdy"
169 -- pdftotextenc = "UTF-8"
170 glossarycmd = "makeglossaries"
171 -- Verify the file exists:
172 if (lfs.attributes(conffile,"mode")==nil) then
173 -- file not exists
174 print ("lwarpmk: ===")
175 print ("lwarpmk: File \"" .. conffile .."\" does not exist.")
176 print ("lwarpmk: Move to the project's source directory,")
177 print ("lwarpmk: recompile using pdflatex, xelatex, or lualatex,")
178 print ("lwarpmk: then try using lwarpmk again.")
179 if ( arg[argindex] ~= nil ) then
180 print (
181 "lwarpmk: (\"" .. confroot ..
182 "\" does not appear to be a project name.)"
183 )
184 end
185 print ("lwarpmk: ===")
186 printhelp () ;
187 os.exit(1) -- exit the entire lwarpmk script
188 else -- file exists
189 -- Read the file:
190 print ("lwarpmk: Reading " .. conffile ..".")
191 local cfile = io.open(conffile)
192 -- Scan each line, parsing each line as: name = [[string]]
193 local linenum = 0
194 for line in cfile:lines() do -- scan lines
195 linenum = linenum + 1
196 i,j,cvarname,cvalue = string.find (line,"([%w-_]*)%s*=%s*%[%[([^%]]*)%]%]") ;
197 -- Error if incorrect enclosing characters:
198 if ( i == nil ) then
199 print ("lwarpmk: ===")
200 print ("lwarpmk: " .. linenum .. " : " .. line ) ;
201 print ("lwarpmk: Incorrect entry in " .. conffile ..".\n" ) ;
202 print ("lwarpmk: ===")
203 -- printconf () ;
204 os.exit(1) ;
205 end -- nil
206 if ( cvarname == "confversion" ) then
207 confversion = cvalue
208 elseif ( cvarname == "opsystem" ) then
209 -- Verify choice of opsystem:
210 if ( (cvalue == "Unix") or (cvalue == "Windows") ) then
211 opsystem = cvalue
212 else
213 cvalueerror ( line, linenum , cvalue )
214 end
215 elseif ( cvarname == "sourcename" ) then sourcename = cvalue
216 elseif ( cvarname == "homehtmlfilename" ) then homehtmlfilename = cvalue
217 elseif ( cvarname == "htmlfilename" ) then htmlfilename = cvalue
218 elseif ( cvarname == "imagesdirectory" ) then imagesdirectory = cvalue
219 elseif ( cvarname == "imagesname" ) then imagesname = cvalue
220 elseif ( cvarname == "latexmk" ) then latexmk = cvalue
221 elseif ( cvarname == "printlatexcmd" ) then printlatexcmd = cvalue
222 elseif ( cvarname == "HTMLlatexcmd" ) then HTMLlatexcmd = cvalue
223 elseif ( cvarname == "printindexcmd" ) then printindexcmd = cvalue
224 elseif ( cvarname == "HTMLindexcmd" ) then HTMLindexcmd = cvalue
225 elseif ( cvarname == "latexmkindexcmd" ) then latexmkindexcmd = cvalue
226 elseif ( cvarname == "glossarycmd" ) then glossarycmd = cvalue
227 elseif ( cvarname == "pdftotextenc" ) then pdftotextenc = cvalue
228 else
229 print ("lwarpmk: ===")
230 print ("lwarpmk: " .. linenum .. " : " .. line ) ;
231 print (
232 "lwarpmk: Incorrect variable name \"" .. cvarname .. "\" in " ..
233 conffile ..".\n"
234 ) ;
235 print ("lwarpmk: ===")
236 -- printconf () ;
237 os.exit(1) ;
238 end -- cvarname
239 end -- do scan lines
240 io.close(cfile)
241 end -- file exists
242 -- Error if sourcename is "lwarp".
243 -- This could happen if a local copy of lwarp has recently been recompiled.
244 if sourcename=="lwarp" then
245 print ("lwarpmk: ===")
246 print ("lwarpmk: lwarp.sty has recently been recompiled in this directory,")
247 print ("lwarpmk: and \"lwarpmk.conf\" is no longer set for your own project.")
248 print ("lwarpmk: (Perhaps you are not in your project's directory?)")
249 print ("lwarpmk: In your project directory, recompile your project")
250 print ("lwarpmk: using pdf/lua/xelatex <projectname>.")
251 print ("lwarpmk: After a recompile, \"lwarpmk.conf\" will be set for your project,")
252 print ("lwarpmk: and you may again use lwarpmk.")
253 print ("lwarpmk: ===")
254 os.exit(1)
255 end -- sourcename of "lwarp"
256 -- Select some operating-system commands:
257 if opsystem=="Unix" then -- For Unix / Linux / Mac OS:
258 rmname = "rm"
259 mvname = "mv"
260 cpname = "cp"
261 touchnamepre = "touch"
262 touchnamepost = ""
263 newtouchname = "touch"
264 dirslash = "/"
265 opquote= "\'"
266 cmdgroupopenname = " ( "
267 cmdgroupclosename = " ) "
268 seqname = " && "
269 bgname = " &"
270 elseif opsystem=="Windows" then -- For Windows
271 rmname = "DEL"
272 mvname = "MOVE"
273 cpname = "COPY"
274 touchnamepre = "COPY /b"
275 touchnamepost = "+,,"
276 newtouchname = "echo empty >"
277 dirslash = "\\"
278 opquote= "\""
279 cmdgroupopenname = ""
280 cmdgroupclosename = ""
281 seqname = " & "
282 bgname = ""
283 else
284 print ("lwarpmk: ===")
285 print ("lwarpmk: Select Unix or Windows for opsystem." )
286 print ("lwarpmk: ===")
287 os.exit(1)
288 end --- for Windows
289 -- Warning if the operating system does not appear to be correct,
290 -- in case files were transferred to another system.
291 if ( (package.config:sub(1,1)) ~= dirslash ) then
292 print ("lwarpmk: ===")
293 print ("lwarpmk: It appears that lwarpmk.conf is for a different operating system." )
294 printhowtorecompile ()
295 print ("lwarpmk: ===")
296 os.exit(1)
297 end
298 -- Error if the configuration file's version is not current:
299 if ( confversion ~= requiredconfversion ) then
300 print ("lwarpmk: ===")
301 printhowtorecompile ()
302 print ("lwarpmk: ===")
303 os.exit(1)
304 end
305 end -- loadconf
306
307 function executecheckerror ( executecommands , errormessage )
308 --
309 -- Execute an operating system call,
310 -- and maybe exit with an error message.
311 --
312 local err
313 err = os.execute ( executecommands )
314 if ( err ~= 0 ) then
315 print ("lwarpmk: ===")
316 print ("lwarpmk: " .. errormessage )
317 print ("lwarpmk: ===")
318 os.exit(1)
319 end
320 end -- executecheckerror
321
322 function refreshdate ()
323 os.execute(touchnamepre .. " " .. sourcename .. ".tex " .. touchnamepost)
324 end
325
326 function reruntoget (filesource)
327 --
328 -- Scan the LaTeX log file for the phrase "Rerun to get",
329 -- indicating that the file should be compiled again.
330 -- Return true if found.
331 --
332 local fsource = io.open(filesource)
333 for line in fsource:lines() do
334 if ( string.find(line,"Rerun to get") ~= nil ) then
335 io.close(fsource)
336 return true
337 end -- if
338 end -- do
339 io.close(fsource)
340 return false
341 end
342
343 function onetime (latexcmd, fsuffix)
344 --
345 -- Compile one time, return true if should compile again.
346 -- fsuffix is "" for print, "_html" for HTML output.
347 --
348 print("lwarpmk: Compiling with: " .. latexcmd)
349 executecheckerror (
350 latexcmd ,
351 "Compile error."
352 )
353 return (reruntoget(sourcename .. fsuffix .. ".log") ) ;
354 end
355
356 function manytimes (latexcmd, fsuffix)
357 --
358 -- Compile up to five times.
359 -- fsuffix is "" for print, "_html" for HTML output
360 --
361 if onetime(latexcmd, fsuffix) == true then
362 if onetime(latexcmd, fsuffix) == true then
363 if onetime(latexcmd, fsuffix) == true then
364 if onetime(latexcmd, fsuffix) == true then
365 if onetime(latexcmd, fsuffix) == true then
366 end end end end end
367 end
368
369 function verifyfileexists (filename)
370 --
371 -- Exit if the given file does not exist.
372 --
373 if (lfs.attributes ( filename , "modification" ) == nil ) then
374 print ("lwarpmk: ===")
375 print ("lwarpmk: " .. filename .. " not found." ) ;
376 print ("lwarpmk: ===")
377 os.exit (1) ;
378 end
379 end
380
381 function pdftohtml ()
382 --
383 -- Convert <project>_html.pdf into HTML files:
384 --
385 -- Convert to text:
386 print ("lwarpmk: Converting " .. sourcename
387 .."_html.pdf to " .. sourcename .. "_html.html")
388 err = os.execute("pdftotext -enc " .. pdftotextenc .. " -nopgbrk -layout "
389 .. sourcename .. "_html.pdf " .. sourcename .. "_html.html")
390 if ( err ~= 0 ) then
391 print ("lwarpmk: ===")
392 print ("lwarpmk: Ensure that the Poppler utilities are installed." )
393 print ("lwarpmk: See the Lwarp manual: `Installing additional utilities'." )
394 print ("lwarpmk: ===")
395 os.exit(1)
396 end
397 -- Split the result into individual HTML files:
398 splitfile (homehtmlfilename .. ".html" , sourcename .. "_html.html")
399 end
400
401 function removeaux ()
402 --
403 -- Remove auxiliary files:
404 -- All .aux files are removed since there may be many bbl*.aux files.
405 -- Also removes sourcename_html.pdf, sourcename_html.html,
406 -- and sourcename_html.sidetoc, plus comment_*.cut.
407 --
408 os.execute ( rmname .. " *.aux " ..
409 sourcename ..".toc " .. sourcename .. "_html.toc " ..
410 sourcename ..".lof " .. sourcename .. "_html.lof " ..
411 sourcename ..".lot " .. sourcename .. "_html.lot " ..
412 sourcename ..".bbl " .. sourcename .. "_html.bbl " ..
413 " *.idx " ..
414 " *.ind " ..
415 sourcename ..".ps " .. sourcename .."_html.ps " ..
416 sourcename ..".log " .. sourcename .. "_html.log " ..
417 sourcename ..".gl* " .. sourcename .. "_html.gl* " ..
418 sourcename .. "_html.pdf " ..
419 sourcename .. "_html.html " ..
420 sourcename .. "_html.sidetoc " ..
421 " *_html_inc.* " ..
422 " comment_*.cut"
423 )
424 end
425
426 function checkhtmlpdfexists ()
427 --
428 -- Error if the HTML document does not exist.
429 -- The lateximages are drawn from the HTML PDF version of the document,
430 -- so "lwarpmk html" must be done before "lwarpmk limages".
431 --
432 local htmlpdffile = io.open(sourcename .. "_html.pdf", "r")
433 if ( htmlpdffile == nil ) then
434 print ("")
435 print ("lwarpmk: ===")
436 print ("lwarpmk: The HTML version of the document does not exist.")
437 print ("lwarpmk: Enter \"lwarpmk html\" to compile the HTML version.")
438 print ("lwarpmk: ===")
439 os.exit(1)
440 end
441 io.close (htmlpdffile)
442 end -- checkhtmlpdfexists
443
444 function warnlimages ()
445 --
446 -- Warning of a missing <sourcename>-images.txt file:
447 print ("lwarpmk: ===")
448 print ("lwarpmk: \"" .. sourcename .. "-images.txt\" does not exist.")
449 print ("lwarpmk: Your project does not use SVG math or other lateximages,")
450 print ("lwarpmk: or the file has been deleted somehow.")
451 print ("lwarpmk: Use \"lwarpmk html1\" to recompile your project")
452 print ("lwarpmk: and recreate \"" .. sourcename .. "-images.txt\".")
453 print ("lwarpmk: If your project does not use SVG math or other lateximages,")
454 print ("lwarpmk: then \"" .. sourcename .. "-images.txt\" will never exist, and")
455 print ("lwarpmk: \"lwarpmk limages\" will not be necessary.")
456 print ("lwarpmk: ===")
457 end -- warnlimages
458
459 function warnlimagesrecompile ()
460 -- Warning if must recompile before creating limages:
461 print ("")
462 print ("lwarpmk: ===")
463 print ("lwarpmk: Cross-references are not yet correct.")
464 print ("lwarpmk: The document must be recompiled before creating the lateximages.")
465 print ("lwarpmk: Enter \"lwarpmk html1\" again, then try \"lwarpmk limages\" again.")
466 print ("lwarpmk: ===")
467 end --warnlimagesrecompile
468
469 function checklimages ()
470 --
471 -- Check <sourcename>.txt to see if need to recompile first.
472 -- If any entry has a page number of zero, then there were incorrect images.
473 --
474 print ("lwarpmk: Checking for a valid " .. sourcename .. "-images.txt file.")
475 local limagesfile = io.open(sourcename .. "-images.txt", "r")
476 if ( limagesfile == nil ) then
477 warnlimages ()
478 os.exit(1)
479 end
480 -- Track warning to recompile if find a page 0
481 local pagezerowarning = false
482 -- Scan <sourcename>.txt
483 for line in limagesfile:lines() do
484 -- lwimgpage is the page number in the PDF which has the image
485 -- lwimghash is true if this filename is a hash
486 -- lwimgname is the lateximage filename root to assign for the image
487 i,j,lwimgpage,lwimghash,lwimgname = string.find (line,"|(.*)|(.*)|(.*)|")
488 -- For each entry:
489 if ( (i~=nil) ) then
490 -- If the page number is 0, image references are incorrect
491 -- and must recompile the soure document:
492 if ( lwimgpage == "0" ) then
493 pagezerowarning = true
494 end
495 end -- if i~=nil
496 end -- do
497 -- The last line should be |end|end|end|.
498 -- If not, the compile must have aborted, and the images are incomplete.
499 if ( lwimgpage ~= "end" ) then
500 warnlimagesrecompile()
501 os.exit(1) ;
502 end
503 if ( pagezerowarning ) then
504 warnlimagesrecompile()
505 os.exit(1) ;
506 end -- pagezerowarning
507 end -- checklimages
508
509 function createuniximage ( lwimgfullname )
510 --
511 -- Create one lateximage for Unix / Linux / Mac OS.
512 --
513 executecheckerror (
514 cmdgroupopenname ..
515 "pdfseparate -f " .. lwimgpage .. " -l " .. lwimgpage .. " " ..
516 sourcename .."_html.pdf " ..
517 imagesdirectory .. dirslash .."lateximagetemp-%d" .. ".pdf" ..
518 seqname ..
519 -- Crop the image:
520 "pdfcrop --hires --margins \"0 1 0 0\" " .. imagesdirectory .. dirslash .. "lateximagetemp-" ..
521 lwimgpage .. ".pdf " ..
522 imagesdirectory .. dirslash .. lwimgname .. ".pdf" ..
523 seqname ..
524 -- Convert the image to svg:
525 "pdftocairo -svg -noshrink " .. imagesdirectory .. dirslash .. lwimgname .. ".pdf " ..
526 imagesdirectory .. dirslash .. lwimgname ..".svg" ..
527 seqname ..
528 -- Remove the temporary files:
529 rmname .. " " .. imagesdirectory .. dirslash .. lwimgname .. ".pdf" .. seqname ..
530 rmname .. " " .. imagesdirectory .. dirslash .. "lateximagetemp-" .. lwimgpage .. ".pdf" ..
531 cmdgroupclosename .. " >/dev/null " .. bgname
532 ,
533 "File error trying to convert " .. lwimgfullname
534 )
535 -- Every 32 images, wait for completion at below normal priority,
536 -- allowing other image tasks to catch up.
537 numimageprocesses = numimageprocesses + 1
538 if ( numimageprocesses > 32 ) then
539 numimageprocesses = 0
540 print ( "lwarpmk: waiting" )
541 executecheckerror ( "wait" , "File error trying to wait.")
542 end
543 end -- createuniximage
544
545 function createwindowsimage ( lwimgfullname )
546 --
547 -- Create one lateximage for Windows.
548 --
549 -- Every 32 images, wait for completion at below normal priority,
550 -- allowing other image tasks to catch up.
551 numimageprocesses = numimageprocesses + 1
552 if ( numimageprocesses > 32 ) then
553 numimageprocesses = 0
554 thiswaitcommand = "/WAIT /BELOWNORMAL"
555 print ( "lwarpmk: waiting" )
556 else
557 thiswaitcommand = ""
558 end
559 -- Execute the image generation command
560 executecheckerror (
561 "start /B " .. thiswaitcommand .. " \"\" lwarp_one_limage " ..
562 lwimgpage .. " " ..
563 lwimghash .. " " ..
564 lwimgname .. " " ..
565 sourcename .. " <nul >nul"
566 ,
567 "File error trying to create image."
568 )
569 end -- createwindowsimage
570
571 function createonelateximage ( line )
572 --
573 -- Given the next line of <sourcename>.txt, convert a single image.
574 --
575 -- lwimgpage is the page number in the PDF which has the image
576 -- lwimghash is true if this filename is a hash
577 -- lwimgname is the lateximage filename root to assign for the image
578 i,j,lwimgpage,lwimghash,lwimgname = string.find (line,"|(.*)|(.*)|(.*)|")
579 -- For each entry:
580 if ( (i~=nil) ) then
581 -- Skip if the page number is 0:
582 if ( lwimgpage == "0" ) then
583 pagezerowarning = true
584 -- Skip if the page number is "end":
585 else if ( lwimgpage == "end" ) then
586 else
587 -- Skip is this image is hashed and already exists:
588 local lwimgfullname = imagesdirectory .. dirslash .. lwimgname .. ".svg"
589 if (
590 (lwimghash ~= "true") or
591 (lfs.attributes(lwimgfullname,"mode")==nil) -- file not exists
592 )
593 then -- not hashed or not exists:
594 -- Print the name of the file being generated:
595 print ( "lwarpmk: " .. lwimgname )
596 -- Touch/create the dest so that only once instance tries to build it:
597 executecheckerror (
598 newtouchname .. " " .. lwimgfullname ,
599 "File error trying to touch " .. lwimgfullname
600 )
601 -- Separate out the image into its own single-page pdf:
602 if opsystem=="Unix" then
603 createuniximage (lwimgfullname)
604 elseif opsystem=="Windows" then
605 createwindowsimage (lwimgfullname)
606 end
607 end -- not hashed or not exists
608 end -- not page "end"
609 end -- not page 0
610 end -- not nil
611 end -- createonelateximage
612
613 function createlateximages ()
614 --
615 -- Create lateximages based on <sourcename>-images.txt:
616 --
617 -- See if the document must be recompiled first:
618 checklimages ()
619 -- See if the HTML version exists:
620 checkhtmlpdfexists ()
621 -- Attempt to create the lateximages:
622 print ("lwarpmk: Creating lateximages.")
623 local limagesfile = io.open(sourcename .. "-images.txt", "r")
624 if ( limagesfile == nil ) then
625 warnlimages ()
626 os.exit(1)
627 end
628 -- Create the lateximages directory, ignore error if already exists
629 err = os.execute("mkdir " .. imagesdirectory)
630 -- For Windows, create lwarp_one_limage.cmd from lwarp_one_limage.txt:
631 if opsystem=="Windows" then
632 executecheckerror (
633 cpname .. " lwarp_one_limage.txt lwarp_one_limage.cmd" ,
634 "File error trying to copy lwarp_one_limage.txt to lwarp_one_limage.cmd"
635 )
636 end -- create lwarp_one_limage.cmd
637 -- Track the number of parallel processes
638 numimageprocesses = 0
639 -- Track warning to recompile if find a page 0
640 pagezerowarning = false
641 -- Scan <sourcename>.txt
642 for line in limagesfile:lines() do
643 createonelateximage ( line )
644 end -- do
645 io.close(limagesfile)
646 print ( "lwarpmk limages: ===")
647 print ( "lwarpmk limages: Wait a moment for the images to complete" )
648 print ( "lwarpmk limages: before reloading the page." )
649 print ( "lwarpmk limages: ===")
650 print ( "lwarpmk limages: Done." )
651 if ( pagezerowarning == true ) then
652 print ( "lwarpmk limages: WARNING: Images will be incorrect." )
653 print ( "lwarpmk limages: Enter \"lwarpmk cleanlimages\", then" )
654 print ( "lwarpmk limages: recompile the document one more time, then" )
655 print ( "lwarpmk limages: repeat \"lwarpmk images\" again." )
656 end -- pagezerowarning
657 end -- function
658
659 function convertepstopdf ()
660 --
661 -- Converts EPS files to PDF files.
662 -- The filenames are arg[argindex] and up.
663 -- arg[1] is the command "epstopdf".
664 --
665 ignoreconf ()
666 for i = argindex , #arg do
667 if (lfs.attributes(arg[i],"mode")==nil) then
668 print ("lwarpmk: File \"" .. arg[i] .. "\" does not exist.")
669 else
670 print ("lwarpmk: Converting \"" .. arg[i] .. "\"")
671 thispath, thisfilename, thisextension = splitfilename(arg[i])
672 if ( thispath == nil ) then
673 os.execute ( "epstopdf " .. arg[i] )
674 else
675 os.execute (
676 "epstopdf " ..
677 thispath .. thisfilename .. "." .. thisextension .. " " ..
678 thispath .. thisfilename .. ".pdf"
679 )
680 end
681 end -- if
682 end -- do
683 end --function
684
685 function convertpdftosvg ()
686 --
687 -- Converts PDF files to SVG files.
688 -- The filenames are arg[argindex] and up.
689 -- arg[1] is the command "pdftosvg".
690 --
691 ignoreconf ()
692 for i = argindex , #arg do
693 if (lfs.attributes(arg[i],"mode")==nil) then
694 print ("lwarpmk: File \"" .. arg[i] .. "\" does not exist.")
695 else
696 print ("lwarpmk: Converting \"" .. arg[i] .. "\"")
697 thispath, thisfilename, thisextension = splitfilename(arg[i])
698 if ( thispath == nil ) then
699 os.execute ( "pdftocairo -svg " .. arg[i] )
700 else
701 os.execute (
702 "pdftocairo -svg " ..
703 thispath .. thisfilename .. "." .. thisextension .. " " ..
704 thispath .. thisfilename .. ".svg"
705 )
706 end
707 end -- if
708 end -- do
709 end --function
710
711 -- Force an update and conclude processing:
712 function updateanddone ()
713 print ("lwarpmk: Forcing an update of " .. sourcename ..".tex.")
714 refreshdate ()
715 print ("lwarpmk: " .. sourcename ..".tex is ready to be recompiled.")
716 print ("lwarpmk: Done.")
717 end -- function
718
719 -- Start of the main code: --
720
721 -- lwarpmk --version :
722
723 if (arg[1] == "--version") then
724 print ( "lwarpmk: " .. printversion )
725
726 else -- not --version
727
728 -- print intro:
729
730 print ("lwarpmk: " .. printversion .. " Automated make for the LaTeX Lwarp package.")
731
732 -- lwarpmk print:
733
734 if arg[1] == "print" then
735 loadconf ()
736 if ( latexmk == "true" ) then
737 print ("lwarpmk: Compiling with: " .. printlatexcmd)
738 executecheckerror (
739 printlatexcmd ,
740 "Compile error."
741 )
742 print ("lwarpmk: Done.")
743 else -- not latexmk
744 verifyfileexists (sourcename .. ".tex") ;
745 -- See if up to date:
746 if (
747 ( lfs.attributes ( sourcename .. ".pdf" , "modification" ) == nil ) or
748 (
749 lfs.attributes ( sourcename .. ".tex" , "modification" ) >
750 lfs.attributes ( sourcename .. ".pdf" , "modification" )
751 )
752 ) then
753 -- Recompile if not yet up to date:
754 manytimes(printlatexcmd, "")
755 print ("lwarpmk: Done.") ;
756 else
757 print ("lwarpmk: " .. sourcename .. ".pdf is up to date.") ;
758 end
759 end -- not latexmk
760
761 -- lwarpmk print1:
762
763 elseif arg[1] == "print1" then
764 loadconf ()
765 verifyfileexists (sourcename .. ".tex") ;
766 onetime(printlatexcmd, "")
767 print ("lwarpmk: Done.") ;
768
769 -- lwarpmk printindex:
770 -- Compile the index then touch the source
771 -- to trigger a recompile of the document:
772
773 elseif arg[1] == "printindex" then
774 loadconf ()
775 os.execute ( printindexcmd )
776 print ("lwarpmk: -------")
777 updateanddone ()
778
779 -- lwarpmk printglossary:
780 -- Compile the glossary then touch the source
781 -- to trigger a recompile of the document:
782
783 elseif arg[1] == "printglossary" then
784 loadconf ()
785 print ("lwarpmk: Processing the glossary.")
786
787 os.execute(glossarycmd .. " " .. sourcename)
788 updateanddone ()
789
790 -- lwarpmk html:
791
792 elseif arg[1] == "html" then
793 loadconf ()
794 if ( latexmk == "true" ) then
795 print ("lwarpmk: Compiling with: " .. HTMLlatexcmd)
796 executecheckerror (
797 HTMLlatexcmd ,
798 "Compile error."
799 )
800 pdftohtml ()
801 print ("lwarpmk: Done.")
802 else -- not latexmk
803 verifyfileexists ( sourcename .. ".tex" ) ;
804 -- See if exists and is up to date:
805 if (
806 ( lfs.attributes ( homehtmlfilename .. ".html" , "modification" ) == nil ) or
807 (
808 lfs.attributes ( sourcename .. ".tex" , "modification" ) >
809 lfs.attributes ( homehtmlfilename .. ".html" , "modification" )
810 )
811 ) then
812 -- Recompile if not yet up to date:
813 manytimes(HTMLlatexcmd, "_html")
814 pdftohtml ()
815 print ("lwarpmk: Done.")
816 else
817 print ("lwarpmk: " .. homehtmlfilename .. ".html is up to date.")
818 end
819 end -- not latexmk
820
821 -- lwarpmk html1:
822
823 elseif arg[1] == "html1" then
824 loadconf ()
825 verifyfileexists ( sourcename .. ".tex" ) ;
826 onetime(HTMLlatexcmd, "_html")
827 pdftohtml ()
828 print ("lwarpmk: Done.")
829
830 -- lwarpmk pdftohtml:
831 elseif arg[1] == "pdftohtml" then
832 loadconf ()
833 pdftohtml ()
834
835 -- lwarpmk htmlindex:
836 -- Compile the index then touch the source
837 -- to trigger a recompile of the document:
838
839 elseif arg[1] == "htmlindex" then
840 loadconf ()
841 os.execute ( HTMLindexcmd )
842 print ("lwarpmk: -------")
843 updateanddone ()
844
845 -- lwarpmk htmlglossary:
846 -- Compile the glossary then touch the source
847 -- to trigger a recompile of the document.
848 -- The <sourcename>.xdy file is created by the glossaries package.
849
850 elseif arg[1] == "htmlglossary" then
851 loadconf ()
852 print ("lwarpmk: Processing the glossary.")
853 os.execute(glossarycmd .. " " .. sourcename .. "_html")
854 updateanddone ()
855
856 -- lwarpmk limages:
857 -- Scan the <sourcename>.txt file to create lateximages.
858
859 elseif arg[1] == "limages" then
860 loadconf ()
861 print ("lwarpmk: Processing images.")
862 createlateximages ()
863 print ("lwarpmk: Done.")
864
865 -- lwarpmk again:
866 -- Touch the source to trigger a recompile.
867
868 elseif arg[1] == "again" then
869 loadconf ()
870 updateanddone ()
871
872 -- lwarpmk clean:
873 -- Remove project.aux, .toc, .lof, .lot, .log, *.idx, *.ind, *_html_inc.*, .gl*
874
875 elseif arg[1] == "clean" then
876 loadconf ()
877 removeaux ()
878 print ("lwarpmk: Done.")
879
880 -- lwarpmk cleanall
881 -- Remove project.aux, .toc, .lof, .lot, .log, *.idx, *.ind, *_html_inc.*, .gl*
882 -- and also project.pdf, project.dvi, *.html
883
884 elseif arg[1] == "cleanall" then
885 loadconf ()
886 removeaux ()
887 os.execute ( rmname .. " " ..
888 sourcename .. ".pdf " .. sourcename .. "_html.pdf " ..
889 sourcename .. ".dvi " .. sourcename .. "_html.dvi " ..
890 "*.html"
891 )
892 print ("lwarpmk: Done.")
893
894 -- lwarpmk cleanlimages
895 -- Remove images from the imagesdirectory.
896
897 elseif arg[1] == "cleanlimages" then
898 loadconf ()
899 os.execute ( rmname .. " " .. imagesdirectory .. dirslash .. "*" )
900 print ("lwarpmk: Done.")
901
902 -- lwarpmk epstopdf <list of file names>
903 -- Convert EPS files to PDF using epstopdf
904 elseif arg[1] == "epstopdf" then
905 convertepstopdf ()
906 print ("lwarpmk: Done.")
907
908 -- lwarpmk pdftosvg <list of file names>
909 -- Convert PDF files to SVG using pdftocairo
910 elseif arg[1] == "pdftosvg" then
911 convertpdftosvg ()
912 print ("lwarpmk: Done.")
913
914 -- lwarpmk with no argument :
915
916 elseif (arg[1] == nil) then
917 printhelp ()
918
919 -- lwarpmk -v:
920
921 elseif (arg[1] == "-v" ) then
922 -- The version number has already been printed
923 -- by the lwarpmk intro.
924
925 -- lwarpmk -h or lwarpmk --help :
926
927 elseif (arg[1] == "-h" ) or (arg[1] == "--help") then
928 printusage ()
929
930 -- Unknown command:
931
932 else
933 printhelp ()
934 print ("\nlwarpmk: ****** Unknown command \""..arg[1].."\". ******\n")
935 end
936
937 end -- not --version