你们中有人知道用借位/进位减去两个整数的代码吗?
我努力了
$$\begin{aligned}
296 \\
- \\
129 \\\hline
167
\end{aligned}$$
答案1
如果您愿意并且能够使用 LuaLaTeX,以下解决方案可能会引起您的兴趣:
\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}