背景。
我想更换故意留白的页面或者空页 在scrbook
每张空白页上都会显示一条新引文。感谢scrbook
而 LuaTeX 编写起来并不难。
这是我的问题。
不幸的是,这些页面的索引不起作用。条目未显示在.idx
文件中。
评论。
- 选择与 LuaTeX 不同的引擎不是一个选择。
tables
这里没有显示从 Lua 访问引用的代码,以避免 MWE 臃肿和.lua
文件分离。- 选择不同的类别
scrbook
不是一个选择。 - 页眉和页脚也出现相同的问题。
- 索引
index does work here A
和index does work here B
工作正常。
我的 MWE。
\documentclass[paper=a4,twoside]{scrbook}
\usepackage{fontspec,polyglossia}
\setdefaultlanguage[variant=usmax]{english}
\usepackage{hyperref,makeidx}
\usepackage{scrlayer,scrlayer-scrpage}
\DeclareNewLayer[
foreground,
align=l,
area={.25\paperwidth}{.37\paperheight}{.5\paperwidth}{.5\paperheight},
contents={A quote which is accessed by Lua. But not in the MWE. But the \textbf{index}\index{index does not work here} does not work here!
Just some Lua code: \directlua{tex.sprint(math.exp(-1))}.}
]{intentionallyBlankLayer}
\DeclareNewPageStyleByLayers{intentionallyBlank}{intentionallyBlankLayer}
\KOMAoptions{cleardoublepage=intentionallyBlank}
\ihead[bar \index{bar head index does not work}]{foo \index{foo head index does not work}}
\ifoot[bar \index{bar foot index does not work}]{foo \index{foo foot index does not work}}
\makeindex
\begin{document}
\chapter{Lorem foo}
Some text with a working index\index{index does work here A}.
\chapter{Lorem bar}
Some other text with a working index\index{index does work here B}.
\printindex
\end{document}
答案1
页面样式在输出例程中使用,并且\index
被重新定义为不执行任何操作。您可以尝试使用低级命令编写索引条目,但这样您就无法从 hyperref 获得链接。您还可以将索引代码移动到onselect
页面样式的 -hook。但由于可以在各个地方选择页面样式,而无需在最后使用,因此您可能会得到太多的索引条目。onevenpage
-option 看起来更合乎逻辑,但不起作用。
\RequirePackage{luatex85}
\documentclass[paper=a4,twoside]{scrbook}
\makeatletter
\usepackage{fontspec,polyglossia}
\setdefaultlanguage[variant=usmax]{english}
\usepackage{hyperref}
\usepackage{makeidx}
\usepackage{scrlayer,scrlayer-scrpage}
\makeatletter
\DeclareNewLayer[
foreground,
align=l,
area={.25\paperwidth}{.37\paperheight}{.5\paperwidth}{.5\paperheight},
contents={some content with an index entry without link:
\protected@write\@indexfile{}%
{\string\indexentry{index entry in content}{\thepage}}},
]{intentionallyBlankLayer}
\DeclareNewPageStyleByLayers[
onselect =
{\ifnumodd{\value{page}}{}{\index{index quote in onselect}}}]{intentionallyBlank}{intentionallyBlankLayer}
\KOMAoptions{cleardoublepage=intentionallyBlank}
\makeindex
\begin{document}
\chapter{Lorem foo}
Some text with a working index\index{index does work here A}.
\chapter{Lorem bar}
Some other text with a working index\index{index does work here B}.
\printindex
\end{document}
答案2
乌尔丽克·菲舍尔在她的评论中描述了不同的解决方案KOMA-Script 图层中的索引重新定义\cleardoublepage
。我希望有一个优雅的解决方案,不基于覆盖某些东西。以下代码基于https://tex.stackexchange.com/a/205536/128553。
\documentclass[paper=a4,twoside]{scrbook}
\usepackage{fontspec,polyglossia}
\setdefaultlanguage[variant=usmax]{english}
\usepackage{hyperref,makeidx}
\usepackage{scrlayer,scrlayer-scrpage}
\newcommand*{\blankpage}{%
\par\vspace*{\fill}%
{A quote which is accessed by Lua. But not in the MWE. But the \textbf{index}\index{index does now work here} does not work here!
Just some Lua code: \directlua{tex.sprint(math.exp(-1))}.}
\vspace{\fill}%
}
\makeatletter
\renewcommand*{\cleardoubleoddstandardpage}{%
\clearpage
\if@twoside
\ifodd\c@page
\else
\blankpage
\thispagestyle{empty}%
\newpage
\if@twocolumn\hbox{}\newpage\fi
\fi
\fi
}
\makeatother
\makeindex
\begin{document}
\chapter{Lorem foo}
Some text with a working index\index{index does work here A}.
\chapter{Lorem bar}
Some other text with a working index\index{index does work here B}.
\printindex
\end{document}
评论。这个答案是问题的一部分,现在作为答案发布以遵守本网站的惯例。答案https://tex.stackexchange.com/a/360327/128553因给出两个解决方案而被接受,而这个解决方案只是她第二个建议的实现。