diff options
author | Karl Berry <karl@freefriends.org> | 2011-09-19 23:43:19 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2011-09-19 23:43:19 +0000 |
commit | 4d41d6dca62a66e63d7ec95657880e857efd4be4 (patch) | |
tree | c797e533bc8bc53f5bfd12417dce9fb87d12d867 /Master/texmf-dist/tex/latex/impnattypo | |
parent | d8afb0f4b2b72dc375d1f7024702a7186f994d8c (diff) |
impnattypo 0.5 (19sep11)
git-svn-id: svn://tug.org/texlive/trunk@24019 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/impnattypo')
-rw-r--r-- | Master/texmf-dist/tex/latex/impnattypo/impnattypo.sty | 190 |
1 files changed, 153 insertions, 37 deletions
diff --git a/Master/texmf-dist/tex/latex/impnattypo/impnattypo.sty b/Master/texmf-dist/tex/latex/impnattypo/impnattypo.sty index 9185c353e9d..92f3a4317b2 100644 --- a/Master/texmf-dist/tex/latex/impnattypo/impnattypo.sty +++ b/Master/texmf-dist/tex/latex/impnattypo/impnattypo.sty @@ -20,25 +20,35 @@ %% \NeedsTeXFormat{LaTeX2e}[1999/12/01] \ProvidesPackage{impnattypo} - [2011/09/13 0.3 Recommendations typographiques de l'Imprimerie Nationale Française] + [2011/09/19 0.4 Recommendations typographiques de l'Imprimerie Nationale Française] \ProvidesPackage{impnattypo} -\usepackage{ifluatex} -\newif\if@impnattypo@frenchchapters -\DeclareOption{frenchchapters}{\@impnattypo@frenchchapterstrue} -\newif\if@impnattypo@hyphenation -\DeclareOption{hyphenation}{\@impnattypo@hyphenationtrue} -\newif\if@impnattypo@nosingleletter -\DeclareOption{nosingleletter}{\@impnattypo@nosinglelettertrue} -\newif\if@impnattypo@parindent -\DeclareOption{parindent}{\@impnattypo@parindenttrue} -\newif\if@impnattypo@lastparline -\DeclareOption{lastparline}{\@impnattypo@lastparlinetrue} -\ProcessOptions -\if@impnattypo@hyphenation +\RequirePackage{ifluatex} +\RequirePackage{kvoptions} +\SetupKeyvalOptions{ + family=impnattypo, + prefix=impnattypo, +} +\DeclareBoolOption{draft} +\DeclareBoolOption{frenchchapters} +\DeclareBoolOption{hyphenation} +\DeclareBoolOption{nosingleletter} +\DeclareBoolOption{parindent} +\DeclareBoolOption{lastparline} +\DeclareBoolOption{homeoarchy} +\DeclareStringOption[red]{homeoarchywordcolor} +\DeclareStringOption[orange]{homeoarchycharcolor} +\DeclareStringOption[brown]{nosinglelettercolor} +\DeclareStringOption[teal]{lastparlinecolor} +\DeclareStringOption[1]{homeoarchymaxwords} +\DeclareStringOption[3]{homeoarchymaxchars} +\ProcessKeyvalOptions* +\RequirePackage{xcolor} +\def\usecolor#1{\csname\string\color@#1\endcsname\space} +\ifimpnattypohyphenation \brokenpenalty=10000 \doublehyphendemerits=1000000000 \fi -\if@impnattypo@frenchchapters +\ifimpnattypofrenchchapters \let\frenchchapter\Roman \renewcommand{\thechapter}{% \ifnum\value{chapter}=1 @@ -48,29 +58,30 @@ \fi } \fi -\if@impnattypo@nosingleletter +\ifimpnattyponosingleletter \ifluatex - \usepackage{luatexbase,luacode} + \RequirePackage{luatexbase,luacode} \begin{luacode} local prevent_single_letter = function (head) while head do - if head.id == 37 then -- glyph - if head.prev.id == 10 and head.next.id == 10 then -- only if we are at a one letter word + if head.id == 37 then -- glyph + if (head.char >= 65 and head.char <= 122) or (head.char >= 192 and head.char <= 255) then -- some kind of letter + if head.prev.id == 10 and head.next.id == 10 then -- only if we are at a one letter word - local p = node.new("penalty") - p.penalty = 10000 - - -- Uncomment the next lines to show the position of the ~'s - -- local p = node.new("rule") - -- p.width = 2* 2^16 - -- p.height = 2^16 - -- p.depth = 2^16 + local p = node.new("penalty") + p.penalty = 10000 - p.next = head.next - head.next.prev = p - head.next = p + \ifimpnattypodraft + local w = node.new("whatsit","pdf_literal") + w.data = "q \usecolor{\impnattyponosinglelettercolor} 0 0 m 0 5 l 2 5 l 2 0 l b Q" + node.insert_after(head,head,w) + node.insert_after(head,w,p) + \else + node.insert_after(head,head,p) + \fi + end end end head = head.next @@ -84,12 +95,12 @@ \PackageError{The nosingleletter option only works with LuaTeX} \fi \fi -\if@impnattypo@parindent +\ifimpnattypoparindent \setlength{\parindent}{1em} \fi -\if@impnattypo@lastparline +\ifimpnattypolastparline \ifluatex - \usepackage{luatexbase,luacode} + \RequirePackage{luatexbase,luacode} \begin{luacode} last_line_twice_parindent = function (head) while head do @@ -99,10 +110,16 @@ -- we are at a glue and have less then 2*\parindent to go local p = node.new("penalty") p.penalty = 10000 - p.next = head - head.prev.next = p - p.prev = head.prev - head.prev = p + + \ifimpnattypodraft + local w = node.new("whatsit","pdf_literal") + w.data = "q \usecolor{\impnattypolastparlinecolor} 0 0 m 0 5 l 2 5 l 2 0 l b Q" + + node.insert_after(head,head.prev,w) + node.insert_after(head,w,p) + \else + node.insert_after(head,head.prev,p) + \fi end head = head.next @@ -116,6 +133,105 @@ \setlength{\parfillskip}{0pt plus\dimexpr\textwidth-2\parindent} \fi \fi +\ifimpnattypohomeoarchy + \ifimpnattypodraft + \ifluatex + \RequirePackage{luatexbase,luacode} + \begin{luacode} + compare_lines = function (line1,line2) + local head1 = line1.head + local head2 = line2.head + + local char_count = 0 + local word_count = 0 + + while head1 and head2 do + if (head1.id == 37 and head2.id == 37 + and head1.char == head2.char) -- identical glyph + or (head1.id == 10 and head2.id == 10) then -- glue + + if head1.id == 37 then -- glyph + char_count = char_count + 1 + elseif head1.id == 10 then -- glue + word_count = word_count + 1 + end + head1 = head1.next + head2 = head2.next + elseif (head1.id == 0 or head2.id == 0) then -- end of line + break + elseif (head1.id ~= 37 and head1.id ~= 10) then -- some other kind of node + head1 = head1.next + elseif (head2.id ~= 37 and head2.id ~= 10) then -- some other kind of node + head2 = head2.next + else -- no match, no special node + break + end + end + -- analyze last non-matching node, check for punctuation + if ((head1 and head1.id == 37 and head1.char > 49) + or (head2 and head2.id == 37 and head2.char > 49)) then + -- not a word + elseif char_count > 0 then + word_count = word_count + 1 + end + return char_count,word_count,head1,head2 + end + + highlight = function (line,nend,color) + local n = node.new("whatsit","pdf_literal") + + -- get dimensions + local w,h,d = node.dimensions(line.head,nend) + local w_pts = w/65536 -- scaled points to points + + -- set data + n.data = "q " .. color .. " 0 0 m 0 5 l " .. w_pts .. " 5 l " .. w_pts .. " 0 l b Q" + + -- insert node + n.next = line.head + line.head = n + node.slide(line.head) + end + + homeoarchy = function (head) + local cur_line = head + local prev_line -- initiate prev_head + + local max_char = tonumber(\impnattypohomeoarchymaxchars) + local max_word = tonumber(\impnattypohomeoarchymaxwords) + + while head do + if head.id == 0 then -- new line + prev_line = cur_line + cur_line = head + if prev_line.id == 0 then + char_count,word_count,prev_head,cur_head = compare_lines(prev_line,cur_line) + if char_count >= max_char or word_count >= max_word then + local color + if word_count >= max_word then + color = "q \usecolor{\impnattypohomeoarchywordcolor}" + else + color = "q \usecolor{\impnattypohomeoarchycharcolor}" + end + + -- highlight both lines + highlight(prev_line,prev_head,color) + highlight(cur_line,cur_head,color) + end + end + end + head = head.next + end + return true + end + + luatexbase.add_to_callback("post_linebreak_filter",homeoarchy,"homeoarchy") + \end{luacode} + \else + \PackageError{The homeoarchy option only works with LuaTeX} + \fi + \fi +\fi \endinput %% %% End of file `impnattypo.sty'. |