Category Theory
Zulip Server
Archive

You're reading the public-facing archive of the Category Theory Zulip server.
To join the server you need an invite. Anybody can get an invite by contacting Matteo Capucci at name dot surname at gmail dot com.
For all things related to this archive refer to the same person.


Stream: practice: software

Topic: Typesetting Composition in Double Categories


view this post on Zulip Chad Nester (Jun 04 2025 at 14:31):

Hi folks,

I'm trying to figure out how to typeset vertical and horizontal composition of cells in a double category well in LaTeX, and I imagine someone here has been through this before!

In particular, I'd like to be able to write vertical composition as in ab\frac{a}{b}, and horizontal composition as in aba \mid b. I've done this here as '\frac{a}{b}' and 'a \mid b', and while this works well when I have only two arguments it sort of breaks down when I have more than two.

For example, in abcd\frac{\frac{a}{b}}{\frac{c}{d}}, which is '\frac{\frac{a}{b}}{\frac{c}{d}}', the fact that \frac resizes its arguments is causing a problem. I would want all three horizontal lines to be the same size! Using '\mid' for horizontal composition causes similar problems, since it's a symbol of fixed height, and its operands can be quite tall.

I'm aware that one solution to this problem is to write vertical composition as something like aba \bullet b. Personally I find the ab\frac{a}{b} notation a lot clearer, particularly when terms become large, so if it isn't too much of a fuss I'd like to use that.

Does anyone have a good way to do this?

view this post on Zulip Nathanael Arkor (Jun 04 2025 at 14:35):

Could you simply use an inline table?

view this post on Zulip James Deikun (Jun 04 2025 at 18:07):

You could also make a macro with \genfrac that doesn't resize its arguments. And something like \left. a \middle| b \right.

x=a|bcda|bc|d=ac|bd\def\vc{\genfrac{}{}{1pt}{0}}% \def\hc#1#2{\left.#1\middle|#2\right.}% \begin{aligned} x &= \vc {\hc a{\vc b c}}d \\ \vc{\hc a b}{\hc c d} &= \hc{\vc a c}{\vc b d} \\ \end{aligned}

view this post on Zulip James Deikun (Jun 04 2025 at 18:09):

(You can use "view original message" in the hamburger menu to see the macrology I used to do that.)

view this post on Zulip James Deikun (Jun 04 2025 at 18:26):

(There are advantages to the inline table idea too, especially for if you're using higher-arity composition in one or both directions.)

view this post on Zulip Chad Nester (Jun 05 2025 at 06:49):

Thanks for the suggestions!

My (admittedly naive) attempt to do this using tables didn't really work out. Nesting a 'horizontal' tabular environment (e.g., {c | c}) inside of a 'vertical' one (e.g., {c}) makes the vertical lines touch the horizontal lines, as in:
composition-with-tables.png

The above table is the result of the following LaTeX code:

Code

The \genfrac approach fares better, but there is still some spacing weirdness, apparently caused by nested vertical composition:

nx0x1x2|y|ab|cf\def\vc{\genfrac{}{}{0.4pt}{0}}% \def\hc#1#2{\left.#1\middle|#2\right.}% \begin{aligned} & \vc{\vc{n}{\hc{\hc{\vc{\vc{x_0}{x_1}}{x_2}}{y}}{\vc{a}{\hc{b}{c}}}}}{f} \\ \end{aligned}

Both approaches seem like they could be perfect with a few tweaks. I'll do some reading...

Thanks again!

view this post on Zulip Chad Nester (Jun 05 2025 at 07:03):

Curiously, the "vertical lines extend too far, touching the horizontal lines" thing also happens when I use tables for vertical composition and the command \hc for horizontal composition.

view this post on Zulip Chad Nester (Jun 05 2025 at 07:41):

The issue with using \genfrac for this is that it gives the top and bottom arguments an equal amount of space, which looks weird when, say, the top argument is much larger than the bottom argument.

view this post on Zulip Nathanael Arkor (Jun 05 2025 at 08:07):

To clarify, I didn't mean to suggest nesting tables. I meant that you could use a single table, because it is not important to distinguish between a horizontal composite of vertical composites, and a vertical composite of horizontal composites, since they are equal in a double category.

view this post on Zulip Chad Nester (Jun 05 2025 at 08:24):

I think I still need to be able to make, for example, this shape:

ab0|b1|b2c\def\vc{\genfrac{}{}{0.4pt}{0}}% \def\hc#1#2{\left.#1\middle|#2\right.}% \begin{aligned} & \vc{a}{\vc{\hc{b_0}{\hc{b_1}{b_2}}}{c}} \end{aligned}

I don't see how I would do it as single table, but it is entirely possible that I just don't understand how tables work.

view this post on Zulip Nathanael Arkor (Jun 05 2025 at 08:48):

Most LaTeX packages for tables have support for multi-row and multi-column cells, which achieves this. (I think the best one is tabularray.)

view this post on Zulip Chad Nester (Jun 05 2025 at 09:03):

I didn't know that. Thanks!