答案1
无法避免使用表格,但您可以向用户隐藏它们。
\documentclass{article}
\usepackage{xparse,array,booktabs}
\ExplSyntaxOn
\NewDocumentCommand{\multiplication}{mmmm}
{% #1 = first factor, #2 = second factor, #3 = steps, #4 = result
\gemir_mult:nnnn { #1 } { #2 } { #3 } { #4 }
}
\seq_new:N \l__gemir_mult_steps_in_seq
\seq_new:N \l__gemir_mult_steps_out_seq
\cs_new_protected:Nn \gemir_mult:nnnn
{
\seq_set_split:Nnn \l__gemir_mult_steps_in_seq { \\ } { #3 }
\seq_clear:N \l__gemir_mult_steps_out_seq
% add padding to the steps
\seq_indexed_map_function:NN \l__gemir_mult_steps_in_seq \__gemir_mult_pad:nn
% typeset the table
\begin{tabular}[t]{@{}r@{}}
\tl_map_function:nN { #1 } \__gemir_mult_box:n
\__gemir_mult_box:n { \cdot }
\tl_map_function:nN { #2 } \__gemir_mult_box:n
\\
\midrule
\seq_map_function:NN \l__gemir_mult_steps_out_seq \__gemir_mult_step:n
\midrule
\tl_map_function:nN { #4 } \__gemir_mult_box:n
\end{tabular}
}
\cs_new_protected:Nn \__gemir_mult_pad:nn
{
\seq_put_right:Nx \l__gemir_mult_steps_out_seq
{
#2
\prg_replicate:nn { \seq_count:N \l__gemir_mult_steps_in_seq - #1 } { \scan_stop: }
}
}
\cs_new_protected:Nn \__gemir_mult_box:n
{
\makebox[1em]{$\str_if_eq:nnTF { #1 } { ? } { \_ } { #1 }$}
}
\cs_new_protected:Nn \__gemir_mult_step:n { \tl_map_function:nN { #1 } \__gemir_mult_box:n \\ }
\ExplSyntaxOff
\begin{document}
\multiplication{928}{58}{4640\\7424}{53824}\qquad
\multiplication{928}{58}{4?40\\7424}{53?24}
\end{document}
A?
表示表中的空白。