I am trying to use a macro to reformat content in a clearer fashion. In particular, I am expecting to transform strings such as
foo; bar; baz;
into
foo;
bar;
baz;
Here is the macro I have so far, and its use in a document, working as expected:
\documentclass{article}
\usepackage{xstring}
\newcommand{\splitStatementsAndTextttize}[1]{%
\StrCut{#1}{; }\leftPart\rightPart%
\ifx\rightPart\empty
\leftPart\%
\else
\leftPart;\ \splitStatementsAndTextttize{\rightPart}%
\fi
}%
\begin{document}
\noindent \splitStatementsAndTextttize{foo; bar; baz;}
\end{document}
Gives me the following, with the expected typeset:
foo;
bar;
baz;
Now, this exact content should actually be in a single cell of a table. Following Table with multiple lines in some cells, this can be done by putting the content into a tabular.
Here is what the updated example looks like (same macro, different use):
\documentclass{article}
\usepackage{xstring}
\newcommand{\splitStatementsAndTextttize}[1]{%
\StrCut{#1}{; }\leftPart\rightPart%
\ifx\rightPart\empty
\leftPart\%
\else
\leftPart;\ \splitStatementsAndTextttize{\rightPart}%
\fi
}%
\begin{document}
\begin{tabular}[x]{@{}l@{}}
\splitStatementsAndTextttize{foo; bar; baz;}
\end{tabular}
\end{document}
Which fails for some reason I do not understand...
! Undefined control sequence.
<argument> \rightPart
l.15 ...plitStatementsAndTextttize{foo; bar; baz;}



I would gladly accept this answer, but there is an issue with the example that does not use
– Pamplemousse Apr 23 '21 at 16:04xstring: I am looking to split the string by;and not only;(note the space character). Consequently, when I apply some more typesetting (for example\texttt{}) to#1, the problem becomes apparent: all but the first chunck contain leading spaces!#1;\\% use itemto\texttt{#1;}\\% use itemeverything looks (unless I'm not understanding what you want). Can you confirm that that doesn't work? It is possible to make it delimited by;if you want, of course. Here's a test document with all three options: https://pastebin.com/raw/jWJWHn5n – Phelype Oleinik Apr 23 '21 at 18:20#1;into\texttt{#1;}does not work, because all the lines but the first will display a spurious space at their beginning. – Pamplemousse Apr 23 '21 at 20:00\ignorespacesthere solves the problem – Phelype Oleinik Apr 23 '21 at 20:27