11

I want to typeset some category-theoretic calculations involving adjunctions (sometimes called two-way rules).

In short, they look approximately like this (MWE):

\documentclass[a4paper]{article}
\usepackage{amsmath}

\begin{document}
\begin{align*}
C &\longrightarrow FD\\
\line(1,0){75}&\line(1,0){75}\\
GC &\longrightarrow D\\
\line(1,0){75}&\line(1,0){75}\\
1 &\longrightarrow D^{GC}
\end{align*}
\end{document}

enter image description here

Of course, this looks horrendous, but it should get the approximate idea across.

I would like to have an environment (called, say, adjunctions) which allows me to input the above as, e.g.:

\begin{adjunctions}
C & FD \\
GC & D \\
1 & D^{GC}
\end{adjunctions}

There are several things that I need:

  • An option to set the width of the lines (which is universal throughout the environment), perhaps with the possibility to make them asymmetrical (i.e. longer to the left than to the right);
  • Proper spacing; in the example above, the spacing between GC \to D and the line above it is about what I'm looking for, both top and bottom-margin;
  • Optionally, control over the symbol going at the place of \longrightarrow (universal throughout the environment is fine).

I have looked around on the internet, but I couldn't find anything (not even a properly typeset image). General references for creating custom align-like environments are also very much appreciated.

2 Answers 2

11

Does this answer your need?

\documentclass{article}
\usepackage{array,xparse}

\usepackage{multicol} % just for the example
\setlength{\columnseprule}{.4pt} % just for the example

\ExplSyntaxOn
\NewDocumentEnvironment{adjunctions}{O{}}
 {
  \cs_set_eq:cN {@arraycr} \farin_arraycr:
  \keys_set:nn { farin/adjunction } { #1 }
  \begin{array}
   {
    @{ \hspace { \dim_eval:n { \l_farin_left_shift_dim + \l_farin_padding_dim } } }
    r
    @{ {\farin_strut:} \l_farin_symbol_tl {} }
    l
    @{ \hspace { \dim_eval:n { \l_farin_right_shift_dim + \l_farin_padding_dim } } }
   }
 }
 {
  \end{array}
 }
\keys_define:nn { farin/adjunction }
 {
  leftshift       .dim_set:N = \l_farin_left_shift_dim,
  leftshift       .initial:n = 0pt,
  rightshift      .dim_set:N = \l_farin_right_shift_dim,
  rightshift      .initial:n = 0pt,
  padding         .dim_set:N = \l_farin_padding_dim,
  padding         .initial:n = 6pt,
  symbol          .tl_set:N  = \l_farin_symbol_tl,
  symbol          .initial:n = \longrightarrow,
  verticalspacing .dim_set:N  = \l_farin_vertspac_dim,
  verticalspacing .initial:n = {3pt},
 }
\cs_new_protected:Npn \farin_strut:
 {
  \vrule height \dim_eval:n { \ht\strutbox + 1.2\l_farin_vertspac_dim }
         depth  \dim_eval:n { \dp\strutbox + \l_farin_vertspac_dim }
         width 0pt
 }
\makeatletter
\exp_args:NNo \cs_new:Npn \farin_arraycr:
 {
  \@arraycr\hline
 }
\makeatother
\ExplSyntaxOff
\begin{document}
\begin{multicols}{2}
\noindent
\verb|\begin{adjunctions}|
\[
\begin{adjunctions}
C & FD \\
GC & D \\
1 & D^{GC}
\end{adjunctions}
\]
\verb|\begin{adjunctions}|\\
\verb|  [symbol=\longleftarrow]|
\[
\begin{adjunctions}[symbol=\longleftarrow]
C & FD \\
GC & D \\
1 & D^{GC}
\end{adjunctions}
\]
\verb|\begin{adjunctions}|\\
\verb|  [leftshift=12pt]|
\[
\begin{adjunctions}[leftshift=12pt]
C & FD \\
GC & D \\
1 & D^{GC}
\end{adjunctions}
\]
\verb|\begin{adjunctions}|\\
\verb|  [rightshift=12pt,|\\
\verb|   symbol=\otimes]|
\[
\begin{adjunctions}[rightshift=12pt,symbol=\otimes]
C & FD \\
GC & D \\
1 & D^{GC}
\end{adjunctions}
\]
\verb|\begin{adjunctions}|\\
\verb|  [verticalspacing=2ex]|
\[
\begin{adjunctions}[verticalspacing=2ex]
C & FD \\
GC & D \\
1 & D^{GC}
\end{adjunctions}
\]
\end{multicols}
\end{document}

enter image description here

1
  • I'm awestruck... I couldn't have hoped for a more complete solution. Thanks!
    – Lord_Farin
    Jun 14, 2013 at 17:49
5

A plain TeX solution that should also work in LaTeX.

\def\adjunctions
    {\bgroup
     \def\\%
        {\crcr 
         \noalign{\vskip 0.2\baselineskip \hrule \vskip 0.2\baselineskip}}%
     \halign \bgroup 
     \hss \mathsurround0pt $\displaystyle ## \longrightarrow {}$%
     &
     \mathsurround0pt $\displaystyle ##$ \cr}

\def\endadjunctions{\crcr\egroup}

\adjunctions
  C  & FD \\
  GC & D \\
  1  & D^{GC}
\endadjunctions

\bye

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .