How would you write a manual summation of numbers in TeX? That is, something like this(not necessarily identical):

How would you write a manual summation of numbers in TeX? That is, something like this(not necessarily identical):

Just for fun, I offer this automated alternative. The \convertchar turns the space separated input into a + separated input, to which \numexpr can be applied. I use right-aligned stacks to compose the result.
\documentclass{article}
\usepackage{stringstrings,stackengine}
\newcounter{mysum}
\newcommand\showsum[1]{%
\convertchar[q]{#1}{ }{+}%
\setcounter{mysum}{\numexpr\thestring\relax}%
\def\stackalignment{r}%
{\ttfamily\stackunder{\underline{+\Longstack{#1}}}{\themysum}}%
}
\begin{document}
\showsum{1 2 3 4} $\qquad$
\showsum{23 567 34 32} $\qquad$
\showsum{1 3567 2334 3352 567}
\end{document}

Leave the computation to TeX. ;-)
\documentclass{article}
\usepackage{xparse,array,booktabs}
\ExplSyntaxOn
\NewDocumentCommand{\computesum}{sO{}m}
{
\chubakueno_computesum:n { #3 }
\IfBooleanTF{#1}
{
\ensuremath { \int_to_arabic:n { \l_chubakueno_sum_int } }
}
{
\group_begin:
\chubakueno_typesetsum:n { #2 }
\group_end:
}
}
\int_new:N \l_chubakueno_sum_int
\seq_new:N \l_chubakueno_summands_seq
\seq_new:N \l_chubakueno_output_summands_seq
\seq_new:N \l__chubakueno_temp_seq
\tl_new:N \l_chubakueno_total_tl
\tl_new:N \l__chubakueno_temp_tl
\cs_generate_variant:Nn \int_set:Nn { Nx }
\keys_define:nn { chubakueno/sum }
{
spacing .dim_set:N = \l_chubakueno_spacing_dim,
align .tl_set:N = \l_chubakueno_align_tl,
align .initial:n = c,
}
\cs_new_protected:Npn \chubakueno_computesum:n #1
{
\int_set:Nn \l_chubakueno_sum_int { #1 }
\seq_set_split:Nnn \l_chubakueno_summands_seq { + } { #1 }
}
\cs_new_protected:Npn \chubakueno_typesetsum:n #1
{
\keys_set:nn { chubakueno/sum } { #1 }
\dim_compare:nTF { \l_chubakueno_spacing_dim = 0pt }
{% do nothing if the space is zero
\seq_set_eq:NN \l_chubakueno_output_summands_seq \l_chubakueno_summands_seq
\tl_set:NV \l_chubakueno_total_tl \l_chubakueno_sum_int
}
{% else add the interline space
\seq_map_inline:Nn \l_chubakueno_summands_seq
{
\seq_set_split:Nnn \l__chubakueno_temp_seq { } { ##1 }
% insert the interdigits space
\__chubakueno_insert_space:N \l__chubakueno_temp_tl
\seq_put_right:NV \l_chubakueno_output_summands_seq \l__chubakueno_temp_tl
}
\seq_set_split:NnV \l__chubakueno_temp_seq { } \l_chubakueno_sum_int
\__chubakueno_insert_space:N \l_chubakueno_total_tl
}
\begin{tabular} [\l_chubakueno_align_tl] { >{$}r<{$} @{$\;$} >{$}r<{$} }
& \seq_use:Nnnn \l_chubakueno_output_summands_seq { \\ + & } { \\ & } { \\ + & }
\\
\midrule
& \tl_use:N \l_chubakueno_total_tl
\end{tabular}
}
\cs_new_protected:Npn \__chubakueno_insert_space:N #1
{
\tl_set:Nx #1
{
\seq_use:Nn \l__chubakueno_temp_seq { \skip_horizontal:n { \l_chubakueno_spacing_dim } }
}
}
\ExplSyntaxOff
\begin{document}
Just the sum: \computesum*{345+6543+345}
The unspaced sum: \computesum{345+6543+345}
Spaced sum: \computesum[spacing=.1em,align=b]{640+231+100+91+1003}
Top aligned: \computesum[align=t,spacing=.2em]{333 + 333 + 333 + 2}
\end{document}
The first task is to compute the sum, storing it into an integer variable. The summands are also stored in a sequence, for later processing. If just \computesum* is called, only the sum is printed.
With the normal call, some possible options are evaluated: spacing is for interdigit space (default zero), align is for the overall alignment of the tabular, it can be c (default), t or b. Spaces around + in the mandatory argument are ignored.
Then the table is built by saving the summands with the interdigit space in a new sequence that's used in a tabular. The last row of the tabular is similarly built from the total.

One possible solution could be a simple table.
\begin{table}[h]
\begin{tabular}{r}
1234 \\
345 \\
+6543 \\
345 \\ \hline
8467
\end{tabular}
\end{table}
Edit: Results in following:

array environment and write {}+6543 rather than +6543 to ensure proper spacing around +.
– Bernard
Dec 22 '14 at 17:31
& . Thank you anyway!
– chubakueno
Dec 24 '14 at 21:25
\documentclass{...}and ending with\end{document}. – Dec 22 '14 at 14:22