2

I adapted a solution from Typesetting coordinates to typeset sets, but it seems to have difficulty with nested usage.

$\coord[\big]{0,1, \coord{A,B,C}, \coord{3,2,1}}$

yields:

enter image description here

Code:

\documentclass{article}
\usepackage{amsmath}
\usepackage{xparse}

\ExplSyntaxOn  %% https://tex.stackexchange.com/a/53961/4301
\NewDocumentCommand{\coord}{sO{}m}
 {
  \IfBooleanTF{#1}
   {\left(\coord_print:n {#3}\right)}
   {\mathopen{#2\{}\coord_print:n {#3}\mathclose{#2\}}}
 }

\seq_new:N \l_coord_list_seq
\tl_new:N \l_coord_last_tl
\cs_new_protected:Npn \coord_print:n #1
 {
  \seq_set_split:Nnn \l_coord_list_seq { , } { #1 }
  \seq_pop_right:NN \l_coord_list_seq \l_coord_last_tl
  \seq_map_inline:Nn \l_coord_list_seq { ##1 , }
  \tl_use:N \l_coord_last_tl
 }
\ExplSyntaxOff

\begin{document}
    $\coord[\big]{0,1, \coord{A,B,C}, \coord{3,2,1}}$
\end{document}
  • 1
    Insert \group_begin: and \group_end: at appropriate places (in my test I added them inside \coord_print:n) – daleif Mar 14 '16 at 8:21
  • @daleif: Thanks. Replacing \coord_print:n {#3} with {\coord_print:n {#3}} seems to do he trick. Please post an answer. – Peter Grill Mar 14 '16 at 8:29
2

It is just a case of grouping. Either use

\NewDocumentCommand{\coord}{sO{}m}
 {
  \IfBooleanTF{#1}
   {\left(\coord_print:n {#3}\right)}
   {\mathopen{#2\{}{\coord_print:n {#3}}\mathclose{#2\}}}
 }

note the extra {} around \coord_print:m {#3}. Or use

\cs_new_protected:Npn \coord_print:n #1
 {
  \group_start:
  \seq_set_split:Nnn \l_coord_list_seq { , } { #1 }
  \seq_pop_right:NN \l_coord_list_seq \l_coord_last_tl
  \seq_map_inline:Nn \l_coord_list_seq { ##1 , }
  \tl_use:N \l_coord_last_tl
  \group_end:
 }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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