1

I have a follow-up question for https://tex.stackexchange.com/a/522907/46023

Is it possible to add the \overline-command for grouped and linebreaked numbers?

Maybe to get \overline from a certain digit, say $23.456\overline{78910}$?

enter image description here

\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}
cis
  • 8,073
  • 1
  • 16
  • 45

1 Answers1

1

There's a tricky solution for LuaLaTeX using luacode and umoline. I've adapted the Lua code from 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}

enter image description here

Sorry, I don't speak expl3, I think it's a very cumbersome language.