| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
% gridset.dtx |
| 4 |
% |
| 5 |
%% Copyright (C) 2008-2024 Markus Kohm |
| 6 |
%% |
| 7 |
%% This work may be distributed and/or modified under the |
| 8 |
%% conditions of the LaTeX Project Public License, either version 1.3c |
| 9 |
%% of this license or (at your option) any later version. |
| 10 |
%% The latest version of this license is in |
| 11 |
%% http://www.latex-project.org/lppl.txt |
| 12 |
%% and version 1.3c or later is part of all distributions of LaTeX |
| 13 |
%% version 2005/12/01 or later. |
| 14 |
%% |
| 15 |
%% This work has the LPPL maintenance status "maintained". |
| 16 |
%% |
| 17 |
%% The author and current maintainer of this work is |
| 18 |
%% Markus Kohm <[email protected]>. |
| 19 |
%% |
| 20 |
%% This work consists of the files gridset.dtx and README.md. |
| 21 |
%% |
| 22 |
%% Important Recommendation: |
| 23 |
%% The LPPL requires that distributions of the Work contain all the files of |
| 24 |
%% the Work (see ``Important Recommendations'' at lppl.txt). |
| 25 |
%% |
| 26 |
% |
| 27 |
%<*dtx> |
| 28 |
\ifx\ProvidesFile\undfined\def\ProvidesFile#1[#2]{}\fi |
| 29 |
\ProvidesFile{gridset.dtx} |
| 30 |
%</dtx> |
| 31 |
%<*dtx|package|example> |
| 32 |
%<package>\ProvidesPackage{gridset} |
| 33 |
%<example>\ProvidesFile{gridsetexample.tex} |
| 34 |
[2024-08-17 v0.4 grid - a.k.a. in-register - setting] |
| 35 |
%</dtx|package|example> |
| 36 |
%<*dtx> |
| 37 |
\ifx\documentclass\undefined |
| 38 |
\input docstrip.tex |
| 39 |
\keepsilent |
| 40 |
\askforoverwritefalse |
| 41 |
\usedir{tex/latex/gridset} |
| 42 |
\preamble |
| 43 |
|
| 44 |
IMPORTANT NOTE: |
| 45 |
|
| 46 |
This is a generated file and you are not allowed to distribute it |
| 47 |
without the source ot the work. See below about more informations |
| 48 |
about the files the work consists of. |
| 49 |
|
| 50 |
\endpreamble |
| 51 |
|
| 52 |
\generate{% |
| 53 |
\file{gridset.ins}{\from{gridset.dtx}{ins}}% |
| 54 |
\file{gridset.sty}{\from{gridset.dtx}{package}}% |
| 55 |
\file{gridsetexample.tex}{\from{gridset.dtx}{example}}% |
| 56 |
} |
| 57 |
|
| 58 |
\ifToplevel{% |
| 59 |
\Msg{*********************************************************************} |
| 60 |
\Msg{*} |
| 61 |
\Msg{* gridset} |
| 62 |
\Msg{* =======} |
| 63 |
\Msg{*} |
| 64 |
\Msg{* THIS IS AN ALPHA VERSION!} |
| 65 |
\Msg{* DON'T USE IT ONLY TEST IT!} |
| 66 |
\Msg{*} |
| 67 |
\Msg{* To finish the installation run} |
| 68 |
\Msg{* \space\space latex gridset.dtx} |
| 69 |
\Msg{* or} |
| 70 |
\Msg{* \space\space pdflatex gridset.dtx} |
| 71 |
\Msg{* and then copy} |
| 72 |
\Msg{* \space\space gridset.sty to .../tex/latex/gridset/} |
| 73 |
\Msg{* \space\space gridset.dvi or gridset.pdf to .../doc/latex/gridset/} |
| 74 |
\Msg{* \space\space gridset.dtx and README to .../source/latex/gridset/} |
| 75 |
\Msg{* where .../ is your local TDS tree.} |
| 76 |
\Msg{* On some systems you'll get the local TDS tree using:} |
| 77 |
\Msg{* \space\space kpsewhich -var-value=TEXMFLOCAL} |
| 78 |
\Msg{*} |
| 79 |
\Msg{*********************************************************************} |
| 80 |
} |
| 81 |
\else |
| 82 |
\let\endbatchfile\relax |
| 83 |
\fi |
| 84 |
\endbatchfile |
| 85 |
\documentclass{ltxdoc} |
| 86 |
\begin{document} |
| 87 |
\RecordChanges |
| 88 |
\GetFileInfo{gridset.dtx} |
| 89 |
\DocInput{gridset.dtx} |
| 90 |
\end{document} |
| 91 |
%</dtx> |
| 92 |
% \fi ^^A meta-comment |
| 93 |
% |
| 94 |
% \title{Semi-Manual Grid Setting Using \textsf{gridset}% |
| 95 |
% \footnote{This is an alpha version! Don't use it! Only test it! There's no |
| 96 |
% support and everything may change!}% |
| 97 |
% } |
| 98 |
% \author{Markus Kohm} |
| 99 |
% \date{\filedate~\fileversion} |
| 100 |
% \maketitle |
| 101 |
% \begin{abstract} |
| 102 |
% Grid setting\,---\,also known as strict in-register setting\,---\,is |
| 103 |
% something, that should be done for a lot of documents but is not easy |
| 104 |
% using \LaTeX{}. Package \textsf{gridset} helps to get the information |
| 105 |
% needed for grid setting. It does not implement auto grid setting, but |
| 106 |
% there is a command \cs{vskipnextgrid}, that moves to the next grid |
| 107 |
% position. This may be enough under some circumstances. In other |
| 108 |
% circumstances it may fail. So \textsf{gridset} is only one more step for |
| 109 |
% grid setting not a complete solution. |
| 110 |
% |
| 111 |
% \paragraph*{Important Note:} This package should have been never released, |
| 112 |
% because it was only a very quick implementation of an idea. You should not |
| 113 |
% use it for any productive purpose. It has been made for testing only. I |
| 114 |
% would prefer to retire it from any distribution. Nevertheless I know few |
| 115 |
% persons using the package. So it will be still there but without any |
| 116 |
% support! |
| 117 |
% \end{abstract} |
| 118 |
% \tableofcontents |
| 119 |
% \section{User Manual} |
| 120 |
% |
| 121 |
% \DescribeMacro{\gridinterval}% |
| 122 |
% This macro contains a number without unit! The number is the distance |
| 123 |
% between two grid lines in unit `scale points' (sp). You may set it so |
| 124 |
% another value using, e.g. |
| 125 |
% \begin{flushleft} |
| 126 |
% |\newlength{\|\meta{name of your length}|}|\\ |
| 127 |
% |\setlength{\|\meta{name of your length}|}{|\meta{new length value}|}|\\ |
| 128 |
% |\newcounter{\|\meta{name of your counter}|}|\\ |
| 129 |
% |\setcounter{\|\meta{name of your counter}|}{\|\meta{name of your |
| 130 |
% length}|}|\\ |
| 131 |
% |\edef\gridinterval{\|\meta{name of your length}|}|\\ |
| 132 |
% \end{flushleft} |
| 133 |
% |
| 134 |
% \DescribeMacro{\gridbase}% |
| 135 |
% This macro contains an integer number, that represents the y-coordinate of |
| 136 |
% the upper start of the grid. If you want to change it, just save a position |
| 137 |
% and \cs{edef} the \cs{gridbase} to the y-pos of that position. |
| 138 |
% |
| 139 |
% Most time you don't need to change \cs{gridinterval} and \cs{gridposition}, |
| 140 |
% because they are initialized to a base line grid at start of first page. |
| 141 |
% Because of this, it doesn't matter, that changing them is not really user |
| 142 |
% friendly. |
| 143 |
% |
| 144 |
% \DescribeMacro{\SavePos}% |
| 145 |
% \DescribeMacro{\savepos}% |
| 146 |
% \cs{SavePos}\marg{unique name} saves informations about the current position |
| 147 |
% to the \texttt{aux}-file. These informations are read at next \LaTeX{} run |
| 148 |
% and may be used (see \cs{the\dots} commands below) then. The \meta{unique |
| 149 |
% name} has to be a position name, that is unique for all saved position |
| 150 |
% informations of the current document. Note that the command has been renamed |
| 151 |
% from \cs{savepos} to \cs{SavePos} in release~0.2, because Lua\TeX{} since |
| 152 |
% 0.85 uses \cs{savepos} as a new primitive. On other engines the old name |
| 153 |
% \cs{savepos} is still available. |
| 154 |
% |
| 155 |
% \DescribeMacro{\vskipnextgrid} |
| 156 |
% This command moves to the next grid position. To achieve this, a position |
| 157 |
% information is saved at this and used at next \LaTeX{} run. The used name |
| 158 |
% of the position information is \texttt{vb!\meta{number of |
| 159 |
% skip}}. \meta{number of skip} is the number of the current |
| 160 |
% \cs{vskipnextgrid} usage. Counter \texttt{gridcnt} is used to number the |
| 161 |
% usage of \cs{vskipnextgrid}. |
| 162 |
% |
| 163 |
% \DescribeMacro{\thegridinfo} |
| 164 |
% \cs{thegridinfo}\marg{name} outputs |
| 165 |
% \begin{itemize} |
| 166 |
% \item arabic page number of the named position, |
| 167 |
% \item grid base, that was valid saving the information of the named |
| 168 |
% position, |
| 169 |
% \item grid interval, that was valid saving the information of the named |
| 170 |
% position, |
| 171 |
% \item x-coordinate of the named position, |
| 172 |
% \item y-coordinate of the named position. |
| 173 |
% \end{itemize} |
| 174 |
% The coordinates and intervals are numbers without units. The unit is `scale |
| 175 |
% points' (sp). |
| 176 |
% |
| 177 |
% \DescribeMacro{\theposinfo} |
| 178 |
% \cs{theposinfo}\marg{name} outputs |
| 179 |
% \begin{itemize} |
| 180 |
% \item y-coordinate of the named position, |
| 181 |
% \item grid line number (first is 0) of the next grid position, |
| 182 |
% \item offset of the next grid position from grid base, |
| 183 |
% \item distance to the next grid position. |
| 184 |
% \end{itemize} |
| 185 |
% The coordinates, offsets and distances are numbers without units. The unit |
| 186 |
% is `scale points' (sp). |
| 187 |
% |
| 188 |
% \DescribeMacro{\theypos} |
| 189 |
% \cs{theypos}\marg{name} outputs the y-coordinate of the named position. |
| 190 |
% |
| 191 |
% |
| 192 |
% \StopEventually{\PrintIndex\PrintChanges} |
| 193 |
% |
| 194 |
% \section{Implementation} |
| 195 |
% |
| 196 |
% \iffalse meta-comment |
| 197 |
%<*package> |
| 198 |
% \fi ^^A meta-comment |
| 199 |
% |
| 200 |
% \begin{macro}{gridset@luaorpdf} |
| 201 |
% \changes{v0.2}{2017/06/05}{new internal because of Lua\TeX~0.85} |
| 202 |
% \begin{macro}{\gridset@pageheight} |
| 203 |
% \changes{v0.2}{2017/06/05}{new internal because of Lua\TeX~0.85} |
| 204 |
% \begin{macro}{\gridset@pagewidth} |
| 205 |
% \changes{v0.2}{2017/06/05}{new internal because of Lua\TeX~0.85} |
| 206 |
% \begin{macro}{\gridset@savepos} |
| 207 |
% \changes{v0.2}{2017/06/05}{new internal because of Lua\TeX~0.85} |
| 208 |
% \begin{macro}{\gridset@lastxpos} |
| 209 |
% \changes{v0.2}{2017/06/05}{new internal because of Lua\TeX~0.85} |
| 210 |
% \begin{macro}{\gridset@lastypos} |
| 211 |
% \changes{v0.2}{2017/06/05}{new internal because of Lua\TeX~0.85} |
| 212 |
% We need some locals because Lua\TeX{} changed the names of several |
| 213 |
% primitives inherited from PDF\TeX. |
| 214 |
% \begin{macrocode} |
| 215 |
\newcommand*{\gridset@luaorpdf}[1]{% |
| 216 |
\expandafter\newcommand\csname gridset@#1\endcsname{}% |
| 217 |
\ifcsname pdf#1\endcsname |
| 218 |
\expandafter\let\csname gridset@#1\expandafter\endcsname |
| 219 |
\csname pdf#1\endcsname |
| 220 |
\else |
| 221 |
\ifcsname #1\endcsname |
| 222 |
\expandafter\let\csname gridset@#1\expandafter\endcsname |
| 223 |
\csname #1\endcsname |
| 224 |
\else |
| 225 |
\PackageError{gridset}{% |
| 226 |
neither \expandafter\string\csname #1\endcsname\space |
| 227 |
nor \xpandafter\string\csname pdf#1\endcsname\space |
| 228 |
defined% |
| 229 |
}{This package needs either PDFTeX or LuaTeX or XeTeX.}% |
| 230 |
\fi |
| 231 |
\fi |
| 232 |
} |
| 233 |
\gridset@luaorpdf{pageheight} |
| 234 |
\gridset@luaorpdf{pagewidth} |
| 235 |
\gridset@luaorpdf{savepos} |
| 236 |
\gridset@luaorpdf{lastxpos} |
| 237 |
\gridset@luaorpdf{lastypos} |
| 238 |
% \end{macrocode} |
| 239 |
% \end{macro} |
| 240 |
% \end{macro} |
| 241 |
% \end{macro} |
| 242 |
% \end{macro} |
| 243 |
% \end{macro} |
| 244 |
% \end{macro} |
| 245 |
% |
| 246 |
% \begin{macro}{\gridbase} |
| 247 |
% \changes{v0.2}{2017/06/05}{prepared for Lua\TeX~0.85} |
| 248 |
% \begin{macro}{\gridinterval} |
| 249 |
% \changes{v0.2}{2017/06/05}{prepared for Lua\TeX~0.85} |
| 250 |
% These contain the grid information. \cs{gridbase} is a integer number |
| 251 |
% representing the absolute y coordinate of the upper end of the |
| 252 |
% grid relative to the same reference point \cs{pdfsavepos} |
| 253 |
% uses. \cs{gridinterval} is a integer number representing the distance of |
| 254 |
% two grid lines. The unit is `scaled point' (sp) both time. |
| 255 |
% \begin{macrocode} |
| 256 |
\newcommand*{\gridbase}{} |
| 257 |
\newcommand*{\gridinterval}{} |
| 258 |
% \end{macrocode} |
| 259 |
% \cs{gridbase} and \cs{gridinterval} need to be initialized at the start of |
| 260 |
% the first page (fixme: shouldn't this be done at the start of every |
| 261 |
% page?). We use this occasion to also initialize \cs{pdfpageheight} and |
| 262 |
% \cs{pdfpagewidth} if this hasn't been done already. |
| 263 |
% \begin{macrocode} |
| 264 |
\AtBeginDocument{% |
| 265 |
\ifdim\gridset@pageheight=\z@ |
| 266 |
\gridset@pageheight=\paperheight |
| 267 |
\fi |
| 268 |
\ifdim\gridset@pagewidth=\z@ |
| 269 |
\gridset@pagewidth=\paperwidth |
| 270 |
\fi |
| 271 |
\begingroup |
| 272 |
\@tempdima=\dimexpr \gridset@pageheight - \topmargin - 1in |
| 273 |
- \headheight - \headsep |
| 274 |
- \topskip \relax |
| 275 |
\@tempcnta=\@tempdima |
| 276 |
\xdef\gridbase{\the\@tempcnta}% |
| 277 |
\@tempcnta=\baselineskip |
| 278 |
\xdef\gridinterval{\the\@tempcnta}% |
| 279 |
\endgroup |
| 280 |
} |
| 281 |
% \end{macrocode} |
| 282 |
% \end{macro} |
| 283 |
% \end{macro} |
| 284 |
% |
| 285 |
% \begin{macro}{\savepos} |
| 286 |
% \changes{v0.2}{2017/06/05}{macro renamed} |
| 287 |
% \begin{macro}{\SavePos} |
| 288 |
% \changes{v0.2}{2017/06/05}{new name} |
| 289 |
% \changes{v0.2}{2017/06/05}{prepared for Lua\TeX~0.85} |
| 290 |
% Save current position on the page to the \texttt{aux}-file. The argument |
| 291 |
% is a unique name for the position. The saved informations are: |
| 292 |
% \begin{itemize} |
| 293 |
% \item the name of the position, |
| 294 |
% \item the arabic page number of the page with the position, |
| 295 |
% \item the grid base, that was valid for this position, |
| 296 |
% \item the grid interval, that was valid for this position, |
| 297 |
% \item the x-coordinate of the absolute position, |
| 298 |
% \item the y-coordinate of the absolute position. |
| 299 |
% \end{itemize} |
| 300 |
% \begin{description} |
| 301 |
% \item[Todo:] Currently we use our own command \cs{newpos} to store the |
| 302 |
% position information in the \texttt{aux}-file. But with the extended |
| 303 |
% reference mechanism of \LaTeX{} since 2023-11-01 this should be replaced |
| 304 |
% by the new properties. |
| 305 |
% \end{description} |
| 306 |
% \begin{macrocode} |
| 307 |
\newcommand*{\SavePos}[1]{% |
| 308 |
\begingroup |
| 309 |
\gridset@savepos |
| 310 |
\protected@write\@auxout{}{% |
| 311 |
\protect\newpos{#1}{\the\count\z@}{\gridbase}{\gridinterval}{% |
| 312 |
\noexpand\number\gridset@lastxpos |
| 313 |
}{% |
| 314 |
\noexpand\number\gridset@lastypos |
| 315 |
}% |
| 316 |
}% |
| 317 |
\endgroup |
| 318 |
} |
| 319 |
\ifx\savepos\gridset@savepos |
| 320 |
\PackageInfo{gridset}{LuaTeX detected.\MessageBreak |
| 321 |
Note, gridset command is \string\SavePos\MessageBreak |
| 322 |
but not \string\savepos, which is\MessageBreak |
| 323 |
a LuaTeX primitive |
| 324 |
}% |
| 325 |
\else |
| 326 |
\PackageInfo{gridset}{\string\savepos\space defined as an alias of |
| 327 |
\string\SavePos}% |
| 328 |
\newcommand*{\savepos}{\SavePos}% |
| 329 |
\fi |
| 330 |
% \end{macrocode} |
| 331 |
% \end{macro} |
| 332 |
% \end{macro} |
| 333 |
% |
| 334 |
% \begin{macro}{\newpos} |
| 335 |
% This is the command, that has been written to the \texttt{aux}-file. |
| 336 |
% Reading the \texttt{aux}-file it defines several position dependant macros |
| 337 |
% to store the position information. Reading the \texttt{aux}-file while |
| 338 |
% \cs{begin{document}} a double definition test is done. Reading the |
| 339 |
% \texttt{aux}-file while \cs{end{document}} a test is done, if the position |
| 340 |
% has been changed and notes the user about needed additional \LaTeX{} runs. |
| 341 |
% (fixme: shouldn't the test be done with the x- and the y-coordinate |
| 342 |
% instead of the vskip only?) |
| 343 |
% The defined macros are: |
| 344 |
% \begin{description} |
| 345 |
% \item[\cs{pos@\meta{position name}@page}] the arabic page number of the |
| 346 |
% position |
| 347 |
% \item[\cs{pos@\meta{position name}@base}] the valid grid base while |
| 348 |
% saving the position |
| 349 |
% \item[\cs{pos@\meta{position name}@interval}] the valid grid interval |
| 350 |
% while saving the position |
| 351 |
% \item[\cs{pos@\meta{position name}@x}] the x-coordinate of the position |
| 352 |
% \item[\cs{pos@\meta{position name}@y}] the y-coordinate of the postion |
| 353 |
% \item[\cs{pos@\meta{position name}@line}] the number of the next grid line |
| 354 |
% for the position (first grid line has number 0) |
| 355 |
% \item[\cs{pos@\meta{position name}@offset}] distance of the next grid line |
| 356 |
% from the grid base |
| 357 |
% \item[\cs{pos@\meta{position name}@vskip}] distance to the next grid line |
| 358 |
% for the position |
| 359 |
% \end{description} |
| 360 |
% All values are integers. The unit to all values is `scaled points' |
| 361 |
% (sp). See \cs{pdfsavepos} at the pdf\TeX{} user manual for more |
| 362 |
% information. |
| 363 |
% \begin{macrocode} |
| 364 |
\newcommand*{\newpos}[6]{% |
| 365 |
\grid@unique@test{#1}{#2}% |
| 366 |
\expandafter\global\@namedef{pos@#1@page}{#2}% |
| 367 |
\expandafter\global\@namedef{pos@#1@base}{#3}% |
| 368 |
\expandafter\global\@namedef{pos@#1@interval}{#4}% |
| 369 |
\expandafter\global\@namedef{pos@#1@x}{#5}% |
| 370 |
\expandafter\global\@namedef{pos@#1@y}{#6}% |
| 371 |
\begingroup |
| 372 |
\@tempcnta=\numexpr \@nameuse{pos@#1@base} - \@nameuse{pos@#1@y}\relax |
| 373 |
\@tempcnta=\numexpr \@tempcnta + \@nameuse{pos@#1@interval} - 1\relax |
| 374 |
\divide\@tempcnta by\@nameuse{pos@#1@interval}\relax |
| 375 |
\expandafter\xdef\csname pos@#1@line\endcsname{\the\@tempcnta}% |
| 376 |
\@tempcnta=\numexpr \@tempcnta * \@nameuse{pos@#1@interval}\relax |
| 377 |
\expandafter\xdef\csname pos@#1@offset\endcsname{\the\@tempcnta}% |
| 378 |
\@tempcnta=\numexpr \@nameuse{pos@#1@y} |
| 379 |
- ( \@nameuse{pos@#1@base} - \@tempcnta )\relax |
| 380 |
\expandafter\let\expandafter\@tempa\csname pos@#1@vskip\endcsname% |
| 381 |
\expandafter\xdef\csname pos@#1@vskip\endcsname{\the\@tempcnta}% |
| 382 |
\expandafter\ifx\csname pos@#1@vskip\endcsname\@tempa\else |
| 383 |
\grid@ReRunMessage |
| 384 |
\fi |
| 385 |
\endgroup |
| 386 |
} |
| 387 |
% \end{macrocode} |
| 388 |
% \begin{macro}{\grid@unique@test} |
| 389 |
% A very simple test to warn if a position name isn't unique. |
| 390 |
% \begin{macrocode} |
| 391 |
\newcommand*{\grid@unique@test}[2]{% |
| 392 |
\expandafter\ifx\csname pos@#1@page\endcsname\relax\else |
| 393 |
\PackageError{gridset}{position `#1' is not unique.\@gobble}{% |
| 394 |
You have used the position name `#1' you are using on page |
| 395 |
`#2'\MessageBreak |
| 396 |
already on page `\csname pos@#1@page\endcsname'.\MessageBreak |
| 397 |
You should stop processing, remove the aux-files and correct the |
| 398 |
names.\MessageBreak |
| 399 |
If you'd continue, this will result in grid position |
| 400 |
failures,\MessageBreak |
| 401 |
that won't be reported!}% |
| 402 |
\fi |
| 403 |
} |
| 404 |
% \end{macrocode} |
| 405 |
% \changes{0.4}{2024/08/17}{fix deactivation of |
| 406 |
% \cs{grid@unique@test} |
| 407 |
% (\href{https://github.com/komascript/gridset/issues/1}{Issue \#1})} |
| 408 |
% The test should be done only, when reading the \texttt{aux} file at |
| 409 |
% |\begin{document}|, but not later (e.g. at |\end{document}|). So we |
| 410 |
% deactivate the test after reading the \texttt{aux} file in |
| 411 |
% |\begin{document}|. |
| 412 |
% \begin{macrocode} |
| 413 |
\AtBeginDocument{% |
| 414 |
\global\let\grid@unique@test\@gobbletwo |
| 415 |
} |
| 416 |
% \end{macrocode} |
| 417 |
% \end{macro} |
| 418 |
% \begin{macro}{\grid@ReRunMessage} |
| 419 |
% The change test will be done for each \cs{newpos} but one user information |
| 420 |
% at the end of the document should be enough. So we use a message macro, |
| 421 |
% that destroys itself after first usage. |
| 422 |
% \begin{macrocode} |
| 423 |
\newcommand*\grid@ReRunMessage{} |
| 424 |
\AtBeginDocument{% |
| 425 |
\renewcommand*\grid@ReRunMessage{% |
| 426 |
\PackageWarningNoLine{gridset}{Grid position labels may have |
| 427 |
changed.\MessageBreak |
| 428 |
Rerun to get grid positions right}% |
| 429 |
\global\let\grid@ReRunMessage\relax |
| 430 |
}% |
| 431 |
} |
| 432 |
% \end{macrocode} |
| 433 |
% \end{macro} |
| 434 |
% \end{macro} |
| 435 |
% |
| 436 |
% \begin{macro}{\vskipnextgrid} |
| 437 |
% \begin{macro}{gridcnt} |
| 438 |
% Move to next grid position. The counter \texttt{gridcnt} is used to give |
| 439 |
% every move to position a unique position name. The names are |
| 440 |
% `\texttt{vp!\meta{number of the move to position}}'. You may use this to |
| 441 |
% get informations e.g. about the last move to position. |
| 442 |
% \begin{macrocode} |
| 443 |
\newcounter{gridcnt} |
| 444 |
\newcommand*{\vskipnextgrid}{% |
| 445 |
\begingroup |
| 446 |
\stepcounter{gridcnt}\edef\@tempa{vp!\thegridcnt}% |
| 447 |
\ifvmode |
| 448 |
% \end{macrocode} |
| 449 |
% \cs{pdfsavepos} in vertical mode is a problem, because the base line |
| 450 |
% alignment will be done at least at paragraph breaking. Because of this, |
| 451 |
% we have to leave the vertical mode and do it then. But remark: If you |
| 452 |
% change the base line skip e.g. changing the font size, the next line would |
| 453 |
% not be grid aligned! |
| 454 |
% \begin{macrocode} |
| 455 |
\leavevmode\SavePos{\@tempa}% |
| 456 |
\expandafter\ifx\csname pos@\@tempa @vskip\endcsname\relax |
| 457 |
\else |
| 458 |
\expandafter\ifnum \csname pos@\@tempa @vskip\endcsname =\z@\else |
| 459 |
\PackageInfo{gridset}{% |
| 460 |
vmode \string\vskip\csname pos@\@tempa @vskip\endcsname sp% |
| 461 |
}% |
| 462 |
\vskip -\parskip\vskip -\baselineskip |
| 463 |
\expandafter\vskip\csname pos@\@tempa @vskip\endcsname sp\relax |
| 464 |
\fi |
| 465 |
\fi |
| 466 |
\else |
| 467 |
% \end{macrocode} |
| 468 |
% \cs{pdfsavepos} in horizontal mode is a problem too, because we have to |
| 469 |
% enter the vertical mode to do vertical skips. Because of this, the remark |
| 470 |
% is the same like the vertical mode remark. |
| 471 |
% \begin{macrocode} |
| 472 |
\parskip=\z@ |
| 473 |
\SavePos{vp!\thegridcnt}% |
| 474 |
\expandafter\ifx\csname pos@\@tempa @vskip\endcsname\relax |
| 475 |
\else |
| 476 |
\expandafter\ifnum \csname pos@\@tempa @vskip\endcsname =\z@\else |
| 477 |
\PackageInfo{gridset}{% |
| 478 |
hmode \string\vskip\csname pos@\@tempa @vskip\endcsname sp% |
| 479 |
}% |
| 480 |
\vskip \dimexpr -\baselineskip |
| 481 |
+ \csname pos@\@tempa @vskip\endcsname sp\relax |
| 482 |
% \end{macrocode} |
| 483 |
% \changes{v0.3}{2020/02/12}{support for twocolumn mode} |
| 484 |
% In twocolumn mode we have to take care that in the second column we reduce |
| 485 |
% the horizontal movement by the width of the first column plus the column |
| 486 |
% separation. |
| 487 |
% Note: This may fail, because the column information may be wrong |
| 488 |
% outside the output routine. Maybe we should add this information to |
| 489 |
% \cs{SavePos} or correct the x-pos there. |
| 490 |
% \begin{macrocode} |
| 491 |
\leavevmode |
| 492 |
\if@twoside |
| 493 |
\expandafter\ifodd\csname pos@\@tempa @page\endcsname\relax |
| 494 |
\hskip \dimexpr -1in - \oddsidemargin - \parindent |
| 495 |
\if@twocolumn\if@firstcolumn\else |
| 496 |
- \columnwidth - \columnsep |
| 497 |
\fi\fi |
| 498 |
+ \csname pos@\@tempa @x\endcsname sp\relax |
| 499 |
\else |
| 500 |
\hskip \dimexpr -1in - \evensidemargin - \parindent |
| 501 |
\if@twocolumn\if@firstcolumn\else |
| 502 |
- \columnwidth - \columnsep |
| 503 |
\fi\fi |
| 504 |
+ \csname pos@\@tempa @x\endcsname sp\relax |
| 505 |
\fi |
| 506 |
\else |
| 507 |
\hskip \dimexpr -1in - \oddsidemargin - \parindent |
| 508 |
\if@twocolumn\if@firstcolumn\else |
| 509 |
- \columnwidth - \columnsep |
| 510 |
\fi\fi |
| 511 |
+ \csname pos@\@tempa @x\endcsname sp\relax |
| 512 |
\fi |
| 513 |
\fi |
| 514 |
\fi |
| 515 |
\fi |
| 516 |
\endgroup |
| 517 |
} |
| 518 |
% \end{macrocode} |
| 519 |
% (fixme: A better solution would be to first move and then set the |
| 520 |
% position. But that solution needs some more tests and maybe some more |
| 521 |
% ideas, because after moving the position is on grid and so the saved x-pos |
| 522 |
% would be on grid.) |
| 523 |
% \end{macro} |
| 524 |
% \end{macro} |
| 525 |
% |
| 526 |
% \begin{macro}{\thegridinfo} |
| 527 |
% \begin{macro}{\theposinfo} |
| 528 |
% \begin{macro}{\theypos} |
| 529 |
% Some informations about the grid (valid for a position) or the position. |
| 530 |
% \begin{macrocode} |
| 531 |
\newcommand*{\thegridinfo}[1]{% |
| 532 |
page=\@nameuse{pos@#1@page}, |
| 533 |
base=\@nameuse{pos@#1@base}, |
| 534 |
interval=\@nameuse{pos@#1@interval}, |
| 535 |
x=\@nameuse{pos@#1@x}, |
| 536 |
y=\@nameuse{pos@#1@y}% |
| 537 |
} |
| 538 |
\newcommand*{\theposinfo}[1]{% |
| 539 |
y=\@nameuse{pos@#1@y}, |
| 540 |
gridline=\@nameuse{pos@#1@line}, |
| 541 |
gridoffset=\@nameuse{pos@#1@offset}, |
| 542 |
movedown=\@nameuse{pos@#1@vskip}% |
| 543 |
} |
| 544 |
\newcommand*{\theypos}[1]{\@nameuse{pos@#1@y}} |
| 545 |
% \end{macrocode} |
| 546 |
% \end{macro} |
| 547 |
% \end{macro} |
| 548 |
% \end{macro} |
| 549 |
% |
| 550 |
% \iffalse meta-comment |
| 551 |
%<*FALSE> |
| 552 |
\csname endinput\endcsname |
| 553 |
%</FALSE> |
| 554 |
%</package> |
| 555 |
% \fi |
| 556 |
% |
| 557 |
% \section{Example} |
| 558 |
% |
| 559 |
% You may try the following example document. You have to do several \LaTeX{} |
| 560 |
% runs until no new rerun warning occurs. |
| 561 |
% \iffalse meta-comment |
| 562 |
%<*example> |
| 563 |
% \fi |
| 564 |
% \begin{macrocode} |
| 565 |
\documentclass[a4paper,12pt]{article} |
| 566 |
\usepackage{gridset} |
| 567 |
\usepackage{blindtext} |
| 568 |
\raggedbottom |
| 569 |
|
| 570 |
\pagestyle{myheadings} |
| 571 |
|
| 572 |
\begin{document} |
| 573 |
\markright{gridbase=\gridbase, gridinterval=\gridinterval\ without move down}% |
| 574 |
\newcounter{Zeile}% |
| 575 |
\makeatletter |
| 576 |
\@whilenum \value{Zeile}<40\do {% |
| 577 |
\stepcounter{Zeile}% |
| 578 |
\theZeile. Zeile: |
| 579 |
\SavePos{\thepage.\theZeile}\thegridinfo{\thepage.\theZeile}\par |
| 580 |
}% |
| 581 |
\makeatother |
| 582 |
\clearpage |
| 583 |
\setcounter{Zeile}{0} |
| 584 |
\makeatletter |
| 585 |
\@whilenum \value{Zeile}<20\do {% |
| 586 |
\stepcounter{Zeile}% |
| 587 |
\theZeile. Zeile: |
| 588 |
\SavePos{\thepage.\theZeile}\theposinfo{\thepage.\theZeile}\par |
| 589 |
}% |
| 590 |
\makeatother |
| 591 |
\clearpage |
| 592 |
\parskip=.5\baselineskip |
| 593 |
\setcounter{Zeile}{0} |
| 594 |
\makeatletter |
| 595 |
\@whilenum \value{Zeile}<20\do {% |
| 596 |
\stepcounter{Zeile}% |
| 597 |
\theZeile. Zeile: |
| 598 |
\SavePos{\thepage.\theZeile}\theposinfo{\thepage.\theZeile}\par |
| 599 |
}% |
| 600 |
\makeatother |
| 601 |
\clearpage |
| 602 |
\markright{gridbase=\gridbase, gridinterval=\gridinterval\ with real move down |
| 603 |
at vmode}% |
| 604 |
\parskip=.5\baselineskip |
| 605 |
\setcounter{Zeile}{0} |
| 606 |
\makeatletter |
| 607 |
\@whilenum \value{Zeile}<25\do {% |
| 608 |
\stepcounter{Zeile}% |
| 609 |
\vskipnextgrid\theZeile. Zeile: \theposinfo{vp!\thegridcnt}\par |
| 610 |
}% |
| 611 |
\makeatother |
| 612 |
\clearpage |
| 613 |
\markright{gridbase=\gridbase, gridinterval=\gridinterval\ with real move down |
| 614 |
at hmode}% |
| 615 |
\parskip=.5\baselineskip |
| 616 |
\setcounter{Zeile}{0} |
| 617 |
\makeatletter |
| 618 |
\@whilenum \value{Zeile}<25\do {% |
| 619 |
\stepcounter{Zeile}% |
| 620 |
\theZeile. Zeile: \vskipnextgrid\theposinfo{vp!\thegridcnt}\par |
| 621 |
}% |
| 622 |
\makeatother |
| 623 |
\clearpage |
| 624 |
\parskip=0pt |
| 625 |
\blindtext |
| 626 |
\begin{itemize} |
| 627 |
\item Test |
| 628 |
\item Test |
| 629 |
\end{itemize} |
| 630 |
\vskipnextgrid\theposinfo{vp!\thegridcnt}\blindtext |
| 631 |
|
| 632 |
\end{document} |
| 633 |
% \end{macrocode} |
| 634 |
% \iffalse meta-comment |
| 635 |
%</example> |
| 636 |
% \fi |
| 637 |
% |
| 638 |
% \Finale |
| 639 |
% |
| 640 |
\endinput |
| 641 |
% |
| 642 |
% end of `gridset.dtx' |
| 643 |
% |
| 644 |
%%% Local Variables: |
| 645 |
%%% mode: docTeX |
| 646 |
%%% TeX-master: t |
| 647 |
%%% End: |