In this particular case, it's actually a table of contents, which can be simply be produced with \tableofcontents
:
\documentclass{article}
\begin{document}
\tableofcontents
\section{Introduction}
This is an introductory section.
\subsection{Sample Subsection}
This is a sample sub-section.
\end{document}
This doesn't require any external tools, just two instances of LaTeX (pdflatex
, xelatex
or lualatex
, as appropriate).

Here's a slightly longer example:
\documentclass{book}
\title{Sample Document}
\author{Ann Other}
\begin{document}
\maketitle
\frontmatter
\tableofcontents
\chapter{Preface}
This is the preface.
\mainmatter
\part{Sample Part}
\chapter{Introduction}
This is an introductory chapter.
\section{Sample section}
This is a sample section.
\subsection{Sample Subsection}
This is a sample sub-section.
\appendix
\chapter{Sample Appendix}
This is a sample appendix.
\chapter{Another Sample Appendix}
This is another sample appendix.
\end{document}
The table of contents now looks like:

This deals with all the numbering automatically. (\frontmatter
switches to lower case Roman numerals for the page numbers and also suppresses the numbering of the section commands. \mainmatter
switches back.)
If you were to use \index
, makeindex would order alphabetically. For example:
\documentclass{book}
\usepackage{makeidx}
\makeindex
\title{Sample Document}
\author{Ann Other}
\begin{document}
\maketitle
\frontmatter
\printindex
\chapter{Preface}\index{Preface}
This is the preface.
\mainmatter
\part{Sample Part}\index{I Sample Part}
\chapter{Introduction}\index{1 Introduction}
This is an introductory chapter.
\section{Sample section}\index{1.1 Sample section}
This is a sample section.
\subsection{Sample Subsection}\index{1.1.2 Sample subsection}
This is a sample sub-section.
\appendix
\chapter{Sample Appendix}\index{A Sample Appendix}
This is a sample appendix.
\chapter{Another Sample Appendix}\index{B Another Sample Appendix}
This is another sample appendix.
\end{document}
This produces:

To answer your actual question of changing the separator between the indexed item and the corresponding number, you need to create a style file that changes the appropriate delimiters:
\documentclass{article}
\usepackage{makeidx}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.ist}
delim_0 "\\dotfill"
delim_1 "\\dotfill"
delim_2 "\\dotfill"
\end{filecontents*}
\makeindex
\begin{document}
Test\index{test}\index{test!subitem}\index{test!subitem!subsubitem}.
\printindex
\end{document}
The call to makeindex
now needs to include -s
with the .ist
file created by the filecontents
environment. For example, if the document is called myDoc.tex
then:
pdflatex myDoc
makeindex -s myDoc.ist myDoc
pdflatex myDoc

The index defaults to 2 column format, which is why the dots don't span the entire page width. You may prefer to use imakeidx
instead of makeidx
to make it easier to customize.
\index{test}
in your document and omit the\include
instances. Alternatively, you can use thetestidx
package, which is designed for testing index styles:\documentclass{article}\usepackage{makeidx}\usepackage{testidx} \makeindex \begin{document} \testidx \printindex \end{document}
. That makes it easier to test and propose a solution.\index
to simply create a table of contents? Is there any particular reason why you're not just using\tableofcontents
?\tableofcontents
provides the desired behavior. I'll try it, and if you write it in the form of an answer I'll accept it ;) Thank you!