Text FormattingMinus in code listing

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
trophi20
Posts: 7
Joined: Thu Apr 02, 2020 7:17 pm

Minus in code listing

Post by trophi20 »

I've got a question, topic is the code listing.
How is it possible to write a minus (-) in a code listing?

I'm using Texmaker and MikTex.

Here's a example:

Code: Select all

\documentclass{article}
\usepackage{listings}  

\begin{document}
\begin{lstlisting}
    a = 10;
    a = 10 - 2;
\end{lstlisting}
\end{document}
The error:

Code: Select all

! Undefined control sequence.
<argument> \textminus
Does somebody know this error?

EDIT

Escape text solves this problem. But is this a good way?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

rais
Posts: 419
Joined: Sun Nov 16, 2014 8:51 pm

Minus in code listing

Post by rais »

The code provided does not result in the error shown.
And why should it? A - in the text is just a hyphen, not a minus sign...
You seem to be doing something else than shown.

KR
Rainer
Post Reply