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 am new to Latex, I need to create a user defined command or Macro. I need to print unix shell commands on a pdf, the code looks like below

$sudo apt-get install build-essential

This has to be done for every unix command and I have lot too many of them. For this reason I thought I can create a new command called \shell like this


I am getting some !Emergency stop errors. can someone tell me what am I doing wrong. Thank you.

share|improve this question
Possible duplicate of How can I define a custom listing environment? – samcarter Feb 25 at 18:18
lstlisting are very fragile constructs - do not try to build your own commands around them if you do not really need them. But if you want to save the work of typing [language=bash] every time, there are other ways. – samcarter Feb 25 at 18:22
could you please tell me the other ways? – Bharadwaj Feb 25 at 18:22
Have a look at tex.stackexchange.com/a/78995/36296, sounds like \lstnewenvironment might be of use. – samcarter Feb 25 at 18:24
up vote 3 down vote accepted

Try using this command and you will not receive that emergency stop error:

\newcommand{\shell}[1]{\lstinline[language=bash] {#1} } 

I am not sure about correctness of using newcommand while, in fact, you are defining newenvironment. If you are interested in defining a new environment, you can use the syntax addressed here: https://en.wikibooks.org/wiki/LaTeX/Macros#New_environments

share|improve this answer
Even better, \newcommand{\shell}{\lstinline[language=bash]} – egreg Feb 25 at 18:37

As stated in comments, I would dissuade from trying to wrap lstlisting into custom environments. They are really fragile and do behave different from "normal" tex commands. But listings itself provides the ability to define own lstnewenvironment which saves you from typing [language=bash] every time.





$sudo apt-get install build-essential

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.