1

hyphenation{} does not work in Index in the first line and in \texttt.

How can I switch it on?

How can we prevent new column when the hyphenation is switched on?

Only Index settings of hyphenation are preferable.

The problem is discussed on the base of the following MWE:

Remove (delete) unexpected new line when the word in index is long (hyphenation)

\documentclass{memoir}
\usepackage{imakeidx}
\usepackage{blindtext}
\makeindex[program=makeindex,
options=-s myindex.ist,
title={First},
name=first]


%https://tex.stackexchange.com/a/392783/44348
\usepackage{tempora} %TemporaLGCUni of Times type
\usepackage{newtxmath} %math font of Times type
% need to set the monospace=typewritter font
%https://tex.stackexchange.com/questions/213835/using-many-typewriter-fonts-in-a-single-document
\makeatletter %load fonts for cmtt
\providecommand{\EC@ttfamily}[5]{%
    \DeclareFontShape{#1}{#2}{#3}{#4}{
        <-8.5>#50800
        <8.5-9.5>#50900
        <9.5-10.5>#51000
        <10.5-11.5>#51095
        <11.5-13>#51200
        <13-15.5>#51440
        <15.5-18.5>#51728
        <18.5-22>#52074
        <22-27>#52488
        <27-32>#52986
        <32->#53583}{}}
\DeclareFontFamily{T2A}{cmtt}{\hyphenchar\font\m@ne}
\EC@ttfamily{T2A}{cmtt}{m}{n}{latt}
\EC@ttfamily{T2A}{cmtt}{m}{sl}{last}
\EC@ttfamily{T2A}{cmtt}{m}{it}{lait}
\EC@ttfamily{T2A}{cmtt}{m}{sc}{latc}
\DeclareFontShape{T2A}{cmtt}{bx}{n}%
{<->ssub*cmtt/m/n}{}
\DeclareFontShape{T2A}{cmtt}{bx}{it}%
{<->ssub*cmtt/m/it}{}
\makeatletter
\renewcommand{\ttdefault}{cmtt}


%       https://tex.stackexchange.com/a/132415/44348
\makeatletter
% we don't want a page break before a subitem
\renewcommand\subitem{\@idxitem\nobreak\hspace*{20\p@}}
\makeatother


%does not work 
%\hyphenation{foofoofoo-foofoofoo-foofoofoo-foofoofoofoofo-ofoofoofoo-foo}
\hyphenation{barbarbar-barbarbarbar-barbarbarbarbarbar-barbarbarbarbar}
\hyphenation{Diag-nos-tic-Tests-Sca-ling-And-In-fer-ring}




\begin{document}
Einstein\index[first]{Einstein\-EinsteinEinstein\-Einstein\-Einstein!NewLine}
Heisenberg\index[first]{Heisenberg} % Person index

\blindtext


barbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbar barbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbar
\blindtext[4]



Einstein\index[first]{Einstein\-EinsteinEinstein\-Einstein\-Einstein!NewLine}
\index[first]{foofoofoofoo\-foofoofoofoofoofoo\-foofoofoofoofoo\-foofoofoo}

\index[first]{barbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbar}

%       \index[first]{algorithm!barbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbar}

%\index[first]{barbarbar\-barbarbarbar\-barbarbarbarbarbar\-barbarbarbarbar}
\index[first]{algorithm!\texttt{DiagnosticTestsScalingAndInferring}} 

\blindtext


\printindex[first] 

\end{document}

PDF

enter image description here

UDT

Additional question "How to force word Newline after Einstein not to go to the next column?" can be solved using this answer https://tex.stackexchange.com/a/132415/44348

However with these commands "last" Einstein go to the new line.

  • Your NewLine is a subitem (because of the !). You want to prevent breaks between item and subitem. The answer is here: tex.stackexchange.com/a/132415/2388. And please don't ask two questions at once. – Ulrike Fischer Oct 4 '17 at 8:56
  • Your text doesn't hyphenate as it is in \texttt. See here about how to enable hyphenation with the typewriter font: tex.stackexchange.com/questions/204412/… – Ulrike Fischer Oct 4 '17 at 9:01
  • @UlrikeFischer, these questions are connected, because when we add code presented by @greg, local hyphenation force new line in the second column. There is no problem with \texttt, you can comment it if you wish. The problem with \hyphenation{barbar...} still take place. – Vladimir Parkhomenko Oct 4 '17 at 9:04
  • @UlrikeFischer, moreover \texttt works fine with local hyphenation \-. – Vladimir Parkhomenko Oct 4 '17 at 9:08
  • It doesn't matter if there are connected. It is confusing if the title of the question and the text are about different things. Your barbar doesn't hyphenate as it is the first word in a paragraph. – Ulrike Fischer Oct 4 '17 at 9:10
1

In order to hyphenate monospaced text, load the fonts without \hyphenchar\font=-1; in order to allow hyphenation in the first word, modify \@idxitem adding \hspace{0pt}\ignorespaces at the end.

\documentclass{memoir}
\usepackage[T2A,T1]{fontenc}
\usepackage{imakeidx}
\usepackage{blindtext}
\makeindex[program=makeindex,
%options=-s myindex.ist,
title={First},
name=first]


%https://tex.stackexchange.com/a/392783/44348
\usepackage{tempora} %TemporaLGCUni of Times type
\usepackage{newtxmath} %math font of Times type
% need to set the monospace=typewritter font
%https://tex.stackexchange.com/questions/213835/using-many-typewriter-fonts-in-a-single-document
\makeatletter %load fonts for cmtt
\providecommand{\EC@ttfamily}[5]{%
    \DeclareFontShape{#1}{#2}{#3}{#4}{
        <-8.5>#50800
        <8.5-9.5>#50900
        <9.5-10.5>#51000
        <10.5-11.5>#51095
        <11.5-13>#51200
        <13-15.5>#51440
        <15.5-18.5>#51728
        <18.5-22>#52074
        <22-27>#52488
        <27-32>#52986
        <32->#53583}{}}
\DeclareFontFamily{T1}{cmtt}{}
\DeclareFontFamily{T2A}{cmtt}{}
\EC@ttfamily{T1}{cmtt}{m}{n}{ectt}
\EC@ttfamily{T1}{cmtt}{m}{sl}{ecst}
\EC@ttfamily{T1}{cmtt}{m}{it}{ecit}
\EC@ttfamily{T1}{cmtt}{m}{sc}{ectc}
\DeclareFontShape{T1}{cmtt}{bx}{n}%
  {<->ssub*cmtt/m/n}{}
\DeclareFontShape{T1}{cmtt}{bx}{it}%
  {<->ssub*cmtt/m/it}{}
\EC@ttfamily{T2A}{cmtt}{m}{n}{latt}
\EC@ttfamily{T2A}{cmtt}{m}{sl}{last}
\EC@ttfamily{T2A}{cmtt}{m}{it}{lait}
\EC@ttfamily{T2A}{cmtt}{m}{sc}{latc}
\DeclareFontShape{T2A}{cmtt}{bx}{n}%
{<->ssub*cmtt/m/n}{}
\DeclareFontShape{T2A}{cmtt}{bx}{it}%
{<->ssub*cmtt/m/it}{}
\makeatletter
\renewcommand{\ttdefault}{cmtt}


%       https://tex.stackexchange.com/a/132415/44348
\makeatletter
% we want hyphenation also in the first word
\renewcommand{\@idxitem}{\par\hangindent40\p@\hspace{0pt}\ignorespaces}
% we don't want a page break before a subitem
\renewcommand\subitem{\@idxitem\nobreak\hspace*{20\p@}}
\makeatother


%does not work 
%\hyphenation{foofoofoo-foofoofoo-foofoofoo-foofoofoofoofo-ofoofoofoo-foo}
\hyphenation{barbarbar-barbarbarbar-barbarbarbarbarbar-barbarbarbarbar}
\hyphenation{Diag-nos-tic-Tests-Sca-ling-And-In-fer-ring}




\begin{document}
Einstein\index[first]{Einstein\-EinsteinEinstein\-Einstein\-Einstein!NewLine}
Heisenberg\index[first]{Heisenberg} % Person index

\blindtext


barbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbar barbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbar
\blindtext[4]



Einstein\index[first]{Einstein\-EinsteinEinstein\-Einstein\-Einstein!NewLine}
\index[first]{foofoofoofoo\-foofoofoofoofoofoo\-foofoofoofoofoo\-foofoofoo}

\index[first]{barbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbar}

%       \index[first]{algorithm!barbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbar}

%\index[first]{barbarbar\-barbarbarbar\-barbarbarbarbarbar\-barbarbarbarbar}
\index[first]{algorithm!\texttt{DiagnosticTestsScalingAndInferring}} 

\blindtext


\printindex[first] 

\end{document}

enter image description here

|improve this answer|||||
  • many thanks! Special gratitude for enabling T1 fonts! – Vladimir Parkhomenko Oct 5 '17 at 15:25

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.