Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
1  
Welcome to TeX.SX! –  egreg Nov 16 '12 at 23:41
add comment

marked as duplicate by Andrew Stacey, Guido, cgnieder, 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 Answer

up vote 5 down vote accepted

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.

share|improve this answer
    
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
add comment

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