# How to add an arbitrary item to the TOC in OPmac

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:

\def\Xspace#1{\addto\toclist{\par#1}}
\input opmac
.
.
.
\Xspace{{\vskip 20pt}}
.
.
.
\bye


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

\write\reffile{\string\addto\string\toclist{\vskip20pt}}


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:

\def\tocline#1#2#3#4#5{%
\ifnum#1=0 \vskip20pt \relax \fi % <<< this line is new, adds the desired \vskip
{\leftskip=#1\iindent \rightskip=2\iindent

I'm not thrilled with the need to put things in {{ }}
This double brace is used in the context of \wref macro:
\wref\Xcommand{{first}{second}{third}}

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