4

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 2

7

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. :) 
\NewDocumentCommand\alotofdots{ 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

12
  • 1
    See my edited answer, please
    – user220367
    Jul 25, 2020 at 22:10
  • 2
    +1 You should allow a second optional argument so that, for example, $\alotofdots(\cdot)[14]$ would use \cdot instead of \ldotp. Of course, this could allow anything to be put inside but that's ok. This isn't so straightforward with my approach.
    – user30471
    Jul 25, 2020 at 22:15
  • 1
    @Sebastiano Noone's answer is better as it is easily extendable to other types of dots. They were also first and both solutions are short. It is clear that Noone is more deserving of the tick!
    – user30471
    Jul 25, 2020 at 22:42
  • 2
    @Noone Just a few comment on your answer: \a_lot_of_dots is a really bad name for a function. A function in expl3 should always be named as \<module>_<name>:<signature>. Here <module> can be sebastiano or manydots. <name> can be a_lot_of_dots if you want, or something less wordy that describes what the function does. <signature> here must be n, because the function takes one argument. (something like \sebastiano_manydots:n would be fine). Also you should use \cs_new_protected:Npn here, instead of \cs_new:Npn Jul 25, 2020 at 23:19
  • 2
    You can simplify the new version using \NewDocumentCommand\alotofdots{ D(){\ldotp} O{3} }{\mathinner{\prg_replicate:nn{#2}{#1}}}. In particular, it is better to use different delimiters for the two optional argument so that they can be used independently.
    – user30471
    Jul 26, 2020 at 4:24
8

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
\newcommand\ndots[1][3]{%
  \@tempdima=\dimexpr#1ex+1ex\relax%
  \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

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.