In order to convince TeX to keep the grid I tried to program a command, that takes a font size switch as parameter and calculates the reminder of the division of the corresponding baseline skip and the \onelineskip (the baseline skip of the default size). The commands output should then be use to set some lengths.

Basically, what I want to do, is passing the output of a custom command directly to \setlength.

But I ran into some problems, as if I do something like this:


where \trueGird is my custom command putting out a length, I get:

Missing number, treated as zero

I guess this hangs together with the way TeX is expanding, and I'm wondering, if the approach of using a commands output within \setlength is possible at all, and if it is, how?

A workaround could be to set a custom length within the command and use that in \setlength:

\trueGrid{\secheadstyle} % put the result of it calculations into the length `trueGridOutput`
\setbeforesecskip{-2\onelineskip + \trueGridOutput}

Here is a working example:

\usepackage{fp, calc}



% Get baselineskip of the given font size.
\settoheight{\trueGridH}{#2 \raisebox{0pt}[\baselineskip][0pt]{}}%
% Set the baselineskip. Default is \onelineskip.
% We do not have modulo function, so we calculate the
% reminder of the devision the given (#2) hight and 
% the default line hight.
\remainder pt%
\setbeforesecskip{-2\onelineskip + \trueGrid{\secheadstyle}}

  • I might be wrong, but I think it should be expandable to be used within \setlength and your macro contains assignments. But do you really need to create your own version instead of simply using one of the existing packages? – TeXnician Sep 24 '18 at 8:22
  • @TeXnician I didn't find a package which helped me in a simple way to hold the grid. But I am grateful for any hint. But I would like to know how to do something like this the right way nevertheless. – user5950 Sep 24 '18 at 8:34
  • Have a look at ctan.org/pkg/grid (there are some other packages around as well as tex.stackexchange.com/questions/1418/grid-system-in-latex). I must confess that in comparison with ConTeXt grid typesetting in LaTeX is a bit tedious. – TeXnician Sep 24 '18 at 8:46
  • @TeXnician Thanks, I will have a look. Switching to ConTeXt is not an option here. But I like to control where the extra space are put, so it is not such a big effort to do it manually. The thing is, that I am too lazy to do the math again every time I use a different font size. – user5950 Sep 24 '18 at 8:50
  • Unlike TikZ, which runs everything through \pgfmathparse, LaTeX command do not evaluate math expression. You need \dimexpr (or \numexpr) for that. – John Kormylo Sep 24 '18 at 14:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.