# Trouble nesting multiple commands using \newcommandx

First Question in this forum, so go easy on me :) I made a few meeting minutes documents for my business and I wanted a custom command for adding a note in a document. I wanted the color of the text and the text box width to be optional. Also, want this to be a package I can call instead of putting this command code in every document I want to use it. Below is my attempt at a solution.

Here is my .sty file

\ProvidesPackage{pnutscommands}
\usepackage{color}
\usepackage{seqsplit}
\usepackage{xargs}
\usepackage{xstring}

\newcommandx{\colornote}[3][1=red, 2=3in]{%
\begin{minipage}{#2}
\textcolor{#1}{\seqsplit{\StrSubstitute{#3}{ }{~}}}
\end{minipage}
}


Here is my .txt

\documentclass{article}
\usepackage{pnutscommands}

\begin{document}

\colornote[blue][5in]
{17823941dsfdsfdsf 23471239047123 9407123408917234890123748912034712985712389012351}

\colornote
{17823941237490812347123904712389 dsdsfdsfdsfdfs 23748912034712985712389012351}

\end{document}


This code works if you replace \StrSubstitute{#3}{ }{~}} with #3. The issue was that \seqsplit removes spaces in the string. So I tried \StrSubstitute but it returns an error that I'm unfamiliar with.

% Console output:
! Use of \@xs@StrSubstitute@@ doesn't match its definition.
\kernel@ifnextchar ...rved@d =#1\def \reserved@a {
#2}\def \reserved@b {#3}\f...
l.7 ...408917234890123748912034712985712389012351}


Can someone help me either fix this error or point me to a better solution?

• @egreg Thanks! I actually ran into a few of your comments while working on this new command. Seems you're quite active. – P-nut Oct 19 '15 at 14:13

The problem has nothing to do with \newcommandx. You have to first do the substitutions and then apply \seqsplit to the string you got.

There's also the complication of avoiding that xstring expands too much.

\documentclass{article}

\usepackage{color}
\usepackage{seqsplit}
\usepackage{xargs}
\usepackage{xstring}

\newcommandx{\colornote}[3][1=red, 2=3in]{%
\begin{minipage}{#2}
\noexpandarg
\StrSubstitute{#3}{ }{~}[\TEMP]%
\textcolor{#1}{\expandafter\seqsplit\expandafter{\TEMP}}%
\end{minipage}
}

\begin{document}

\colornote[blue][5in]
{17823941dsfdsfdsf 23471239047123 9407123408917234890123748912034712985712389012351}

\colornote
{17823941237490812347123904712389 dsdsfdsfdsfdfs 23748912034712985712389012351}

\end{document}


The mandatory expl3 implementation:

\documentclass{article}

\usepackage{color}
\usepackage{seqsplit}
\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\colornote}{O{red}O{3in}m}
{
\begin{minipage}{#2}
\tl_set:Nn \l_tmpa_tl { #3 }
\tl_replace_all:Nnn \l_tmpa_tl { ~ } { \nobreakspace }
\breslend_color_seqsplit:Vn \l_tmpa_tl { #1 }
\end{minipage}
}

\cs_new_protected:Nn \breslend_color_seqsplit:nn
{
\textcolor{#2}{\seqsplit{#1}}
}
\cs_generate_variant:Nn \breslend_color_seqsplit:nn { V }
\ExplSyntaxOff

\begin{document}

\colornote[blue][5in]
{17823941dsfdsfdsf 23471239047123 9407123408917234890123748912034712985712389012351}

\colornote
{17823941237490812347123904712389 dsdsfdsfdsfdfs 23748912034712985712389012351}

\end{document}

• I'll continue on with your first solution. I'm trying to expand from this basic example to more complex commands. Appreciate the help @egreg ! – P-nut Oct 19 '15 at 14:39