I have been trying to define a verbatim environment in plain TeX with |...| for inline and ||...|| for display. Optimally, with an easy way to alter so that the visibility of spaces can be toggled (e.g. commenting out a line of code or using a different character like *...* and **...**).

I know that tugboat.sty defines this (see lines 1632-1963), but it is a very long process and frankly quite hard to decipher. I was wondering what the easiest way to do this in plain TeX is.

I have also seen a few questions regarding verbatim in plain TeX (see Define a special verbatim commmand and How to display code snippets in plain TeX), but these both use commands (e.g. \verb{...} and \verbatim ...\endverbatim).

This is for my own curiosity, as way to better understand TeX, and for use in my own plain TeX documents.

  • 1
    It's not like that the author of tugboat intentionally write it in a difficult way, so maybe tugboat.dtx have the documentation of that code for you to read...?
    – user202729
    Jun 25, 2022 at 6:43

1 Answer 1


here is a short implementation if it's what you're after (probably not very robust).

\def|{\begingroup \def\do##1{\catcode`##1=12 }\dospecials \verbA}
\def\verbA#1{\ifx|#1\catcode`|=12 \expandafter\verblong \else \verbshort#1\fi}

lorem ipsum |{fjasdf&@(^#(%%| dolor ||\bye|\end|| \bye


  • Thanks, this is exactly what I was looking for! Couldn't you do \tmp{\centerline{\tt#1}\endgroup} instead of using math mode and \hbox?
    – btshepard
    Jun 25, 2022 at 18:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .