如何为分组和换行数字添加 `\overline`

如何为分组和换行数字添加 `\overline`

我有一个后续问题 https://tex.stackexchange.com/a/522907/46023

是否可以添加\overline用于分组和换行数字的命令?

也许可以\overline从某个数字得到,比如说 $23.456\overline{78910}$

在此处输入图片描述

\documentclass[]{article}
% \groupify{<digits>}{<my number>}
% https://tex.stackexchange.com/a/522907/46023
\usepackage{xparse}
\ExplSyntaxOn
\NewExpandableDocumentCommand \groupify { O{\,\allowbreak} m m }
  { \jakob_groupify:nnn {#1} {#2} {#3} }
\cs_new:Npn \jakob_groupify:nnn #1 #2 #3
  { \__jakob_groupify_loop:nnw { 1 } {#2} #3 \q_recursion_tail {#1} \q_recursion_stop }
\cs_new:Npn \__jakob_groupify_loop:nnw #1 #2 #3
  {
    \quark_if_recursion_tail_stop:n {#3}
    \exp_not:n {#3}
    \int_compare:nNnTF {#1} = {#2}
      { \__jakob_groupify_sep:n }
      { \exp_args:Nf \__jakob_groupify_loop:nnw { \int_eval:n { #1+1 } } }
          {#2}
  }
\cs_new:Npn \__jakob_groupify_sep:n #1 #2 \q_recursion_tail #3
  {
    \tl_if_empty:nF {#2} { \exp_not:n {#3} }
    \__jakob_groupify_loop:nnw { 1 } {#1}
    #2 \q_recursion_tail {#3}
  }
\ExplSyntaxOff

\begin{document}
\section{Without overline: Good}
$x=452.\groupify{3}{353602874713526624977572470936999
    59574966967627724076630353547594571382178525
    166427427466391932003059921817413596629043572
    9003342952605956307381323286279434907632338298807531952
    510190115738
    3418793070215408914993}$   

\section{With overline: Bad}
$x=452.353602874713526624977572470936999
59574966967627724076630353547\overline{\groupify{3}{594571382178525
166427427466391932003059921817413596629043572
9003342952605956307381323286279434907632338298807531952
510190115738
 3418793070215408914993}}$   

\section{Simple example for the target}
$x = 23.456\overline{78910}$
\end{document}

答案1

对于 LuaLaTeX 来说,有一个巧妙的解决方案,使用luacodeumoline。我改编了 Lua 代码https://stackoverflow.com/a/39481287/11954069

%!TEX program = lualatex
\documentclass{article}
\usepackage{luacode}
\usepackage{umoline}
\begin{luacode*}
function splitByChunk(text, chunkSize)
    local s = {}
    for i=1, #text, chunkSize do
        s[#s+1] = text:sub(i,i+chunkSize - 1)   
    end
    tex.print([[\Overline{%]])
    for i,v in ipairs(s) do
        tex.print(s[i])
    end
    tex.print([[}]])
end
\end{luacode*}
%The first argument is the number; the second is the chunk size
\newcommand{\DirtyOverline}[2]{%
\directlua{
splitByChunk("#2",#1)
}%
}
\begin{document}
    \DirtyOverline{3}{54487755314354687344656897842}
\end{document}

在此处输入图片描述

抱歉,我不会说expl3,我认为这是一种非常繁琐的语言。

相关内容