hyphenation{}
在 Index 的第一行和 \texttt 中不起作用。
我怎样才能打开它?
new column
当连字功能打开时,我们该如何预防呢?
只有连字符的索引设置才是可取的。
基于以下MWE讨论了该问题:
\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}
自定义测试类型
附加问题“如何强制单词Newline
不Einstein
进入下一列?”可以使用此答案解决
https://tex.stackexchange.com/a/132415/44348
但是,使用这些命令“最后”Einstein
会转到新行。
答案1
为了给等宽文本连字,请加载不带\hyphenchar\font=-1
; 的字体。为了允许在第一个单词中使用连字,请修改末尾的\@idxitem
添加。\hspace{0pt}\ignorespaces
\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}