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}$$
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}
\documentclassand 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: https://tex.stackexchange.com/questions/87824/how-to-do-simple-calculation-in-latex, https://tex.stackexchange.com/questions/167222/perform-simple-calculations-on-user-defined-variables – gernot Nov 25 '21 at 17:03