summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/plain/pitex/pitex.tex
blob: 7f6e1823865880219c02110dfc7cfe76d132aadd (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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
% This is piTeX, a set of macros I (Paul Isambert) use to
% typeset documentations for my packages (that's why it is
% archived on CTAN).
%
% Perhaps in the future, when this achieves some kind of
% format-like completude, there'll be a documentation and
% it'll be publicly announced.
%
% You can of course use those macros, but you are on your
% own, and the files will probably be modified without announcement.
% The file is supposed to be \input on plain TeX with LuaTeX, at least v.0.6.
%
%
% The files needed are:
%
% texapi.tex (an independent package \input in the following file)
% yax.tex (an independent package)
% fonts.ptx (piTeX font "management")
% luaotfload.sty (an independent package (not by me))
% sections.ptx (piTeX sectionning commands)
%
% Date: June 2010.
%
%
% User interface
\input yax % which itself \input's texapi

\setcatcodes{\@\_=11}
\def\ptx@error{\senderror{PiTeX}}

% This to write in latin1.
\directlua{%
 function convert(buf)
   return string.gsub(buf,"(.)", function (ch)
       return unicode.utf8.char(string.byte(ch))
     end)
 end
 callback.register('process_input_buffer',convert)
 }

\newdimen\urvsize
\urvsize\vsize

\def\inputpitexfile#1 {\input #1.ptx }

\inputpitexfile fonts
\inputpitexfile sections
% No footnotes in documentations.
%\input footnotes.tex
% I redefine the output routine on every job.
%\input output.tex

\defactiveparameter document{%
  \pdfinfo{%
    /Author (\usevalueor #1 : author {Unknown author})
    /Title  (\usevalueor #1 : pdftitle  {\usevalueor #1 : title {No title}})
    \ifattribute #1 : subject {/Subject (\usevalue #1 : subject )}{}
    \ifattribute #1 : keywords {/Keywords (\usevalue #1 : keywords )}{}
    }%
  \pdfcatalog{%
    /PageMode
      \ifcasevalue #1 : display
        \val outlines   /UseOutlines
        \val signets    /UseOutlines % French!
        \val thumbs     /UseThumbs
        \val thumbnails /UseThumbs
        \val full       /FullScreen
        \val fullscreen /FullScreen
        \elseval        /UseNone
      \endval
    }%
  }

\restrictparameter document : author title pdftitle date subject keywords display version\par
\restrictattribute document:display outlines signets thumbs thumbnails full fullscreen\par


\defactiveparameter page{%
  \settovalue\pdfpagewidth  #1 : pagewidth
  \settovalue\pdfpageheight #1 : pageheight
  \settovalue\baselineskip  #1 : baselineskip
  \settovalueor\topskip     #1 : topskip {\topskip=\baselineskip}%
  \settovalue\pdfhorigin    #1 : left
  \ifattribute #1 : right
              {\hsize = \dimexpr(\pdfpagewidth-\pdfhorigin-\usevalue #1 : right )\relax}
              {\settovalue\hsize #1 : hsize }%
  \settovalue\pdfvorigin    #1 : top
  \settovalue\parindent     #1 : parindent
  \settovalue\parskip       #1 : parskip
  \ifattribute #1 : lines {\vsize=\usevalue #1 : lines \baselineskip}{}%
  }
\restrictparameter page : pagewidth
                          pageheight
                          hsize
                          baselineskip
                          topskip
                          left
                          right
                          top
                          lines
                          parindent
                          parskip
                          \par

% Defaults... they don't produce anything beautiful.
% I redefine them on every job.
\setparameter page:
  pageheight   = 28cm
  pagewidth    = 21cm
  hsize        = 15cm
  baselineskip = 12pt
  lines        = 42
  left         = 1in
  top          = 1in
  parskip      = 0pt


% Should be used with YaX to set parameters.
\long\pdef\newblock{%
  \ifnext*{\gobbleoneand\ptx@newblock_group}
          {\ptx@newblock_nogroup}%
  }
\def\ptx@newblock_nogroup#1#2#3{%
  \def#1{\ifnext/{\gobbleoneand{#3}}{#2}}%
  }
\def\ptx@newblock_group#1#2#3{%
  \def#1{\ifnext/{\gobbleoneand{#3\egroup}}{\bgroup#2}}%
  }
\def\antigobblespace{%
  \ifcatnext a{ }{\iffnext({ }}%
  }


% PDF links
\def\dest#1#2{%
  \ifcs{ptx@link_name=#1}
       {\ptx@error{Link `#1' already exists}#2}
       {\letcs{ptx@link_name=#1}\relax
        \bgroup
          \ifvmode
            \pdfdest name {#1} xyz #2%
          \else
            \setbox0=\hbox{#2}%
            \raise\ht0\hbox{\pdfdest name {#1} xyz}#2%
          \fi
        \egroup
        }%
  }
\def\link#1#2{%
  \pdfstartlink attr {/Border [0 0 0]} goto name {#1}#2\pdfendlink
  }

% Verbatim facilities.

\def\tcode#1{{\codefont#1}}
\long\def\com#1{%
  \bgroup
    \codefont
    \string#1%
  \egroup
  \antigobblespace
  }
\def\arg#1{{\codefont\it<#1>}\iffnext\spacechar{\kern.2ex }}
\def\barg#1{{\codefont\char"007B\relax{\it<#1>}\char"007D\relax}}


\def\exampleskip{\vskip\baselineskip}
\def\example{%
  \exampleskip
  \bgroup
  \parindent0pt
  \setcatcodes{\\\{\}\$\&\#\^\_\ \~\%=12,\^^M=13}%
  \codefont
  \readexample
  }%
\bgroup
\setcatcodes{\\=12,\|=0,\^^M=13}%
|gdef|readexample#1^^M#2\example/{#2|egroup|exampleskip}%
|restorecatcodes%
\setcatcodes{\^^M=13}%
\gdef^^M{\quitvmode\endgraf}%
\egroup%
\def\verb#1{%
  \def\ptx@verb##1#1{##1\egroup}%
  \bgroup
  \setcatcodes{\\\{\}\$\&\#\^\_\ \~\%=12}%
  \codefont
  \ptx@verb
  }

%
% Read and process examples.
%
\newwrite\ptx@examplewrite

\bgroup
\setcatcodes{\%=12,\/=14}
\gdef\Example{/
  \immediate\openout\ptx@examplewrite=\jobname.pex
  \immediate\write\ptx@examplewrite{% This is a scratch file used to typeset examples in \jobname.tex.}/
  \immediate\write\ptx@examplewrite{% You can delete it.}/
  \immediate\write\ptx@examplewrite{%}/
  \bgroup
  \setcatcodes{\\\#\%\^^M\ =12}/
  \writeexample
  }/
\egroup

\bgroup
\setcatcodes{\^^M=12}%
\gdef\writeexample#1^^M{%
  \immediate\write\ptx@examplewrite{\noexpand\example}%  
  \ptx@writeexample}%
\gdef\ptx@writeexample#1^^M{%
  \passexpanded{\ifstring{#1}}{\examplestring}%
               {\immediate\write\ptx@examplewrite{\string\example/}%
                \immediate\closeout\ptx@examplewrite\egroup%
                \processexample}%
               {\immediate\write\ptx@examplewrite{\primunexpanded{#1}}%
                \ptx@writeexample}%
  }%
{\setcatcodes{\\=12,\|=0}|gdef|examplestring{\Example/}}%
\egroup

\def\typesetexample{{\input\jobname.pex }}
\def\doexample{{\let\example\ptx@Example\input\jobname.pex }}
\def\ptx@Example{%
  \iffnext/{\gobbleoneand\endinput}%
  }
% To be redefined for different layout.
\def\processexample{\typesetexample\doexample}

\def\verb#1{%
  \def\ptx@verb##1#1{##1\egroup}%
  \bgroup
  \setcatcodes{\\\{\}\$\&\#\^\_\ \~\%=12}%
  \codefont
  \ptx@verb
  }


\newdimen\extraboxspace
\newdimen\ptx@extraboxspace_top
\newdimen\ptx@extraboxspace_right
\newdimen\ptx@extraboxspace_bottom
\newdimen\ptx@extraboxspace_left

\newfornoempty\ptx@colorbox_loop{1}#2,{%
  \ifcase#1
    \ptx@extraboxspace_top    =#2
    \ptx@extraboxspace_right  =#2
    \ptx@extraboxspace_bottom =#2
    \ptx@extraboxspace_left   =#2
  \or
    \ptx@extraboxspace_right  =#2
    \ptx@extraboxspace_left   =#2
  \or
    \ptx@extraboxspace_bottom =#2
  \or
    \ptx@extraboxspace_left   =#2
  \fi
  \passarguments{\numexpr(#1+1)}%
  }
\def\colorbox{%
  \ifnextnospace[\ptx@colorbox_setborders
          {\ptx@extraboxspace_top    =\extraboxspace
           \ptx@extraboxspace_right  =\extraboxspace
           \ptx@extraboxspace_bottom =\extraboxspace
           \ptx@extraboxspace_left   =\extraboxspace
           \ptx@colorbox_do}%
  }
\def\ptx@colorbox_setborders[#1]{%
  \ptx@colorbox_loop{0}{#1,}%
  \ptx@colorbox_do
  }
{\setcatcodes{pt=12}
\gdef\noPT#1pt{#1 }}
\def\ptx@colorbox_do#1#2{%
  \bgroup
  \setbox0=\hbox{#2}%
  \hbox{%
    \pdfliteral{
      q #1 rg #1 RG
      -\expandafter\noPT\the\ptx@extraboxspace_left
       \expandafter\noPT\the\dimexpr(\ht0+\ptx@extraboxspace_top)\relax
       \expandafter\noPT\the\dimexpr(\wd0+\ptx@extraboxspace_left+\ptx@extraboxspace_right)\relax
      -\expandafter\noPT\the\dimexpr(\ht0+\ptx@extraboxspace_top+\dp0+\ptx@extraboxspace_bottom)\relax
      re f Q}%
    #2}%
  \egroup
  }

\def\trace{\tracingcommands4 \tracingmacros4 }
\def\untrace{\tracingcommands0 \tracingmacros0 }

\restorecatcodes