TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Deeply inspired by Paulo Cereda's answer on the ways TeX can be used apart from document creation. If you haven't seen the program mentioned: it's a Reversi TeX game that during the compile asks the user for the next move in the game and provides feedback. At the end the whole game is produced as a dvi.

Immediately practical uses of this popped up: Asking users for layout, colors, language. So on to terra incognita!

I tried to dissect the Reversi game, but it's not written for readability. I searched around, but user input to TeX programs is not an everyday thing.

How do I take input from the user compiling the document?

For example, I could ask a user for their name, and then print "Hello, [user's name]".

Update 1: I've now stumbled upon the \read macro, and it seems to be on the way, but it isn't really what I want.



Hello, \read


Update 2: David Carlisle pointed me to makebst a program to generate bibTeX styles. I'm looking into the source.

share|improve this question
up vote 8 down vote accepted

LaTeX provides the command \typein[var]{message} that should do what you're looking for:

\typein[\name]{What's your name? } % take user input
Hello \name!

There's also the sibling command \typeout{message} to output text on the console.

share|improve this answer

From makebst I found this code that seems to work in TeX.



\def\remblk#1 @@{#1}
\def\ask#1#2{\mes{#2}\read\ttyin to #1\ifx#1\defpar\def#1{}\else


\ask{\name}{What is your name?}

Hello, \name

share|improve this answer

Your Answer


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.