# Composition and tensor product

> Boxes stacked on one wire compose; boxes side by side are tensored. A String diagrams example with its complete LaTeX source, ready to copy or open in TeXeR.

A String diagrams example in the TeXeR TikZ library: https://texer.org/library/string-diagrams/composition-tensor

Package: [String diagrams](https://texer.org/library/string-diagrams.md), on CTAN at https://ctan.org/pkg/pgf.

Tags: composition, tensor product, monoidal category

## Source

```latex
\begin{tikzpicture}[thick, box/.style={draw, fill=white, minimum width=8mm, minimum height=6mm}]
  \draw (0,0) node[below] {$A$} -- (0,3) node[above] {$C$};
  \node[box] at (0,0.9) {$f$};
  \node[box] at (0,2.1) {$g$};
  \node at (0,-0.9) {$g \circ f$};

  \draw (2.5,0) node[below] {$A$} -- (2.5,3) node[above] {$B$};
  \draw (3.7,0) node[below] {$C$} -- (3.7,3) node[above] {$D$};
  \node[box] at (2.5,1.5) {$f$};
  \node[box] at (3.7,1.5) {$g$};
  \node at (3.1,-0.9) {$f \otimes g$};
\end{tikzpicture}
```

## As a complete document

The same example in a document that compiles on its own with pdfLaTeX:

```latex
\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usepackage{xcolor}
\usepackage{amsmath}
\usepackage{amssymb}

\begin{document}
\begin{tikzpicture}[thick, box/.style={draw, fill=white, minimum width=8mm, minimum height=6mm}]
  \draw (0,0) node[below] {$A$} -- (0,3) node[above] {$C$};
  \node[box] at (0,0.9) {$f$};
  \node[box] at (0,2.1) {$g$};
  \node at (0,-0.9) {$g \circ f$};

  \draw (2.5,0) node[below] {$A$} -- (2.5,3) node[above] {$B$};
  \draw (3.7,0) node[below] {$C$} -- (3.7,3) node[above] {$D$};
  \node[box] at (2.5,1.5) {$f$};
  \node[box] at (3.7,1.5) {$g$};
  \node at (3.1,-0.9) {$f \otimes g$};
\end{tikzpicture}
\end{document}
```
