summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/impnattypo
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2011-09-21 23:27:26 +0000
committerKarl Berry <karl@freefriends.org>2011-09-21 23:27:26 +0000
commit032c722f921577a65cf81ba8be3247d49d7e4388 (patch)
treec4666d318e3ac384055069841713ff75178fc32e /Master/texmf-dist/tex/latex/impnattypo
parentf6c677e8d5591621594cf65c7e687edcdc28584a (diff)
impnattypo (21sep11)
git-svn-id: svn://tug.org/texlive/trunk@24057 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/impnattypo')
-rw-r--r--Master/texmf-dist/tex/latex/impnattypo/impnattypo.sty230
1 files changed, 208 insertions, 22 deletions
diff --git a/Master/texmf-dist/tex/latex/impnattypo/impnattypo.sty b/Master/texmf-dist/tex/latex/impnattypo/impnattypo.sty
index 92f3a4317b2..79638f99a63 100644
--- a/Master/texmf-dist/tex/latex/impnattypo/impnattypo.sty
+++ b/Master/texmf-dist/tex/latex/impnattypo/impnattypo.sty
@@ -20,13 +20,13 @@
%%
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{impnattypo}
- [2011/09/19 0.4 Recommendations typographiques de l'Imprimerie Nationale Française]
+ [2011/09/20 1.0 Typographic utilities inspired by the French Imprimerie Nationale]
\ProvidesPackage{impnattypo}
\RequirePackage{ifluatex}
\RequirePackage{kvoptions}
\SetupKeyvalOptions{
family=impnattypo,
- prefix=impnattypo,
+ prefix=int,
}
\DeclareBoolOption{draft}
\DeclareBoolOption{frenchchapters}
@@ -35,20 +35,22 @@
\DeclareBoolOption{parindent}
\DeclareBoolOption{lastparline}
\DeclareBoolOption{homeoarchy}
+\DeclareBoolOption{rivers}
\DeclareStringOption[red]{homeoarchywordcolor}
\DeclareStringOption[orange]{homeoarchycharcolor}
\DeclareStringOption[brown]{nosinglelettercolor}
\DeclareStringOption[teal]{lastparlinecolor}
+\DeclareStringOption[lime]{riverscolor}
\DeclareStringOption[1]{homeoarchymaxwords}
\DeclareStringOption[3]{homeoarchymaxchars}
\ProcessKeyvalOptions*
\RequirePackage{xcolor}
\def\usecolor#1{\csname\string\color@#1\endcsname\space}
-\ifimpnattypohyphenation
+\ifinthyphenation
\brokenpenalty=10000
\doublehyphendemerits=1000000000
\fi
-\ifimpnattypofrenchchapters
+\ifintfrenchchapters
\let\frenchchapter\Roman
\renewcommand{\thechapter}{%
\ifnum\value{chapter}=1
@@ -58,23 +60,23 @@
\fi
}
\fi
-\ifimpnattyponosingleletter
+\ifintnosingleletter
\ifluatex
\RequirePackage{luatexbase,luacode}
\begin{luacode}
local prevent_single_letter = function (head)
while head do
- 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
+ if head.id == 37 then -- glyph
+ if unicode.utf8.match(unicode.utf8.char(head.char),"%a") 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
- \ifimpnattypodraft
+ \ifintdraft
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"
+ w.data = "q \usecolor{\intnosinglelettercolor} 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)
@@ -95,10 +97,10 @@
\PackageError{The nosingleletter option only works with LuaTeX}
\fi
\fi
-\ifimpnattypoparindent
+\ifintparindent
\setlength{\parindent}{1em}
\fi
-\ifimpnattypolastparline
+\ifintlastparline
\ifluatex
\RequirePackage{luatexbase,luacode}
\begin{luacode}
@@ -111,9 +113,9 @@
local p = node.new("penalty")
p.penalty = 10000
- \ifimpnattypodraft
+ \ifintdraft
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"
+ w.data = "q \usecolor{\intlastparlinecolor} 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)
@@ -133,8 +135,8 @@
\setlength{\parfillskip}{0pt plus\dimexpr\textwidth-2\parindent}
\fi
\fi
-\ifimpnattypohomeoarchy
- \ifimpnattypodraft
+\ifinthomeoarchy
+ \ifintdraft
\ifluatex
\RequirePackage{luatexbase,luacode}
\begin{luacode}
@@ -152,7 +154,7 @@
if head1.id == 37 then -- glyph
char_count = char_count + 1
- elseif head1.id == 10 then -- glue
+ elseif char_count > 0 and head1.id == 10 then -- glue
word_count = word_count + 1
end
head1 = head1.next
@@ -177,6 +179,49 @@
return char_count,word_count,head1,head2
end
+ compare_lines_reverse = function (line1,line2)
+ local head1 = node.tail(line1.head)
+ local head2 = node.tail(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 char_count > 0 and head1.id == 10 then -- glue
+ word_count = word_count + 1
+ end
+ head1 = head1.prev
+ head2 = head2.prev
+ elseif (head1.id == 0 or head2.id == 0) then -- start of line
+ break
+ elseif (head1.id ~= 37 and head1.id ~= 10) then -- some other kind of node
+ head1 = head1.prev
+ elseif (head2.id ~= 37 and head2.id ~= 10) then -- some other kind of node
+ head2 = head2.prev
+ elseif (head1.id == 37 and head1.char < 48) then -- punctuation
+ head1 = head1.prev
+ elseif (head2.id == 37 and head2.char < 48) then -- punctuation
+ head2 = head2.prev
+ 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")
@@ -193,25 +238,40 @@
node.slide(line.head)
end
+ highlight_reverse = function (nstart,line,color)
+ local n = node.new("whatsit","pdf_literal")
+
+ -- get dimensions
+ local w,h,d = node.dimensions(nstart,node.tail(line.head))
+ 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
+ node.insert_after(line.head,nstart,n)
+ end
+
homeoarchy = function (head)
local cur_line = head
- local prev_line -- initiate prev_head
+ local prev_line -- initiate prev_line
- local max_char = tonumber(\impnattypohomeoarchymaxchars)
- local max_word = tonumber(\impnattypohomeoarchymaxwords)
+ local max_char = tonumber(\inthomeoarchymaxchars)
+ local max_word = tonumber(\inthomeoarchymaxwords)
while head do
if head.id == 0 then -- new line
prev_line = cur_line
cur_line = head
if prev_line.id == 0 then
+ -- homeoarchy
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}"
+ color = "q \usecolor{\inthomeoarchywordcolor}"
else
- color = "q \usecolor{\impnattypohomeoarchycharcolor}"
+ color = "q \usecolor{\inthomeoarchycharcolor}"
end
-- highlight both lines
@@ -226,6 +286,132 @@
end
luatexbase.add_to_callback("post_linebreak_filter",homeoarchy,"homeoarchy")
+
+ homoioteleuton = function (head)
+ local cur_line = head
+ local prev_line -- initiate prev_line
+
+ local max_char = tonumber(\inthomeoarchymaxchars)
+ local max_word = tonumber(\inthomeoarchymaxwords)
+
+ local linecounter = 0
+
+ while head do
+ if head.id == 0 then -- new line
+ linecounter = linecounter + 1
+ if linecounter > 1 then
+ prev_line = cur_line
+ cur_line = head
+ if prev_line.id == 0 then
+ -- homoioteleuton
+ char_count,word_count,prev_head,cur_head = compare_lines_reverse(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{\inthomeoarchywordcolor}"
+ else
+ color = "q \usecolor{\inthomeoarchycharcolor}"
+ end
+
+ -- highlight both lines
+ highlight_reverse(prev_head,prev_line,color)
+ highlight_reverse(cur_head,cur_line,color)
+ end
+ end
+ end
+ end
+ head = head.next
+ end
+
+ return true
+ end
+
+ luatexbase.add_to_callback("post_linebreak_filter",homoioteleuton,"homoioteleuton")
+ \end{luacode}
+ \else
+ \PackageError{The homeoarchy option only works with LuaTeX}
+ \fi
+ \fi
+\fi
+\ifintrivers
+ \ifintdraft
+ \ifluatex
+ \RequirePackage{luatexbase,luacode}
+ \begin{luacode}
+river_analyze_line = function(line,dim1,dim2)
+ local head = line.head
+
+ while head do
+ if head.id == 10 then -- glue node
+ local w1,h1,d1 = node.dimensions(line.glue_set,line.glue_sign,line.glue_order,line.head,head.prev)
+ local w2,h2,d2 = node.dimensions(line.glue_set,line.glue_sign,line.glue_order,line.head,head)
+ --print("dim1:"..dim1.."; dim2:"..dim2.."; w1:"..w1.."; w2:"..w2)
+ if w1 > dim2 then -- out of range
+ return false,head
+ elseif w1 < dim2 and w2 > dim1 then -- found
+ return true,head
+ end
+ end
+ head = head.next
+ end
+
+ return false,head
+end
+
+rivers = function (head)
+ local prev_prev_line
+ local prev_line
+ local cur_line = head
+ local cur_node
+ local char_count
+
+ local linecounter = 0
+
+ while head do
+ if head.id == 0 then -- new line
+ linecounter = linecounter + 1
+ prev_prev_line = prev_line
+ prev_line = cur_line
+ cur_line = head
+ if linecounter > 2 then
+ cur_node = cur_line.head
+ char_count = 0
+
+ while cur_node do
+ if cur_node.id == 37 then -- glyph
+ char_count = char_count + 1
+ elseif cur_node.id == 10 and char_count > 0 and cur_node.next then -- glue node
+ local w1,h1,d1 = node.dimensions(head.glue_set,head.glue_sign,head.glue_order,head.head,cur_node.prev)
+ local w2,h2,d2 = node.dimensions(head.glue_set,head.glue_sign,head.glue_order,head.head,cur_node)
+ found_pp,head_pp = river_analyze_line(prev_prev_line,w1,w2)
+ found_p,head_p = river_analyze_line(prev_line,w1,w2)
+
+ if found_pp and found_p then
+ local n_pp = node.new("whatsit","pdf_literal")
+ n_pp.data = "q \usecolor{\intriverscolor} 0 0 m 0 5 l 5 5 l 5 0 l b Q"
+ node.insert_after(prev_prev_line,head_pp.prev,n_pp)
+
+ local n_p = node.new("whatsit","pdf_literal")
+ n_p.data = "q \usecolor{\intriverscolor} 0 0 m 0 5 l 5 5 l 5 0 l b Q"
+ node.insert_after(prev_line,head_p.prev,n_p)
+
+ local n_c = node.new("whatsit","pdf_literal")
+ n_c.data = "q \usecolor{\intriverscolor} 0 0 m 0 5 l 5 5 l 5 0 l b Q"
+ node.insert_after(cur_line,cur_node.prev,n_c)
+ end
+ end
+ cur_node = cur_node.next
+ end
+ end
+ end
+ head = head.next
+ end
+
+ return true
+
+end
+
+luatexbase.add_to_callback("post_linebreak_filter",rivers,"rivers")
\end{luacode}
\else
\PackageError{The homeoarchy option only works with LuaTeX}