[Tex/LaTex] \node : Undefined control sequence with tikz

tikz-pgf

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}[node distance=2.5cm,auto,>=latex',
squarednode/.style={rectangle, draw=black!80, fill=black!100, very thick, minimum size=5mm,text=white}]
    \node [squarednode] (encoder) {$\text{encoder}$};
\end{tikzpicture}

\end{document}

When compiling, here is the error message :

! Undefined control sequence.
<recently read> \text 

l.10     \node [squarednode] (encoder) {$\text
                                              {encoder}$};

I do not understand… it works perfectly on another .tex that has the same code (but it's a beamer package slide tex file)

Any idea on why this might not work?

Thanks

Best Answer

Welcome to TeX-SE! This has nothing to do with tikz, but the error message just tells you that \text is not defined. \text comes with amsmath. Of course, in your application, \text is not necessary, you could just do \node [squarednode] (encoder) {encoder};.

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}[node distance=2.5cm,auto,>=latex',
squarednode/.style={rectangle, draw=black!80, fill=black!100, very thick, minimum size=5mm,text=white}]
    \node [squarednode] (encoder) {$\text{encoder}$};
\end{tikzpicture}

\end{document}