--[[TeXworksScript Title: Parse LaTeX Log (Example) Description: Gives examples of how to modify the output log of a LaTeX run Author: Alain Delmotte from Stefan Loeffler base Version: 0.1 Date: 2009-10-17 Script-Type: hook Hook: AfterTypeset ]] local errors = "" local badboxes = "" local warnings = "" local place = 1 local chaine = "" local log local iserror = false local iswarning = false local isbadbox = false local outnum = 0 function TrouverLigne () local suite = "" repeat suite = suite .. string.sub(log,place,place) place = place + 1 until string.byte(string.sub(log,place,place)) == 10 or place >= string.len(log) return suite end if type(output) == "string" then do log = output chaine = TrouverLigne() while place < string.len(log) do if (string.find(chaine,"%(%a-%.tex")) then i,j = string.find(chaine,"%(%a.-%.tex") fichier = string.sub(chaine,i+1,j) badboxes = badboxes .. "\n***** in: " .. fichier .. "*****\n" warnings = warnings .. "\n***** in: " .. fichier .. "*****\n" errors = errors .. "\n***** in: " .. fichier .. "*****\n" while (string.find(chaine,"%(%a.-%.tex",j+1)) do i,j = string.find(chaine,"%(%a.-%.tex",j+1) fichier = string.sub(chaine,i+1,j) badboxes = badboxes .. "\n***** in: " .. fichier .. "*****\n" warnings = warnings .. "\n***** in: " .. fichier .. "*****\n" errors = errors .. "\n***** in: " .. fichier .. "*****\n" end elseif (string.find(chaine,"Overfull") ~= nil) then isbadbox = true badboxes = badboxes .. chaine chaine = TrouverLigne() badboxes = badboxes .. chaine chaine = TrouverLigne() badboxes = badboxes .. chaine .. "\n" elseif (string.find(chaine,"Underfull") ~= nil) then isbadbox = true badboxes = badboxes .. chaine .. "\n" elseif string.find(chaine,"LaTeX Warning") ~= nil then iswarning = true warnings = warnings .. chaine .. "\n" elseif string.find(chaine,"! ") ~= nil then iserror = true errors = errors .. chaine chaine = TrouverLigne() errors = errors .. chaine chaine = TrouverLigne() if chaine ~= "" then errors = errors .. chaine .. "\n" else errors = errors .. "\n" end end chaine = TrouverLigne() end output = {} if iserror then outnum = outnum + 1 output[outnum] = { ["label"] = "Errors"; ["type"] = 1; ["data"] = errors } end if iswarning then outnum = outnum + 1 output[outnum] = { ["label"] = "Warnings"; ["type"] = 1; ["data"] = warnings } end if isbadbox then outnum = outnum + 1 output[outnum] = { ["label"] = "Bad boxes"; ["type"] = 1; ["data"] = badboxes } end end end