0

I'm defining this command for my index: \newcommand*{command}{\iffirstsubsubitem\unskip\firstsubsubitemfalse\ \else; \fi} and I'm wondering if there is a way to eliminate the white space it prints just before the semicolon.

I tried with \newcommand*{command}{\iffirstsubsubitem\unskip\firstsubsubitemfalse\ \else\kern{-1ex}; \fi}, but the result isn't good.

Here is the MWE:

\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[no-math]{fontspec}
\defaultfontfeatures{Ligatures={TeX, NoCommon}}

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

\usepackage{microtype}
\usepackage{imakeidx}
\usepackage{xparse}
\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=singlepar,font=footnotesize]{idxlayout}

\usepackage{xpatch}


\makeatletter
\def\@idxitem{\par\addvspace{10\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

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

\begin{document}


text

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

\autori{Author2!4,34}
\autori{Author3!6,12} 
\autori{Author3!9,4}
\
\printindex[4]

\end{document}
qwertxyz
  • 542
  • 1
    Please provide a minimal working example (MWE), otherwise it will be difficult to help you. There is no explicit space before the semicolon here. Maybe you are using \usepackage[french]{babel}, which might explain some things, but I can't find my good crystal ball, so... – frougon Apr 22 '20 at 23:34
  • Sorry, I added an MWE – qwertxyz Apr 22 '20 at 23:37
  • 1
    Sorry, but this doesn't appear to be minimal. – frougon Apr 22 '20 at 23:38
  • Without these information you can't see the result printed in the index I think – qwertxyz Apr 22 '20 at 23:39
  • It is possible that your problem is related to the index. Unfortunately, I'm not competent in this area, especially with imakeidx which I have never used. What I can say with certainty is that a space before the ; here isn't caused by the \iffirstsubitem ... \else ... \fi construct. Your code appears to define several macros twice (e.g., \subitem, \subsubitem). Why? – frougon Apr 22 '20 at 23:46
  • It modifies the layout of the index, see this question and the answer: https://tex.stackexchange.com/q/477447/41963 – qwertxyz Apr 22 '20 at 23:51
  • The answer there doesn't duplicate the definitions, AFAICS. Several of your \defs (at least 3) are completely useless due to the subsequent \renewcommands. – frougon Apr 22 '20 at 23:57
  • Without testing. This may not work, but is worth trying. Move the \unskip before the \iffirstsubitem. That \if... may insert bits that render the \unskip inoperative, and in any case, in its present position it doesn't apply to the \else condition, which is where the semicolon is inserted.. – barbara beeton Apr 23 '20 at 14:10
  • Thank you @barbarabeeton, it works perfectly! – qwertxyz Apr 23 '20 at 18:52

1 Answers1

2

In an attempt to separate your index entry references by semicolons you have defined the following:

\newcommand*{command}{\iffirstsubsubitem\unskip\firstsubsubitemfalse\ \else; \fi}

Let's take a careful look at this.

Presumably the entries, after sorting, have a space after the page number. You certainly don't want a space after a page number before the semicolon. So you have specified \unskip, which is headed in the right direction. However, you insert the \unskip after testing for the first reference ... and then you explicitly insert a space after the reference ("first subsubitem").

But the \iffirstsubsubitem undoubtedly does some things that effectively separate what precedes that \if... from the \unskip, so that \unskip may have no effect (not tested, so I'm not sure). However, whether or not the \unskip works there, you haven't done anything to remove the space that you wanted to obliterate before the semicolon. You could add another \unskip after the \else and before the semicolon, but there's a better way.

Simply move the \unskip to the beginning of the definition, before the \if..., giving this:

\newcommand*{command}{\unskip\iffirstsubsubitem\firstsubsubitemfalse\ \else; \fi}