How to change the font in the table of contents generated by opmac?

I am trying to change the font used in the table of contents. The problem is: with the table of contents generated by opmac, the fonts are rm by default.

I managed to change a few codes in the opmac file to change the title font and the page number font, but the actual text is not changed at all.

In opmac the following changes are made:

1. In line 180, after \resizeall, I changed the font to \tocfont.
2. In line 360, after \wtotoc0 I again changed the font to \tocfont (for chap command).
3. The same changes are made in lines 366 and 372 (for sec and secc commands).
4. In line 485, replace all occurrence of fonts with \tocfont again.

Then a minimal example document is:

\input opmac

\font\tocfont="Bradley Hand" at 18pt

\nonum\notoc\sec \tocfont Contents

\tocfont

\maketoc

\sec First

\sec Second

\secc Sub

\sec Third

\bye


If I look into \jobname.ref, then I can see that it still uses rm in those places.

Below is an image of what I got so far.

And below is what I want (the picture is produced by my own macros):

Any suggestion or help is sincerely appreciated.

P.S. I don't understand Czech, so please explain if referencing to a Czech document, thanks. :p

• it would be easier to answer if you provided an example, but failing all else \begingroup\let\rm\relax...\endgroup around your toc would stop \rm changing the font. – David Carlisle Oct 9 '16 at 19:00
• Thanks so much! This is what will happen if one didn't think about \relax! ;p If you post this as an answer, I would happily accept it. And I don't know what you mean by an example. Shall I post the changed definitions in opmac? Thanks a lot! :) – awllower Oct 10 '16 at 1:41
• By "example" I meant (as frequently asked for on this site) an example that people can run that demonstrates the problem. Most people here (or anywhere) only have a passing acquaintance with opmac so it would be much easier to construct a real answer given a small example document to test. But anyway I made my comment into an answer as requested. The solution there is just to hit it with a sledgehammer so it doesn't need refined test cases:-) – David Carlisle Oct 10 '16 at 6:40
• This is one of the cases where I'm tempted to vote for closing the question as unclear as soon as it appears. You seem to be believing that everybody here is able to concoct a suitable example in order to help you. Well, no, you're wrong. – egreg Oct 10 '16 at 7:53
• @egreg: Sorry for that impression. I was just unsure of what an example should look like: I made changes to codes inside opmac, and I don't understand how the macros there work. Though there is already an answer, I will indicate what changes I made in opmac, and provide a minimal document as an example. Thanks again for pointing this out. :) – awllower Oct 10 '16 at 8:04

It would be easier to answer if you provided an example, but failing all else

\begingroup\let\rm\relax
...
\endgroup


around your table of contents would stop \rm changing the font

Unfortunately, opmac.tex hardwires several choices about fonts.

\input opmac

\font\tocfont="Linux Biolinum O" at 18pt

\eoldef\chap#1{\ifnonum\else \global\advance\chapnum by1 \fi
\chaphook {\globaldefs=1 \secnum=0 \seccnum=0 \tnum=0 \fnum=0 \dnum=0}\relax
\edef\thechapnum{\the\chapnum}\let\thetocnum=\thechapnum
\def\dotocnumafter{\wtotoc0\tocfont{#1}}%
\printchap{#1}\resetnonumnotoc
}
\eoldef\sec#1{\ifnonum\else \global\advance\secnum by1 \fi
\sechook {\globaldefs=1 \seccnum=0 \tnum=0 \fnum=0 \dnum=0}\relax
\edef\thesecnum{\othe\chapnum.\the\secnum}\let\thetocnum=\thesecnum
\def\dotocnumafter{\wtotoc1\tocfont{#1}}%
\printsec{#1}\resetnonumnotoc
}
\eoldef\secc#1{\ifnonum\else \global\advance\seccnum by1 \fi
\secchook {}\relax
\edef\theseccnum{\othe\chapnum.\the\secnum.\the\seccnum}\let\thetocnum=\theseccnum
\def\dotocnumafter{\wtotoc2\tocfont{#1}}%
\printsecc{#1}\resetnonumnotoc
}
\def\maketoc{\par \ifx\toclist\empty
\opwarning{\noexpand\maketoc -- data unavailable, TeX me again}\openref
\else \begingroup\baselineskip=27pt\toclist\endgroup \fi}

\def\tocline#1#2#3#4#5{{\leftskip=#1\iindent \rightskip=2\iindent

\nonum\notoc\sec \tocfont Contents

\maketoc

\sec First

\sec Second

\secc Sub

\sec Third

\bye


I used a different font because I don't have Bradley Hand.

Some more granularity:

\input opmac

\eoldef\chap#1{\ifnonum\else \global\advance\chapnum by1 \fi
\chaphook {\globaldefs=1 \secnum=0 \seccnum=0 \tnum=0 \fnum=0 \dnum=0}\relax
\edef\thechapnum{\the\chapnum}\let\thetocnum=\thechapnum
\def\dotocnumafter{\wtotoc0\tocchapfont{#1}}%
\printchap{#1}\resetnonumnotoc
}
\eoldef\sec#1{\ifnonum\else \global\advance\secnum by1 \fi
\sechook {\globaldefs=1 \seccnum=0 \tnum=0 \fnum=0 \dnum=0}\relax
\edef\thesecnum{\othe\chapnum.\the\secnum}\let\thetocnum=\thesecnum
\def\dotocnumafter{\wtotoc1\tocsecfont{#1}}%
\printsec{#1}\resetnonumnotoc
}
\eoldef\secc#1{\ifnonum\else \global\advance\seccnum by1 \fi
\secchook {}\relax
\edef\theseccnum{\othe\chapnum.\the\secnum.\the\seccnum}\let\thetocnum=\theseccnum
\def\dotocnumafter{\wtotoc2\tocssecfont{#1}}%
\printsecc{#1}\resetnonumnotoc
}
\def\maketoc{\par \ifx\toclist\empty
\opwarning{\noexpand\maketoc -- data unavailable, TeX me again}\openref
\else \toclist \fi}

\def\tocline#1#2#3#4#5{{\leftskip=#1\iindent \rightskip=2\iindent

\font\tocfont="Linux Biolinum O" at 18pt
\font\tocchapfont="Linux Biolinum O" at 10pt
\let\tocsecfont\tocchapfont
\let\tocssecfont\tocsecfont

\nonum\notoc\sec \tocfont Contents

\maketoc

\sec First

\sec Second

\secc Sub

\sec Third

\bye


• I wonder whether it wasn't easier to implement your own sectioning commands on top of, say, eplain, rather than patching opmac. – erreka Oct 12 '16 at 22:41
• @erreka The OP is using opmac; I don't think it is compatible with eplain. – egreg Oct 12 '16 at 22:44
• @egreg You're right: I meant to ask that question to @awllower; my apologies. – erreka Oct 12 '16 at 23:45
• @erreka Thanks for the suggestion, I shall look into it afterwards. :) – awllower Oct 13 '16 at 3:19