While trying to customize my TOC for a book project, I wanted to add some vertical space between two items in the TOC.

From reading the OPmac source, it seems that the TOC is generated from the .ref file at the time that \input opmac is read by TeX. So in order to add a custom TOC entry, one would need to write the code before the \input opmac line.

To that end I wrote this:

\input opmac
\Xspace{{\vskip 20pt}}

I do in fact achieve my goal of inserting 20pt of vertical space at the point I expect to see it, but I'm not thrilled with the need to put things in {{ }} double braces and not sure how to resolve that.

My question is this: is there a more idiomatic way in OPmac to achieve my goal of adding arbitrary content to the TOC?


Of course, if you need to declare new command used in .ref file (such as \Xspace) then you have to define it before \input *.ref, which is done during \input opmac.

On the other hand, simple commands can be written to the .ref file without declaring new special macro. Instead

\wref\Xspace{{\vskip 20pt}}

you can write


But this approach with \addto\toclist has a problem. The \toclist is used in two different cases: when TOC is generated and when \outlines macro generates PDF outlines. In the second case the \tocline macro (which is included in \toclist) is redefined.

My first idea was slight different. When typo-designer needs to print a different shape of the TOC, then he can redefine the \tocline macro. This macro has five parameters:

\tocline {level}{recommended font}{number}{text}{page}

where \level=0 for chapters, \level=1 for sections, \level=2 for subsections etc. You can copy the definition of \tocline from opmac.tex and add the new line:

   \ifnum#1=0 \vskip20pt \relax \fi % <<< this line is new, adds the desired \vskip
   {\leftskip=#1\iindent \rightskip=2\iindent
   \ifischap\advance\leftskip by\iindent\fi
   \ifnum#1>1 \advance\leftskip by\iindent\fi
   \toclinehook \noindent\llap{#2\toclink{#3}\enspace}%

I'm not thrilled with the need to put things in {{ }}

This double brace is used in the context of \wref macro:


which does more sense when \Xcommand has more than one parameter.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.