I'm using some code I found to generate, from simple input, a nicely formatted list of steps in solving an equation. However, my method is adding unwanted space to the left and at the bottom of the result. Please have a look:
\documentclass{article}
\usepackage{xstring} % using: StrSubstitute
% equation solving list
\renewcommand\equation[1]{
\everymath{\displaystyle}
\renewcommand{\arraystretch}{2.5}
\begin{tabular}{@{}r@{}c@{}l@{}}
\foreach{\makeeq}{}{#1}
\end{tabular}\\
}
% equation helper function (first parameter is unused)
\def\makeeq#1#2{
\saveexpandmode\expandarg
\StrSubstitute[1]{#2}{=}{$&$\ =\ $&$}[\subbed]
\restoreexpandmode
\subbed\\
}
% % % FOREACH % % %
\makeatletter
% Functional foreach construct
% #1 - Function to call on each comma-separated item in #3
% #2 - Parameter to pass to function in #1 as first parameter
% #3 - Comma-separated list of items to pass as second parameter to function #1
\def\foreach#1#2#3{%
\@test@foreach{#1}{#2}#3,\@end@token%
}
% Internal helper function - Eats one input
\def\@swallow#1{}
% Internal helper function - Checks the next character after #1 and #2 and
% continues loop iteration if \@end@token is not found
\def\@test@foreach#1#2{%
\@ifnextchar\@end@token%
{\@swallow}%
{\@foreach{#1}{#2}}%
}
% Internal helper function - Calls #1{#2}{#3} and recurses
% The magic of splitting the third parameter occurs in the pattern matching of the \def
\def\@foreach#1#2#3,#4\@end@token{%
#1{#2}{#3}%
\@test@foreach{#1}{#2}#4\@end@token%
}
\makeatother
% % % % % %
\begin{document}
desired result: \
start
\everymath{\displaystyle}
\renewcommand{\arraystretch}{2.5}
\begin{tabular}{@{}r@{}c@{}l@{}}
$ X $&$\ =\ $&$ 1 + 1 $ \\
$ $&$\ =\ $&$ 2 $ \\
\end{tabular}\
end
\bigskip
actual result: \
start
\equation{
$ X = 1 + 1 $,
$ = 2 $
}
end
\end{document}
The output:
I can't figure out what's adding the whitespace. Any help would be appreciated. Thanks!
\renewcommand{\equation}
to begin with. Choose another name, becauseequation
is a very important environment and it may come useful for you.