# Define functions in a tikzcd diagram

I have this diagram

    \begin{tikzcd}
R^{\bigoplus\mathcal{I}} \arrow{r}{\gamma} \arrow{ur}{\beta} & M
\end{tikzcd}


Now I want to define $\gamma$ and $\beta$ in the diagram. I mean, I want to replace $\gamma$ and $\beta$ in the diagram by

\begin{array}{rcl}
\gamma \colon R^{\bigoplus\mathcal{I}} & \longrightarrow & M\\
e_{i} & \longmapsto & \gamma(e_{i})
\end{array}


and

\begin{array}{rcl}
\beta \colon R^{\bigoplus\mathcal{I}} & \longrightarrow & N\\
e_{i} & \longmapsto & g_{i}
\end{array}


Finally, I also want to add this

\begin{array}{rcl}
\pi^{-1} \colon M & \longrightarrow & N\\
\gamma(e_{i}) & \longmapsto & g_{i}
\end{array}


(This means preimage, obv $\pi$ may not be bijective)Any ideas?(when replacing the arrows, I want to keep the arrow's names above the arrows). I want this diagram to check that $R^{\bigoplus\mathcal{I}}$ (free module over \mathcal{I}) is a projective module.

• the images seems to be missing – Cuniye Datacu Jul 5 at 18:33
• Welcome to TeX SX! No image is visible. How could someone have an idea? – Bernard Jul 5 at 18:33
• edited! now the images are available – Smm Jul 5 at 18:41
• Mathematically, what is I? and the direct sul of I? – Bernard Jul 5 at 18:43
• $R^{\bigoplus\mathcal{I}}$ is the free $R$-module over the set $\mathcal{I}$. – Smm Jul 5 at 18:46

For fun, a solution with the psmatrix environment, from pstricks:

\documentclass{article}
\usepackage{amsmath}
\usepackage{pst-node}

\begin{document}
%
$\everypsbox{\scriptstyle} \psset{arrows=->, arrowinset=0.15, linewidth=0.4pt, nodesep=3pt, labelsep=2pt, rowsep=1.2cm, colsep=1.5cm, shortput=nab} \begin{psmatrix} %%%nodes & [name=N] N \\% R^{ \oplus \mathcal{I}}\pnode{R} & [name=M] M \end{psmatrix} %%% arrows \ncline{2,1}{1,2}\naput[npos=0.45,labelsep =0pt]{\beta } \ncline{2,1}{2,2}^{\gamma } \ncline{1,2}{2,2}_{\pi } %%%% \psset{arrows=|->,offset =2.5ex} \ncline{2,1}{1,2} \uput{4ex}[125]{45}(R){e_i} \uput{2ex}[140]{45}(N){g_i} %%% \ncline[offset=-2ex]{2,1}{2,2} \uput{1ex}[-110]{0}(R){e_i} \uput{1ex}[-60]{0}(M){\gamma (e_i)} %%% \ncline[linestyle=dashed, arrows=<-|]{1,2}{2,2}\naput[npos=0.43]{\pi^{-1}} \uput{2ex}[r]{0}(N){g_i}$

\end{document}


• Oh, that's awesome! I hadn't say it, but I need to put it on a beamer, and it seems that it doesn't work. I have the packages and I've written \begin{frame}[fragile] on the top of the frame. What's wrong? – Smm Jul 5 at 22:38
• Maybe I need more packages or something... – Smm Jul 5 at 22:40
• If you compîle with pdflatex, it can't work as is, because pdftex doesn't understand the postscript language (albeit the pdf format is a subset of postscript). But with xelatex, it works fine (it's a little longer). Other than that, you can follow the old style way: latex -> dvips -> pstopdf. – Bernard Jul 5 at 22:45
• Perfect! It works with xelatex. Great Job! – Smm Jul 5 at 22:50
• Just a final suggestion: maybe it would be faster to compile if such diagrams were compiled alone with the standalone class: they will be cropped to their bounding box, and you can insert them as .pdf graphic files in your main document via \includegraphics. – Bernard Jul 5 at 22:55

As long as you add an ampersand replacement you can use these arrays.

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz-cd}
\begin{document}

\begin{tikzcd}[column sep=8em,ampersand replacement=\&]
R^{\bigoplus\mathcal{I}} \arrow[r,"{\begin{array}{rcl}
\gamma \colon R^{\bigoplus\mathcal{I}} & \longrightarrow & M\\
e_{i} & \longmapsto & \gamma(e_{i})
\end{array}}" swap]
\arrow[ur,"{\begin{array}{rcl}
\beta \colon R^{\bigoplus\mathcal{I}} & \longrightarrow & N\\
e_{i} & \longmapsto & g_{i}
\end{array}}" sloped] \& M \arrow[u,twoheadrightarrow,bend right=80,"{\begin{array}{rcl}
\pi^{-1} \colon M & \longrightarrow & N\\
\gamma(e_{i}) & \longmapsto & g_{i}
\end{array}}" swap]
\end{tikzcd}
\end{document}


Define a macro for the complicated thing:

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

\newcommand{\funcdef}[5]{%
\mbox{\scriptsize\begin{aligned} #1\colon #2 & \longrightarrow #3 \\[-1ex] #4 &\longmapsto #5 \end{aligned}}%
}

\begin{document}

\begin{tikzcd}[column sep=8em]