summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/gridset/gridset.sty
blob: 00a11c2c83e642b65988e2e84cef19d3d836bbfb (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
%%
%% This is file `gridset.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% gridset.dtx  (with options: `package')
%% 
%% IMPORTANT NOTE:
%% 
%% This is a generated file and you are not allowed to distribute it
%% without the source ot the work.  See below about more informations
%% about the files the work consists of.
%% 
%% Copyright (C) 2008-2020 Markus Kohm
%%
%% This work 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.
%% The latest version of this license is in
%% http://www.latex-project.org/lppl.txt
%% and version 1.3c or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%%
%% This work has the LPPL maintenance status "maintained".
%%
%% The author and current maintainer of this work is
%% Markus Kohm <komascript@gmx.info>.
%%
%% This work consists of the files gridset.dtx and README.md.
%%
%% Important Recommendation:
%% The LPPL requires that distributions of the Work contain all the files of
%% the Work (see ``Important Recommendations'' at lppl.txt).
%%
\ProvidesPackage{gridset}
                 [2020-02-12 v0.3 grid - a.k.a. in-register - setting]
\newcommand*{\gridset@luaorpdf}[1]{%
  \expandafter\newcommand\csname gridset@#1\endcsname{}%
  \ifcsname pdf#1\endcsname
    \expandafter\let\csname gridset@#1\expandafter\endcsname
    \csname pdf#1\endcsname
  \else
    \ifcsname #1\endcsname
      \expandafter\let\csname gridset@#1\expandafter\endcsname
      \csname #1\endcsname
    \else
      \PackageError{gridset}{%
        neither \expandafter\string\csname #1\endcsname\space
        nor \xpandafter\string\csname pdf#1\endcsname\space
        defined%
      }{This package needs either PDFTeX or LuaTeX or XeTeX.}%
    \fi
  \fi
}
\gridset@luaorpdf{pageheight}
\gridset@luaorpdf{pagewidth}
\gridset@luaorpdf{savepos}
\gridset@luaorpdf{lastxpos}
\gridset@luaorpdf{lastypos}
\newcommand*{\gridbase}{}
\newcommand*{\gridinterval}{}
\AtBeginDocument{%
  \ifdim\gridset@pageheight=\z@
    \gridset@pageheight=\paperheight
  \fi
  \ifdim\gridset@pagewidth=\z@
    \gridset@pagewidth=\paperwidth
  \fi
  \begingroup
    \@tempdima=\dimexpr \gridset@pageheight - \topmargin - 1in
                      - \headheight - \headsep
                      - \topskip \relax
    \@tempcnta=\@tempdima
    \xdef\gridbase{\the\@tempcnta}%
    \@tempcnta=\baselineskip
    \xdef\gridinterval{\the\@tempcnta}%
  \endgroup
}
\newcommand*{\SavePos}[1]{%
  \begingroup
    \gridset@savepos
    \protected@write\@auxout{}{%
      \protect\newpos{#1}{\the\count\z@}{\gridbase}{\gridinterval}{%
        \noexpand\number\gridset@lastxpos
      }{%
        \noexpand\number\gridset@lastypos
      }%
    }%
  \endgroup
}
\ifx\savepos\gridset@savepos
  \PackageInfo{gridset}{LuaTeX detected.\MessageBreak
    Note, gridset command is \string\SavePos\MessageBreak
    but not \string\savepos, which is\MessageBreak
    a LuaTeX primitive
  }%
\else
  \PackageInfo{gridset}{\string\savepos\space defined as an alias of
    \string\SavePos}%
  \newcommand*{\savepos}{\SavePos}%
\fi
\newcommand*{\newpos}[6]{%
  \grid@unique@test{#1}{#2}%
  \expandafter\global\@namedef{pos@#1@page}{#2}%
  \expandafter\global\@namedef{pos@#1@base}{#3}%
  \expandafter\global\@namedef{pos@#1@interval}{#4}%
  \expandafter\global\@namedef{pos@#1@x}{#5}%
  \expandafter\global\@namedef{pos@#1@y}{#6}%
  \begingroup
    \@tempcnta=\numexpr \@nameuse{pos@#1@base} - \@nameuse{pos@#1@y}\relax
    \@tempcnta=\numexpr \@tempcnta + \@nameuse{pos@#1@interval} - 1\relax
    \divide\@tempcnta by\@nameuse{pos@#1@interval}\relax
    \expandafter\xdef\csname pos@#1@line\endcsname{\the\@tempcnta}%
    \@tempcnta=\numexpr \@tempcnta * \@nameuse{pos@#1@interval}\relax
    \expandafter\xdef\csname pos@#1@offset\endcsname{\the\@tempcnta}%
    \@tempcnta=\numexpr \@nameuse{pos@#1@y}
                      - ( \@nameuse{pos@#1@base} - \@tempcnta )\relax
    \expandafter\let\expandafter\@tempa\csname pos@#1@vskip\endcsname%
    \expandafter\xdef\csname pos@#1@vskip\endcsname{\the\@tempcnta}%
    \expandafter\ifx\csname pos@#1@vskip\endcsname\@tempa\else
      \grid@ReRunMessage
    \fi
  \endgroup
}
\newcommand*{\grid@unique@test}[2]{%
  \expandafter\ifx\csname pos@#1@page\endcsname\relax\else
    \PackageError{gridset}{position `#1' is not unique.\@gobble}{%
      You have used the position name `#1' you are using on page
      `#2'\MessageBreak
      already on page `\csname pos@#1@page\endcsname'.\MessageBreak
      You should stop processing, remove the aux-files and correct the
      names.\MessageBreak
      If you'd continue, this will result in grid position
      failures,\MessageBreak
      that won't be reported!}%
  \fi
}
\AtBeginDocument{%
  \global\let\grid@unique@test\@gobble
}
\newcommand*\grid@ReRunMessage{}
\AtBeginDocument{%
  \renewcommand*\grid@ReRunMessage{%
    \PackageWarningNoLine{gridset}{Grid position labels may have
      changed.\MessageBreak
      Rerun to get grid positions right}%
    \global\let\grid@ReRunMessage\relax
  }%
}
\newcounter{gridcnt}
\newcommand*{\vskipnextgrid}{%
  \begingroup
    \stepcounter{gridcnt}\edef\@tempa{vp!\thegridcnt}%
    \ifvmode
      \leavevmode\SavePos{\@tempa}%
      \expandafter\ifx\csname pos@\@tempa @vskip\endcsname\relax
      \else
        \expandafter\ifnum \csname pos@\@tempa @vskip\endcsname =\z@\else
          \PackageInfo{gridset}{%
            vmode \string\vskip\csname pos@\@tempa @vskip\endcsname sp%
          }%
          \vskip -\parskip\vskip -\baselineskip
          \expandafter\vskip\csname pos@\@tempa @vskip\endcsname sp\relax
        \fi
      \fi
    \else
      \parskip=\z@
      \SavePos{vp!\thegridcnt}%
      \expandafter\ifx\csname pos@\@tempa @vskip\endcsname\relax
      \else
        \expandafter\ifnum \csname pos@\@tempa @vskip\endcsname =\z@\else
          \PackageInfo{gridset}{%
            hmode \string\vskip\csname pos@\@tempa @vskip\endcsname sp%
          }%
          \vskip \dimexpr -\baselineskip
                          + \csname pos@\@tempa @vskip\endcsname sp\relax
          \leavevmode
          \if@twoside
            \expandafter\ifodd\csname pos@\@tempa @page\endcsname\relax
              \hskip \dimexpr -1in - \oddsidemargin - \parindent
                            \if@twocolumn\if@firstcolumn\else
                              - \columnwidth - \columnsep
                            \fi\fi
                              + \csname pos@\@tempa @x\endcsname sp\relax
            \else
              \hskip \dimexpr -1in - \evensidemargin - \parindent
                            \if@twocolumn\if@firstcolumn\else
                              - \columnwidth - \columnsep
                            \fi\fi
                              + \csname pos@\@tempa @x\endcsname sp\relax
            \fi
          \else
            \hskip \dimexpr -1in - \oddsidemargin - \parindent
                            \if@twocolumn\if@firstcolumn\else
                              - \columnwidth - \columnsep
                            \fi\fi
                            + \csname pos@\@tempa @x\endcsname sp\relax
          \fi
        \fi
      \fi
    \fi
  \endgroup
}
\newcommand*{\thegridinfo}[1]{%
  page=\@nameuse{pos@#1@page},
  base=\@nameuse{pos@#1@base},
  interval=\@nameuse{pos@#1@interval},
  x=\@nameuse{pos@#1@x},
  y=\@nameuse{pos@#1@y}%
}
\newcommand*{\theposinfo}[1]{%
  y=\@nameuse{pos@#1@y},
  gridline=\@nameuse{pos@#1@line},
  gridoffset=\@nameuse{pos@#1@offset},
  movedown=\@nameuse{pos@#1@vskip}%
}
\newcommand*{\theypos}[1]{\@nameuse{pos@#1@y}}
\endinput
%%
%% End of file `gridset.sty'.