From 4d41d6dca62a66e63d7ec95657880e857efd4be4 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Mon, 19 Sep 2011 23:43:19 +0000 Subject: impnattypo 0.5 (19sep11) git-svn-id: svn://tug.org/texlive/trunk@24019 c570f23f-e606-0410-a88d-b1316a301751 --- .../texmf-dist/doc/latex/impnattypo/impnattypo.pdf | Bin 51098 -> 62863 bytes .../source/latex/impnattypo/impnattypo.dtx | 283 +++++++++++++++++---- .../texmf-dist/tex/latex/impnattypo/impnattypo.sty | 190 +++++++++++--- Master/tlpkg/libexec/ctan2tds | 7 +- 4 files changed, 394 insertions(+), 86 deletions(-) (limited to 'Master') diff --git a/Master/texmf-dist/doc/latex/impnattypo/impnattypo.pdf b/Master/texmf-dist/doc/latex/impnattypo/impnattypo.pdf index 8527120ede4..43bfaddabf3 100644 Binary files a/Master/texmf-dist/doc/latex/impnattypo/impnattypo.pdf and b/Master/texmf-dist/doc/latex/impnattypo/impnattypo.pdf differ diff --git a/Master/texmf-dist/source/latex/impnattypo/impnattypo.dtx b/Master/texmf-dist/source/latex/impnattypo/impnattypo.dtx index 16644e211fd..5ca9ccfe90c 100644 --- a/Master/texmf-dist/source/latex/impnattypo/impnattypo.dtx +++ b/Master/texmf-dist/source/latex/impnattypo/impnattypo.dtx @@ -26,16 +26,17 @@ %\NeedsTeXFormat{LaTeX2e}[1999/12/01] %\ProvidesPackage{impnattypo} %<*package> - [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] % % %<*driver> \documentclass{ltxdoc} -\usepackage[hyphenation,nosingleletter,parindent,lastparline]{impnattypo}[2011/09/13] \usepackage[french]{babel} \usepackage{fontspec} +\usepackage[svgnames]{xcolor} \setmainfont{Linux Libertine O} \usepackage{metalogo} +\usepackage[draft,hyphenation,nosingleletter,parindent,lastparline,homeoarchy]{impnattypo}[2011/09/19] \usepackage[all]{nowidow} \EnableCrossrefs \CodelineIndex @@ -48,7 +49,7 @@ % % \fi % -% \CheckSum{66} +% \CheckSum{96} % % \CharacterTable % {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z @@ -67,6 +68,8 @@ % Right brace \} Tilde \~} % % +% \changes{0.5}{2011/09/19}{Add homeoarchy detection} +% \changes{0.4}{2011/09/15}{Add draft mode} % \changes{0.3}{2011/09/13}{Add parindent and lastparline options} % \changes{0.2}{2011/09/13}{Add nosingleletter option} % \changes{0.1}{2011/09/11}{First version} @@ -87,12 +90,14 @@ % le \emph{Lexique des règles typographiques en usage à l'Imprimerie Nationale} % est une référence incontournable. % -% Si la majorité des recommendations de cet ouvrage concerne la ponctuation, -% l'usage des petites capitales ou encore l'ordre des parties d'un livre, -% certaines autres recommendations méritent d'être automatisées pour être +% Si la majorité des recommendations de cet ouvrage est implémentée dans +% le module \textsf{frenchb} pour \textsf{babel}, +% certaines autres recommendations méritent encore d'être automatisées pour être % implémentées en \LaTeX. % -% C'est le but de ce paquet, qui implémente plusieurs règles +% C'est le but de ce paquet, initié par une question sur le site +% tex.stackexchange.com\footnote{\url{http://tex.stackexchange.com/questions/20493/french-typography-recommendations}}, +% et qui implémente plusieurs règles % édictées dans ce lexique afin de les rendre plus facilement applicables % aux textes édités avec \LaTeX. % @@ -153,6 +158,11 @@ % \usepackage[lastparline]{impnattypo} % \end{verbatim} % +% Lorsque l'option \texttt{draft} est activée et que \LuaTeX est utilisé, +% les espaces insécables insérés sont colorés en +% {\color{\impnattypolastparlinecolor}\impnattypolastparlinecolor}. +% La couleur utilisée peut être ajustée par l'option \texttt{lastparlinecolor}. +% % \DescribeMacro{nosingleletter} % Il est également recommendé d'éviter les coupures isolant une lettre. % La solution proposée par Patrick Gundlach\footnote{\url{http://tex.stackexchange.com/questions/27780/one-letter-word-at-the-end-of-line}} @@ -166,6 +176,45 @@ % Lorsque cette option est activée, seul \LuaTeX{} (via la commande |lualatex|) % pourra effectuer le rendu du document. % +% Lorsque l'option \texttt{draft} est activée, +% les espaces insécables insérés sont colorés en +% {\color{\impnattyponosinglelettercolor}\impnattyponosinglelettercolor}. +% La couleur utilisée peut être ajustée par l'option \texttt{nosinglelettercolor}. +% +% \DescribeMacro{homeoarchy} +% Lorsque deux lignes consécutives commencent par le même mot +% ou la même série de lettres, cela peut induire le lecteur +% en erreur et cela est donc à éviter. +% +% La correction automatique de ce phénomène est très complexe +% et en général non souhaitable. C'est pourquoi l'option +% \texttt{homeoarchy} de ce paquet se contente +% de les détecter et de les afficher. Leur correction +% consistera en général en l'introduction d'un +% espace insécable dans le paragraphe. +% +% \begin{verbatim} +% \usepackage[homeoarchy]{impnattypo} +% \end{verbatim} +% +% Cette option n'est effective que si l'option \texttt{draft} est activée. +% +% Les espaces insécables insérés sont colorés de deux couleurs. +% Les mots entiers sont colorés en +% {\color{\impnattypohomeoarchywordcolor}\impnattypohomeoarchywordcolor} +% et cette couleur peut être ajustée par l'option \texttt{homeoarchywordcolor}. +% Les mots partiels sont colorés en +% {\color{\impnattypohomeoarchycharcolor}\impnattypohomeoarchycharcolor} +% et cette couleur peut être ajustée par l'option \texttt{homeoarchycharcolor}. +% +% Une séquence de glyphes est considéré comme problématique si: +% +% \begin{itemize} +% \item Le nombre de mots entiers matchant est supérieur à \impnattypohomeoarchymaxwords. Ce paramètre peut être ajusté par l'option \texttt{homeoarchymaxwords}; +% \item Le nombre de caractères matchant est supérieur à \impnattypohomeoarchymaxchars. Ce paramètre peut être ajusté par l'option \texttt{homeoarchymaxchars}; +% \end{itemize} +% +% % \subsection{Numérotation des chapitres} % % \DescribeMacro{frenchchapters} @@ -202,7 +251,28 @@ % \end{verbatim} % % Voir la documentation de ce paquet pour plus d'options. -% +% +% +% \subsection{Mode brouillon} +% +% \DescribeMacro{draft} +% Le paquet \textsf{impnattypo} dispose d'un mode brouillon +% permettant de visualiser les pénalités (espaces insécables) +% ajoutés par les options \texttt{nosingleletter} et +% \texttt{lastparline}. En mode brouillon, +% les emplacements des espaces insécables insérés +% sont marqués par des rectangles de couleur. +% +% Pour activer le mode brouillon, utilisez l'option \texttt{draft}, +% par exemple: +% +% \begin{verbatim} +% \usepackage[draft,lastparline]{impnattypo} +% \end{verbatim} +% +% Cette document est générée avec l'option \texttt{draft} afin d'en +% montrer les effets. +% % % \StopEventually{} % @@ -214,24 +284,34 @@ % % \begin{macrocode} \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} % \end{macrocode} % % \marginpar{No page finishes with an hyphenated word} % % \begin{macrocode} +\ifimpnattypohyphenation \brokenpenalty=10000 % \end{macrocode} % \marginpar{Discourage hyphenation on two lines in a row} @@ -243,7 +323,7 @@ % \marginpar{Number chapters} % % \begin{macrocode} -\if@impnattypo@frenchchapters +\ifimpnattypofrenchchapters \let\frenchchapter\Roman \renewcommand{\thechapter}{% \ifnum\value{chapter}=1 @@ -258,29 +338,30 @@ % \marginpar{No single letter} % % \begin{macrocode} -\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 - - 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 - - p.next = head.next - head.next.prev = p - head.next = p + 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 + + \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 @@ -299,7 +380,7 @@ % \marginpar{Paragraph indentation} % % \begin{macrocode} -\if@impnattypo@parindent +\ifimpnattypoparindent \setlength{\parindent}{1em} \fi % \end{macrocode} @@ -307,9 +388,9 @@ % \marginpar{Last line of paragraph} % % \begin{macrocode} -\if@impnattypo@lastparline +\ifimpnattypolastparline \ifluatex - \usepackage{luatexbase,luacode} + \RequirePackage{luatexbase,luacode} \begin{luacode} last_line_twice_parindent = function (head) while head do @@ -319,10 +400,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 @@ -338,6 +425,110 @@ \fi % \end{macrocode} % +% \marginpar{Detect homeoarchies} +% +% \begin{macrocode} +\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 +% \end{macrocode} +% % \iffalse % % \fi 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'. diff --git a/Master/tlpkg/libexec/ctan2tds b/Master/tlpkg/libexec/ctan2tds index 9e8ca6ed11e..2454e3989b1 100755 --- a/Master/tlpkg/libexec/ctan2tds +++ b/Master/tlpkg/libexec/ctan2tds @@ -505,9 +505,10 @@ chomp ($Build = `cd $Master/../Build/source && pwd`); 'makebarcode', "&MAKEcopy", 'makecell', "&MAKEnosymlinks", 'makedtx', "&MAKEflatten", - 'maketexwork', "die 'skipping, too old'", - 'makor', "&MAKEbase", - 'malayalam', "die 'skipping, until asked for'",#language/malayalam + 'makedlossariesgui', "skipping, impossible java'", + 'maketexwork', "die 'skipping, too old'", + 'makor', "&MAKEbase", + 'malayalam', "die 'skipping, until asked for'",#language/malayalam 'malayalam-omega', "die 'skipping, until asked for'", 'manjutex', "die 'skipping, obsolete on CTAN'", #"&MAKEflatten", 'manpage', "die 'skipping, nonfree license'", -- cgit v1.2.3