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.


2 Answers 2


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

  • 2
    Even better, \newcommand{\shell}{\lstinline[language=bash]}
    – egreg
    Feb 25, 2016 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


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .