0

I wanted to do something that enables me to write \tikzdiagram{ stuff } or something like \tik stuff \zcd instead of having to write \[\begin{tikzcd} stuff \end{tikzcd}\] every time I want a diagram.

I tried things like \newcommand{\tikd}[1]{\[\begin{tikzcd}#1\end{tikzcd}\]} but that did not work very well.

I'm sure this must be a common desire, but I couldn't find any information out there (but maybe someone who is better knowing what words to search for will).

I also thought this could be related: New Command For Inline Code

Edit: It seems like it is indeed drawing a diagram since \tikd{a\ar{r}} is giving the "no shape" error, but that the & sign is not working out since it gets a "wrong catcode" error.

Edit2: Following Piet's suggestion, I settled for the following:

\newcommand{\tik}{\[\begin{tikzcd}}
\newcommand\zcd{\end{tikzcd}\]}
6
  • 2
    Try newenvironment rather than newcommand. Commented Nov 4, 2016 at 16:28
  • 2
    The tikzcd environment changes the catcode of &, so you cannot pick up the contents of the environment and pass it around. Commented Nov 4, 2016 at 16:33
  • I don't recommend doing this: you save just a few keys at the expense of markup. If you decide that a diagram should have a number, you'll need \begin{equation} and the shorthand will not work.
    – egreg
    Commented Nov 4, 2016 at 16:41
  • @egreg But that can be done with another shorthand. Commented Nov 4, 2016 at 16:51
  • @PietvanOostrum Is it worth the trouble? And another one if you want the diagram in a gather and so on?
    – egreg
    Commented Nov 4, 2016 at 16:55

1 Answer 1

0
\newcommand{\tik}{\[\begin{tikzcd}}
\newcommand\zcd{\end{tikzcd}\]}

\tik a & b \\ c & d \zcd
2
  • Works quite well, it seems! Wonder why my attempt at the same thing didn't work...
    – neptun
    Commented Nov 4, 2016 at 16:38
  • Don't use a definition that needs #1. Commented Nov 4, 2016 at 16:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .