5

Background. I would like to replace the intentionally blank pages or vacat pages in scrbook with a page which shows a new quote on every new blank page. Thanks to scrbook and LuaTeX this is not that difficult to write.

Here is my problem. Unfortunately, the index on these pages does not work. The entry does not show up in the .idx-file.

Remarks.

  • Choosing a different engine than LuaTeX is not an option.
  • The code which accesses the quote from Lua-tables is not shown here to avoid a bloated MWE and a separated .lua-file.
  • Choosing a different class than scrbook is not an option.
  • The same problem occurs in the header and footer.
  • The indexes index does work here A and index does work here B work fine.

My 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}
  • Great MWE. Your example works well. In my idx file I get \indexentry{index does work here A|hyperpage}{1} Fixing the page number is the only issue I see. – Marco Daniel Mar 25 '17 at 9:42
  • 1
    @MarcoDaniel: I don't get it, and page 1 is the wrong page anyway. – Ulrike Fischer Mar 25 '17 at 10:19
  • @Maco Daniel: The index I do not get is index does not work here. – CampanIgnis Mar 25 '17 at 11:23
  • @Ulrike Fischer: Observing my PDF, page 1 is correct. – CampanIgnis Mar 25 '17 at 11:26
  • @CampanIgnis: I was referring to Marco's comment, imho he looked at the wrong entry. – Ulrike Fischer Mar 25 '17 at 11:34
3

The page style is used during the output routine and there \index is redefined to do nothing. You can try to write the index entry with low level commands, but then you don't get links from hyperref. You could also move the index code to the onselect-hook of the page style. But as pagestyles can be selected in various places without being used at the end you could end with too many index entries. The onevenpage-option looks more logical but doesn't work.

\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}
  • "\index is redefined to do nothing" I thought of something similar, but what is the reason for this definition? Why did you include http://www.ctan.org/pkg/xfp? – CampanIgnis Mar 25 '17 at 11:59
  • 1
    You can try contents={some content with an index entry without link: \protected@write\@indexfile{}% {\string\indexentry{index entry in content|hyperpage}{\thepage}}}, to get a link. – Marco Daniel Mar 25 '17 at 12:16
  • 2
    Well when the pagestyle is used you are in the middle of the output routine and normally you don't want some commands to interfere. Imho trying to inject an index entry and a quote through a page style is a bit dubious. It would be better to define your own \cleardoublepage-command or to ask the KOMA-maintainer to add a hook for text content in this pages (if it doesn't exist yet). Or you could hook in the chapter command. After all you are trying something similar to a epigraph. – Ulrike Fischer Mar 25 '17 at 12:25
0

Ulrike Fischer describes a different solution in her comment Index in KOMA-Script layers does not work with a redefinition of \cleardoublepage. I hoped for an elegant solution which is not based on overriding something. The following code is based on 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}

Remark. This answer was part of the question and is now posted as an answer to honor the conventions of this site. The answer https://tex.stackexchange.com/a/360327/128553 is accepted for giving two solutions, this one is a just a realisation of her second suggestion.

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.