TransWikia.com

Specific command to have a number of dots chosen by the user

TeX - LaTeX Asked on December 29, 2020

Starting from this simple code,

documentclass[12pt]{article}
usepackage{amsmath}
begin{document}
[begin{pmatrix}
a 
b
ldots ldots
end{pmatrix}
]
end{document}

enter image description here

my question is:

Isn’t there a specific package that creates exactly user-defined suspension dots? Usually it’s always three dots and to get six of them, for example, I have to write the specific dot command twice. But if you wanted a default number, 14, 7, which are not multiples of three, what solution would you adopt?

2 Answers

From the definition of ldots:

documentclass{article}
%For older distributions
usepackage{expl3}
%%%%%%%%%%%%%%%%%%%%%%%%
ExplSyntaxOn 
cs_new_protected:Npn sebastiano_alotofdots:n #1{
mathinner{
prg_replicate:nn{#1}{ldotp}
}
}
newcommand{alotofdots}[1][3]{sebastiano_alotofdots:n{#1}}
ExplSyntaxOff 
begin{document}
$alotofdots$

$alotofdots[7]$

$alotofdots[14]$
end{document}

enter image description here

You can redefine ldots so it accepts an optional argument, but I wouldn't recommend it.

EDIT

Thanks to Andrew and Phelype for their suggestions. A more flexible approach, using xparse and incorporating the elegant suggestion made by Andrew, could be (colors for highlighting):

documentclass{article}
%For older distributions
usepackage{expl3}
%%%%%%%%%%%%%%%%%%%%%%%%
usepackage{xparse}
ExplSyntaxOn 
%Thanks, Andrew! This looks way better than my previous example. :) 
NewDocumentCommandalotofdots{ D(){ldotp} O{3}}
{mathinner{prg_replicate:nn{#2}{#1}}}
ExplSyntaxOff 
begin{document}
    %Three dots (just the same as ldots)
    $alotofdots$
    %Number of repetitions is specified by [number]
    $alotofdots[4]$
    %The dot can be changed by (another symbol)
    %cdot does not work here
    $alotofdots(cdotp)$
    %And now two arguments
    $alotofdots(cdotp)[7]$    
end{document}

enter image description here

Correct answer by user220367 on December 29, 2020

Here is another approach using dotfill inside a box of length the number of dots plus 1, all times 1ex. By default three dots are produced by ndots and an optional argument changes this so that the code

documentclass{article}
makeatletter
newcommandndots[1][3]{%
  @tempdima=dimexpr#1ex+1exrelax%
  hbox to @tempdima{dotfill}%
}
makeatletter%

begin{document}

default: ndots

1: ndots[1]

2: ndots[2]

3: ndots[3]

4: ndots[4]

5: ndots[5]

6: ndots[6]

7: ndots[7]

8: ndots[8]

9: ndots[9]


end{document}

produces:

enter image description here

Answered by user30471 on December 29, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP