7

Possible Duplicate:
Problem with defining shortcuts for TikZ matrices.

When I use the code below to draw a tikzpicture in the body of my document, it works just fine. However, when I define a command and try to use it, I get a Missing $ inserted error.

\documentclass[11pt]{amsart}
\usepackage{tikz}
\usetikzlibrary{matrix, shapes, backgrounds}
\newcommand{\matrixa}{ 
\begin{tikzpicture}[>=latex]
\matrix (A) [matrix of math nodes,%
         left delimiter  = (,%             
         right delimiter = )] at (0,0) {%
         \cdot & \cdot  & \cdot  \\
          \cdot & \cdot  & \cdot  \\
          \cdot & \cdot  & \cdot  \\
           \\ };%     
         \end{tikzpicture}}
\begin{document}
\matrixa
\end{document}

marked as duplicate by Loop Space, Guido, clemens, Claudio Fiandrino, Thorsten Nov 17 '12 at 9:17

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    Welcome to TeX.SX! – egreg Nov 16 '12 at 23:41
5

In this case you have to use a replacement for the ampersand:

\documentclass[11pt]{amsart}
\usepackage{tikz}
\usetikzlibrary{matrix, shapes, backgrounds}
\newcommand{\matrixa}{%
  \begin{tikzpicture}[>=latex]
  \matrix (A) [matrix of math nodes,
    left delimiter  = (,
    ampersand replacement=\&,
    right delimiter = )] at (0,0)
    {
     \cdot \& \cdot \& \cdot \\
     \cdot \& \cdot \& \cdot \\
     \cdot \& \cdot \& \cdot \\
    };
  \end{tikzpicture}}
\begin{document}
\matrixa
\end{document}

It's not necessarily \&, but this is usually chosen.

  • 1
    Thanks for the helpful tip! Is there an alternative to newcommand that will just paste the indicated code wherever you call it? (so that my original version would work.) – ZRmath Nov 18 '12 at 2:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.