# Subtracting whole numbers in latex code [closed]

do anyone of you knows the codes for subtracting two whole numbers with borrowing/carry?

I have tried

\begin{aligned} 296 \\ - \\ 129 \\\hline 167 \end{aligned}

New contributor
jenn kim is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
• Welcome to TeX.SE! Nov 25 at 16:30
• Welcome! Can you be a bit more specific about what you want to achieve? And can you please include a complete document, starting with \documentclass and ending with \end{document}? There are several ways of doing calculations in LaTeX automatically. Which solution is best depends on your setting (that we don't know). Maybe related: tex.stackexchange.com/questions/87824/…, tex.stackexchange.com/questions/167222/… Nov 25 at 17:03

If you're willing and able to use LuaLaTeX, the following solution may be of interest to you:

\documentclass{article}
\usepackage{luacode} % for "\luaexec" macro
\luaexec{%

    function dosubtraction ( n1 , n2 )
tex.sprint ( "\\begin{array}{@{}r@{}}" )
tex.sprint ( n1 .. "\\\\ \\llap{$-$}" ..  n2 .. "\\\\ \\hline" )
tex.sprint ( n1-n2 )
tex.sprint ( "\\end{array}" )
end

}
% LaTeX "wrapper" macro to access the 'dosubtracton' Lua function:
\newcommand\dosubtraction[2]{\luaexec { dosubtraction ( #1 , #2 ) }}

\begin{document}

$\dosubtraction{2}{1} \qquad \dosubtraction{296}{129} \qquad \dosubtraction{1961}{2021}$

\end{document}