This MWE is boiled down so much the usefulness of the code is lost. However, the code nevertheless still exhibits the problem I'm encountering.
\documentclass{article}
\usepackage{pgffor}
\usepackage{etoolbox}
\makeatletter
\newcommand\aetest[1]{%%
\foreach \myl in {#1}
{%%
\expandafter\ae@parse@line\myl
}%%
}
%% read the next character and
%% branch off if its "*"
\def\ae@parse@line{%%
\@ifnextchar*
{\s@ae@parse@line}
{\@ae@parse@line[]}}
%% what to do if there is no "*"
\def\@ae@parse@line[#1]#2#3{%%
\fbox{Case #2}\hspace*{0.5em}%%
\def\ae@tmp{#3}%%
\typeout{==[base case][#2]==>\expandonce\ae@tmp}%%
\@ae@parse@content#3\@nil
}
%% If there's "*" the command now
%% expects three arguments with the argument
%% #3 dressed up like an optional argument.
%% After processing, pass arguments back to
%% "\@ae@parse@line"
\def\s@ae@parse@line*#1#2[#3]{%%
\def\ae@tmp{#2}%%
\typeout{==[star case]___==>\expandonce\ae@tmp}%%
\@ae@parse@line[#3]{#1}{#2}}
%% the "content" argument
%% may start with "[" which
%% signals that the "content"
%% should go in a `minipage`.
\def\@ae@parse@content{%%
\@ifnextchar[%%]
{\@ae@parse@mp}
{\@@ae@parse@content}}
%% formatting for "non-minipage" case
\def\@@ae@parse@content#1\@nil{%%
\textbf{#1}\par}
%% formatting for "minipage" case
\def\@ae@parse@mp[#1]#2\@nil{%%
\fbox{\begin{minipage}[t]{#1}
#2
\end{minipage}}\par}
\makeatother
\begin{document}
\aetest{
{A}{formatted correctly},
*{B} {formatted correctly}[],
*{C} {[4in] spurious space, and is \textbf{not} correct formatted}[],
*{D}{[4in] no spurious space and correctly formatted}[],
{E} {[2in] spurious space but still correctly formatted},
{F}{[3in] no spurious space, formatted correctly},
{G} {done as expected}}
\end{document}
producing
What I'm curious about is why does case C
not get correctly formatted, but case E
does. It seems to me that, if they both suffer from the same spurious space, then I would expect them to be handled similarly.
Looking at the log
file shows that in cases B
and C
the space is parsed as part of the argument and so the braces are not lost. But why do the braces then disappear is cases E
and G
?
Here's the relevant portion of the log file. The ==>
points to the content of the passed argument and shows the spurious space and the braces.
==[base case][A]==>formatted correctly
==[star case]___==> {formatted correctly}
==[base case][B]==> {formatted correctly}
==[star case]___==> {[4in] spurious space, and is \textbf {not} correct formatted}
==[base case][C]==> {[4in] spurious space, and is \textbf {not} correct formatted}
==[star case]___==>[4in] no spurious space and correctly formatted
==[base case][D]==>[4in] no spurious space and correctly formatted
==[base case][E]==>[2in] spurious space but still correctly formatted
==[base case][F]==>[3in] no spurious space, formatted correctly
==[base case][G]==>done as expected
#2
in\s@ae@parse@line
is delimited (by[
), so TeX doesn't skip spaces when looking for it. And, in case C, the initial space prevents the brace stripping.\def\something #1\@nil{\def\noleadingwhitespace{#1}}
, but that seems like it would interrupt the argument flow and create further headaches.#2
in theminipage
. At the end of a paragraph TeX only removes one space. Thus if#2
ends with a space it is kept.