Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to put my source plain TeX file in the output of the same plain TeX file.

As I remember coming through a macro, that can put a file's content in to the output, but only \input comes to mind. What could it be?

Becoming frustrated—and so tired—I decided, to use the \openin, \read, \closein macros, but failed. For the same file, nothing is read. Only for a text file, the very first line is read, but only if the condition is after the body of the loop.

However, while I was writing this question, a suggestion were showed here, which I learned from that I was missing \unless. It is fine, but now everything is interpreted. How can I avoid that?

share|improve this question
add comment

1 Answer 1

up vote 4 down vote accepted
\input eplain

This is my plain \TeX{} file that contains a listing of itself.

\listing{\jobname.tex}

\bye

The \listing command is defined as

\def\listing#1{%
   \par \begingroup
   \@setuplisting
   \setuplistinghook
   \input #1
   \endgroup
}%
\let\setuplistinghook = \relax
{%
  \makeactive\^^L
  \let^^L = \relax
  \gdef\@setuplisting{%
     \uncatcodespecials
     \obeywhitespace
     \makeactive\`
     \makeactive\^^I
     \makeactive\^^L
     \def^^L{\vfill\break}%
     \parskip = 0pt
     \listingfont
  }%
}%

and this depends on many other definitions. If your file doesn't contain strange things, a simpler definition might work:

\def\listing#1{\par\begingroup
  \parindent=0pt
  \def\do##1{\catcode`##1=12 }\dospecials
  \def\par{\endgraf\leavevmode}%
  \obeyspaces\obeylines\tt
  \input #1 \endgroup}

It doesn't work with Spanish inverted marks.

share|improve this answer
    
And it is not possible without eplain, right? –  Adam L. S. Dec 15 '11 at 12:54
    
eplain.tex makes available the command. I'll try to look if it's practical to extract the definition. –  egreg Dec 15 '11 at 17:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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