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

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

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