3

enter image description here

A picture is more than 100 words. How do I align the dotts (automatically) and properly at the top?

Code currently in use is from here:

\documentclass[12pt]{article}
%% packages
\usepackage{amsmath,multicol,graphics,enumerate}
\usepackage{graphicx}
\usepackage[margin=1cm]{geometry}

\makeatletter
\DeclareRobustCommand{\periodfl}[1]{\@periodflold#1\@nil\relax}
\def\@periodflold#1#2{%
  \ifx#2\relax
    \expandafter\@gobble
  \else
    \expandafter\@firstofone
  \fi
  {\@periodflold@i#1#2}%
}
\def\@periodflold@i#1#2{%
  \dot{#1}%
  \ifx#2\@nil
    \expandafter\@gobble
  \else
    \expandafter\@firstofone
  \fi
  {\@periodflold@ii#2}%
}
\def\@periodflold@ii#1#2{%
  \ifx#2\@nil
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi
  {\dot{#1}}{#1\@periodflold@ii#2}%
}
\makeatother

\begin{document}
\pagestyle{empty}
\setlength{\parindent}{0pt}

Prove that $0.\periodfl{0x}=\frac{x}{99}$.

\end{document}

Thanks!

  • what alignment do you want here? the code posted produces essentially the output you show, or do you mean that you want all the dots at the same height? – David Carlisle Feb 13 '16 at 00:12
  • @DavidCarlisle Changed the code fragments. Sorry if it was not clear. I want either make the x bigger, or make the dots at the same height. So that the dots look like on the same horizontal line. – Chen Stats Yu Feb 13 '16 at 00:14

1 Answers1

4

Just add \vphantom{0} in the argument in the two instances of \dot:

\documentclass{article}

\makeatletter
\DeclareRobustCommand{\periodfl}[1]{\@periodflold#1\@nil\relax}
\def\@periodflold#1#2{%
  \ifx#2\relax
    \expandafter\@gobble
  \else
    \expandafter\@firstofone
  \fi
  {\@periodflold@i#1#2}%
}
\def\@periodflold@i#1#2{%
  \dot{\vphantom{0}#1}%
  \ifx#2\@nil
    \expandafter\@gobble
  \else
    \expandafter\@firstofone
  \fi
  {\@periodflold@ii#2}%
}
\def\@periodflold@ii#1#2{%
  \ifx#2\@nil
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi
  {\dot{\vphantom{0}#1}}{#1\@periodflold@ii#2}%
}
\makeatother

\begin{document}

Prove that $0.\periodfl{0x}=\frac{x}{99}$.

Prove that $0.\periodfl{00x}=\frac{x}{999}$.

\end{document}

enter image description here

For completeness, here's the fix for the expl3 version:

\documentclass{article}
\usepackage{xparse}

\ExplSyntaxOn
%% Dots on the first and last digit
\NewDocumentCommand{\periodfl}{m}
 {
  \repdec_initial_final_dots:n { #1 }
 }

\seq_new:N \l__repdec_digits_seq
\tl_new:N \l__repdec_first_tl
\tl_new:N \l__repdec_last_tl

\cs_new_protected:Npn \repdec_initial_final_dots:n #1
 {
  \seq_set_split:Nnn \l__repdec_digits_seq {} { #1 }
  \seq_pop_left:NN \l__repdec_digits_seq \l__repdec_first_tl
  \seq_pop_right:NN \l__repdec_digits_seq \l__repdec_last_tl
  \quark_if_no_value:VF \l__repdec_first_tl { \dot{\vphantom{0}\l__repdec_first_tl} }
  \seq_use:Nn \l__repdec_digits_seq {}
  \quark_if_no_value:VF \l__repdec_last_tl { \dot{\vphantom{0}\l__repdec_last_tl} }
 }
\cs_generate_variant:Nn \quark_if_no_value:nF { V }
\ExplSyntaxOff

\begin{document}

Prove that $0.\periodfl{0x}=\frac{x}{99}$.

Prove that $0.\periodfl{00x}=\frac{x}{999}$.

\end{document}
egreg
  • 1,121,712