4

The sequence 4813065297 has 5 adjacent pairs in descending order; namely 81, 30, 65, 52, 97. I want to highlight these pairs by means of overlines, but the pair 65 overlaps with 52, so I can only get a continuous overline:

\[4\overline{81}\overline{30}\overline{652}\overline{97}\]

Q: How can I get an overline from 6 to the middle of 5, followed by another from there to 2, with a small visible gap?

1
  • Maybe you're interested in a command that also computes by itself the overlines. See my edited answer.
    – egreg
    Sep 22 at 7:56
5

All \overlines will run into each other, so first is needed a narrowed overline, to leave a gap.

Here, I create \noverline (narrow-overline) that uses kerning tricks to narrow the width of the overline, based on the length that is \defed into \nindent.

Then, you need something to do what the question asks, create an overline that leave a gap midway. For that, I create \midoverline.

\documentclass{article}
\usepackage{mathtools}
\newcommand\nindent{.5pt}
\newcommand\noverline[1]{%
  \kern\nindent\overline{\kern-\nindent#1\kern-\nindent}\kern\nindent}
\newcommand\midoverline[1]{%
  \sbox0{$#1$}%
  \bgroup\ooalign{$#1$\cr$\noverline{\rule{.5\wd0}{0pt}\vphantom{#1}}%
  \noverline{\rule{.5\wd0}{0pt}\vphantom{#1}}$}\egroup
}
\begin{document}
\[4\noverline{81}\noverline{30}\midoverline{652}\noverline{97}\]
\end{document}

enter image description here

1
  • Thank you! I knew it was not straightforward. This type of answer helps me learn.
    – yrodro
    Sep 21 at 21:41
4

You can reduce the length of the overline and exploit that the digits all have the same width.

\documentclass{article}
\usepackage{amsmath}

\newmuskip\ovskip
\ovskip=1mu

\newcommand{\decr}[1]{%
  \mspace{\ovskip}%
  \overline{\mspace{-\ovskip}#1\mspace{-\ovskip}}%
  \mspace{\ovskip}%
}
\newcommand{\decrdbl}[3]{%
  \decr{#1\hspace{0.5\fontcharwd\textfont0`0}}%
  \hspace{-0.5\fontcharwd\textfont0`0}%
  #2%
  \hspace{-0.5\fontcharwd\textfont0`0}%
  \decr{\hspace{0.5\fontcharwd\textfont0`0}#3}%
}

\begin{document}

\[
4\decr{81}\decr{30}\decrdbl{6}{5}{2}\decr{97}
\]

\end{document}

enter image description here

With \ovskip=1.5mu you'd get

enter image description here

Experiment what seems the best for your taste.

Automatic version

Just for fun, here's a version that does all the work for you.

\documentclass{article}
\usepackage{amsmath}

\newmuskip\ovskip
\ovskip=1mu

\ExplSyntaxOn

\NewDocumentCommand{\markdecrease}{m}
 {
  \yrodro_markdecrease:n { #1 }
 }

\tl_new:N \l__yrodro_markdecrease_tl
\seq_new:N \l__yrodro_markdecrease_seq

\cs_new_protected:Nn \yrodro_markdecrease:n
 {
  % typeset the number
  #1
  % back up
  \hspace{-\tl_count:n { #1 } \fontcharwd\textfont0`0}
  % compute the overlines
  \tl_clear:N \l__yrodro_markdecrease_tl
  \__yrodro_markdecrease:NN #1 \q_nil
 }
\cs_new_protected:Nn \__yrodro_markdecrease:NN
 {
  \quark_if_nil:NTF { #2 }
   {% end of the recursion, add the last digit
    \tl_put_right:Nn \l__yrodro_markdecrease_tl { #1 }
    % split at periods
    \seq_set_split:NnV \l__yrodro_markdecrease_seq { . } \l__yrodro_markdecrease_tl
    % produce the overlines
    \seq_map_function:NN \l__yrodro_markdecrease_seq \__yrodro_markdecrease_item:n
   }
   {% there are more digits, add the first one
    \tl_put_right:Nn \l__yrodro_markdecrease_tl { #1 }
    % if the next digit is not less than the current one, add a period
    \int_compare:nF { #1 > #2 }
     {
      \tl_put_right:Nn \l__yrodro_markdecrease_tl { . }
     }
    % restart the recursion with the next digit as the first one
    \__yrodro_markdecrease:NN #2
   }
 }

\cs_new_protected:Nn \__yrodro_markdecrease_item:n
 {
  \int_case:nnF { \tl_count:n { #1 } }
   {
    {1}{ \__yrodro_markdecrease_blank: }
    {2}{ \__yrodro_markdecrease_over:n {00} }
   }
   { \__yrodro_markdecrease_more:n { #1 } }
 }

\cs_new_protected:Nn \__yrodro_markdecrease_blank:
 {
  \phantom{0}
 }
\cs_new_protected:Nn \__yrodro_markdecrease_over:n
 {
  \mspace{\ovskip}
  \overline{\mspace{-\ovskip}\phantom{#1}\mspace{-\ovskip}}
  \mspace{\ovskip}
 }
\cs_new_protected:Nn \__yrodro_markdecrease_more:n
 {
  \__yrodro_markdecrease_oneandhalf:
  \prg_replicate:nn { \tl_count:n { #1 } - 3 } { \__yrodro_markdecrease_over:n {0} }
  \__yrodro_markdecrease_oneandhalf:
 }
\cs_new_protected:Nn \__yrodro_markdecrease_oneandhalf:
 {
  \mspace{\ovskip}
  \overline{\mspace{-\ovskip}\phantom{0}\hspace{0.5\fontcharwd\textfont0`0}\mspace{-\ovskip}}
  \mspace{\ovskip}
 }

\ExplSyntaxOff

\begin{document}

\[
\markdecrease{4813065297}\quad\markdecrease{9876543210}
\]

\end{document}

enter image description here

A slightly different version that draws overlines starting from and ending at the middle of digits (with a small gap).

\documentclass{article}
\usepackage{amsmath}

\newmuskip\ovskip
\ovskip=1mu

\ExplSyntaxOn

\NewDocumentCommand{\markdecrease}{m}
 {
  \yrodro_markdecrease:n { #1 }
 }

\tl_new:N \l__yrodro_markdecrease_tl
\seq_new:N \l__yrodro_markdecrease_seq

\cs_new_protected:Nn \yrodro_markdecrease:n
 {
  % typeset the number
  #1
  % back up
  \hspace{-\tl_count:n { #1 } \fontcharwd\textfont0`0}
  % compute the overlines
  \tl_clear:N \l__yrodro_markdecrease_tl
  \__yrodro_markdecrease:NN #1 \q_nil
 }
\cs_new_protected:Nn \__yrodro_markdecrease:NN
 {
  \quark_if_nil:NTF { #2 }
   {% end of the recursion, add the last digit
    \tl_put_right:Nn \l__yrodro_markdecrease_tl { #1 }
    % split at periods
    \seq_set_split:NnV \l__yrodro_markdecrease_seq { . } \l__yrodro_markdecrease_tl
    % produce the overlines
    \seq_map_function:NN \l__yrodro_markdecrease_seq \__yrodro_markdecrease_item:n
   }
   {% there are more digits, add the first one
    \tl_put_right:Nn \l__yrodro_markdecrease_tl { #1 }
    % if the next digit is not less than the current one, add a period
    \int_compare:nF { #1 > #2 }
     {
      \tl_put_right:Nn \l__yrodro_markdecrease_tl { . }
     }
    % restart the recursion with the next digit as the first one
    \__yrodro_markdecrease:NN #2
   }
 }

\cs_new_protected:Nn \__yrodro_markdecrease_item:n
 {
  \hspace{0.5\fontcharwd\textfont0`0}
  \prg_replicate:nn { \tl_count:n { #1 } - 1 }
   {
    \mspace{\ovskip}
    \overline{\mspace{-\ovskip}\phantom{0}\mspace{-\ovskip}}
    \mspace{\ovskip}
   }
  \hspace{0.5\fontcharwd\textfont0`0}
 }

\ExplSyntaxOff

\begin{document}

\[
\markdecrease{4813065297}\quad\markdecrease{9876543210}
\]

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.