1

In another question I asked how to get custom delimiters with the idxlayout package using the singlepar option: I would ask if it is possible to mantain the same delimiters with the option abshang, printing only the last level of each entry formatted in a single paragraph.

For example:

    \index{Author!Work1!1,15} 
    \index{Author!Work1!9,32}
    \index{Author!Work2!2,24} 
    \index{Author!Work2!5,11}

    \index{Author2!2,45} 
    \index{Author2!4,34}
    \index{Author2!6,12} 
    \index{Author2!9,4}

should give this:

my desired output

Here is an MWE:

\documentclass{article}

\usepackage{fontspec}
\setmainfont{times.ttf}
\usepackage{imakeidx}
\usepackage{polyglossia}

\begin{filecontents*}{colon.ist}
delim_0 ": "
delim_1 ": "
delim_2 ": "
\end{filecontents*}

\usepackage[itemlayout=abshang]{idxlayout}

\makeatletter
\def\@idxitem{\par\addvspace{5\p@ \@plus 5\p@ \@minus 3\p@}\hangindent 40\p@}
\def\subitem{\par\hangindent 40\p@ \hspace*{20\p@}}
\def\subsubitem{\par\hangindent 40\p@ \hspace*{30\p@}}
\def\indexspace{}
\patchcmd\theindex{\indexname}{\indexname\vspace{12pt}}{}{}
\makeatother

\makeatletter
\newif\iffirstsubitem
\newif\iffirstsubsubitem
\renewcommand{\indexsubsdelim}{ }
\newcommand*{\indexsubsdelimb}{\iffirstsubsubitem\unskip\firstsubsubitemfalse\ \else --- \fi}
\renewcommand{\subitem}{\iffirstsubitem\unskip\firstsubitemfalse, \else --- \fi\firstsubsubitemtrue}%
\renewcommand{\subsubitem}{\indexsubsdelimb}%
\renewcommand{\@idxitem}{\par\setlength{\hangindent}{\ila@hangindent}\firstsubitemtrue}
\makeatother

\makeindex[options=-s colon]

\begin{document}

test

\index{Author!Work1!1,11} 
\index{Author!Work1!9,31}
\index{Author!Work2!2,21} 
\index{Author!Work2!5,12}
\index{Author!Work1!1,11} 
\index{Author!Work1!9,34}
\index{Author!Work2!2,22} 
\index{Author!Work2!5,15}
\index{Author!Work1!1,17} 
\index{Author!Work1!9,38}
\index{Author!Work2!2,27} 
\index{Author!Work2!5,14}

\index{Author2!2,45} 
\index{Author2!4,34}
\index{Author2!6,12} 
\index{Author2!9,4}
\index{Author2!2,41} 
\index{Author2!4,32}
\index{Author2!6,13} 
\index{Author2!9,5}
\index{Author2!2,46} 
\index{Author2!4,37}
\index{Author2!6,18} 
\index{Author2!9,9}

\printindex

\end{document}

Thank you!

EDIT: by removing this line \renewcommand{\subitem}{\iffirstsubitem\unskip\firstsubitemfalse, \else --- \fi\firstsubsubitemtrue}% I obtained the desired output for the index with two sublevel, but the index with one sublevel stacks vertically (see the image).

enter image description here

For egreg: here is the file I'm trying to compile, with your code integrated.

\begin{filecontents*}{\jobname.mst}
item_0 "\n\n \\item "
item_1 " \\firstlevel "
item_2 " \\secondlevel "
item_01 " \\firstlevel "
item_x1 " \\firstlevel "
item_12 " \\secondlevel "
item_x2 " \\secondlevel "
delim_0 ":~"
delim_1 ":~"
delim_2 ":~"
\end{filecontents*}

\documentclass[a4paper, 11pt, twoside, openright]{article}

\usepackage[top=49.5mm,bottom=52.5mm,inner=39mm,outer=39mm, headheight=4mm, headsep=6mm, marginparwidth=14mm, marginparsep=2mm, nofoot]{geometry}

\usepackage[en]{metre}
\usepackage{metrix}

\usepackage{alphalph}

\usepackage[no-math]{fontspec}
\defaultfontfeatures{Ligatures={TeX, NoCommon}}
\setmainfont[SmallCapsFont=Kallimachos_SC.ttf, BoldFont=Kallimachos_Bold,ItalicFont=Kallimachos_Italic]{Leptos.ttf}
\newfontfamily\greekfont[Script=Greek]{Leptos.ttf}

\newcommand{\lts}[1]{{\addfontfeature{LetterSpace=15 plus 1 minus 1}#1}}
\newcommand{\ltsb}[1]{{\addfontfeature{LetterSpace=12 plus 1 minus 1}#1}}
\newcommand{\ltsc}[1]{{\addfontfeature{LetterSpace=10 plus 1 minus 1}#1}}
\newcommand{\grk}[1]{{\selectlanguage[variant=ancient]{greek}#1}}

\usepackage{polyglossia}
\setmainlanguage{italian}
\setotherlanguage[variant=ancient]{greek}
\setotherlanguage{german}
\setotherlanguage{english}
\setotherlanguage{latin}

\usepackage{xunicode,xltxtra}

\usepackage[figuresright]{rotating} % comando \begin{sidewaysfigure}

\usepackage{xpatch}

\usepackage{microtype}
\usepackage{comment}

\usepackage{url}
\urlstyle{rm}

\usepackage{tikz}
\usepackage{array}
\usepackage{scrextend}

\usepackage{ragged2e} 
\usepackage{hyphenat}
\usepackage{hanging} 
\usepackage{rotating}
\usepackage{lscape}
\usepackage[thinlines]{easytable}
\usepackage{makecell}
\usepackage{tabu} 
\usepackage{float}
\usepackage[export]{adjustbox}
\usepackage{caption}
\usepackage{stackrel}   
\usepackage{amsmath}
\usepackage{afterpage}

\newcommand\blankpage{%
    \null
    \thispagestyle{empty}%
    \addtocounter{page}{-1}%
    \newpage}



\usepackage{imakeidx}
\usepackage{xparse}
%\usepackage[itemlayout=singlepar]{idxlayout}

\ExplSyntaxOn
\seq_new:N \l_ale_index_item_seq
\seq_new:N \l_ale_index_subitem_seq
\tl_new:N \l_ale_index_author_tl
\tl_new:N \l_ale_index_work_tl
\dim_new:N \l_ale_index_indent_dim

\cs_set_protected:cpn { @idxitem } #1 \par
 {
  \tl_if_in:nnTF { #1 } { \firstlevel }
   {
    \tl_if_in:nnTF { #1 } { \secondlevel }
     {
      \ale_index_secondlevel:n { #1 }
     }
     {
      \ale_index_firstlevel:n { #1 }
     }
   }
   {
    \ale_index_nolevel:n { #1 }
   }
 }

\cs_new_protected:Npn \ale_index_nolevel:n #1
 {
  \seq_set_split:NVn \l_ale_index_item_seq \c_colon_str { #1 }
  \seq_pop_left:NN \l_ale_index_item_seq \l_ale_index_author_tl
  \hbox_set:Nn \l_tmpa_box { \l_ale_index_author_tl, }
  \dim_set:Nn \l_ale_index_indent_dim { \box_wd:N \l_tmpa_box }
  \par\hangindent\l_ale_index_indent_dim
  \l_ale_index_author_tl, \seq_use:Nn \l_ale_index_item_seq { }
 }
\cs_generate_variant:Nn \seq_set_split:Nnn { NV }

\cs_new_protected:Npn \ale_index_secondlevel:n #1
 {
  \seq_set_split:Nnn \l_ale_index_item_seq { \firstlevel } { #1 }
  \seq_pop_left:NN \l_ale_index_item_seq \l_ale_index_author_tl
  \l_ale_index_author_tl\par\nobreak
  \seq_map_function:NN \l_ale_index_item_seq \ale_index_subitem:n
 }
\cs_new_protected:Npn \ale_index_subitem:n #1
 {
  \seq_set_split:Nnn \l_ale_index_subitem_seq { \secondlevel } { #1 }
  \seq_pop_left:NN \l_ale_index_subitem_seq \l_ale_index_work_tl
  \hbox_set:Nn \l_tmpa_box { \qquad \l_ale_index_work_tl,~ }
  \dim_set:Nn \l_ale_index_indent_dim { \box_wd:N \l_tmpa_box }
  \par\hangindent\l_ale_index_indent_dim
  \qquad\l_ale_index_work_tl,~\seq_use:Nn \l_ale_index_subitem_seq { ~---~ }
 }

\cs_new_protected:Npn \ale_index_firstlevel:n #1
 {
  \seq_set_split:Nnn \l_ale_index_item_seq { \firstlevel } { #1 }
  \seq_pop_left:NN \l_ale_index_item_seq \l_ale_index_author_tl
  \hbox_set:Nn \l_tmpa_box { \l_ale_index_author_tl,~ }
  \dim_set:Nn \l_ale_index_indent_dim { \box_wd:N \l_tmpa_box }
  \par\hangindent\l_ale_index_indent_dim
  \l_ale_index_author_tl,~\seq_use:Nn \l_ale_index_item_seq { ~---~ }
 }


\ExplSyntaxOff

\makeindex[name=1,title=,options=-s Intero.ist]
\makeindex[name=2,title=,options=-s Intero.ist]
\makeindex[name=3,title=,options=-s Intero.ist]
\makeindex[name=4,title=,options=-s Intero.ist]
%\usepackage[itemlayout=abshang]{idxlayout}


\autorisetup{level=\subsection*,toclevel=\subsection*,noclearpage,firstpagestyle=fancy}


\newcommand*{\cose}[1]{\index[1]{#1}\ignorespaces}

\newcommand*{\parole}[1]{\index[2]{#1}\ignorespaces}

\newcommand*{\autori}[1]{\index[4]{#1}\ignorespaces}

\newcommand{\nn}[2]{#1 \textit{nt. }#1}
\newcommand{\nv}[2]{#1 \textit{nt. }#1,}
\newcommand{\qt}[1]{\textbf{#1}}

\newcommand{\pageandfn}[2]{#2 n. #1}  
\newcommand{\autorifn}[1]{\autori[1]{#1|pageandfn{\thefootnote}}}    


\usepackage[noend,noeledsec,nocritical,nofamiliar,noledgroup]{reledmac}
\usepackage[continuousnumberingwithcolumns]{reledpar}

\linenumberLevenifblanktrue

\setlength{\Lcolwidth}{0.45\textwidth}
\setlength{\Rcolwidth}{0.45\textwidth}
\columnsposition{c}
\setlength{\beforecolumnseparator}{0.05\textwidth}
\setlength{\aftercolumnseparator}{0.05\textwidth}


\usepackage{parcolumns}

\makeatletter
\newbox\mybox
\def\pcol@makenormalcol{%
  \ifvoid\footins 
  \else
\global\setbox\mybox\box\footins
   \fi
\setbox\@outputbox\box\@holdpg
  \let\@elt\relax
  \xdef\@freelist{\@freelist\@midlist}%
  \global\let\@midlist\@empty
  \@combinefloats}

\makeatother

\begin{document}


\autori{Author!Work1!1,15} 
\autori{Author!Work1!9,32}
\autori{Author!Work2!2,24} 
\autori{Author!Work2!5,11}
\autori{Author!Work1!11,42}

\autori{Author2!2,45} 
\autori{Author2!4,34}
\autori{Author2!6,12} 
\autori{Author2!9,4}
\autori{Author3}

\printindex[1]

\end{document}

1 Answer 1

2
+25

A very different implementation:

\begin{filecontents*}{\jobname.mst}
item_0 "\n\n \\item "
item_1 " \\firstlevel "
item_2 " \\secondlevel "
item_01 " \\firstlevel "
item_x1 " \\firstlevel "
item_12 " \\secondlevel "
item_x2 " \\secondlevel "
delim_0 ":~"
delim_1 ":~"
delim_2 ":~"
\end{filecontents*}
\documentclass{article}
\usepackage{lipsum}
\usepackage{imakeidx}
\usepackage{xparse}
%\usepackage[itemlayout=singlepar]{idxlayout}

\ExplSyntaxOn
\seq_new:N \l_ale_index_item_seq
\seq_new:N \l_ale_index_subitem_seq
\tl_new:N \l_ale_index_author_tl
\tl_new:N \l_ale_index_work_tl
\dim_new:N \l_ale_index_indent_dim

\cs_set_protected:cpn { @idxitem } #1 \par
 {
  \tl_if_in:nnTF { #1 } { \firstlevel }
   {
    \tl_if_in:nnTF { #1 } { \secondlevel }
     {
      \ale_index_secondlevel:n { #1 }
     }
     {
      \ale_index_firstlevel:n { #1 }
     }
   }
   {
    \ale_index_nolevel:n { #1 }
   }
 }

\cs_new_protected:Npn \ale_index_nolevel:n #1
 {
  \seq_set_split:NVn \l_ale_index_item_seq \c_colon_str { #1 }
  \seq_pop_left:NN \l_ale_index_item_seq \l_ale_index_author_tl
  \hbox_set:Nn \l_tmpa_box { \l_ale_index_author_tl, }
  \dim_set:Nn \l_ale_index_indent_dim { \box_wd:N \l_tmpa_box }
  \par\hangindent\l_ale_index_indent_dim
  \l_ale_index_author_tl, \seq_use:Nn \l_ale_index_item_seq { }
 }
\cs_generate_variant:Nn \seq_set_split:Nnn { NV }

\cs_new_protected:Npn \ale_index_secondlevel:n #1
 {
  \seq_set_split:Nnn \l_ale_index_item_seq { \firstlevel } { #1 }
  \seq_pop_left:NN \l_ale_index_item_seq \l_ale_index_author_tl
  \l_ale_index_author_tl\par\nobreak
  \seq_map_function:NN \l_ale_index_item_seq \ale_index_subitem:n
 }
\cs_new_protected:Npn \ale_index_subitem:n #1
 {
  \seq_set_split:Nnn \l_ale_index_subitem_seq { \secondlevel } { #1 }
  \seq_pop_left:NN \l_ale_index_subitem_seq \l_ale_index_work_tl
  \hbox_set:Nn \l_tmpa_box { \qquad \l_ale_index_work_tl,~ }
  \dim_set:Nn \l_ale_index_indent_dim { \box_wd:N \l_tmpa_box }
  \par\hangindent\l_ale_index_indent_dim
  \qquad\l_ale_index_work_tl,~\seq_use:Nn \l_ale_index_subitem_seq { ~---~ }
 }

\cs_new_protected:Npn \ale_index_firstlevel:n #1
 {
  \seq_set_split:Nnn \l_ale_index_item_seq { \firstlevel } { #1 }
  \seq_pop_left:NN \l_ale_index_item_seq \l_ale_index_author_tl
  \hbox_set:Nn \l_tmpa_box { \l_ale_index_author_tl,~ }
  \dim_set:Nn \l_ale_index_indent_dim { \box_wd:N \l_tmpa_box }
  \par\hangindent\l_ale_index_indent_dim
  \l_ale_index_author_tl,~\seq_use:Nn \l_ale_index_item_seq { ~---~ }
 }


\ExplSyntaxOff

\makeindex

\begin{document}
\lipsum[1]

\index{Author!Work1!1,15} 
\index{Author!Work1!9,32}
\index{Author!Work2!2,24} 
\index{Author!Work2!5,11}
\index{Author!Work1!11,42}

\index{Author2!2,45} 
\index{Author2!4,34}
\index{Author2!6,12} 
\index{Author2!9,4}
\index{Author3}

\newpage
text
\index{Author3}

\printindex
\end{document}

The .ind file will be more structured and the structure is used to split into cases: no subitem, one level subitems, two level subitems.

enter image description here

11
  • Thank you very much for your impressive answer. I'm trying to integrate the code in my file, but it gives me many errors when I try to compile. I'm updating the post in order to show you the exact file I'm trying to compile.
    – qwertxyz
    Apr 9, 2020 at 18:38
  • The errors are: Argument of \@idxitem has an extra } and Argument of \@idxitem has an extra }.
    – qwertxyz
    Apr 9, 2020 at 20:38
  • 1
    @ALE Of course you should not use option=-s Intero.ist
    – egreg
    Apr 9, 2020 at 20:39
  • I already tried to write only \makeindex[name=4,title=] and nonetheless it gives me the errors
    – qwertxyz
    Apr 9, 2020 at 20:41
  • @ALE Sorry, it should be options=-s \jobname.mst. On the other hand, you didn't specify you have different indices with different specifications.
    – egreg
    Apr 9, 2020 at 20:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .