Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to do code listing in Latex without line numbers (when using lstlisting environment)

Tags:

latex

I have been writing a project report and have added some pseudo codes using the following command : lstlisting in Latex as shown bellow.

         \begin{lstlisting}[language=c++]

             # On leave focus of email field

           IF email is blank
         Error message: "Please enter an email address"

           ELSE IF email field value is not a valid email address
        Error message: "Wrong email please try again"}  

         # On leave focus of password

          IF password is not sufficiently strong
       Error message: "Password strength is not good" 

         \end{lstlisting}

The above works just fine but in the code block thy are some line numbers appearing and I would like to get ride of those. Any hints on how to remove them? I also know the following:

     \section*{New section}

Would give a section title without number. But in the case of code listing it doesn't work and produce an error instead.

like image 317
JNW Avatar asked Jun 14 '17 14:06

JNW


People also ask

What is the listings package for latex?

The listings package offers source code highlighting for various languages. Learn by example how to use it in your LaTeX documents. The listings package is a powerful way to get nice source code highlighting in LaTeX.

How to highlight source code in latex?

- LaTeX-Tutorial.com Highlight source code in LaTeX with the lstlisting package. The listings package offers source code highlighting for various languages. Learn by example how to use it in your LaTeX documents. The listings package is a powerful way to get nice source code highlighting in LaTeX.

How to add breaklines to a snippet in latex?

Simply specify the breaklines option on your snippet. The downside is that you have to process the document with the --shell-escape option because the external program pygmentize is used to format the source code. Thanks for contributing an answer to TeX - LaTeX Stack Exchange! Please be sure to answer the question.

How do I display code in latex?

The default tool to display code in LaTeX is verbatim, which generates an output in monospaced font. The code above produces the following output: Just as in the example at the introduction, all text is printed keeping line breaks and white spaces. There's a starred version of this command whose output is slightly different.


1 Answers

You used:

\begin{lstlisting}[language=c++]

Specifying that the language is C++, the same way you can specify you don't whant line numbers:

\begin{lstlisting}[language=c++,numbers=none]

In the code you posted this is not C++ and you said it is for pseudocode, so you can get rid of the language parameter and just keep:

\begin{lstlisting}[numbers=none]
like image 178
pinam45 Avatar answered Nov 12 '22 13:11

pinam45