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.

Possible Duplicate:
Syntax Coloring in LaTeX
Unix Command Highlighting latex

I am after some advice on how to display Linux terminal commands into LaTeX, so that they are indented and look different from normal text.

I have tried to insert the following into LaTeX

  $\emph {wget http://etc...................}

this outputs the wget onto a single line and then the part starting http onto another line. I want it all to appear on one line. Can someone body please give me some advice.

share|improve this question

marked as duplicate by Martin Schröder, Kurt, Scott H., lockstep, Qrrbrbirlbel Nov 26 '12 at 4:45

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
Could you give us more of your code? I'm getting the output as you seem to want it. Also, for command line text I'd used \ttfamily. Finally, you've got a stand alone $ which should either be \$ or not there at all. –  A.Ellett Nov 25 '12 at 16:00
3  
See the answer of of tex.stackexchange.com/questions/46953/… –  zunbeltz Nov 25 '12 at 16:03
1  
At a simple level remember LaTeX's standard command \verb and the environement verbatim. For more sophisticated formatting see also tex.stackexchange.com/q/867/15925 –  Andrew Swann Nov 25 '12 at 16:39
1  
Welcome to TeX.sx! Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Upvoting is the preferred way here to say "thank you" to users who helped you. –  Andrew Swann Nov 25 '12 at 16:44

4 Answers 4

up vote 10 down vote accepted

You can use the features provided by the listings package.

\documentclass{article}

\usepackage{listings}

\begin{document}

\noindent See the following command :
\begin{lstlisting}[language=bash]
  $ wget http://tex.stackexchange.com
\end{lstlisting}

\end{document}

Listing

share|improve this answer
    
This is exactly what I want, thanks for the help. –  mitchnufc Nov 25 '12 at 16:17

You can also use the minted package:

\documentclass{article}
\usepackage{minted}

\begin{document}
\noindent See the following command :
\begin{minted}{bash}
  $ wget http://tex.stackexchange.com
\end{minted}
\end{document}

Compiled result of above code

You need Pygments and the --shell-escape flag when you compile.

share|improve this answer

You can use pythontex. It uses the Python library Pygments to provide some syntax highlighting.

If you don't need syntax highlighting, fancyvrb is nice for typesetting verbatim text with custom indentation, frames, line numbers, etc. Internally, pythontex uses much of fancyvrb, combined with syntax highlighting from Pygments.

enter image description here

\documentclass{article}

\usepackage{pythontex}
\setpygmentspygopt{bash}{style=default} %Set syntax highlighting style
\setpygmentsfv{xleftmargin=4ex} %Pass fancyvrb options, in this case, left margin

\begin{document}

\noindent Block use:
\begin{pygments}{bash}
$ wget http://tex.stackexchange.com
\end{pygments}
And after the block.

Inline use:  \pygment{bash}{wget http://tex.stackexchange.com}.  And after inline

\end{document}
share|improve this answer

You can use the listings packages:

Add the following to the header:

\usepackage{listings}

And type your code like this:

\begin{lstlisting}
print('print me')
\end{lstlisting}

For more detail, read the Wikibooks chapter about the package. Wikibooks

share|improve this answer
    
Thanks for the help, I appreciate it. –  mitchnufc Nov 25 '12 at 16:18
    
I like your answer :) I think you would have received more up votes if you had made a complete MWE, as the other answer did; Welcome to TeX.SE! –  cmhughes Nov 25 '12 at 16:57

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