Title says it all. Since I am a newbie, I don't know how to do this.
Any help?
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this communityIf you're thinking of using a horizontal bar over a recurring group of decimals, you could use the \overline
command:
\documentclass{article}
\begin{document}
$\frac{1}{7}=0.\overline{142857}$
\end{document}
siunitx
, see also tex.stackexchange.com/a/97329/90237
– arekolek
Jun 9 '16 at 8:41
There are at least four representations; here is a way to produce all of them, take your pick (the macro names can of course be modified). I strongly suggest to use a special macro name, even if you decide to use the overline, so you can change your mind later and choose another realization.
\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{\l__repdec_first_tl} }
\seq_use:Nnnn \l__repdec_digits_seq {}{}{}
\quark_if_no_value:VF \l__repdec_last_tl { \dot{\l__repdec_last_tl} }
}
\cs_generate_variant:Nn \quark_if_no_value:nF { V }
%% Dots on all digits
\NewDocumentCommand{\periodalldots}{m}
{
\repdec_initial_all_dots:n { #1 }
}
\cs_new_protected:Npn \repdec_initial_all_dots:n #1
{
\tl_map_inline:nn { #1 } { \dot{##1} }
}
%% Bar over period
\NewDocumentCommand{\periodbar}{m}
{
\overline{ #1 }
}
%% Parentheses around period
\NewDocumentCommand{\periodparens}{m}
{
(#1)
}
%% Dot on unique digit, bar on several digits
\NewDocumentCommand{\periodmixed}{m}
{
\repdec_mixed:n { #1 }
}
\cs_new_protected:Npn \repdec_mixed:n #1
{
\int_case:nnn { \tl_count:n { #1 } }
{
{ 0 } { }
{ 1 } { \dot{#1} }
}
{
\overline{#1}
}
}
\ExplSyntaxOff
\begin{document}
$1.2\periodfl{3}$ --- $1.2\periodfl{34}$ --- $1.2\periodfl{345}$ ---
$1.2\periodfl{3456}$ --- $1.2\periodfl{34567}$
\medskip
$1.2\periodalldots{3}$ --- $1.2\periodalldots{34}$ --- $1.2\periodalldots{345}$ ---
$1.2\periodalldots{3456}$ --- $1.2\periodalldots{34567}$
\medskip
$1.2\periodbar{3}$ --- $1.2\periodbar{34}$ --- $1.2\periodbar{345}$ ---
$1.2\periodbar{3456}$ --- $1.2\periodbar{34567}$
\medskip
$1.2\periodparens{3}$ --- $1.2\periodparens{34}$ --- $1.2\periodparens{345}$ ---
$1.2\periodparens{3456}$ --- $1.2\periodparens{34567}$
\medskip
$1.2\periodmixed{3}$ --- $1.2\periodmixed{34}$ --- $1.2\periodmixed{345}$ ---
$1.2\periodmixed{3456}$ --- $1.2\periodmixed{34567}$
\end{document}
For \periodbar
and \periodparens
the overhead of xparse
is not necessary and they can be realized with the standard
\newcommand{\periodbar}[1]{\overline{#1}}
\newcommand{\periodparens}[1]{(#1)}
A different definition of \repdec_initial_final_dots:n
can be as follows
\int_new:N \l__repdec_digits_int
\int_new:N \l__repdec_count_int
\cs_new_protected:Npn \repdec_initial_final_dots:n #1
{
\int_set:Nn \l__repdec_digits_int { \tl_count:n { #1 } }
\int_zero:N \l__repdec_count_int
\tl_map_inline:nn { #1 } { \__repdec_add_dot:n { ##1 } }
}
\cs_new_protected:Npn \__repdec_add_dot:n #1
{
\int_incr:N \l__repdec_count_int
\int_case:nnn { \l__repdec_count_int }
{
{ 1 } { \dot{#1} }
{ \l__repdec_digits_int } { \dot{#1} }
}
{
#1
}
}
However, the sequence method seems more general.
Just for completeness, here is a possible approach for this macro in the traditional LaTeX programming:
\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
\periodmixed
.
– egreg
Oct 4 '12 at 14:35
1.233... -- 1.23434... -- 1.2345345... -- 1.234563456... -- etc.
– Egon
Oct 4 '12 at 17:01
0.9
with a dot on top of the 9. – Lucas Oct 4 '12 at 11:420.\dot{9}
? – Alexander Oct 4 '12 at 11:4517/99
then? This way?0.\dot{1}\dot{7}
. We used to write0.\overline{17}
, recently I use0.(17)^\omega
and my friends0.(17)^{\mathbb{N}}
. This just shows that there're many ways how to write it and you have to specify which exactly you want to typeset. – yo' Oct 4 '12 at 11:50