Debian Codegraph @

texmf-dist/tex/plain/pitex/pitex.tex

raw
1 % This is piTeX, a set of macros I (Paul Isambert) use to
2 % typeset documentations for my packages (that's why it is
3 % archived on CTAN).
4 %
5 % Perhaps in the future, when this achieves some kind of
6 % format-like completude, it'll be publicly announced. In the
7 % meanwhile, a documentation exists (pitex-doc.pdf, also readable
8 % in a text editor as pitex-doc.txt).
9 %
10 %
11 % You can of course use those macros, but you are on your
12 % own, and the files will probably be modified without announcement.
13 % The file is supposed to be \input on plain TeX with LuaTeX, at least v.0.6.
14 %
15 %
16 % The files needed are:
17 %
18 % texapi.tex (an independent package for programming)
19 % yax.tex (an independent package for key=value interface)
20 % gates.tex and gates.lua (an independant package for overall architecture)
21 % navigator.tex (an independant package for PDF features)
22 % lua.ptx and base.ptxlua (Lua side)
23 % files.ptx (file management)
24 % fonts.ptx, fonts.ptxlua and foundry-settings.lua
25 % (fonts, should be independant some day; actually
26 % fonts.ptxlua can be used independantly, but there is
27 % no doc)
28 % sections.ptx (sectionning commands)
29 % blocks.ptx (text blocks)
30 % references.ptx (labels and references)
31 % verbatim.ptx (typesetting verbatim)
32 % inserts.ptx (footnotes and figures, a mess)
33 % output.ptx (output routine)
34 %
35 % The file i-pitex.lua is needed only to typeset the documentation with the
36 % Interpreter package.
37 %
38 %
39 % Date: November 2011.
40 %
41 %
42 % User interface
43 \input yax % which itself \input's texapi
44 \input gates
45
46 \setcatcodes{\@\_=11}
47 \suppressoutererror=1
48
49 % MESSAGES
50 \def\ptx@error{\senderror{PiTeX}}
51 \def\ptx@log#1{%
52 \immediate\write17{^^J#1^^J}%
53 }
54 \def\ptx@warn#1{%
55 \ptx@log{PiTeX warning: #1}%
56 }
57
58 % ATTRIBUTES
59 \newcount\ptx@attribute_count
60 \ptx@attribute_count=100 % The first 100 attributes are scratch.
61 \def\newattribute#1{%
62 \advance\ptx@attribute_count1
63 \attributedef#1=\ptx@attribute_count
64 \xdefcs{ptx@attribute:\commandtoname#1}{\the\ptx@attribute_count}%
65 }
66 \def\unsetattribute#1{#1=-"7FFFFFFF\relax}
67 \def\attributenumber#1{\usecs{ptx@attribute:\commandtoname#1}}
68
69 % FREEDEF
70 \def\freedef#1{%
71 \def#1{%
72 \ifnextnospace"
73 {\ptx@freedef_quote#1}
74 {\ifnextnospace/
75 {\ptx@freedef_slash#1}
76 {\usecs{ptx@freedef_user:\commandtoname#1}}}%
77 }%
78 \defcs{ptx@freedef_user:\commandtoname#1}##1%
79 }
80 \def\ptx@freedef_quote#1"#2"{%
81 \usecs{ptx@freedef_user:\commandtoname#1}{#2}%
82 }
83 \def\ptx@freedef_slash#1/#2/{%
84 \usecs{ptx@freedef_user:\commandtoname#1}{#2}%
85 }
86
87
88 \newbox\ptx@box_temp
89
90 \newif\ifmaintext
91 \maintexttrue
92
93 % CATCODE TABLES
94 \newcount\ptx@catcodetable_count
95 \ptx@catcodetable_count=100 % First 100 are scratch.
96 \def\newcatcodetable#1#2{%
97 \global\advance\ptx@catcodetable_count1
98 \chardef#1=\ptx@catcodetable_count
99 \begingroup
100 \setcatcodes{#2}%
101 \savecatcodetable#1%
102 \endgroup
103 }
104
105 \newcatcodetable\texcatcodes{\@\_=12}
106
107 \def\inputpitexfile#1 {\input #1.ptx }
108
109 \inputpitexfile lua
110 \inputpitexfile files
111 \inputpitexfile fonts
112 \inputpitexfile sections
113 \inputpitexfile blocks
114 \inputpitexfile references
115 \inputpitexfile verbatim
116 \inputpitexfile inserts
117 \inputpitexfile output
118 \input navigator.tex
119
120 % AUXILIARY FILE
121 \iffile{\jobname.aux}{%
122 \ptx@lua{%
123 remove_conversion()
124 tex.print("\luaescapestring{\noexpand\input\noexpand\jobname.aux}")
125 }%
126 \directlua{restore_conversion()}}
127 \immediate\openout\ptx@auxfile=\jobname.aux
128
129 % PDF SETTINGS
130 \restrictparameter document : author title pdftitle date pdfdate subject keywords mode layout version\par
131 \restrictattribute document : mode outlines bookmarks thumbs thumbnails attachments files oc\par
132 \restrictattribute document : layout onepage onecolumn twopage twocolumn twopage* twocolumn*\par
133
134 \suppressoutererror=1
135 \let\ptx@bye\bye
136 \def\bye{%
137 \passvalueand{\setattribute navigator : title = } document : pdftitle { }{}
138 % The "date" attribute in the "document" parameter isn't supposed to hold a
139 % PDF-date, as navigator expects.
140 \deleteattribute document : date
141 \passvalueand{\setattribute navigator : date = } document : pdfdate { }{}
142 \finishpdffile\ptx@bye
143 }
144
145 \setattribute navigator : meta = document
146
147 % Turns a dimen into PostScript points, without the unit (as wanted by PDF).
148 \def\pdfpoint#1{%
149 \directlua{%
150 local d = "\the\dimexpr#1"
151 d = string.gsub(d, "pt", "")
152 tex.print(tostring(d * (72/72.27)))
153 }}
154
155
156
157
158 % TEX SETTINGS
159 \long\def\ptx@tex_set#1#2#3{%
160 \ifcs{#2}
161 {\usecs{#2}=#3\relax}
162 {\ptx@error{No TeX parameter `#2'}}
163 }
164
165 \defactiveparameter tex {%
166 \parameterloop #1 : \ptx@tex_set
167 }
168
169 \frenchspacing
170 \maxdepth=\maxdimen
171
172 \def\antigobblespace{%
173 \ifcatnext a{ }{\iffnext({ }}%
174 }
175
176 \def\strut#1#2{%
177 \vrule height#1 depth#2 width0pt
178 }
179
180 \newdimen\extraboxspace
181 \newdimen\ptx@extraboxspace_top
182 \newdimen\ptx@extraboxspace_right
183 \newdimen\ptx@extraboxspace_bottom
184 \newdimen\ptx@extraboxspace_left
185
186 \newfornoempty\ptx@colorbox_loop{1}#2,{%
187 \ifcase#1
188 \ptx@extraboxspace_top =#2
189 \ptx@extraboxspace_right =#2
190 \ptx@extraboxspace_bottom =#2
191 \ptx@extraboxspace_left =#2
192 \or
193 \ptx@extraboxspace_right =#2
194 \ptx@extraboxspace_left =#2
195 \or
196 \ptx@extraboxspace_bottom =#2
197 \or
198 \ptx@extraboxspace_left =#2
199 \fi
200 \passarguments{\numexpr(#1+1)}%
201 }
202 \def\colorbox{%
203 \ifnextnospace[\ptx@colorbox_setborders
204 {\ptx@extraboxspace_top =\extraboxspace
205 \ptx@extraboxspace_right =\extraboxspace
206 \ptx@extraboxspace_bottom =\extraboxspace
207 \ptx@extraboxspace_left =\extraboxspace
208 \ptx@colorbox_do}%
209 }
210 \def\ptx@colorbox_setborders[#1]{%
211 \ptx@colorbox_loop{0}{#1,}%
212 \ptx@colorbox_do
213 }
214 {\setcatcodes{pt=12}
215 \gdef\noPT#1pt{#1 }}
216 \def\ptx@colorbox_do#1#2{%
217 \bgroup
218 \setbox\ptx@box_temp=\hbox{#2}%
219 \hbox{%
220 \pdfliteral{
221 q #1 rg #1 RG
222 -\expandafter\noPT\the\ptx@extraboxspace_left
223 \expandafter\noPT\the\dimexpr(\ht\ptx@box_temp+\ptx@extraboxspace_top)\relax
224 \expandafter\noPT\the\dimexpr(\wd\ptx@box_temp+\ptx@extraboxspace_left+\ptx@extraboxspace_right)\relax
225 -\expandafter\noPT\the\dimexpr(\ht\ptx@box_temp+\ptx@extraboxspace_top+\dp\ptx@box_temp+\ptx@extraboxspace_bottom)\relax
226 re f Q}%
227 #2}%
228 \egroup
229 }
230
231 \def\og{\char"00AB~} \def\fg{~\char"00BB\antigobblespace}
232
233 \def\trace{\tracingcommands3 \tracingmacros2 }
234 \def\untrace{\tracingcommands0 \tracingmacros0 }
235
236 \restorecatcodes