13

Title says it all, but here's an example: the KOMA-Script classes provide the option toc which can have multiple values that don't interfere with each other, like values that enable the Bibliography in the TOC and others that just influence the layout of the TOC. When I need several of these values for the class option toc, how can I pass them all together to toc without having to repeat toc= all the time?

What I have currently:

\documentclass[toc=listof, toc=bibliography, toc=flat]{scrbook}

Idea of what I'd like to have (but what does not work)

\documentclass[toc={listof, bibliography, flat}]{scrbook}

Is this somehow possible? If yes, how?

  • 2
    write a feature request to the author of the KOMA classes – user2478 Jan 15 '13 at 10:39
  • Ah, so this depends on the class itself and not on some general Latex syntax? – Foo Bar Jan 15 '13 at 10:41
  • yes, it depends on how the class reads and sets its options. – user2478 Jan 15 '13 at 10:43
13

The standard LaTeX \documentclass syntax doesn't use = at all, just a comma separated list of values like [12pt,twoside] so

\documentclass[toc=listof, toc=bibliography, toc=flat]{article}

would just be three (undefined) options toc=listof , toc=bibliography and toc=flat There is no mechanism for passing values to an option toc.

Some classes load keyval or similar packages and redefine \documentclass to use that so then your example passes the three values listof, bibliography and flat to the toc key defined by that class.

In your example toc={listof, bibliography, flat} the keyval parser will pass the single value listof, bibliography, flat to the toc key, but then it is up to the definition of that key in the class whether it treats this as an unknown value or whether it further processes it as a comma separated list.

| improve this answer | |
5

The easiest way I found for solving OP's problem is to introduce a new class file xscrbook. See below.

\ProvidesClass{xscrbook}[2013/01/17 v0.1 Extends KOMA-script-book class (AM)]
\NeedsTeXFormat{LaTeX2e}[2011/06/27]
\protected\def\scr@preprocessclassoptionslist#1{%
  \ifx#1\relax
    \let#1\@empty
  \fi
  \ifx#1\@empty\else
    \begingroup
    \def\scr@tempa{}%
    \def\scr@tempb##1=##2=##3\scr@nil##4{%
      \ifx\relax##2\relax\else
        \def\scr@option{##1}%
        \edef\scr@value{\zap@space##2 \@empty}%
        ##4%
      \fi
    }%
    \@for\reserved@a:=#1\do{%
      \expandafter\scr@tempb\reserved@a==\scr@nil{%
        \@for\reserved@a:=\scr@value\do{%
          \edef\scr@tempa{%
            \scr@tempa\ifx\scr@tempa\@empty\else,\fi
            \scr@option=\reserved@a
          }%
        }%
      }%
    }%
    \edef\scr@tempa{\endgroup\def\noexpand#1{\scr@tempa}}%
    \scr@tempa
  \fi
}
\scr@preprocessclassoptionslist\@classoptionslist
\ifdefined\XKV@classoptionslist
  \scr@preprocessclassoptionslist\XKV@classoptionslist
\fi
\LoadClass{scrbook}

\endinput

Example

\documentclass[toc={listof, bibliography, flat}]{xscrbook}

\begin{document}
x
\end{document}
| improve this answer | |
  • 1
    You certainly can pass keyval options using the \documentclass line: this is standard in KOMA. What you have to watch is that expansion and space-stripping takes place. – Joseph Wright Jan 16 '13 at 6:55
  • What's with all the trailing % signs? – DanielSank Sep 30 '14 at 6:30
2

The correct way to proceed is described in the KOMA-Script documentation as

Some options can have several values simultaneously. For such options, it is possible, with the help of \KOMAoption, to pass a list of values to a single option. The individual values are given as a comma-separated value list.

So, in your example:

\documentclass[any_option]{scrbook}
\KOMAoption{toc}{bibliography,listof,flat}

Please pay attention that, with biblatex, this was not enough to get the bibliography in the table of contents. I had to use:

\printbibliography[heading=bibintoc]

or any equivalent command.

Enjoy!

| improve this answer | |
  • welcome to TEXSE, could you please explain the differences of your answer with respect to the already existings ones? – Raaja is not active on TEXSE Sep 20 '19 at 10:06
  • 1
    @Raaja This is the correct answer, because all classes from KOMA-Script (and that this is used was already written in the question) can use command \KOMAoption or \KOMAoptions to define more class options. That commands can be used in the preamble or in the document ... I also added tag koma-script to the question ... – Mensch Sep 20 '19 at 10:41
  • @Mensch I was not saying it is wrong per se, I was asking what the difference is. If you see David's already accepted answer, the solution is available. – Raaja is not active on TEXSE Sep 20 '19 at 10:52
  • @Raaja That question and answer are from 2013 (sic!). Today, 2019, KOMA-Script is able to handle more that on value per class option as mentioned in this answer ... – Mensch Sep 20 '19 at 11:19
  • @Raaja David's answer is the explanation of the mechanism that is hidden in the KOMA-Script bundle and, as Mensch mentioned, it was written a few years ago. As there was no update and I looked exactely for the same problem 2 hours ago I put here the right process. Hope this helps :) By the way, thanks for the welcome :) – Alexandre Quenon Sep 20 '19 at 12:01

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.