3

In this answer, u/Qrrbrbirlbel has written a wonderful code for a command that makes long exact sequences simply by taking what are the entries. To understand and get a feel for its objective, I suggest visiting the answer once; but to put it simply, the objective was to make a command \longexactsequence{-,-,...,-} that made a long sequence with the objects in the order separated by commas.

I modified the code presented to make it a bit more flexible (the zeros at the start and end were a bit restrictive):

\usepackage{extarrows,pgffor}
\newcommand*{\longexactsequence}[2]{%
  \foreach \superscript/\entry in {#1} {%
    \entry \xlongrightarrow{\ifx\superscript\entry\else\superscript\fi}%
  } #2%
}

This code works exactly the same way the previous one did, except that to write a long sequence that connects A,B,C,D,E, you use:

\longexact{A,B,C,D}{E}

This works wonderfully; it has all the functions the earlier code had (in particular naming functions). But one can see where it falls from being perfect: you have to write the last object in the sequence in a separate bracket.

I would highly appreciate some help with fixing this bit; is there a way to make the command such that you only need one parentheses, without losing all the accessibility (particularly, the arrow labelling) the command already has? I believe something could be done if there was a way to identify the last entry in the input.

I would prefer an answer that does not create a new bit of code, but rather modifies the code already polished and presented, but any answer is welcome!

2 Answers 2

7

If you don't need to label the arrows:

\documentclass{article}
\usepackage{amsmath,extarrows}

\ExplSyntaxOn
\NewDocumentCommand{\longexactsequence}{m}
 {
  \clist_use:nn { #1 } { \xlongrightarrow{} }
 }
\ExplSyntaxOff

\begin{document}

\[
\longexactsequence{A,B,C,D,E}
\]

\end{document}

enter image description here

For (possibly) labeled arrows, I suggest a different syntax:

\documentclass{article}
\usepackage{amsmath,extarrows}

\ExplSyntaxOn
\NewDocumentCommand{\longexactsequence}{m}
 {
  \pceltide_les:n { #1 }
 }

\seq_new:N \l_pceltide_les_items_seq

\cs_new_protected:Nn \pceltide_les:n
 {
  \seq_set_split:Nnn \l_pceltide_les_items_seq { - } { #1 }
  \seq_indexed_map_function:NN \l_pceltide_les_items_seq \__pceltide_les_item:nn
 }

\cs_new_protected:Nn \__pceltide_les_item:nn
 {
  \int_if_odd:nTF { #1 } { #2 } { \xlongrightarrow{#2} }
 }

\ExplSyntaxOff

\begin{document}

\[
\longexactsequence{A -f- B -- C -g- D -- E}
\]

\end{document}

enter image description here

If you're tied to something like

\longexactsequence{A/f,B,C/g,D,E}

then it's a bit more complicated.

\documentclass{article}
\usepackage{amsmath,extarrows}

\ExplSyntaxOn
\NewDocumentCommand{\longexactsequence}{m}
 {
  \pceltide_les:n { #1 }
 }

\seq_new:N \l_pceltide_les_items_seq
\seq_new:N \l__pceltide_les_term_seq
\tl_new:N \l__pceltide_les_last_tl

\cs_new_protected:Nn \pceltide_les:n
 {
  \seq_set_from_clist:Nn \l_pceltide_les_items_seq { #1 }
  \seq_pop_right:NN \l_pceltide_les_items_seq \l__pceltide_les_last_tl
  \seq_map_function:NN \l_pceltide_les_items_seq \__pceltide_les_item:n
  \tl_use:N \l__pceltide_les_last_tl
 }

\cs_new_protected:Nn \__pceltide_les_item:n
 {
  \seq_set_split:Nnn \l__pceltide_les_term_seq { / } { #1 }
  \seq_item:Nn \l__pceltide_les_term_seq { 1 }
  \xlongrightarrow { \seq_item:Nn \l__pceltide_les_term_seq { 2 } }
 }

\ExplSyntaxOff

\begin{document}

\[
\longexactsequence{A/f,B,C/g,D,E}
\]

\end{document}
3
  • That's nice... could we add the arrow labelling to this too?
    – PCeltide
    Commented Apr 20, 2023 at 14:33
  • 1
    @PCeltide Added two ways.
    – egreg
    Commented Apr 20, 2023 at 14:42
  • 1
    Thank you, that's gorgeous!
    – PCeltide
    Commented Apr 20, 2023 at 14:51
10

What we can do without expl3 and using only TeX primitives and basic plain TeX macros:

\def\longexactsequence #1{\lexseA #1 --\end}
\def\lexseA #1{#1\lexseB}
\def\lexseB #1-#2-#3{\ifx#3\end\else 
   \buildrel#2\over\longrightarrow #3\expandafter\lexseB\fi}

$$
\longexactsequence{A -f- B -- C -g- D -- E}
$$

Note: it works in LaTeX too.

1
  • 2
    This is much easier to look at, compared to the long ugly names used in expl3 syntax
    – User
    Commented Apr 20, 2023 at 19:39

You must log in to answer this question.

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