1
$\begingroup$

A maths student takes his first course on homological algebra, and wants to write his answer in LaTeX. What is the simplest way for him to write commutative diagrams in LaTeX?

$\endgroup$
4
  • 14
    $\begingroup$ Have you seen tex.stackexchange.com? $\endgroup$
    – user1815
    Apr 7 at 19:07
  • 8
    $\begingroup$ Are you the student, the instructor, or something else? $\endgroup$ Apr 8 at 1:23
  • 2
    $\begingroup$ This site can be of interest. See an example here. $\endgroup$
    – Pedro
    Apr 8 at 12:12
  • 1
    $\begingroup$ @Pedro That might be better posted as an answer. $\endgroup$
    – wizzwizz4
    Apr 8 at 13:47

4 Answers 4

5
$\begingroup$

This is coming from somebody who started with plain TeX in the 1980s! My first math typesetting was with a typewriter (before electric typewriters) when we had to turn the platen knob a click up or down for exponents and subscripts.

The best way (currently) to do commutative diagrams in LaTeX is with TikZ, and with the help of a large language model (LLM).

If I take this diagram,

Description

from the Wikipedia page for commutative diagrams and paste it into an LLM (ChatGPT) then we get this code back!

One could also start with a good photo (from one's phone) of a commutative diagram drawn on paper or a chalkboard.

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

\begin{document}

    \begin{tikzcd}
        G \arrow[r, "f"] \arrow[d, "\pi"']
        & H \\
        G/\ker(f) \arrow[ru, "\overline{f}",dashrightarrow]\\
    \end{tikzcd}

\end{document}

After compiling, you might see some things need adjusting. So be prepared for some back and forth in the LLM chat session.

These transformer things are good at image to text, hence good at image to code. It's just the way of the world. We have to keep up.

$\endgroup$
4
  • 2
    $\begingroup$ Is the single ' just after the \pi supposed to be there? It looks odd but I don't have a latex distribtion at hand to test it right now. $\endgroup$
    – quarague
    Apr 8 at 6:53
  • 2
    $\begingroup$ The single ' has the effect of placing the label for the arrow to the left. So arguments to the arrow are direction (d for down), label (so \pi), then position. $\endgroup$
    – user52817
    Apr 8 at 12:31
  • 6
    $\begingroup$ It's one thing to show that this kind of thing can be done with LLMs nowadays. Sure this is a an option that'll be most convenient for most students' need. But presenting it as "the way" to go is just something I can't agree with. LLMs are a power that the student can never expect to properly control. It's harmless for creating some small diagrams, but insanity when the students get used to just accepting whatever the model suggests without understanding what happens in the code. And don't fool yourself: they won't understand such code anywhere near as well as code they wrote themselves. $\endgroup$ Apr 8 at 14:15
  • $\begingroup$ @leftaroundabout I appreciate your point. But the OP is about somebody taking homological algebra, and so we are starting with a critical thinker. To get a good commutative diagram, an iterative process with the LLM is needed. To build a more complicated diagram, the dialog steers the LLM from a simple start, building complexity. One actually learns a lot about tikz by this iterative process. $\endgroup$
    – user52817
    Apr 8 at 14:45
3
$\begingroup$

You can also suggest using a WYSIWYG app like Quiver, which you can use to generate tikz-cd commutative diagrams.

Quiver requires including the quiver package in your document (can be found here).

Minimal example:

\documentclass{standalone}
\usepackage{quiver}
% https://q.uiver.app/#q=WzAsMyxbMCwwLCJHIl0sWzIsMCwiSCJdLFswLDIsIkcvIFxca2VyKGYpIl0sWzAsMSwiZiJdLFswLDIsIlxccGkiLDJdLFsyLDEsIlxcdGlsZGV7Zn0iLDIseyJzdHlsZSI6eyJib2R5Ijp7Im5hbWUiOiJkYXNoZWQifX19XV0=
\begin{document}
\begin{tikzcd}
    G && H \\
    \\
    {G/ \ker(f)}
    \arrow["f", from=1-1, to=1-3]
    \arrow["\pi"', from=1-1, to=3-1]
    \arrow["{\tilde{f}}"', dashed, from=3-1, to=1-3]
\end{tikzcd}
\end{document}

This generates the same diagram as in @user52817's answer.

$\endgroup$
3
$\begingroup$

Whoa. It is relatively easy to use "xypic" to make lots of basic diagrams, with relatively small amounts of code.

It is amazing to me, though perhaps I'm "just old", to use AI's to generate TeX to show a diagram, etc. The real issue, I guess, is, "is it really easier?"

Crazy new times? :)

$\endgroup$
3
  • $\begingroup$ xypic is a real gem. A few years ago, whenever I wanted to use TikZ, I would hunt for a starting place from a source like this tikz.dev. The examples are always much more complex than what I need. I was always starting with mysterious code that was much more complicated than I could understand, and proceeded to reduce it, never really knowing what I was doing. Now I give AI a start with something more simple than I want, and then through dialog build it up. When I get there, I feel like I have a much better understanding of my final code than I did with the complex->simple approach. $\endgroup$
    – user52817
    Apr 11 at 1:35
  • $\begingroup$ I think I would point a student to xymatrix ctan.org/pkg/xymatrix specifically, rather than the more general xypic . I find xymatrix much simpler than tikz-cd , and its what I use for 90% of my diagrams although, when I want something tricky, I switch to tikz-cd . $\endgroup$ Apr 11 at 15:08
  • $\begingroup$ Like Paul, I'm surprised that the answers suggest using LLM's rather than just learning to use one of these packages, but I guess I'm old. $\endgroup$ Apr 11 at 15:09
2
$\begingroup$

Another response in the category of "TikZ with LLM":

One place you might look is today's MAA Math Values Blog Post:

A Mathematician’s Quest to Shape AI into the Ideal Calculus Student. April 9, 2024. Link: https://www.mathvalues.org/masterblog/a-mathematicians-quest-to-shape-ai-into-the-ideal-calculus-student

In this blog post, the author describes using ChatGPT in conjunction with hand drawn diagrams to figure out what the corresponding TeX code should look like, and then makes tweaks to it. Perhaps assigning this blog post as reading would be of use to you and/or the hypothetical student.

$\endgroup$
2
  • 1
    $\begingroup$ +1 Came here to share exactly this link :) $\endgroup$ Apr 10 at 15:34
  • $\begingroup$ @BrendanW.Sullivan it seems timely and appropriate! On the other hand, lol who is voting this down!!@Downvoter [who is assuredly not BWS], please comment with your rationale and I will try to address it!** $\endgroup$ Apr 23 at 4:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.