| 1 |
#!/usr/bin/env texlua |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
printversion = "v0.921" |
| 6 |
requiredconfversion = "2" |
| 7 |
|
| 8 |
function printhelp () |
| 9 |
print ("lwarpmk: Use lwarpmk -h or lwarpmk --help for help.") ; |
| 10 |
end |
| 11 |
|
| 12 |
function printusage () |
| 13 |
|
| 14 |
|
| 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 |
|
| 45 |
end |
| 46 |
|
| 47 |
function splitfilename ( pathandfilename ) |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
if lfs.attributes(pathandfilename,"mode") == "directory" then |
| 57 |
local strPath = pathandfilename:gsub("[\\/]$","") |
| 58 |
return strPath.."\\","","" |
| 59 |
end |
| 60 |
pathandfilename = pathandfilename.."." |
| 61 |
return pathandfilename:match("^(.-)([^\\/]-)%.([^\\/%.]-)%.?$") |
| 62 |
end |
| 63 |
|
| 64 |
function splitfile (destfile,sourcefile) |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 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 |
|
| 79 |
io.output(newfilename) ; |
| 80 |
else |
| 81 |
if ( (i~= nil) and (copen == "<!--") and (cstart == "Using lwarp")) then |
| 82 |
|
| 83 |
usinglwarp = true ; |
| 84 |
else |
| 85 |
|
| 86 |
io.write (line .. "\n") ; |
| 87 |
end end |
| 88 |
end |
| 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 |
| 101 |
|
| 102 |
function cvalueerror ( line, linenum , cvalue ) |
| 103 |
|
| 104 |
|
| 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 |
|
| 114 |
os.exit(1) ; |
| 115 |
end |
| 116 |
|
| 117 |
function printhowtorecompile () |
| 118 |
|
| 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 |
| 130 |
|
| 131 |
function ignoreconf () |
| 132 |
|
| 133 |
argindex = 2 |
| 134 |
end |
| 135 |
|
| 136 |
function loadconf () |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
local conffile = "lwarpmk.conf" |
| 142 |
local confroot = "lwarpmk" |
| 143 |
|
| 144 |
argindex = 2 |
| 145 |
|
| 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 |
|
| 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 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
glossarycmd = "makeglossaries" |
| 171 |
|
| 172 |
if (lfs.attributes(conffile,"mode")==nil) then |
| 173 |
|
| 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) |
| 188 |
else |
| 189 |
|
| 190 |
print ("lwarpmk: Reading " .. conffile ..".") |
| 191 |
local cfile = io.open(conffile) |
| 192 |
|
| 193 |
local linenum = 0 |
| 194 |
for line in cfile:lines() do |
| 195 |
linenum = linenum + 1 |
| 196 |
i,j,cvarname,cvalue = string.find (line,"([%w-_]*)%s*=%s*%[%[([^%]]*)%]%]") ; |
| 197 |
|
| 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 |
|
| 204 |
os.exit(1) ; |
| 205 |
end |
| 206 |
if ( cvarname == "confversion" ) then |
| 207 |
confversion = cvalue |
| 208 |
elseif ( cvarname == "opsystem" ) then |
| 209 |
|
| 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 |
|
| 237 |
os.exit(1) ; |
| 238 |
end |
| 239 |
end |
| 240 |
io.close(cfile) |
| 241 |
end |
| 242 |
|
| 243 |
|
| 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 |
| 256 |
|
| 257 |
if opsystem=="Unix" then |
| 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 |
| 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 |
| 289 |
|
| 290 |
|
| 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 |
|
| 299 |
if ( confversion ~= requiredconfversion ) then |
| 300 |
print ("lwarpmk: ===") |
| 301 |
printhowtorecompile () |
| 302 |
print ("lwarpmk: ===") |
| 303 |
os.exit(1) |
| 304 |
end |
| 305 |
end |
| 306 |
|
| 307 |
function executecheckerror ( executecommands , errormessage ) |
| 308 |
|
| 309 |
|
| 310 |
|
| 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 |
| 321 |
|
| 322 |
function refreshdate () |
| 323 |
os.execute(touchnamepre .. " " .. sourcename .. ".tex " .. touchnamepost) |
| 324 |
end |
| 325 |
|
| 326 |
function reruntoget (filesource) |
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 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 |
| 338 |
end |
| 339 |
io.close(fsource) |
| 340 |
return false |
| 341 |
end |
| 342 |
|
| 343 |
function onetime (latexcmd, fsuffix) |
| 344 |
|
| 345 |
|
| 346 |
|
| 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 |
|
| 359 |
|
| 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 |
|
| 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 |
|
| 384 |
|
| 385 |
|
| 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 |
|
| 398 |
splitfile (homehtmlfilename .. ".html" , sourcename .. "_html.html") |
| 399 |
end |
| 400 |
|
| 401 |
function removeaux () |
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 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 |
|
| 429 |
|
| 430 |
|
| 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 |
| 443 |
|
| 444 |
function warnlimages () |
| 445 |
|
| 446 |
|
| 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 |
| 458 |
|
| 459 |
function warnlimagesrecompile () |
| 460 |
|
| 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 |
| 468 |
|
| 469 |
function checklimages () |
| 470 |
|
| 471 |
|
| 472 |
|
| 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 |
|
| 481 |
local pagezerowarning = false |
| 482 |
|
| 483 |
for line in limagesfile:lines() do |
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
i,j,lwimgpage,lwimghash,lwimgname = string.find (line,"|(.*)|(.*)|(.*)|") |
| 488 |
|
| 489 |
if ( (i~=nil) ) then |
| 490 |
|
| 491 |
|
| 492 |
if ( lwimgpage == "0" ) then |
| 493 |
pagezerowarning = true |
| 494 |
end |
| 495 |
end |
| 496 |
end |
| 497 |
|
| 498 |
|
| 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 |
| 507 |
end |
| 508 |
|
| 509 |
function createuniximage ( lwimgfullname ) |
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
executecheckerror ( |
| 514 |
cmdgroupopenname .. |
| 515 |
"pdfseparate -f " .. lwimgpage .. " -l " .. lwimgpage .. " " .. |
| 516 |
sourcename .."_html.pdf " .. |
| 517 |
imagesdirectory .. dirslash .."lateximagetemp-%d" .. ".pdf" .. |
| 518 |
seqname .. |
| 519 |
|
| 520 |
"pdfcrop --hires --margins \"0 1 0 0\" " .. imagesdirectory .. dirslash .. "lateximagetemp-" .. |
| 521 |
lwimgpage .. ".pdf " .. |
| 522 |
imagesdirectory .. dirslash .. lwimgname .. ".pdf" .. |
| 523 |
seqname .. |
| 524 |
|
| 525 |
"pdftocairo -svg -noshrink " .. imagesdirectory .. dirslash .. lwimgname .. ".pdf " .. |
| 526 |
imagesdirectory .. dirslash .. lwimgname ..".svg" .. |
| 527 |
seqname .. |
| 528 |
|
| 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 |
|
| 536 |
|
| 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 |
| 544 |
|
| 545 |
function createwindowsimage ( lwimgfullname ) |
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 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 |
|
| 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 |
| 570 |
|
| 571 |
function createonelateximage ( line ) |
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
i,j,lwimgpage,lwimghash,lwimgname = string.find (line,"|(.*)|(.*)|(.*)|") |
| 579 |
|
| 580 |
if ( (i~=nil) ) then |
| 581 |
|
| 582 |
if ( lwimgpage == "0" ) then |
| 583 |
pagezerowarning = true |
| 584 |
|
| 585 |
else if ( lwimgpage == "end" ) then |
| 586 |
else |
| 587 |
|
| 588 |
local lwimgfullname = imagesdirectory .. dirslash .. lwimgname .. ".svg" |
| 589 |
if ( |
| 590 |
(lwimghash ~= "true") or |
| 591 |
(lfs.attributes(lwimgfullname,"mode")==nil) |
| 592 |
) |
| 593 |
then |
| 594 |
|
| 595 |
print ( "lwarpmk: " .. lwimgname ) |
| 596 |
|
| 597 |
executecheckerror ( |
| 598 |
newtouchname .. " " .. lwimgfullname , |
| 599 |
"File error trying to touch " .. lwimgfullname |
| 600 |
) |
| 601 |
|
| 602 |
if opsystem=="Unix" then |
| 603 |
createuniximage (lwimgfullname) |
| 604 |
elseif opsystem=="Windows" then |
| 605 |
createwindowsimage (lwimgfullname) |
| 606 |
end |
| 607 |
end |
| 608 |
end |
| 609 |
end |
| 610 |
end |
| 611 |
end |
| 612 |
|
| 613 |
function createlateximages () |
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
checklimages () |
| 619 |
|
| 620 |
checkhtmlpdfexists () |
| 621 |
|
| 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 |
|
| 629 |
err = os.execute("mkdir " .. imagesdirectory) |
| 630 |
|
| 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 |
| 637 |
|
| 638 |
numimageprocesses = 0 |
| 639 |
|
| 640 |
pagezerowarning = false |
| 641 |
|
| 642 |
for line in limagesfile:lines() do |
| 643 |
createonelateximage ( line ) |
| 644 |
end |
| 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 |
| 657 |
end |
| 658 |
|
| 659 |
function convertepstopdf () |
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 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 |
| 682 |
end |
| 683 |
end |
| 684 |
|
| 685 |
function convertpdftosvg () |
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 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 |
| 708 |
end |
| 709 |
end |
| 710 |
|
| 711 |
|
| 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 |
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
if (arg[1] == "--version") then |
| 724 |
print ( "lwarpmk: " .. printversion ) |
| 725 |
|
| 726 |
else |
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
print ("lwarpmk: " .. printversion .. " Automated make for the LaTeX Lwarp package.") |
| 731 |
|
| 732 |
|
| 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 |
| 744 |
verifyfileexists (sourcename .. ".tex") ; |
| 745 |
|
| 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 |
|
| 754 |
manytimes(printlatexcmd, "") |
| 755 |
print ("lwarpmk: Done.") ; |
| 756 |
else |
| 757 |
print ("lwarpmk: " .. sourcename .. ".pdf is up to date.") ; |
| 758 |
end |
| 759 |
end |
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
elseif arg[1] == "print1" then |
| 764 |
loadconf () |
| 765 |
verifyfileexists (sourcename .. ".tex") ; |
| 766 |
onetime(printlatexcmd, "") |
| 767 |
print ("lwarpmk: Done.") ; |
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
elseif arg[1] == "printindex" then |
| 774 |
loadconf () |
| 775 |
os.execute ( printindexcmd ) |
| 776 |
print ("lwarpmk: -------") |
| 777 |
updateanddone () |
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 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 |
|
| 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 |
| 803 |
verifyfileexists ( sourcename .. ".tex" ) ; |
| 804 |
|
| 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 |
|
| 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 |
| 820 |
|
| 821 |
|
| 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 |
|
| 831 |
elseif arg[1] == "pdftohtml" then |
| 832 |
loadconf () |
| 833 |
pdftohtml () |
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
elseif arg[1] == "htmlindex" then |
| 840 |
loadconf () |
| 841 |
os.execute ( HTMLindexcmd ) |
| 842 |
print ("lwarpmk: -------") |
| 843 |
updateanddone () |
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 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 |
|
| 857 |
|
| 858 |
|
| 859 |
elseif arg[1] == "limages" then |
| 860 |
loadconf () |
| 861 |
print ("lwarpmk: Processing images.") |
| 862 |
createlateximages () |
| 863 |
print ("lwarpmk: Done.") |
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
elseif arg[1] == "again" then |
| 869 |
loadconf () |
| 870 |
updateanddone () |
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
elseif arg[1] == "clean" then |
| 876 |
loadconf () |
| 877 |
removeaux () |
| 878 |
print ("lwarpmk: Done.") |
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 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 |
|
| 895 |
|
| 896 |
|
| 897 |
elseif arg[1] == "cleanlimages" then |
| 898 |
loadconf () |
| 899 |
os.execute ( rmname .. " " .. imagesdirectory .. dirslash .. "*" ) |
| 900 |
print ("lwarpmk: Done.") |
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
elseif arg[1] == "epstopdf" then |
| 905 |
convertepstopdf () |
| 906 |
print ("lwarpmk: Done.") |
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
elseif arg[1] == "pdftosvg" then |
| 911 |
convertpdftosvg () |
| 912 |
print ("lwarpmk: Done.") |
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
elseif (arg[1] == nil) then |
| 917 |
printhelp () |
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
elseif (arg[1] == "-v" ) then |
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
elseif (arg[1] == "-h" ) or (arg[1] == "--help") then |
| 928 |
printusage () |
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
else |
| 933 |
printhelp () |
| 934 |
print ("\nlwarpmk: ****** Unknown command \""..arg[1].."\". ******\n") |
| 935 |
end |
| 936 |
|
| 937 |
end |