summaryrefslogtreecommitdiff
path: root/macros/luatex/latex/linebreaker/linebreaker.sty
blob: 3442adad8c25f1fd55734a98bca56a382b5fc31f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
% 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