2

I need to type some code in Latex, but when I type [replace] (as a part of the code) it says:

"Missing number, treated as zero"

Here is my minimal working example:

       \documentclass[]{report}
       \begin{document}
       \texttt{
       [some text]\\
       some other text\\
       [replace]\\
        blablabla\\
        }
       \end{document}

Any Help is appreciated :) Thanks a lot in advance!

ShreevatsaR
  • 45,428
  • 10
  • 117
  • 149
Kathiieee
  • 879
  • 1
    It's because of the square parenthesis after the double backslash. Try this: \documentclass{report} \begin{document} \texttt{ [some text]\ some other text\\~ [replace]\ blablabla\ } \end{document} – bersanri Jun 27 '13 at 13:26

1 Answers1

2

The problem is that [...] after \\ is read as an optional argument. It can be used to specify more vertical space between the lines via e.g. \\[12pt]. But here you do not want your text [...] read as an argument to the \\ command, instead you need to tell LaTeX to take it easy with \\\relax:

\documentclass{report}

\begin{document}

\texttt{
[some text]\\
some other text\\\relax
[replace]\\
blablabla\\
}

\end{document}

In genaral you should not be using \\ to break lines on ordinary text. A blank line will give a new paragraph. \\ is appropriate in environments such as center or flushleft. For code examples the verbatim environment would be a better start:

\begin{verbatim}
[some text]
some other text
[replace]
blablabla
\end{verbatim}

Here the line breaks in your source are respected and you don't need \\. More sophisticated code typesetting is provided by packages such as listings.

ShreevatsaR
  • 45,428
  • 10
  • 117
  • 149
Andrew Swann
  • 95,762