2

The code below produces the mistake in the picture. Any idea why?

% !TEX encoding = UTF-8 Unicode
\documentclass[a4paper,12pt]{report}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{datetime}
\usepackage[turkish]{babel}
\usepackage{amsmath}
\usepackage{amssymb}

\begin{document}

\begin{bmatrix}
a & b \\
c & d
\end{bmatrix}

\end{document} 

enter image description here

LaRiFaRi
  • 43,807
Günal
  • 3,393
  • 8
  • 31
  • 31
  • Above is the minimal example. I have not given the all code because the error is related to matrix. So, other packages are needed for the rest of the code. What do you mean by math-mode? – Günal Oct 31 '14 at 12:17
  • some "math" environments can stand alone, for example equation and align. others have to be embedded in an explicitly math environment. if this is meant as a display, then wrapping it in \[ ... \] or the equation environment would be appropriate. – barbara beeton Oct 31 '14 at 12:19
  • 1
    You might also find this answer helpful http://tex.stackexchange.com/questions/15662/what-is-math-mode. – Thruston Oct 31 '14 at 12:21

1 Answers1

2

The matrix environments of the amsmath package have to be set in math mode. You didn't do that, thus TeX is searching for some $ which enables this math mode. If you put it in $...$, \(...\), \[...\], \begin{displaymath}...\end{displaymath}, \begin{equation}...\end{equation} or \begin{equation*}...\end{equation*}, (and most certainly others...,) it will work.

\documentclass[a4paper,12pt]{report}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}

\begin{document}
    \[\begin{bmatrix}
        a & b \\
        c & d
    \end{bmatrix}\] 
\end{document} 

enter image description here

LaRiFaRi
  • 43,807
  • How can I do it with documentclass "standalone"? I need it to create small graphs. But it seems \bmatrix doesn't work there. – skan Feb 25 '20 at 19:20
  • 1
    @skan https://tex.stackexchange.com/questions/518273/cant-create-multiline-matrix-with-standalone – LaRiFaRi Jun 17 '20 at 06:51