summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/lualatex/placeat
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2014-04-16 21:50:22 +0000
committerKarl Berry <karl@freefriends.org>2014-04-16 21:50:22 +0000
commit712e18adbc3a3747f8baa04df86593602cc032e6 (patch)
treead001706d85bdc5a5f045e712cd6e6b31d6b7cfb /Master/texmf-dist/tex/lualatex/placeat
parentf96c6f3b55f5a86a5f9dd5dbfe6422c72d1b4b8e (diff)
placeat (16apr14)
git-svn-id: svn://tug.org/texlive/trunk@33467 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/lualatex/placeat')
-rw-r--r--Master/texmf-dist/tex/lualatex/placeat/placeat.sty201
1 files changed, 201 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/lualatex/placeat/placeat.sty b/Master/texmf-dist/tex/lualatex/placeat/placeat.sty
new file mode 100644
index 00000000000..59ac22fa518
--- /dev/null
+++ b/Master/texmf-dist/tex/lualatex/placeat/placeat.sty
@@ -0,0 +1,201 @@
+%%
+%% This is file `placeat.sty',
+%% generated with the docstrip utility.
+%%
+%% The original source files were:
+%%
+%% placeat.dtx (with options: `package')
+%%
+%% EXPERIMENTAL CODE
+%%
+%% This package is copyright © 2014 Arno L. Trautmann. It may be distributed and/or
+%% modified under the conditions of the LaTeX Project Public License, either version 1.3c
+%% of this license or (at your option) any later version. This work has the LPPL mainten-
+%% ance status ‘maintained’.
+\ProvidesPackage{placeat}%
+ [2014/04/15 v0.1 absolute content positioning]
+\RequirePackage{luatexbase}
+\RequirePackage{luacode}
+\RequirePackage{atbegshi}
+\RequirePackage{xparse}
+\directlua{dofile(kpse.find_file("placeat.lua"))}
+\NewDocumentCommand\placeat{ggd()d<>O{}mo}{
+ \IfValueT{#1}{ %% two coordinates in { }{ } pair.
+ \IfValueT{#2}{ %% if second argument is not given, everything breaks. not nice.
+ \def\cox{#1}
+ \def\coy{#2}
+ }
+ }
+ \IfValueT{#3}{ %% one argument as ( , ) coordinate pair.
+ \def\cox{\firstof#3X}
+ \def\coy{\secondof#3X}
+ }
+ \IfValueT{#4}{
+ \luadirect{
+ y = string.byte('#4',1)-64
+ x = string.byte('#4',2)-48
+ x2 = string.byte('#4',3)
+ if x2 then x = x*10 + x2-48 end -- FIXME: what exactly happens here? …
+ }
+ \def\cox{\luadirect{tex.print(x)}}
+ \def\coy{\luadirect{tex.print(y)}}
+ }
+ \placeatthreenumbers{\cox}{\coy}{\llap{#5}#6}
+
+ \IfValueT{#7}{
+ \expandafter\gdef\csname #7x\endcsname{\firstof#3X}
+ \expandafter\gdef\csname #7y\endcsname{\secondof#3X}
+ }
+}
+\NewDocumentCommand\placerelto{oggd()d<>O{}mo}{
+ \IfValueT{#2}{ %% two coordinates in { }{ } pair.
+ \IfValueT{#3}{ %% if second argument is not given, everything breaks. not nice.
+ \def\cox{#2}
+ \def\coy{#3}
+ }
+ }
+ \IfValueT{#4}{ %% one argument as ( , ) coordinate pair.
+ \def\cox{\firstof#4X}
+ \def\coy{\secondof#4X}
+ }
+ \IfValueT{#5}{
+ \luaexec{
+ y = string.byte('#5',1)-64
+ x = string.byte('#5',2)-48
+ x2 = string.byte('#5',3)
+ if x2 then x = x*10 + x2-48 end -- FIXME: what exactly happens here? …
+ tex.print("\\def\\cox{"..(x).."}\\def\\coy{"..(y).."}")
+ }
+ }
+ \placeatthreenumbers
+ {\cox + \csname #1x\endcsname}
+ {\coy + \csname #1y\endcsname}
+ {\llap{#6}#7}
+ \IfValueT{#8}{
+ \expandafter\xdef\csname #8x\endcsname{\cox + \csname #1x\endcsname}
+ \expandafter\xdef\csname #8y\endcsname{\coy + \csname #1y\endcsname}
+ }
+}
+\NewDocumentCommand\placeminipageat{d()O{10cm}m}{
+ \gdef\widthofplaceat{#2}
+ \placeat(#1)
+ {\begin{minipage}{\widthofplaceat}{#3}\end{minipage}}
+}
+\def\placeatthreenumbers#1#2#3{
+ \luaexec{
+ nr = nr+1
+ dacoordtmp = ((#1-1+offsetx)*tex.pagewidth/65536/gridnrx*1.005)..","..(-(#2-1+offsety)*tex.pageheight/65536/gridnry)
+ dacoord[nr] = "\\put("..dacoordtmp..")"
+ tex.print("\\expandafter\\gdef\\csname command"..(nr).."\\endcsname")}% begin of command definition
+ {#3} %% this is what \command[nr] will contain
+}
+\def\firstof #1,#2X{#1}
+\def\secondof #1,#2X{#2}
+\let\ifdrawgrid\iftrue
+\luaexec{
+ drawgrid = false
+ nr = 0
+ dacoord = {}
+ gridnr = 10
+ gridnrx = 10
+ gridnry = 10
+ gridlinewidth = 0.01
+ offsetx = 0
+ offsety = 0
+}
+\AtBeginDocument{
+ \AtBeginShipout{%
+ \AtBeginShipoutUpperLeftForeground{%
+ \ifdrawgrid\drawgrid\fi
+ \luaexec{%
+ for i = 1,nr do
+ tex.print(dacoord[i].."{\\csname command"..(i).."\\endcsname}")
+ end
+ nr=0
+ }
+ }
+ }
+}
+\def\drawgrid{
+ \luatexlatelua{
+ pdf_print("q")
+ linewidth(gridlinewidth)
+ for i = 1,math.max(gridnrx,gridnry) do
+ h = i*tex.pageheight/gridnry/65536
+ w = i*tex.pagewidth/gridnrx/65536
+ move(0,-h) line(tex.pagewidth,-h) stroke()
+ move(w,0) line(w,-tex.pageheight) stroke()
+ end
+ pdf_print("Q")
+ }
+ { %% 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.
+%% would also be nice to maybe adapt the fontsize to the grid size
+ \normalfont\fontsize{8}{10}\selectfont
+ \luaexec{
+ for i=1,math.max(gridnrx+offsetx,gridnry+offsety) do
+ hfac = tex.pageheight/gridnry/65536 %% another empirical factor
+ wfac = tex.pagewidth/gridnrx/65536*1.005 %% another empirical factor
+ h = (i-1)*hfac
+ w = (i-1)*wfac
+ tex.print("\\put("..(w)..",-7){\\rlap{"..(i-offsetx).."}}")
+ if alphanumgrid then
+ tex.print("\\put(0,"..(-h-0.05*hfac).."){\\char00"..(64+i-offsety).."}") %%-- for alphanumeric grid.
+ else
+ tex.print("\\put(0,"..(-h-0.05*hfac).."){"..(i-offsety).."}")
+ end
+ end
+ }
+ }
+}
+\NewDocumentCommand\placelineat{ou{(}u{,}u{)(}u{,}u{)}}{
+ \placeat{#3}{#4}{\ignorespaces\IfValueT{#1}{\color{#1}}%
+ \luatexlatelua{placelineat(#3,-#4,#5,-#6)}
+ }
+}
+\NewDocumentCommand\placearrowat{ou{(}u{,}u{)(}u{,}u{)}}{
+ \placeat{#3}{#4}{\ignorespaces\IfValueT{#1}{\color{#1}}%
+ \luatexlatelua{placearrowat(#3,-#4,#5,-#6)}
+ }
+}
+\NewDocumentCommand\placecircleat{ou{(}u{,}u{)}G{3}}{
+ \placeat{#3}{#4}{\ignorespaces\IfValueT{#1}{\color{#1}}%
+ \luatexlatelua{placecircleat(#5)}
+ }
+}
+\NewDocumentCommand\placesquareat{ou{(}u{,}u{)}G{3}}{
+ \placeat{#3}{#4}{\ignorespaces\IfValueT{#1}{\color{#1}}%
+ \luatexlatelua{placesquareat(#5)}
+ }
+}
+\NewDocumentCommand\placerectangleat{ou{(}u{,}u{)(}u{,}u{)}}{
+ \placeat{#3}{#4}{\ignorespaces\IfValueT{#1}{\color{#1}}%
+ \luatexlatelua{placerectangleat(#3,-#4,#5,-#6)}
+ }
+}
+\NewDocumentCommand\placefilledrectangleat{ou{(}u{,}u{)(}u{,}u{)}}{
+ \placeat{#3}{#4}{\ignorespaces\IfValueT{#1}{\color{#1}}%
+ \luatexlatelua{placefilledrectangleat(#3,-#4,#5,-#6)}
+ }
+}
+\ExplSyntaxOn
+\keys_define:nn{placeat}{
+ alphanumgrid.code:n = \directlua{alphanumgrid = true},
+ final.code:n = \luaexec{placeat_final = true} \let\ifdrawgrid\iffalse,
+ drawgrid.code:n = \global\let\ifdrawgrid\iftrue,
+ gridnumber.code:n = \directlua{gridnr = #1 gridnrx = gridnr~gridnry = gridnr},
+ gridnumberx.code:n = \directlua{gridnrx = #1},
+ gridnumbery.code:n = \directlua{gridnry = #1},
+ gridlinewidth.code:n = \directlua{gridlinewidth = #1},
+ nogrid.code:n = \global\let\ifdrawgrid\iffalse,
+ numnumgrid.code:n = \directlua{alphanumgrid = false},
+ offsetx.code:n = \directlua{offsetx = #1},
+ offsety.code:n = \directlua{offsety = #1},
+ startzero.code:n = \directlua{offsetx = 1 offsety = 1}
+}
+\DeclareDocumentCommand\placeatsetup{m}{
+ \keys_set:nn{placeat}{#1}
+}
+\ExplSyntaxOff
+%%
+%%
+%% End of file `placeat.sty'.