# Problem with macro [closed]

I can not understand why this latex code does not work as expected:

\documentclass{article}

\usepackage{xstring}

\newcommand{\doparamG}[2]{%
\StrCut{#2}{"}\LeftString\RightString%
\doparam{#1}{\LeftString}%
\StrCut{\RightString}{"}\RLeftString\RRightString%
\StrLen{\RLeftString}[\rlstrLen]%
\StrLen{\RRightString}[\rrstrLen]%
\ifnum\rlstrLen > 0 M:#1{\RLeftString}\fi%
\ifnum\rrstrLen > 0 \doparamG{#1}{\RRightString}\fi%
}

\newcommand{\doparam}[2]{%
\StrCut{#2}{ }\LeftString\RightString%
\StrLen{\LeftString}[\lstrLen]%
\StrLen{\RightString}[\rstrLen]%
\ifnum\lstrLen > 0 #1{\LeftString}\fi%
\ifnum\rstrLen > 0 \doparam{#1}{\RightString}\fi%
}

\newcommand{\doparamGDEBUG}[2]{%
\StrCut{#2}{"}\LeftString\RightString%
Left:\LeftString\\%
\StrCut{\RightString}{"}\RLeftString\RRightString%
\StrLen{\RLeftString}[\rlstrLen]%
\StrLen{\RRightString}[\rrstrLen]%
Middle:\RLeftString ,len: \rlstrLen\\%\ifnum\rlstrLen > 0 #1{\RLeftString}\fi%
Right:\RRightString ,len: \rrstrLen\\%\ifnum\rrstrLen > 0 \doparamGDBG{#1}{\RRightString}\fi%
\ifnum\rrstrLen > 0 \doparamGDEBUG{#1}{\RRightString}\fi%
}

\newcommand{\justnewline}[1]{#1\\}

\begin{document}
Simple test:\\
\doparam{\justnewline}{ line1 line2   line3 }
\doparamG{\justnewline}{ "line 4" line5   "line 6" }

But we have:\\
\doparamGDEBUG{\justnewline}{ "line 4" line5   "line 6" }

\end{document}


## closed as unclear what you're asking by egreg, user13907, Mensch, user36296, Stefan PinnowSep 16 '16 at 17:14

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• What is the expected behaviour? – Karlo Aug 17 '16 at 7:00
• Note the warnings about bad boxes are due to misuse of \\  which should never be used at the end of a paragraph. Apart from that unless you say what your expectation is, hard to say how that differs from what the code does. – David Carlisle Aug 17 '16 at 7:14
• I expect "line 4" in a new line after "line3", and "line5" and "line 6" for next lines. Compare output of <doparamGDEBUG> with output – Abdollah Aug 17 '16 at 7:23
• .. with output of <doparamG> which has no output! – Abdollah Aug 17 '16 at 7:24
• but you should say in words what the code is trying to do, I would guess that it is trying to replace every space not inside ".." with \\  is that right? – David Carlisle Aug 17 '16 at 8:22

Alternative with expl3 and some hackery.

\documentclass{scrartcl}
\usepackage{etoolbox}
\usepackage{xparse}

\newcommand\justpar[1]{#1\par}

\ExplSyntaxOn

\NewDocumentCommand \doparam { O{\justpar} m }
{
\abdollah_doparam:Nn #1 { #2 }
}
\cs_new_protected:Npn \abdollah_doparam:Nn #1 #2
{
\tl_set:Nn \l_tmpa_tl { #2 }
\tl_replace_all:Nnn \l_tmpa_tl { " } { \abdollah_doparam_quote:w }
\tl_set:Nx \l_tmpa_tl { \l_tmpa_tl }
\seq_set_split:NnV \l_tmpa_seq { ~ } \l_tmpa_tl
\seq_map_inline:Nn \l_tmpa_seq { \tl_if_empty:nF {##1} { #1 {##1} } }
}
\cs_new:Npn \abdollah_doparam_quote:w #1 \abdollah_doparam_quote:w { { #1 } }

\ExplSyntaxOff

\begin{document}

\doparam{ line1 line2   line3  "line 4" line5   "line 6" }

\end{document}

• Thanks a lot dear @Manuel, it works but generates errors. pdflatex's last message is <l.28 ...line2 line3 "line 4" line5 "line 6" }>. – Abdollah Aug 17 '16 at 15:32
• It works for me. – Manuel Aug 18 '16 at 13:51
• \seq_show:N looks like a leftover – clemens Sep 16 '16 at 17:44
• @clemens It definitely was :) I just removed that line. – Manuel Sep 16 '16 at 17:59