I've extended myself too much, so the short question is:
Why can't I define macros with the
tikzcd
package as defined below? (right above the "Old Solution" section)
Description
I recently developed a notation for functors and it was tempting to use the tikzcd
environment. However, the problem is that 1) The macro must have more than 9 entries (I found a solution here). 2) The spacing was pretty terrible.
I finded a solution using array and some rotations (the solution code will be at the end), but mostly it works fine.
But, when using big categories names or whatever, space between terms becomes way to strange and preety lame. Back to tikzcd
, I've almost with some additional tricks (but mostly "fairier"):
\begin{tikzcd}[row sep={0.22em}, column sep={0.01em}]
{F}: & {\boldsymbol{\mathscr C}} \arrow[rr] &\hspace{0.5cm}& {\boldsymbol{\mathscr D}} & \\
& {X} \arrow[dd,"{\phi}"'] \arrow[rr, mapsto] & & {F(X)} \arrow[dd,"{F(\phi)}"'] & {x} \arrow[dd,mapsto]\\
& \, & & & \\
& {Y} \arrow[rr,mapsto] & & {Y} & {F(\phi)(x)}
\end{tikzcd}
Which produces:
Now the arrows adjust itself to each case. So im done and wanted to define that macro. Copying what I did in the old way, it should be:
%----------------
% Black Tex Magic
%----------------
% Provide a way to declare and renew a command in one command
\newcommand{\neworrenewcommand}[1]{\providecommand{#1}{}\renewcommand{#1}}
% Covariant functor
\newcommand{\covfunctor}[9]{
\neworrenewcommand{\ccovfunctor}[2]{
\begin{tikzcd}[row sep={0.22em}, column sep={0.01em}]
{#1}: & {#2} \arrow[rr] &\hspace{0.5cm} & {#3} & \\
& {#4} \arrow[dd,"{#8}"'] \arrow[rr, mapsto] & & {#5} \arrow[dd,"{#9}"'] & {##1} \arrow[dd,mapsto]\\
& \, & & & \\
& {#6} \arrow[rr,mapsto] & & {#7} & {##2}
\end{tikzcd}
}
\ccovfunctor
}
Well… nothing could be that simple in TeX: It compiles an error but it doesn't show me exactly what it is. So… what went wrong?
Old Solution
It uses the same \neworrenewcommand
as above.
\usepackage{rotating}
\usepackage{scalerel}
\newcommand{\covfunctor}[9]{
\neworrenewcommand{\ccovfunctor}[2]{
\begin{array}{rcccc}
{#1}: & \hphantom{{#8}} {#2} & \longrightarrow & {#3} & \\
& \hphantom{{#8}} {#4} & \longmapsto & {#5} & {##1}\\
& \begin{turn}{90}
\ensuremath{\overset{\begin{turn}{270}
\scaleobj{0.7}{\ensuremath{{#8}}}
\end{turn}}{\longleftarrow}}
\end{turn} & & \begin{turn}{90}
\ensuremath{\overset{\begin{turn}{270}
\scaleobj{0.7}{\ensuremath{{#9}}}
\end{turn}}{\longleftarrow}}
\end{turn} \hphantom{\scaleobj{0.7}{{#9}}} & \begin{turn}{90}
\reflectbox{\ensuremath{\longmapsto}}
\end{turn}\\
& \hphantom{{#8}} {#6} & \longmapsto & {#7} & {##2}
\end{array}
}
\ccovfunctor
}
Best Answer
I believe everything is in the link you posted and in your code. Note that
&\hspace{0.5cm}&
is not right, you should write&[1cm]&
and it is not necessary an extra row, this space can be adjusted with\\[5mm]
.which generates the following