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

I'm trying to include a kernel version info (i.e. \texttt{}) in my LaTeX document. However, LaTeX keeps trying to put it into "math-text" ("Missing $ inserted" and so on).

How do I escape this text, so that I can place it as text, not an equation?

share|improve this question
up vote 23 down vote accepted

The problem is the underscore. TeX uses that as a special character to denote subscripts, as in x_1,x_2. TeX assumes that wherever it encounters an underscore the author means it to be a subscript.

Fortunately, this behaviour can be overridden. Even more fortunately, you don't need to know how this is done since it is already solved for you! LaTeX provides the \verb (short for "verbatim") command which typesets its contents in the \texttt family and sorts out all the "special" characters so that they appear as is. A way to use it for you would be:


The + is a delimiter that you yourself can choose, so if the string has + in it then you can choose something else, such as *. Just make sure that the delimiter is not something that appears in the string that you want to typeset.

share|improve this answer
This is wonderful, thank you! – user7822 Sep 13 '11 at 9:15

To complete other answers, I should mention that if the text is entered manually (not programmatically generated), \_ or \textunderscore can be used to easily obtain the underscore:

\texttt{\textunderscore 64}

I suppose \_ is as close to escaping as you can get :-)

share|improve this answer
(for completeness: even if programmatically generated, you could pipe through sed or similar to find/replace such instances) – Sean Allred Nov 12 '15 at 13:19

It's also possible to run the shell command from inside LaTeX; for example, here is how to get the output of uname -a:


\def\uname{{\ttfamily\def\do##1{\catcode`##1=12 }\dospecials
  \catcode` =10 \pdfprimitive\input|"uname -a" }\unskip}


For this it's necessary to run pdflatex with the -shell-escape option.

A more general version might be:

\def\syscommand#1{{\ttfamily\def\do##1{\catcode`##1=12 }\dospecials
  \catcode` =10 \pdfprimitive\input|"#1" }\unskip}

and \syscommand{uname -a} would give the same result as before. Use with great care.

share|improve this answer

Your Answer


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