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'm trying to include a kernel version info (i.e. \texttt{2.6.40.4-5.fc15.x86_64}) 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
add comment

3 Answers

up vote 24 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:

\verb+2.6.40.4-5.fc15.x86_64+

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! –  dare2be Sep 13 '11 at 9:15
add comment

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{2.6.40.4-5.fc15.x86\_64}
\texttt{2.6.40.4-5.fc15.x86\textunderscore 64}

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

share|improve this answer
add comment

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

\documentclass[a4paper]{article}
\usepackage[T1]{fontenc}

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

\begin{document}
\uname
\end{document}

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
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.