paolobrasolin / commutative-diagrams

CoDi: Commutative Diagrams for TeX
https://paolobrasolin.github.io/commutative-diagrams/
MIT License
30 stars 3 forks source link

Convenient syntax for inclusion arrows #32

Closed leahneukirchen closed 4 years ago

leahneukirchen commented 4 years ago

I tried to do the equivalent of A\arrow[hookrightarrow]B in CoDi (which is great, btw!) and it was quite tricky. The hook is provided in arrows.meta, but I couldn't figure out the syntax to use Hooks[right] inline. Instead, I had to define a key:

\pgfkeys{C /.tip = {Hooks[right]}}

Then I can use \mor A C-> B;.

As this notation is quite common, do you think it makes sense to include this or a similar shortcut?

paolobrasolin commented 4 years ago

CoDi (which is great, btw!)

Thanks @leahneukirchen! ❤️

couldn't figure out the syntax to use Hooks[right] inline

You can use it inline like this --even if I wouldn't recommend it except for one-off usage:

\documentclass{article}
\usepackage{commutative-diagrams}
\usetikzlibrary{arrows.meta}
\begin{document}
  \begin{codi}
    \obj{ A & B \\ C & D \\ };
    \mor A f:{{Hooks[right]}->} B; % i.e. wrap the key in a group
    \mor C f:[{Hooks[right]}->] D; % i.e. wrap the key in a keylist
  \end{codi}
\end{document}

As this notation is quite common, do you think it makes sense to include this or a similar shortcut?

It definitely makes sense.

Right now CoDi encodes almost no shortcuts implying stylistic preferences because i want to keep it very pliable, a framework almost. Of course it's not "ready for daily use" like this and it needs some readily available style packs for the occasional user.

I'm not saying defaults because I'd rather have the occasional user ask for \usetikzpackage{codi.starterpack} than have the power user dance around defaults. In fact I took care to build some facilities to let users easily define their own styles in perfect isolation. The "neat" way of implementing your solution as your own style pack would be:

% This file is tikzlibrarycommutative-diagrams.styles.leah.code.tex

\usetikzlibrary{arrows.meta}

\pgfqkeys{/codi/arrows}{
  C/.tip = {Hooks[right]},
}
% This file is main.tex

\documentclass{article}
\usepackage{commutative-diagrams}
\usetikzlibrary{commutative-diagrams.styles.leah}

\begin{document}
  \begin{codi}
    \obj{ A & B \\ };
    \mor A f:C-> B;
  \end{codi}
\end{document}

This should get you started on building your own reusable stylesheet!

Unfortunately I'm not doing CT in my day-to-day right now so I doubt I can grok what would be "reasonable defaults for everyone" to put in a starter pack included in CoDi.

I was hoping that perhaps some consensus could be reached collaborating with early adopters. On that note, I'm opening https://github.com/paolobrasolin/commutative-diagrams/issues/35 and adding your suggestion there.

leahneukirchen commented 4 years ago

Thanks, this works for me!