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.

I am a newbie and I asked in How to create rectangles like in this example? about how to make some rectangles. I am trying to read the code and understand it as I need rectangles rather than squares. But I cannot find in the net what this #1 to #4 are? As the notation is short I can't even search it up. So I would be happy if somebody helps me with it.

\newcommand\catalannumber[3]{
  % start point, size, Dyck word (size x 2 booleans)
  \fill[cyan!25]  (#1) rectangle +(#2,#2);
  \fill[fill=lime]
  (#1)
  \foreach \dir in {#3}{
    \ifnum\dir=0
    -- ++(1,0)
    \else
    -- ++(0,1)
    \fi
  } |- (#1);
  \draw[help lines] (#1) grid +(#2,#2);
  \draw[dashed] (#1) -- +(#2,#2);
  \coordinate (prev) at (#1);
  \foreach \dir in {#3}{
    \ifnum\dir=0
    \coordinate (dep) at (1,0);
    \else
    \coordinate (dep) at (0,1);
    \fi
    \draw[line width=2pt,-stealth] (prev) -- ++(dep) coordinate (prev);
  };
}
share|improve this question
6  
#1 and so on have nothing to do with TikZ; they represent the arguments: when you call \catalannumber{arg1}{arg2}{arg3}, #1 will be replaced by arg1 and so on. –  egreg Apr 5 '13 at 21:39
2  
The # has little to do with TikZ. It's used in the expression of formal parameters in the definition of a command (here: \catalannumber). In lay terms, "#1" refers to the first argument passed to \catalannumber, "#2" refers to the second argument, etc. –  Jubobs Apr 5 '13 at 21:40
2  
Also a good read What's the meaning of ## symbol in an argument –  percusse Apr 5 '13 at 21:51

1 Answer 1

up vote 11 down vote accepted

The "#" has little to do with TikZ. It's used in the expression of formal parameters in the definition of a command (here: \catalannumber). In lay terms, #1 refers to the first argument passed to \catalannumber, #2 refers to the second argument, etc.

I'm not familiar with Catalan numbers, so I'm not even sure that what follows makes any mathematical sense, but if you want to get a rectangular lattice instead of a square one, you can adapt the code from How to draw a Catalan number diagram on TikZ as follows. The second argument to \catalannumberrectangle is "m,n", where "m" is the number of columns and "n" is the number of rows of the lattice.

enter image description here

\documentclass[border=2mm]{standalone}
\usepackage{tikz}

\newcommand\catalannumberrectangle[3]{
  % start point, size, Dyck word (size x 2 booleans)
  \fill[cyan!25]  (#1) rectangle +(#2);
  \fill[fill=lime]
  (#1)
  \foreach \dir in {#3}{
    \ifnum\dir=0
    -- ++(1,0)
    \else
    -- ++(0,1)
    \fi
  } |- (#1);
  \draw[help lines] (#1) grid +(#2);
  \draw[dashed] (#1) -- +(#2);
  \coordinate (prev) at (#1);
  \foreach \dir in {#3}{
    \ifnum\dir=0
    \coordinate (dep) at (1,0);
    \else
    \coordinate (dep) at (0,1);
    \fi
    \draw[line width=2pt,-stealth] (prev) -- ++(dep) coordinate (prev);
  };
}

\begin{document}
\begin{tikzpicture}
  \catalannumberrectangle{0,-9}{8,4}{0,1,0,0,1,1,0,1,0,0,0,0};
\end{tikzpicture}
\end{document}
share|improve this answer
    
Thanks a lot, can you please also tell me why I get this: i46.tinypic.com/21eyubn.jpg Rather than the one like yours? –  Naji Apr 5 '13 at 22:10
    
this is what I run:\catalannumberrectangle{0,-4}{4,5}{0,1,0,0,1,1,0,1,1}; –  Naji Apr 5 '13 at 22:11
1  
Do you mean that you get a different result with the code from my answer? If so, you might want to check that you have the latest version of PGF/TikZ. Or do you mean that you want to get an output like in the picture you link to? –  Jubobs Apr 5 '13 at 22:13
    
no I want my result to look like yours. Mine is only showing a lime triangle as you can see! I will try to update my TikZ then... –  Naji Apr 5 '13 at 22:20
    
problem solved after updating. Thanks again. –  Naji Apr 6 '13 at 0:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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