0

How to capitalize LaTeX3 sequence element in document input stream? The problem with \seq_item:N I think, becaue it unexpandable.

\documentclass{article}


\ExplSyntaxOn


\seq_new:N \g_syllabus_kafname_seq

\NewDocumentCommand\kafname{ m }
 {
    \seq_gput_right:Nn \g_syllabus_kafname_seq { #1 }
 }


\NewDocumentCommand{\thekaf}{ O{1} }
 {
     \seq_item:Nn \g_syllabus_kafname_seq { #1 }
 }

\NewDocumentCommand \firstcap { m } {   \text_titlecase:n  {#1} }

\ExplSyntaxOff

\begin{document}
\kafname{aass}
\kafname{bbb}
\kafname{ccc}


\firstcap{\thekaf[2]} %Need Bbb

\end{document}
2
  • 1
    seq_item is expandable, but thekaf is not. – Ulrike Fischer Dec 15 '20 at 12:13
  • @UlrikeFischer Yes, thank you. But if I write \NewExpandableDocumentCommand{\thekaf}{O{1}} this one does not work with O{} parameter, but with m does. – sergiokapone Dec 15 '20 at 12:15
2

you could put the formatting command inside the \thekaf command:

\documentclass{article}


\ExplSyntaxOn


\seq_new:N \g_syllabus_kafname_seq

\NewDocumentCommand\kafname{ m }
 {
    \seq_gput_right:Nn \g_syllabus_kafname_seq { #1 }
 }

\cs_new:Npn \__syllabus_kaf_format:n {}

\NewDocumentCommand{\thekaf}{ O{1} }
 {
     \__syllabus_kaf_format:n 
       {\seq_item:Nn \g_syllabus_kafname_seq { #1 }}
 }

\NewDocumentCommand \firstcap { m } {
  \group_begin:
  \cs_set_eq:NN \__syllabus_kaf_format:n\text_titlecase:n  
   #1
  \group_end: 
    }

\ExplSyntaxOff

\begin{document}
\kafname{aass}
\kafname{bbb}
\kafname{ccc}

\thekaf[2],  \firstcap{\thekaf[2]} %Need Bbb

\end{document}

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.