1

In a book-length document with memoir, I'm getting the following peculiar output from this code for the beginning of the index:

\renewcommand{\indexname}{Index}
\renewcommand{\preindexhook}{%
\emph{%
For $d$\emph{-ball},  $d$\emph{-bounded set}, $d$\emph{-open set},  $(d,d')$\emph{-continuous map}, 
etc., see the corresponding entry \emph{ball}, \emph{bounded set}, \emph{open set}, \emph{continuous map}, etc.%
\vskip\onelineskip}%
}
\printindex\cleardoublepage%

parens in \preindexhook arg changed to dims?

The surprise is not only that the left- and right-parentheses from $(d,d')$\emph{-continuous map} have disappeared, but also that they have been replaced by -.04em and -.15em, respectively.

The peculiar output occurs no matter whether I use pdflatex or xelatex (which, as the example below indicates, determines which fonts are used); thus the error occurs with both newtxtext/newtxmath and TeX Gyre Termes/Tex Gyre Termes Math.

Environment of the actual book:

I'm using MacTeX/TeXLive 2020, with all current updates applied.

Typically, I just run "Typeset" on the root source file topology.tex with engine pdflatexmk inside TeXShop.app. The effect should be the same as successively running:

pdflatex topology
bibtex topology
pdflatex topology
pdflatex topology
makeindex topology.nlo -s topology.ist -o topology.nls
makeindex names.idx -s names.ist -o names.ind
makeindex -s topology.ist topology
pdflatex topology
pdflatex topology

Here is the beginning of the .ind file for the book:

\begin{theindex}
\begingroup
  \medskip\hfill\large\sffamily\bfseries\ifthenelse{\boolean{colorsecs}}{\color{myseccolor}}{} A\hfill\endgroup\medskip\nopagebreak

\item \idxmark{absolute-value function}, \hyperpage{17}, \hyperpage{323} \item \idxmark{abstract quotient map}, \hyperpage{419}

Question: How can that be fixed?

Failed attempts to fix:

The following attempts failed to correct the issue:

  • \protecting each parenthesis
  • \usepackage{ragged2e) and changing \renewcommand{\preindexhook}{... to \renewcommand{\preindexhook}{\RaggedRight...
  • replacing ( and ), respectively, with \lparens and \rparens (from mathtools)
  • deleting \, from $(d,\,d')$

Simple example?

I'm unable to reproduce that output in any simple example short of the entire 600+-page book!

Below is such an example, where the output is OK, but with all the relevant code (I hope) and probably some totally irrelevant code (but included "just in case"):

% book.tex

\RequirePackage{filecontents} \begin{filecontents}{book.ist} % book.ist - MakeIndex style file % output main entry <entry> as: \item \idxmark{<entry>}, item_0 "\n\item \idxmark{" delim_0 "}, " % not forgetting the subitem case item_x1 "} \n \subitem " headings_flag 1 heading_prefix "{\medskip\hfill\large\textsf{\textbf{" heading_suffix "}}\hfill}\medskip\nopagebreak\n" \end{filecontents}

\documentclass{memoir}

\RequirePackage[T2A,T1]{fontenc} \RequirePackage{amsmath} % avoid \dddot clash \RequirePackage{mathtools} % load now to avoid unicode-math clash \RequirePackage{amsthm} % load now to avoid openbox clash \usepackage{iftex}

\ifTUTeX \usepackage{fontspec} \usepackage{polyglossia} \usepackage{unicode-math} \setdefaultlanguage[variant=american]{english} \setotherlanguages{french,german,polish,russian} \setmainfont{TeX Gyre Termes}[Scale=1.0] \defaultfontfeatures{Scale=MatchLowercase, Ligatures=TeX} \setmathfont{TeX Gyre Termes Math} \newfontfamily{\cyrillicfont}{PT Serif} \newcommand{\textsi}[1]{\textsc{#1}} \newfontfamily{\xcheckmarkfont}{LibertinusSerif-Regular.otf} \else \usepackage[russian,french,ngerman,polish,main=english]{babel} \babeltags{russian=russian,french=french,german=ngerman,polish=polish} \RequirePackage{substitutefont} % to allow non-default Cyrillic \substitutefont{T2A}{\rmdefault}{Tempora-TLF} % for Cyrillic \RequirePackage[theoremfont]{newtxtext} \RequirePackage[vvarbb]{newtxmath}% \fi

% Additional font series macros % light series \DeclareRobustCommand\ltseries {\not@math@alphabet\ltseries\relax \fontseries\ltdefault\selectfont} % \newcommand{\ltdefault}{l} % \DeclareTextFontCommand{\textlt}{\ltseries} % heavy(bold) series \DeclareRobustCommand\hbseries {\not@math@alphabet\hbseries\relax \fontseries\hbdefault\selectfont} \newcommand{\hbdefault}{hb} \DeclareTextFontCommand{\texthb}{\hbseries}

\usepackage{microtype} \usepackage{ragged2e}

%% PAGE DIMENSIONS \setstocksize{11in}{8.5in} \setpagecc{55.25pc}{38pc}{} \settypeblocksize{45pc}{28pc}{} \setlrmargins{}{}{} \setulmargins{}{}{} \checkandfixthelayout

%% PENALTIES % set \clubpenalty, etc. to distinctive values for use % in tracing page breaks. \clubpenalty=9996 \widowpenalty=9999 \brokenpenalty=4991 \predisplaypenalty=10000 \postdisplaypenalty=1549 \displaywidowpenalty=1602

\nouppercaseheads \makepagestyle{mypage} \makeheadrule{mypage}{\textwidth}{\normalrulethickness} \makeevenhead{mypage}{\bfseries\sffamily\thepage}{}{\bfseries\sffamily\leftmark} \makeoddhead{mypage}{\bfseries\sffamily\rightmark}{}{\bfseries\sffamily\thepage} \addtopsmarks{mypage}{}{% % insert "Chapter\space" & "Section\space" if desired as 4th argument: \createmark{chapter}{left}{shownumber}{}{\enspace} \createmark{section}{right}{shownumber}{}{\enspace} } \makepsmarks{mypage}{% \createmark{chapter}{both}{shownumber}{}{\enspace} % use both not left \createmark{section}{right}{shownumber}{}{\enspace} \createplainmark{toc}{both}{\contentsname} \createplainmark{shorttableofconents}{both}{\shorttocname} \createplainmark{longtableofcontents}{both}{\longtocname} \createplainmark{lof}{both}{\listfigurename} \createplainmark{lot}{both}{\listtablename} \createplainmark{bib}{both}{\bibname} \createplainmark{index}{both}{\indexname} \createplainmark{glossary}{both}{\glossaryname} \createplainmark{nomenclature}{both}{\nomname} } \providecommand\gobbleone[1]{} \newcommand{\idxmark}[1]{{\let\gobbleone\relax\markboth{\sffamily\bfseries#1}{\sffamily\bfseries#1}}#1} \makepagestyle{index} \makeheadrule{index}{\textwidth}{\normalrulethickness} % Fix for babel error by daleif (Lars Madsen} % https://tex.stackexchange.com/a/501483/13492 \makeevenhead{index}% {\let\gobbleone\relax\sffamily\bfseries\rightmark}% {\sffamily\bfseries\MakeTextUppercase{\indexname}}% {\let\gobbleone\relax\sffamily\bfseries\leftmark} \makeoddhead{index}% {\let\gobbleone\relax\sffamily\bfseries\rightmark}% {\sffamily\bfseries\MakeTextUppercase{\indexname}}% {\let\gobbleone\relax\sffamily\bfseries\leftmark} \makeevenfoot{index}{}{\sffamily\thepage}{} \makeoddfoot{index}{}{\sffamily\thepage}{}

\makechapterstyle{mychapter}{% \renewcommand{\chapnamefont}{\sffamily\bfseries} \renewcommand{\chapnumfont}{\fontsize{58}{64}\selectfont\sffamily\bfseries} \renewcommand{\chaptitlefont}{\Huge\sffamily\bfseries} % \settoheight{\midchapskip}{\chapnumfont 1} \setlength{\midchapskip}{0pt} \setlength{\afterchapskip}{48pt} % \renewcommand{\printchaptername}{% \chapnamefont\centering\MakeUppercase{@chapapp}\par} % \renewcommand*{\printchapternum}{% \vskip -8pt\centering \chapnumfont\thechapter} % or omit the vskip? % \renewcommand{\afterchapternum}{% \par\nobreak\vskip \midchapskip% \centering\rule{0.825\textwidth}{\normalrulethickness}% \newline} \renewcommand{\printchaptertitle}[1]{\centering\chaptitlefont ##1} } \chapterstyle{mychapter}

\usepackage{blindtext}

\makeindex

\begin{document}

\mainmatter

\pagestyle{mypage}

\Blindtext[1]

Alpaca\index{abc} Zebra\index{zombie}% to fill up index page... \index{a}\index{aa}\index{aaa}\index{aaaa}\index{aaaaa}\index{aaaaaa}\index{aaaaaaa}\index{aaaaaaaa} \index{b}\index{bb}\index{bbb}\index{bbbb}\index{bbbbb}\index{bbbbbb}\index{bbbbbbb}\index{bbbbbbbb} \index{c}\index{cc}\index{ccc}\index{cccc}\index{ccccc}\index{cccccc}\index{ccccccc}\index{cccccccc} \index{d}\index{dd}\index{ddd}\index{dddd}\index{ddddd}\index{dddddd}\index{ddddddd}\index{dddddddd} \index{e}\index{ee}\index{eee}\index{eeee}\index{eeeee}\index{eeeeee}\index{eeeeeee}\index{eeeeeeee} \index{f}\index{ff}\index{fff}\index{ffff}\index{fffff}\index{ffffff}\index{fffffff}\index{ffffffff} \index{g}\index{gg}\index{ggg} \index{abcdefghijklmnopqustuvwxyzabcdef} \index{zbcdefghijklmnopqustuvwxyzabcdef}

\backmatter

\pagestyle{index}

\setlength{\columnsep}{1em} \renewcommand{\indexname}{Index} \renewcommand{\preindexhook}{% \emph{% For $d$\emph{-ball}, $d$\emph{-bounded set}, $d$\emph{-open set}, $(d,,d')$\emph{-continuous map}, etc., see the corresponding entry \emph{ball}, \emph{bounded set}, \emph{open set}, \emph{continuous map}, etc.% \vskip\onelineskip}% } \printindex\cleardoublepage%

\end{document}

Added:

I also tried in the "simple example" above replacing the preamble by the actual preamble of my book-length document (actually, an inputted .tex file which contains a bunch of \usepackage commands for the several files constituting my preamble — a total of 16 files with some 120K). But still that does not cause the peculiar problem!

Possible work-around:

The following work-around seems to cure the problem. But I'm unhappy about the way that I had to fake the pair of parentheses, which really ought to be inside the inline math!

\renewcommand{\preindexhook}{%
\emph{%
For $d$\emph{-ball},  $d$\emph{-bounded set}, $d$\emph{-open set}, \emph{(}$d,d'$\emph{)\hspace{2pt}-continuous map}, 
etc., 
see the corresponding entry \emph{ball}, \emph{bounded set}, \emph{open set}, \emph{continuous map}, etc.%
\vskip\onelineskip}%
}
murray
  • 7,944
  • Sorry, but if the problem is not reproduced by the example, how can anybody fix it? – egreg Jul 17 '20 at 21:08
  • @egreg: It would surely be impossible (at least, inadvisable) to post 18K bytes of code here. I'm hoping that somebody will have a clue for me to pursue. – murray Jul 17 '20 at 21:09
  • If you have not made modifications to theindex, memoir just places the contents of \preindexhook, without any special processing, after the chapter title. What are the first lines of the .ind file? – egreg Jul 17 '20 at 21:17
  • @egreg: I added to my post the first several lines of the .ind file. – murray Jul 17 '20 at 21:43
  • Sorry, no clue. – egreg Jul 17 '20 at 21:50
  • Well it is easy to force your output -- one only has to make the parens active and define them -- but to be able to say which part of your code is doing something similar, one need the actual code for inspection. – Ulrike Fischer Jul 21 '20 at 21:58
  • That \lparen/\rparen doesn't work makes me skeptical of the possibility of an active paren issue, especially since, presumably, parentheses elsewhere in the document are fine. You could, just to be sure, include \message{\the\catcode(}` in the preindexhook to make sure you have a catcode of 12, I'm wondering if something is messed up in the font specifications somehow. – Don Hosek Jul 22 '20 at 04:12
  • (my \message code above fell pray to limitations of markdown. There should be a backtick before the (. – Don Hosek Jul 22 '20 at 04:51
  • Exactly what latex installation are you using? As long as you cannot provide anything that can reproduce the problem then we cannot help. As egreg mentions memoir just adds a \chapter*{\indexname} followed by the (possibly empty) \reindexhook and then the index it self it does notthing special to it. – daleif Jul 22 '20 at 17:34
  • If your entire project fits in a decent sized zip, feel free to send it to my obvious @gmail.com email address – daleif Jul 22 '20 at 18:16
  • @daleif: Whole thing zips to 5MB. I just sent it to you. Thanks for offering to look at it! – murray Jul 22 '20 at 21:57
  • Received, currently going to sleep, I'll see if I can get it to compile tomorrow. Would you please update your question with info about which latex installation you're using – daleif Jul 22 '20 at 22:01

2 Answers2

5

It is a bug in embrac, in one place it uses #4 instead of #3. Try this and notify the author:

\usepackage{embrac}
\ExplSyntaxOn
\cs_set_protected:Npn \__embrac_replace:Nnnnn #1#2#3#4#5
  {
    \tl_replace_all:Nnn #1 {#3}
      {
        \mode_if_math:TF
          {#3} %<---instead of #4
          {
            \embrac_nobreak:
            \embrac_kern:n {#2}
            \embrac_nobreak:
            \embrac_braces_format:n {#3}
            \embrac_nobreak:
            \embrac_kern:n {#4}
            #5
          }
      }
  }
\ExplSyntaxOff
Ulrike Fischer
  • 327,261
3

This is not an answer to the problem, but rather a short write up of the actual problem. It is not related to memoir or \preindexhook, it boils down to a problem with the embrac package that @murray loads deep deep down in their many setup files.

Here is a super short MWE that displays the problem.

\documentclass{article}
\usepackage{embrac}
\begin{document}
\emph{$(d,d')$}
\end{document}

On my fully up to date TeXLive 2020 I get

enter image description here

which is strange as the embrac history mentions that v0.5 was made to not mess with math. But perhaps expl3 was changed.

*File List*
 article.cls    2019/12/20 v1.4l Standard LaTeX document class
  size10.clo    2019/12/20 v1.4l Standard LaTeX file (size option)
  embrac.sty    2019/12/31 v0.9 Upright Brackets in Emphasized Text
   expl3.sty    2020-07-17 L3 programming layer (loader) 
l3backend-pdfmode.def    2020-06-29 L3 backend support: PDF mode
  xparse.sty    2020-05-15 L3 Experimental document command parser
xparse-generic.tex
l3keys2e.sty    2020-05-15 LaTeX2e option processing using LaTeX3 keys
daleif
  • 54,450
  • Given that excellent detective work, I can make a fix at least for the particular instance of the embrac package's messing with math: inside \preindexhook, turn embracs treatment off temporarily with \EmbracOff and turn it back on at the end with \EmbracOn. (So far, I have not yet spotted any ill effects from embrac in theorem statements, but if I find them, I know how to circumvent embrac there and use \textup(, etc.) – murray Jul 23 '20 at 14:26
  • @murray use Ulrike solution, then no fixes should be needed. We could have fixed this a lot sooner if you had providedxa list of the packages you use in the full project. Adding \listfiles before \documentclass will add a list of the used packages to the log – daleif Jul 23 '20 at 14:29
  • Sorry about making this more difficult than it needed to be. I've now cleaned up the files loaded in the preamble so as to eliminate duplication and to align the documentation with the actual packages used. – murray Jul 23 '20 at 15:31