Title says it all. Since I am a newbie, I don't know how to do this.
Any help?
If 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
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}
\ExplSyntaxOn
%% Dots on the first and last digit
\NewDocumentCommand{\periodfl}{m}
{
\repdec_initial_final_dots:n { #1 }
}
\cs_new_protected:Npn \repdec_initial_final_dots:n #1
{
\tl_if_single:nTF { #1 }
{ \dot{#1} } % just one digit
{
\dot{\tl_range:nnn { #1 } { 1 } { 1 } } % first digit
\tl_range:nnn { #1 } { 2 } { -2 } % middle digits
\dot{\tl_range:nnn { #1 } { -1 } { -1 } } % last digit
}
}
%% 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:nnF { \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}
\periodmixed
. - egreg
1.233... -- 1.23434... -- 1.2345345... -- 1.234563456... -- etc.
- Egon
Just for completeness, here is a possible approach for this macro in the traditional TeX programming:
\def\afterfi#1#2\fi{\fi#1}
\def\periodfl#1{\pflA#1.}
\def\pflA#1#2{\dot#1\ifx.#2\else\afterfi{\pflB#2}\fi}
\def\pflB#1#2{\ifx.#2\dot#1\else#1\afterfi{\pflB#2}\fi}
\def\periodalldots#1{\padotsA#1.}
\def\padotsA#1#2{\dot#1\ifx.#2\else\afterfi{\padotsA#2}\fi}
\let\periodbar=\overline
\def\periodparens#1{(#1)}
\def\periodmixed#1{\pmiA#1.}
\def\pmiA#1#2{\ifx.#2\dot#1\else\afterfi{\pmiB#1#2}\fi}
\def\pmiB#1.{\overline{#1}}
$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}$
\bye
Below is a comparable option using LaTeX ( originally posted by egreg [1]):
\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
[1] https://tex.stackexchange.com/revisions/75289/3\periodfl
is simpler than yours. The method used now exploits methods not available at the time the original answer was written. - egreg
{\tracingall $1.2\periodfl{34567}$}
with ergreg's expl3 code then we get 2169 lines in the log file about expansion of the macro \periodfl
. If we do the same in my code, we get 71 lines, i.e. 30 times less than expl3 code. It doesn't seem that egreg's current definition is simpler from this point of view. Expl3 solution is certainly much more time-consuming and doing \tracingall
is of little use because user is lost in tons of output. It means that the macro is practically untraceable. This is typical for LaTeX macros. - wipet
expl3
one wasn't very satisfying. When the question was bumped I realized that the expl3
could be made much simpler with features that weren't available at the time, so the legacy version was no longer relevant. And the new version is simpler than yours, because it is completely straightforward, needing no trick whatsoever: if the argument is a single digit, dot it; otherwise dot the first, print the mddle ones and dot the last one. - egreg
The xlop
package can be used to underline or highlight the period during a Euclidean division.
\documentclass{article}
\usepackage{xlop}
\begin{document}
The \textbf{vruleperiod} parameter (which defaults to -0.2) indicates the period by a line below it.
\opdiv[period,style=text]{1}{7}
\bigskip
It can be positioned above the period with \textbf{vruleperiod=0.7}.
\opdiv[period,style=text,vruleperiod=0.7]{1}{7}
\bigskip
The thickness of the period line is set here with hrulewidth =0.2pt (default value 0.4pt).
\opdiv[period,style=text,equalsymbol=$\approx$,
hrulewidth=0.2pt,vruleperiod=0.7,
afterperiodsymbol=]{1}{7}
\bigskip
The thickness of the period line is set here with hrulewidth=2pt:
\opdiv[period,style=text,equalsymbol=$\approx$,
hrulewidth=2pt,vruleperiod=0.7,
afterperiodsymbol=]{1}{7}
\bigskip
xlop can also be used to set divisions as they are in France.
\opdiv[period]{1}{7}
\end{document}
these answers are very kind but you lot are way over complicating it, literally just do \.{your number}
no need to use any packages, it's built in. or other accents, see https://en.wikibooks.org/wiki/LaTeX/Special_Characters
\d{...}
("dot-over accent") is a text-mode command. It doesn't work in math mode. Even in text mode, its usefulness is rather limited if there's more than 1 recurring decimal. E.g., what do you think readers will "see" if you write \d{142857}
? - Mico
0.9
with a dot on top of the 9. - Zerium0.\dot{9}
? - Alexander17/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'