The following works inside \TeX as long as I keep the \answer fixed to a certain value

I cann't find the right commands to ask for input from the console to get the wanted number

I want the code to work with \gdef\answer{2} commented out and replaced by \askanswer

I want to fix this with only commands as from inside the TeXbook, no extra packages

I am using TeXnicCenter and mikTeX

Typing over the yes/no dialog as in TeXBook p218 results in a similar error and I don't know what is wrong

Why doesn't the compilation stops and asks for a number to typein? I get ! Emergency stop

% An attempt for a general dialog prompt
% source The TeXBook by Donald E. Knuth p218
\global\newcount\choiceno % to count the number of choices
\global\newcount\totalchoices % to count the number of choices
\newif\ifgarbage % to keep track if a valid number has been choosen
                 % \garbagetrue a wrong choice has been made
                 % \gargabefalse a valid choice has been made
\def\space{ }

\def\step#1{\global\advance\choiceno by1\edef\intermediate{%
\intermediate\space\the\choiceno.\space #1}}
\def\gobble#1{} % used only once to remove the most left space

\ifgarbage% to check if this is maybe the choice that has been made
   \ifx\answer\intermediatetwo\garbagefalse\immediate\write16{#2} \fi 
\def\stepsecond{\global\advance\choiceno by1 

\def\askanswer{{\endlinechar=-1 \global\read16 to \answer}} 
  % BUT COMPILING INSIDE DOS PROMPT WITH tex filename.tex works!!

   % \intermediate has the possible choices with 
   % their respective numbers in front of them
   % \choiceno has at the end the total number 
   % of choices, stored in counter totalchoices
\xdef\intro{#1 Choose from 1 to\space\noofchoices\space and hit enter}

\loop% this loop is not added yet because the 
% reading in doesn't work!!
\askanswer% this doesn't work from inside editor, reason unknown, 
          % should work because command listed in TeXBook!!
          % it does work in command prompt with "tex filename.tex"
\ifgarbage\immediate\write16{Invalid entry!!}
% testing and afterwards inside loop repeat
%\immediate\write16{Valid entry!!!}

% the actual command to test
\beginchoices{Make a choice between the following, 
type the number in front of it}\listchoices%
\poschoice{first}{You have choosen for first}% POSsible choice
\poschoice{second}{You have choosen for second}% POSsible choice
\poschoice{third}{You have choosen for third}\endchoices %POSsible choice


Consulted articles that didn't solve the problems:

Carrying on Dialog with TeX by Michael J. Downes reprocessed January 2013

BaSiX: An interpreter written in TeX by Greene, Andrew Marc

checknum.sty Hamilton Kelly, Brian UKTeX91(1) January 1991

searched at TeX - LaTeX Stack Exchange and a lot of posts are about \write16 but not \read16

The TeXBook by Donald E. Knuth p218

  • \newline isn't defined in TeX; maybe you want \break. With that fixed, \askanswer does produce a prompt, but I always get 'Invalid entry!!' This isn't the behaviour you describe; are you sure you have posted the right code? Commented Aug 18, 2017 at 12:19
  • As @IanThompson says, your code does ask for input but then never runs the validation, so always takes the 'invalid' route ...
    – Joseph Wright
    Commented Aug 18, 2017 at 13:33
  • I updated the code and the weird part is that it works when executed from a dos prompt with "tex filename.tex" as command, it doesn't work when build is hit inside TeXnicCenter
    – lampter
    Commented Aug 18, 2017 at 14:05
  • 1
    Look in your TeXnicCenter options; it may be running tex in batch mode or something like that. Commented Aug 18, 2017 at 14:22
  • (To put it differently: if it works fine when tex is invoked at the command line (as it was designed for), but doesn't work when invoked from TeXnicCenter, then the issue is within TeXnicCenter.) Commented Aug 18, 2017 at 18:04

1 Answer 1


here is some code used in an interactive plain tex routine to prepare a sheet for heading a fax. (this was originally written in 1994, well before latex2e was in regular use.) i've included only the portion that deals with issuing a prompt and receiving a response.

\def\prompt#1#2{\message{#1 }
  \read-1 to #2}

\newcount\hours \newcount\minutes \newcount\thetime
\thetime=\time \hours=\thetime
   \divide\hours by 60 \multiply\hours by 60
   \minutes=\thetime \advance\minutes by -\hours
   \divide\hours by 60
\def\now{\number\hours:\ifnum\minutes<10 0\fi\number\minutes}
  January\or February\or March\or April\or May\or June\or
  July\or August\or September\or October\or November\or December\fi
  \space\number\day, \number\year}

\immediate\write16{  }
\prompt{Date (default=\today): }{\calldate}
\prompt{Time (default=\now): }{\calltime}
\prompt{To whom are you sending the FAX? }{\theirname}
\prompt{Whom do they represent? }{\rep}

You must log in to answer this question.

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