4

Hello I've a matrix that I want to use multiple times in a file without having to rewrite it over and again. Is there a way to define a matrix 'object' and use it as an when I need it ?

Here is a minimal example of what I want to do:

\documentclass{article}
\use{amsmath}

\usepackage{tikz}
\begin{document}

% define the matrix 
\begin{pmatrix}
    \ast       & \ast  & 0      & \ast \\
    \ast       & \ast  & \ast   & 0 \\
     0         & \ast  & \ast   & \ast \\
    \ast       & 0     &\ast    &  \ast 
\end{pmatrix}
% end of matrix definition

\begin{equation} \label{eq:mat1}
% use the above defined matrix
\end{equation}

\end{document}

In general it will be good to know if there's a general method to apply such 'object' definition and use them to all kind of objects like figures, tikzpictures, etc multiple times as and when needed in the document

5

The usual method is to define macro via \newcommand.

For a tikzpicture you can use a similar technique or use \pic (example below is directly from the documentation Section 18).

enter image description here

Code

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}

\newcommand*{\MyMatrix}{%
    \begin{pmatrix}
        \ast       & \ast  & 0      & \ast \\
        \ast       & \ast  & \ast   & 0 \\
         0         & \ast  & \ast   & \ast \\
        \ast       & 0     &\ast    &  \ast 
    \end{pmatrix}}
% end of matrix definition


\tikzset{ seagull/.pic={
    \draw (-3mm,0) to [bend left] (0,0) to [bend left] (3mm,0);
  }
}
\begin{document}

\begin{equation} \label{eq:mat1}
    \MyMatrix% use the above defined matrix
\end{equation}

\begin{tikzpicture}
\fill [fill=blue!20, ultra thick] (1,1)
-- (2,2) pic {seagull} -- (3,2) pic {seagull} -- (3,1) pic [rotate=30] {seagull} -- (2,1) pic [red] {seagull};
\end{tikzpicture}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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