As an experiment, I wish to write a manuscript in core TeX, which typesets the text "Hello, world!", and compile it without any format.

If I was using the Plain TeX format, this program would be

Hello, world!
\bye

So to make this program independent of the format, I've copied all the missing definitions from plain.tex, and arrived at the following:

\catcode`\{=1
\catcode`\}=2
\catcode`@=11
\mathchardef\@MM=20000
\def\supereject{\par\penalty-\@MM}
\catcode`@=12
\outer\def\bye{\par\vfill\supereject\end}
Hello, world!
\bye

When I compile this manuscript with tex -ini, the compilation proceeds successfully, and a dvi file is created. However, the dvi is empty. Why?

  • 5
    Nice hobby :) -- you seem to try to learn LaTeX from the scratch. – Dr. Manuel Kuehner Aug 26 '17 at 14:45
  • 11
    You haven't specified any fonts. – cfr Aug 26 '17 at 14:56
  • 7
    Don't you mean tex -ini rather than tex -init? You can run dvitype on the DVI to see what it contains; the DVI format is actually pretty cool. – ShreevatsaR Aug 26 '17 at 15:30
  • 1
    try \hsize=10cm \vsize=10cm \parfillskip=0pt plus 1fil %\lineskip=1pt %\baselineskip=12pt %\lineskiplimit=0pt \font\myfont=cmr10 \myfont Hello world \end – touhami Aug 26 '17 at 15:36
  • 2
    See tug.org/TUGboat/tb36-2/tb113gregorio.pdf for some examples of shooting one's own foot. – egreg Aug 27 '17 at 8:36
up vote 35 down vote accepted

Firstly, let's start with a simpler plain TeX file that does not use the \bye macro:

Hello, world!
\end

This already works fine when run with tex (produces a DVI file containing “Hello, world!”), and (as \end is a TeX primitive and not something defined in plain.tex) can be run with tex -ini without (visible) errors, but producing a “blank” DVI file.

To see what's going on, we'd like to turn on tracing, maybe \tracingall if we don't know what sort of tracing we'd like. This \tracingall is defined in plain.tex, and copying the relevant parts from plain.tex exactly as you did, gives:

\catcode`\{=1%
\catcode`\}=2%

\catcode`@=11%
\chardef\@ne=1
\chardef\tw@=2
\def\loggingall{\tracingcommands\tw@\tracingstats\tw@
  \tracingpages\@ne\tracingoutput\@ne\tracinglostchars\@ne
  \tracingmacros\tw@\tracingparagraphs\@ne\tracingrestores\@ne
  % \showboxbreadth\maxdimen\showboxdepth\maxdimen}
  \showboxbreadth100\showboxdepth100}
\def\tracingall{\tracingonline\@ne\loggingall}
\catcode`@=12%

\tracingall

Hello, world!
\end

(I cheated a bit: the commented out line above with \showboxbreadth\maxdimen\showboxdepth\maxdimen is the original; I just used \showboxbreadth100\showboxdepth100 to avoid having to pull in definitions of \maxdimen which needs \newdimen which needs \alloc@ etc.) Anyway, with this it's easier to see the issue in the output: lines like

{the letter H}
{horizontal mode: the letter H}
Missing character: There is no H in font nullfont!
{the letter e}
Missing character: There is no e in font nullfont!

and so on. Actually you can get this output even with a smaller .tex file:

\tracingonline=1
\tracingcommands=2
\tracinglostchars=1
Hello, world!
\end

Anyway, now that you know that the issue is fonts, you can copy over the relevant bits from plain.tex (again I've replaced a few lines from plain.tex (commented out) with simpler equivalents, to avoid copying a whole lot):

\catcode`\{=1 % left brace is begin-group character
\catcode`\}=2 % right brace is end-group character

\font\tenrm=cmr10 % roman text

% \def\rm{\fam\z@\tenrm}
\def\rm{\fam0\tenrm}
% \normalbaselines\rm % select roman font
\rm % select roman font

Hello, world!
\end

Running this with tex -ini typesets the characters in the output, but causes an interesting issue: the resulting dvi file has two pages, one containing “Hello,” and one containing “world!”

But the original issue is resolved, so I'll leave it to you to figure out this mystery. :-)


Edit: For completeness here is a minimal .tex file that when run with tex -ini produces an identical .dvi file (identical except for the timestamp comment of course) as a .tex file containing Hello, world!\bye does when run with tex:

\catcode`\{=1 % left brace is begin-group character
\catcode`\}=2 % right brace is end-group character

\hsize=6.5in
\vsize=8.9in
\parindent=20pt

\topskip=10pt
\parfillskip=0pt plus 1fil

\font\tenrm=cmr10 % roman text

\def\line{\hbox to\hsize}

\countdef\pageno=0 \pageno=1 % first page is number 1

\output{\plainoutput}
\def\plainoutput{\shipout\vbox{\makeheadline\pagebody\makefootline}}
\def\pagebody{\vbox to\vsize{\boxmaxdepth\maxdepth \pagecontents}}
\def\makeheadline{\vbox to0pt{\vskip-22.5pt \line{\vbox to8.5pt{}\hfil}\vss}}
\def\makefootline{\baselineskip24pt\lineskiplimit0pt\line{\hss\tenrm\number\pageno\hss}}
\def\pagecontents{\unvbox255}

\tenrm % select roman font
Hello, world!
\end

Every line (before the last two) is either from plain.tex or a simplified version of one, and removing any line makes the DVI output no longer identical. (Of course to make it minimal I've removed a lot that is useful such as the instruction in \plainoutput that advances the page number, so this will not work when you have more than one paragraph or even more than one line, let alone more than one page.)

  • Thanks. If you know why, can you please spell out the reason the pdf is 2 pages? There are enough mysteries out there for me to figure out on my own... – Evan Aad Aug 26 '17 at 17:30
  • 1
    @EvanAad You've not set \hsize, so it's 0pt and TeX breaks into pages at every piece of whitespace. You probably want to set that and \parfillskip too. – Joseph Wright Aug 26 '17 at 17:52
  • 1
    @EvanAad I've gone further and produced a minimal .tex file for running with tex -ini, that produces the same output (including the positions on the page, and the page number at the bottom) as the hello-world plain-TeX file. – ShreevatsaR Aug 26 '17 at 18:59

Skip TeX, write a PDF directly, it's a compiler-free solution. (just compiled the examples that I've learned from this blog). Paste it in a text editor and save it as a PDF file.

%PDF-1.1
%¥±ë

1 0 obj
  << /Type /Catalog
     /Pages 2 0 R
  >>
endobj

2 0 obj
  << /Type /Pages
     /Kids [3 0 R]
     /Count 1
     /MediaBox [0 0 100 15]
  >>
endobj

3 0 obj
  <<  /Type /Page
      /Parent 2 0 R
      /Resources
       << /Font
           << /F1
               << /Type /Font
                  /Subtype /Type1
                  /BaseFont /Times-Roman
               >>
           >>
       >>
      /Contents 4 0 R
  >>
endobj

4 0 obj
  << /Length 55 >>
stream
  BT
    /F1 18 Tf
    0 0 Td
    (Hello World) Tj
  ET
endstream
endobj

xref
0 5
0000000000 65535 f 
0000000018 00000 n 
0000000077 00000 n 
0000000178 00000 n 
0000000457 00000 n 
trailer
  <<  /Root 1 0 R
      /Size 5
  >>
startxref
565
%%EOF

enter image description here

  • 2
    Whats's the %¥±ë for? – Dr. Manuel Kuehner Aug 26 '17 at 17:27
  • 3
    @Dr.ManuelKuehner They are the high bit chars. You need at least 4 of them for the header. – percusse Aug 26 '17 at 17:30
  • 3
    @Dr.ManuelKuehner Not really. It's the bizarre PDF specification If a PDF file contains binary data, as most do (see 7.2, "Lexical Conventions"), the header line shall be immediately followed by a comment line containing at least four binary characters—that is, characters whose codes are 128 or greater. This ensures proper behaviour of file transfer applications that inspect data near the beginning of a file to determine whether to treat the file’s contents as text or as binary. – percusse Aug 26 '17 at 17:32
  • 2
    I've upvoted it because writing PDFs by hand is really cool. :-) – ShreevatsaR Aug 26 '17 at 17:48
  • 5
    It might take a while to typeset War and peace, but it will be probably done before my thesis... 😁 – Paulo Cereda Aug 26 '17 at 20:00

Here's a minimal core TeX manuscript that typesets "Hello, world!".

\font\myfont=cmr10\myfont
    % When the font is unspecified, it defaults to the nullfont,
    % in which glyphs have no visual representation.
    % Without this line the dvi page will appear empty.
%
\hsize=10cm
    % When \hsize is unspecified, it defaults to 0pt,
    % which causes TeX to break page at every whitespace.
    % Without this line the words will be placed on separate pages.
%
\parfillskip=0pt plus 1fil
    % When \parfillskip is unspecified,
    % the whitepasce between words will stretch
    % to fill up as much line space as possible
    % while keeping all words on a single line.
    % The total line width is given by \hsize.
    % Without this line the two words will be positioned
    % at the opposite sides of a line that is 10cm wide.
%
Hello, world!
\end

* This answer is based on the contributions of cfr's comment, touhami's comment, ShreevatsaR's answer, and Joseph Wright's comment.

  • 2
    what about \catcode\{=1 \catcode\}=2 \font\myfont=cmr10 \myfont \hbox{Hello world} \end – touhami Aug 27 '17 at 7:46
  • try to type the catcode correctly – touhami Aug 27 '17 at 7:49
  • @touhami: Yes, very nice, but it should be \catcode`, no? I don't know why you never wrote an answer. – Evan Aad Aug 27 '17 at 7:53

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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