% linebreaker.sty
%
% (c) Michal Hoftich <michal.h21@gmail.com>
%
%% This program can be redistributed and/or modified under the terms
%% of the LaTeX Project Public License Distributed from CTAN archives
%% in directory macros/latex/base/lppl.txt.

\ProvidesPackage{linebreaker}

\RequirePackage{luatexbase}
\directlua{%
linebreaker = require "linebreaker"
luatexbase.add_to_callback("linebreak_filter", linebreaker.linebreak, "new linebreak callback")
luatexbase.add_to_callback("post_linebreak_filter", linebreaker.post_linebreak, "new linebreak callback")
luatexbase.add_to_callback("hpack_quality", linebreaker.hpack_quality, "Our overfull box reporting function")
}


% linebreaker setup
\ExplSyntaxOn
\keys_define:nn{linebreaker}{
  debug .code:n = \directlua{linebreaker.debug=true},
  maxtolerance .code:n = \directlua{linebreaker.max_tolerance = tonumber("#1")},
  maxemergencystretch .code:n = \directlua{linebreaker.max_emergencystretch = tex.sp("#1")},
  maxcycles .code:n = \directlua{linebreaker.max_cycles = tonumber("#1")},
  cubic .code:n = \directlua{linebreaker.use_cubic = true}
}
\NewDocumentCommand{\linebreakersetup}{m}{
\keys_set:nn {linebreaker} {#1}
}
\ExplSyntaxOff

% enable/disable linebreaker
\NewDocumentCommand{\linebreakerenable}{}{\directlua{linebreaker.active=true}}
\NewDocumentCommand{\linebreakerdisable}{}{\directlua{linebreaker.active=false}}



\endinput
