我已经知道该怎么做了建立第二个索引,我找到了关于如何在索引中包含章节编号,我找到了关于如何以不同方式标记不同的索引,但我不知道如何将这三者结合起来。
我想要得到的是一个“默认”索引,它只是执行完全正常的imakeidx
开箱即用功能,还有一个第二个索引,它按文档结构而不是页码进行索引(在我的例子中,具体是项目\subsection
所在的位置,或者更好的是;我在部分顶部设置的自定义字符串)。如果有任何不同,索引中的项目将在文档中交错。
因为有人要求做 MWE,所以我从前两个问题中挑选出看起来可能有用、我甚至有点理解的东西,然后将它们复制粘贴在一起。我不明白第三个问题的作用,甚至不理解是否应该尝试将其合并进去,但我认为它只是做了一些不太相关的事情?
我没有理由期望这里与索引相关的任何内容都是合理的方法……或者不是。所以请不要执着于修复下面的任何内容,问题是多于这是我正在尝试解决的问题。
\documentclass[12pt]{article}
\usepackage{imakeidx}
\makeatletter
\renewcommand{\imki@wrindexentrysplit}[3]{%
\expandafter\protected@write\csname#1@idxfile\endcsname{}%
{\string\indexentry{#2}{s\arabic{section},p\thepage}}%
}
\makeatother
\makeindex
\makeindex[name=X,title={X Index}]
\begin{document}
Something to make the page and section different
\clearpage
\section{Foo} \index{foo} \index[X]{foo-x}
...
\clearpage
\section{Bar} \index{bar} \index[X]{bar-x}
...
\clearpage
\printindex
\printindex[X]
\end{document}
这样就产生了两个同时显示两种类型信息指标。
我希望一个索引只显示一个,另一个索引只显示另一个。
指数
酒吧 p3 foo p2
X 索引
bar-x s2 foo-x s1
几乎走到了工作死胡同
下面的做法恰好能生成我想要的排版结果(但无法在 PDF 中生成正确的链接),但这样做的方式从根本上是有缺陷的:它依赖于作者从不以正常方式行事。我看不出如何通过这种方法消除这个问题。
\documentclass[12pt]{article}
\usepackage{imakeidx}
\makeindex
\makeindex[name=X,title={X Index}]
\begin{document}
\makeatletter
\newcommand{\myIndex}[1]{{
\renewcommand{\imki@wrindexentrysplit}[3]{%
\expandafter\protected@write\csname##1@idxfile\endcsname{}%
{\string\indexentry{##2}{S\arabic{section}}}%
}
\index[X]{#1}
}}
\makeatother
Something to make the page and section different
\clearpage
\section{Foo} \index{foo} \myIndex{foo-x}
...
\clearpage
\section{Bar} \index{bar} \myIndex{bar-x}
...
\clearpage
\printindex
\printindex[X]
\end{document}
答案1
在本地而不是全局重新定义索引输出命令,以便它输出您提供的任何内容\thepage
,而所有其他索引不受影响。
组合参考:
简单引用
或者,更有帮助的是:
或者甚至可能是混合层次结构:
这里我们使用imakeidx
和xindy
,并使用 shell-escape 运行。
任何以结构形式输出的内容(例如s\thesection
)都需要定义一个匹配的 Xindy 格式解析器(Xindy 称之为define-location-class
),以便 Xindy 能够对其进行解释(例如映射到:字母、空分隔符、阿拉伯/罗马数字)。
平均能量损失
%---
\begin{filecontents*}[overwrite]{mal-style.xdy}
;;; Load a predefined style:
;(require "makeindex.xdy")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define-attributes ("squarebr"))
(markup-attribute-group-list :sep "; ")
(markup-locref
:attr "squarebr"
:open "[\colorbox{yellow!40}{\hyperpage{"
:close "}}]")
;(markup-locref :class "page-numbers" :attr "definition"
; :open "{\bf " :close "}")
;(markup-locref :class "page-numbers" :attr "definition"
; :open "\textbf{" :close "}")
;(define-letter-groups
; ("a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m"
; "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z"))
;
;(markup-letter-group-list :sep "~n\indexspace")
;(define-letter-group "ly" :after "l" :before "m")
;(define-letter-group "ny" :after "n" :before "o")
;
;(markup-letter-group :open-head "~n {\bf " :close-head "}"
; :capitalize)
;(define-location-class "appendices"
; ("ALPHA" :sep "-" "arabic-numbers")
; :hierdepth 2)
;(markup-locref-list :sep "; " :depth 0 :class "appendices")
;(markup-locref-list :open "~~" :sep ", " :depth 1 :class "appendices")
;(define-alphabet "bible-chapters"
; ("Genesis" "Exodus" "Leviticus" "Numbers" "Deuteronomy"
; ... ))
;(define-location-class "bible-verses"
; ("bible-chapters" :sep " " "arabic-numbers" :sep "," "arabic-numbers"))
; (define-letter-groups (""))
;(define-letter-group "z")
(markup-locclass-list :open ": ")
(define-letter-group "Α" ; Greek alpha
:prefixes ("α");\x0391")
:after "Z"
)
;(define-letter-groups ("Num" "Dtn" "Ps"))
;(define-letter-group "Greek"
; :prefixes ("α" "ω")
; :after "Z")
;%(markup-letter-group [:open string] [:close string] [:group group-name]
;% [:open-head string] [:close-head string]
;% [:upcase | :downcase | :capitalize])
;%
; \\begingroup
; \\setlength{\\fboxsep}{5pt}%
; \\colorbox{blue}{%
; \\color{white}\\large\\sffamily\\bfseries
; \\hbox to \\dimexpr\\linewidth-2\\fboxsep{%
; \\hfill
(markup-letter-group
:open-head "~n {\setlength{\fboxsep}{5pt}\sffamily\bfseries\large\colorbox{blue!30}{\textcolor{yellow!90!red!5}{\hbox to \dimexpr\linewidth-2\fboxsep{
\hfill " ; space is needed
:close-head "\hfill}}\nopagebreak\vspace{2mm}}}"
)
;(markup-letter-group
; :open-head "~n {\sffamily\bfseries\colorbox{blue};;;;{\textcolor{yellow}{"
; :close-head "}}}"
; )
(markup-locclass-list :open "\dotfill" :sep "")
(define-attributes (("texttt" "textsc" "myown")) )
(markup-locref :attr "textbf" :open "\textbf{\hyperpage{" :close "}}")
(markup-locref :attr "textit" :open "\textit{\hyperpage{" :close "}}")
(markup-locref :attr "texttt" :open "\texttt{\hyperpage{" :close "}}")
(markup-locref :attr "textsc" :open "\textsc{\hyperpage{" :close "}}")
(markup-locref :attr "myown" :open "\myown{\hyperpage{" :close "}}")
(markup-locref :attr "hyperpage" :open "\hyperpage{" :close "}")
(markup-locref :attr "default" :open "\hyperpage{" :close "}")
(merge-rule "n" "X" :again)
\end{filecontents*}
%---
\begin{filecontents*}[overwrite]{general-aindex.xdy}
(define-alphabet "secalpha" ("s" "p"))
(define-location-class "section-index" :var
("secalpha"
:sep ""
"arabic-numbers"
:sep "-"
"secalpha" :sep ""
"arabic-numbers" :sep ", "
))
(markup-locclass-list :open "\dotfill " :sep ", " :close "")
(define-attributes (("sectionmark" "sectionmarky")) )
(markup-locref
:attr "sectionmark"
:open "\textbf{\S}"
:close "")
(markup-locref
:attr "sectionmarky"
:open "\colorbox{yellow}{\textbf{\S}"
:close "}")
\end{filecontents*}
\documentclass{article}
\usepackage{xcolor}
\usepackage{fontspec}
\setmainfont{Noto Serif}
\usepackage[hyperindex=false,colorlinks]{hyperref}
%\usepackage{splitidx}
\usepackage{imakeidx}
\usepackage{xparse}
\ExplSyntaxOn
\makeatletter
\NewDocumentCommand { \generalindex } { o m m } {
\IfValueTF {#1}
{
{
% Local redefinition of indexentry to #3 instead of page%
\renewcommand{\imki@wrindexentrysplit}[3]{%
\expandafter\protected@write\csname##1@idxfile\endcsname{}%
{\string\indexentry{##2}{#3}}%
}%
\index[#1]{#2}
}
}
{ }
}
\makeatother
\NewDocumentCommand { \indexsec } { m } {
\generalindex[sec]{#1}{s\thesection-p\thepage}
}
\NewDocumentCommand { \indexsecb } { m } {
\generalindex[secb]{#1}{\thesection}
}
\NewDocumentCommand { \indexsecc } { m } {
\generalindex[secc]{#1|sectionmark}{\thesection}
}
\NewDocumentCommand { \genindex } { m m m } {
\generalindex[#1]{#2}{#3}
}
\ExplSyntaxOff
\makeindex[title=Xindy--demo,
program=texindy,
options=
-M mal-style.xdy
-C utf8
-t secondary.ilg
,
columnseprule,
]
\makeindex[name=s,title=Statutes,
program=texindy,
options=
-M mal-style.xdy
-C utf8
,
columnseprule,
]
\makeindex[name=sec,
title={IndexA Xindy {\small\\ by section}},
program=texindy,
options=-M general-aindex.xdy
-C utf8
-t \jobname aidx.ilg
,
]
\makeindex[name=secb,
title={IndexB Xindy {\small\\ by section only}},
program=texindy,
options=-M general-aindex.xdy
-C utf8
-t secb.ilg
,
]
\makeindex[name=secc,
title={IndexC Xindy {\small\\ by section, with section-mark applied}},
program=texindy,
options=-M general-aindex.xdy
-C utf8
-t secc.ilg
,
]
\makeindex[name=secd,
title={IndexD Xindy {\small\\ mixture of reference types}},
program=texindy,
options=-M general-aindex.xdy
-C utf8
-t secd.ilg
,
columns=1,
]
%=====
\newcommand{\secindex}[1]{\textbf{#1}\indexsec{#1}}
\newcommand{\secbindex}[1]{\indexsecb{#1}}
\newcommand{\seccindex}[1]{\indexsecc{#1}}
\newcommand\yellowcommand[1]{{\sffamily\textbf{#1}}}
\begin{document}
% from tex.se:
\def\myshift#1{\makebox[0pt][r]{\texttt{--}}\texttt{#1}}
\def\myown#1{{\Huge#1}}
\def\mycommand#1{{\color{green}#1}}
\def\mydef#1{\texttt{\makebox[0pt][r]{\char"5C}#1}}
\def\mymath#1{{\color{blue}$#1$}}
\def\myfavorite#1{{\color{cyan}\makebox[0pt][r]{I $\heartsuit$\ }{\color{cyan}#1}}}
\section{My section}\label{mysection}
I refer to my section~\ref{mysection}.
Start. Nunc ligula faucibus\index{xindy|textbf}.
\newpage
\index{vector@Vector}
\index{runme@\mycommand{runme}}
\newpage
\index{asquared@\mymath{a^2}}
\index{bsquared@\mymath{b^2}}
\newpage
x
\newpage
\index{csquared@\mymath{c^2}}
\index{roof|myown}
\newpage
\index{mal@\myshift{mal}}
\index{nature@\textbf{Nature}}
\newpage
\index{home!my own 1}
\index{home!my own 2}
\newpage
\index{definition@\mydef{definition}}
\index{Velocity}
Nullarutrum porttitor...
\newpage
\index{alcohol}\index{beauty}\index{älf}\index{zero}
\newpage
x\index{vectors@\myfavorite{vectors}}
x\index{roof|myown}
\newpage
x\index{roof}
% additions:
x\index{αβγ}
\newpage
x\index{10.2.250.1}
x\index{10.12.250.12}
\newpage
x\index{60.12.250.12}
x\index{128.12.250.12}
\newpage
x\index{128.12.250.12}
x\index[s]{s 7}x\index[s]{s 7B}x\index[s]{s 50}x\index[s]{s 5}x\index[s]{s 3(2)(a)}
\newpage
x\index[s]{SOGA!s 7}x\index[s]{SOGA!s 7B}x\index[s]{SOGA!s 50}x\index[s]{SOGA!s 5}x\index[s]{SOGA!s 3(2)(a)}
x\index[s]{Vsort!V-sort!V128}
x\index[s]{Vsort!V-sort!V64}
x\index[s]{SOGA!s 3(12)(a)}
x\index{first level!second level!third level}
x\index{xfirst level!xsecond level!xthird level|textbf}
\newpage
x\index{xfirst level!xsecond level|textit}
\newpage
x\index{xfirst level|squarebr}
%---------------------------------------------------
\section{Model}
x\secindex{model}
x\secbindex{model}
x\seccindex{model}
y\genindex{secd}{model!amain section@\yellowcommand{main section}|sectionmarky}{\thesection}
y\genindex{secd}{model!details!intro}{p\thepage}
\section{Hypothesis}
x\secindex{hypothesis}
x\secbindex{hypothesis}
x\seccindex{hypothesis}
\section{Testing}
x\secindex{testing}
x\secbindex{testing}
\newpage
x\seccindex{testing}
\section{Methodology}
x\secindex{methodology}
\newpage
x\secbindex{methodology}
x\seccindex{methodology}
y\genindex{secd}{model!details!causative}{p\thepage}
\newpage
\section{Experiment}
x\secindex{experiment}
x\secbindex{experiment}
x\seccindex{experiment}
\newpage
y\genindex{secd}{model!details!error margin}{p\thepage}
\newpage
\section{Results}
x\secindex{results}
x\secbindex{results}
x\seccindex{results}
y\genindex{secd}{model!details!error margin}{p\thepage}
\newpage
y\genindex{secd}{model!details!error margin}{p\thepage}
\section{Conclusions}
x\secindex{conclusions}
x\secbindex{conclusions}
x\seccindex{conclusions}
\section{Acknowledgements}
x\secindex{acknowledgements}
x\secbindex{acknowledgements}
x\seccindex{acknowledgements}
%---------------------------------------------------
\printindex
\printindex[s]
\printindex[sec]
\printindex[secb]
\printindex[secc]
\printindex[secd]
\end{document}