| 1 |
%% |
| 2 |
%% This is file `placeat.sty', |
| 3 |
%% generated with the docstrip utility. |
| 4 |
%% |
| 5 |
%% The original source files were: |
| 6 |
%% |
| 7 |
%% placeat.dtx (with options: `package') |
| 8 |
%% |
| 9 |
%% EXPERIMENTAL CODE |
| 10 |
%% |
| 11 |
%% This package is copyright © 2017 Arno L. Trautmann. It may be distributed and/or |
| 12 |
%% modified under the conditions of the LaTeX Project Public License, either version 1.3c |
| 13 |
%% of this license or (at your option) any later version. This work has the LPPL mainten- |
| 14 |
%% ance status ‘maintained’. |
| 15 |
\ProvidesPackage{placeat}% |
| 16 |
[2017/08/19 v0.1d1 absolute content positioning] |
| 17 |
\RequirePackage{luatexbase} |
| 18 |
\RequirePackage{luacode} |
| 19 |
\RequirePackage{atbegshi} |
| 20 |
\RequirePackage{xparse} |
| 21 |
\directlua{dofile(kpse.find_file("placeat.lua",'lua'))} |
| 22 |
\NewDocumentCommand\placeat{ggd()d<>O{}mo}{ |
| 23 |
\IfValueT{#1}{ %% two coordinates in { }{ } pair. |
| 24 |
\IfValueT{#2}{ %% if second argument is not given, everything breaks. not nice. |
| 25 |
\def\cox{#1} |
| 26 |
\def\coy{#2} |
| 27 |
} |
| 28 |
} |
| 29 |
\IfValueT{#3}{ %% one argument as ( , ) coordinate pair. |
| 30 |
\def\cox{\firstof#3X} |
| 31 |
\def\coy{\secondof#3X} |
| 32 |
} |
| 33 |
\IfValueT{#4}{ |
| 34 |
\luadirect{ |
| 35 |
y = string.byte('#4',1)-64 |
| 36 |
x = string.byte('#4',2)-48 |
| 37 |
x2 = string.byte('#4',3) |
| 38 |
if x2 then x = x*10 + x2-48 end -- FIXME: what exactly happens here? … |
| 39 |
} |
| 40 |
\def\cox{\luadirect{tex.print(x)}} |
| 41 |
\def\coy{\luadirect{tex.print(y)}} |
| 42 |
} |
| 43 |
\placeatthreenumbers{\cox}{\coy}{\llap{#5}#6} |
| 44 |
|
| 45 |
\IfValueT{#7}{ |
| 46 |
\expandafter\gdef\csname #7x\endcsname{\firstof#3X} |
| 47 |
\expandafter\gdef\csname #7y\endcsname{\secondof#3X} |
| 48 |
} |
| 49 |
} |
| 50 |
\NewDocumentCommand\placerelto{oggd()d<>O{}mo}{ |
| 51 |
\IfValueT{#2}{ %% two coordinates in { }{ } pair. |
| 52 |
\IfValueT{#3}{ %% if second argument is not given, everything breaks. not nice. |
| 53 |
\def\cox{#2} |
| 54 |
\def\coy{#3} |
| 55 |
} |
| 56 |
} |
| 57 |
\IfValueT{#4}{ %% one argument as ( , ) coordinate pair. |
| 58 |
\def\cox{\firstof#4X} |
| 59 |
\def\coy{\secondof#4X} |
| 60 |
} |
| 61 |
\IfValueT{#5}{ |
| 62 |
\luaexec{ |
| 63 |
y = string.byte('#5',1)-64 |
| 64 |
x = string.byte('#5',2)-48 |
| 65 |
x2 = string.byte('#5',3) |
| 66 |
if x2 then x = x*10 + x2-48 end -- FIXME: what exactly happens here? … |
| 67 |
tex.print("\\def\\cox{"..(x).."}\\def\\coy{"..(y).."}") |
| 68 |
} |
| 69 |
} |
| 70 |
\placeatthreenumbers |
| 71 |
{\cox + \csname #1x\endcsname} |
| 72 |
{\coy + \csname #1y\endcsname} |
| 73 |
{\llap{#6}#7} |
| 74 |
\IfValueT{#8}{ |
| 75 |
\expandafter\xdef\csname #8x\endcsname{\cox + \csname #1x\endcsname} |
| 76 |
\expandafter\xdef\csname #8y\endcsname{\coy + \csname #1y\endcsname} |
| 77 |
} |
| 78 |
} |
| 79 |
\NewDocumentCommand\placeminipageat{r()O{10cm}m}{ |
| 80 |
\gdef\widthofplaceat{#2} |
| 81 |
\placeat(#1) |
| 82 |
{\begin{minipage}{\widthofplaceat}{#3}\end{minipage}} |
| 83 |
} |
| 84 |
\def\placeatthreenumbers#1#2#3{ |
| 85 |
\luaexec{ |
| 86 |
nr = nr+1 |
| 87 |
dacoordtmp = ((#1-1+offsetx)*tex.pagewidth/65536/gridnrx*1.005)..","..(-(#2-1+offsety)*tex.pageheight/65536/gridnry) |
| 88 |
dacoord[nr] = "\\put("..dacoordtmp..")" |
| 89 |
tex.print("\\expandafter\\gdef\\csname command"..(nr).."\\endcsname")}% begin of command definition |
| 90 |
{#3} %% this is what \command[nr] will contain |
| 91 |
} |
| 92 |
\def\firstof #1,#2X{#1} |
| 93 |
\def\secondof #1,#2X{#2} |
| 94 |
\gdef\drawgridnum{1} |
| 95 |
\luaexec{ |
| 96 |
arrowheadlength = 5 |
| 97 |
drawgrid = false |
| 98 |
nr = 0 |
| 99 |
dacoord = {} |
| 100 |
gridnr = 10 |
| 101 |
gridnrx = 10 |
| 102 |
gridnry = 10 |
| 103 |
gridlinewidth = 0.01 |
| 104 |
offsetx = 0 |
| 105 |
offsety = 0 |
| 106 |
} |
| 107 |
\AtBeginDocument{ |
| 108 |
\AtBeginShipout{% |
| 109 |
\AtBeginShipoutUpperLeftForeground{% |
| 110 |
\ifnum\drawgridnum = 1 \drawgrid\fi |
| 111 |
\luaexec{% |
| 112 |
for i = 1,nr do |
| 113 |
tex.print(dacoord[i].."{\\csname command"..(i).."\\endcsname}") |
| 114 |
end |
| 115 |
nr=0 |
| 116 |
} |
| 117 |
} |
| 118 |
} |
| 119 |
} |
| 120 |
\def\drawgrid{ |
| 121 |
\luatexlatelua{ |
| 122 |
pdf_print("q") |
| 123 |
linewidth(gridlinewidth) |
| 124 |
local factorh = tex.pageheight/gridnry/65536 |
| 125 |
local factorw = tex.pagewidth/gridnrx/65536 |
| 126 |
for i = 1,math.max(gridnrx,gridnry) do |
| 127 |
h = i*factorh |
| 128 |
w = i*factorw |
| 129 |
move(0,-h) line(tex.pagewidth,-h) stroke() |
| 130 |
move(w,0) line(w,-tex.pageheight) stroke() |
| 131 |
end |
| 132 |
pdf_print("Q") |
| 133 |
} |
| 134 |
{ %% extra grouping to keep font size change local. Going to normalfont seems to make sense. An explicit font for the grid might also be nice. Implementation only upon request. |
| 135 |
%% would also be nice to maybe adapt the fontsize to the grid size |
| 136 |
\normalfont\fontsize{8}{10}\selectfont |
| 137 |
\luaexec{ |
| 138 |
for i=1,math.max(gridnrx+offsetx,gridnry+offsety) do |
| 139 |
hfac = tex.pageheight/gridnry/65536 |
| 140 |
wfac = tex.pagewidth/gridnrx/65536*1.005 %% another empirical factor |
| 141 |
h = (i-1)*hfac |
| 142 |
w = (i-1)*wfac |
| 143 |
tex.print("\\put("..(w)..",-7){\\rlap{"..(i-offsetx).."}}") |
| 144 |
if alphanumgrid then |
| 145 |
tex.print("\\put(0,"..(-h-0.05*hfac).."){\\char00"..(64+i-offsety).."}") %%-- for alphanumeric grid. |
| 146 |
else |
| 147 |
tex.print("\\put(0,"..(-h-0.05*hfac).."){"..(i-offsety).."}") |
| 148 |
end |
| 149 |
end |
| 150 |
} |
| 151 |
} |
| 152 |
} |
| 153 |
\NewDocumentCommand\placelineat{or()r()}{ |
| 154 |
\placeat(#2){\ignorespaces\IfValueT{#1}{\color{#1}} % only to fix the color! |
| 155 |
\luatexlatelua{placelineat(#2,#3)} |
| 156 |
} |
| 157 |
} |
| 158 |
\NewDocumentCommand\placearrowat{or()r()}{ |
| 159 |
\placeat(#2){\ignorespaces\IfValueT{#1}{\color{#1}}% |
| 160 |
\luatexlatelua{placearrowat(#2,#3)} |
| 161 |
} |
| 162 |
} |
| 163 |
\NewDocumentCommand\placecircleat{or()D(){.3}}{ |
| 164 |
\placeat(#2){\ignorespaces\IfValueT{#1}{\color{#1}}% |
| 165 |
\luatexlatelua{placecircleat(#3,1)} |
| 166 |
} |
| 167 |
} |
| 168 |
\NewDocumentCommand\placefilledcircleat{or()D(){.3}}{ |
| 169 |
\placeat(#2){\ignorespaces\IfValueT{#1}{\color{#1}}% |
| 170 |
\luatexlatelua{placecircleat(#3,1,true)} |
| 171 |
} |
| 172 |
} |
| 173 |
\NewDocumentCommand\placesquareat{or()G{3}}{ |
| 174 |
\placeat(#2){\ignorespaces\IfValueT{#1}{\color{#1}}% |
| 175 |
\luatexlatelua{placesquareat(#3)} |
| 176 |
} |
| 177 |
} |
| 178 |
\NewDocumentCommand\placecurveat{or()r()r()r()}{ |
| 179 |
\placeat(#2){\ignorespaces\IfValueT{#1}{\color{#1}}% |
| 180 |
\luatexlatelua{placecurveat(#2,#3,#4,#5)} |
| 181 |
} |
| 182 |
} |
| 183 |
\NewDocumentCommand\placerectangleat{O{black}r()d()}{ |
| 184 |
\placeat(#2){\ignorespaces\color{#1}% |
| 185 |
\luatexlatelua{placerectangleat(#2,#3)} |
| 186 |
} |
| 187 |
} |
| 188 |
\NewDocumentCommand\placefilledrectangleat{O{black}r()r()}{ |
| 189 |
\placeat(#2){\ignorespaces\color{#1}% |
| 190 |
\luatexlatelua{placerectangleat(#2,#3,true)} |
| 191 |
} |
| 192 |
} |
| 193 |
\NewDocumentCommand\placeroundedat{sO{black}r()D(){0.1}D<>{1.5}}{ |
| 194 |
\placeat(#3){\ignorespaces\color{#2}% |
| 195 |
\IfBooleanTF{#1}{\luatexlatelua{placecircleat(#4,#5,true)}}% |
| 196 |
{\luatexlatelua{placecircleat(#4,#5)}} |
| 197 |
} |
| 198 |
} |
| 199 |
\ExplSyntaxOn |
| 200 |
\gdef\drawgridnum{1} |
| 201 |
\keys_define:nn{placeat}{ |
| 202 |
alphanumgrid.code:n = \directlua{alphanumgrid = true}, |
| 203 |
arrowheadlength.code:n = \directlua{arrowheadlength=#1}, |
| 204 |
final.code:n = \luaexec{placeat_final = true} \gdef\drawgridnum{0}, |
| 205 |
drawgrid.code:n = \gdef\drawgridnum{1}, |
| 206 |
gridnumber.code:n = \directlua{gridnr = #1 gridnrx = gridnr~gridnry = gridnr}, |
| 207 |
gridnumberx.code:n = \directlua{gridnrx = #1}, |
| 208 |
gridnumbery.code:n = \directlua{gridnry = #1}, |
| 209 |
gridlinewidth.code:n = \directlua{gridlinewidth = #1}, |
| 210 |
linewidth.code:n = {\placeat(1,1){\luatexlatelua{linewidth(#1)}}}, %% FIXME: this is a very nasty hack to implement user's choice of linewidth! |
| 211 |
nogrid.code:n = \gdef\drawgridnum{0}, |
| 212 |
numnumgrid.code:n = \directlua{alphanumgrid = false}, |
| 213 |
offsetx.code:n = \directlua{offsetx = #1}, |
| 214 |
offsety.code:n = \directlua{offsety = #1}, |
| 215 |
startzero.code:n = \directlua{offsetx = 1 offsety = 1} |
| 216 |
} |
| 217 |
\DeclareDocumentCommand\placeatsetup{m}{ |
| 218 |
\keys_set:nn{placeat}{#1} |
| 219 |
} |
| 220 |
\ExplSyntaxOff |
| 221 |
%% |
| 222 |
%% |
| 223 |
%% End of file `placeat.sty'. |