Skip to content

Commit

Permalink
feat(outputters): Add a method to handle empty PDFs vs. cleanup after…
Browse files Browse the repository at this point in the history
… error
  • Loading branch information
alerque committed Dec 12, 2024
1 parent 9df32f1 commit 7f942df
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion core/utilities/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ function utilities.error (message, isbug)
utilities.warn(message, isbug)
_skip_traceback_levels = 2
io.stderr:flush()
SILE.outputter:finish() -- Only really useful from the REPL but no harm in trying
SILE.outputter:abort()
SILE.scratch.caughterror = true
error("", 2)
end
Expand Down
2 changes: 2 additions & 0 deletions outputters/base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ end

function outputter.newPage () end

function outputter:abort () end

function outputter:finish ()
self:runHooks("prefinish")
end
Expand Down
12 changes: 11 additions & 1 deletion outputters/libtexpdf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,23 @@ end
-- pdf structure package needs a tie in here
function outputter._endHook (_) end

function outputter:abort ()
if started then
pdf.endpage()
pdf.finish()
started = false
lastkey = false
end
end

function outputter:finish ()
-- allows generation of empty PDFs
self:_ensureInit()
pdf.endpage()
self:runHooks("prefinish")
pdf.finish()
started = false
lastkey = nil
lastkey = false
end

function outputter.getCursor (_)
Expand Down

0 comments on commit 7f942df

Please sign in to comment.