5

I would like to be able to turn a list A,B,C into A \\ B \\ C, where A, B, C are LaTeX expressions. It would be quite simple to do with a package like xstring, but for the possibility that A, B or C contain a comma. So I thought of using xparse,writing some code like {>{\SplitList{,}}m}.

Unfortunately not only it didn't work, but even trying such a simple thing as:

\DeclareDocumentCommand\foo%
{>{\SplitList{,}}m}%
{\ProcessList{#1}{#1 X}
.......................
\foo{a,b,c}

just produces:

enter image description here

I expected aXbXcX. I really don't understand what's happening, nor what ProcessList does.

Another problem is that up to now, I've no idea how to indicate the replacement of the separating commas with newline commands.

8

\ProcessList doesn't allow inline functions like you've written; the interface expects a single macro to process each subsequent item of the list:

\documentclass[a4paper]{article}
\usepackage{xparse}
\begin{document}
\DeclareDocumentCommand \foo { >{\SplitList{,}} m }
 {
  \ProcessList{#1}{\processfoo}
 }
\newcommand\processfoo[1]{#1X}

\foo{a,b,c}
\end{document} 

The way that you have written it, \ProcessList{#1}{#1 X}, results in receiving arguments like:

\ProcessList{a,b,c}{a,b,c X}

and (for whatever reason) this is how you end up with the unexpected output in your question.

4

The stringstrings package is set up to conveniently manipulate character stings. It has a limited ability to manipulate macro strings like \\. In this MWE, I first show (ABC) the conversion involving \\. For the second example (DEF), it shows the one-line equivalent if the characters involved are not macros. The third output (cde) merely shows that \\ has been properly restored by the \decodetoken.

\documentclass{article}
\usepackage{stringstrings}
\begin{document}
\encodetoken{\\}
\convertchar[e]{A,B,C}{,}{\\}
\retokenize{\thestring}
\thestring
\decodetoken{\\}

\convertchar{D,E,F}{,}{X}

c\\d\\e
\end{document}

enter image description here


In response to the OP's comment about the need to stack inside the matrix environment, I post this addendum to see if a tabstackengine alternative would suffice for stacking matrix-like matter? Here, it is shown using commas as the end-of-line delimiter.

\documentclass{article}
\usepackage{tabstackengine}
\stackMath
\begin{document}
\setstackEOL{,}
\setstacktabulargap{0pt}
\setstackgap{L}{1.3\baselineskip}
\tabularLongstack{rl}{
x =&u^2, y=&v^2, z=&w^2
}
\end{document}

enter image description here

  • Unfortunately that doesn't solve my specific problem: the conversion result must be A\\B\\C. To make it more clear, the result must be the argument of the matrix environment, and the `\` are supposed to denote row change. – Bernard May 21 '14 at 1:31
  • @Bernard Please see addendum to my answer and let me know if there is fruit to be plucked. – Steven B. Segletes May 21 '14 at 1:45
  • @ Steven B. Segletes: Not to be plucked this time, because it has to be used as a sort of "comment" on the right side of a matrix environment, and the vertical spacing between the lines isn't quite the same. This can be adjusted by hand, but I don't see any automatic way. Thank you for your answer; it helped me to understand much better how (tab)stackengine works. – Bernard May 21 '14 at 8:32

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.