summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/impnattypo/impnattypo.sty
blob: 9185c353e9d5f5951fea667ab1d5f74719fe9a31 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
%%
%% This is file `impnattypo.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% impnattypo.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% Copyright (C) 2011 by Raphaël Pinson <raphink@gmail.com>
%% --------------------------------------------------------------------------
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%% 
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{impnattypo}
    [2011/09/13 0.3 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
   \brokenpenalty=10000
   \doublehyphendemerits=1000000000
\fi
\if@impnattypo@frenchchapters
   \let\frenchchapter\Roman
   \renewcommand{\thechapter}{%
     \ifnum\value{chapter}=1
       premier%
     \else
       \frenchchapter{chapter}%
     \fi
   }
\fi
\if@impnattypo@nosingleletter
   \ifluatex
      \usepackage{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

            end
          end
          head = head.next
        end
        return true
      end

      luatexbase.add_to_callback("pre_linebreak_filter",prevent_single_letter,"~")
      \end{luacode}
   \else
      \PackageError{The nosingleletter option only works with LuaTeX}
   \fi
\fi
\if@impnattypo@parindent
\setlength{\parindent}{1em}
\fi
\if@impnattypo@lastparline
   \ifluatex
      \usepackage{luatexbase,luacode}
      \begin{luacode}
      last_line_twice_parindent = function (head)
        while head do
          local _w,_h,_d = node.dimensions(head)
          if head.id == 10 and head.subtype ~= 15 and (_w < 2 * tex.parindent) then

              -- 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
          end

          head = head.next
        end
        return true
      end

      luatexbase.add_to_callback("pre_linebreak_filter",last_line_twice_parindent,"lastparline")
      \end{luacode}
   \else
      \setlength{\parfillskip}{0pt plus\dimexpr\textwidth-2\parindent}
   \fi
\fi
\endinput
%%
%% End of file `impnattypo.sty'.