5

Consider the following example. If I do \seqsplit{ReferencedIDs} the string does not get split. If on the other hand, I insert the string as an argument directly it does. As usual, I don't know why this isn't working. Can anyone enlighten me?

\documentclass[12pt]{article}
\usepackage{seqsplit}
\begin{document}
\gdef \ReferencedIDs{,2014.11.14,2014.11.14,2014.11.17,2014.11.14,2014.07.18.tm,2014.11.12.tm,2013.10.05.kanjur,2013.10.05.powai,2013.10.06,2013.10.28.zhm,2013.10.17,2013.10.22,2013.10.14.ks,2013.10.06,2013.10.17,2013.10.22,2013.10.24,2013.10.28,2013.10.30,2013.11.11,2014.09.05.tm,2014.07.18.tm,2014.11.12.tm,2014.11.17,2015.01.06,2015.01.06}

\seqsplit{\ReferencedIDs}  
\seqsplit{,2014.11.14,2014.11.14,2014.11.17,2014.11.14,2014.07.18.tm,2014.11.12.tm,2013.10.05.kanjur,2013.10.05.powai,2013.10.06,2013.10.28.zhm,2013.10.17,2013.10.22,2013.10.14.ks,2013.10.06,2013.10.17,2013.10.22,2013.10.24,2013.10.28,2013.10.30,2013.11.11,2014.09.05.tm,2014.07.18.tm,2014.11.12.tm,2014.11.17,2015.01.06,2015.01.06}

\end{document}
0

2 Answers 2

6

The argument to \seqsplit is processed token-by-token, assuming that it's fully expanded. This is not the case when you pass a macro (a single token) as the argument. The following setup redefines \seqsplit to expand its argument before processing it.

enter image description here

\documentclass{article}
\usepackage{seqsplit}
\let\oldseqsplit\seqsplit% Copy \seqsplit
\renewcommand{\seqsplit}{% Redefine \seqsplit to...
  \expandafter\oldseqsplit\expandafter}% ...expand its argument before processing it
\begin{document}
\gdef \ReferencedIDs{,2014.11.14,2014.11.14,2014.11.17,2014.11.14,2014.07.18.tm,2014.11.12.tm,2013.10.05.kanjur,2013.10.05.powai,2013.10.06,2013.10.28.zhm,2013.10.17,2013.10.22,2013.10.14.ks,2013.10.06,2013.10.17,2013.10.22,2013.10.24,2013.10.28,2013.10.30,2013.11.11,2014.09.05.tm,2014.07.18.tm,2014.11.12.tm,2014.11.17,2015.01.06,2015.01.06}

\seqsplit{\ReferencedIDs}

\seqsplit{,2014.11.14,2014.11.14,2014.11.17,2014.11.14,2014.07.18.tm,2014.11.12.tm,2013.10.05.kanjur,2013.10.05.powai,2013.10.06,2013.10.28.zhm,2013.10.17,2013.10.22,2013.10.14.ks,2013.10.06,2013.10.17,2013.10.22,2013.10.24,2013.10.28,2013.10.30,2013.11.11,2014.09.05.tm,2014.07.18.tm,2014.11.12.tm,2014.11.17,2015.01.06,2015.01.06}

\end{document}
4

If you don't mind using expl3:

\usepackage{xparse}
\ExplSyntaxOn
\cs_set_eq:NN \faheem_seqsplit:n \seqsplit
\cs_generate_variant:Nn \faheem_seqsplit:n { o }

\NewDocumentCommand{\printIDs}{m}
 {
  \faheem_seqsplit:o { #1 }
 }
\ExplSyntaxOff

and then \printIDs{\ReferencedIDs} will do.

This is not much different from Werner's code, but it hides the technical details from the user; let's see line by line.

We get an “internal” function from `\seqsplit

\cs_set:eq:NN \faheem_seqsplit:n \seqsplit

In this way we are able to define a variant:

\cs_generate_variant:Nn \faheem_seqsplit:n { o }

This variant works like \faheem_seqsplit:n, but before making it act the argument passed to it will be expanded once. Finally

\NewDocumentCommand{\printIDs}{m}{\faheem_seqsplit:o{#1}}

defines a user level command that uses the variant.

As I said, this is mostly equivalent to doing

\newcommand{\printIDs}[1]{\expandafter\seqsplit\expandafter{#1}}

but it's “more abstract” and doesn't require you guess the right chain of expansions.

0

You must log in to answer this question.

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