2

I would like to have part toc entries, which are formatted \bfseries\sffamily, as small-caps. This combination is not available for the font used. Not even with packages. I implemented it "manually" by increasing the font size one level for the corresponding initial letters and then reducing it again. I know this is a "bad hack" and not recommended. But it looks really quite good in this case. Since I need it several times and would like to define something like that and not just "hard-code" it, I wonder whether it would be possible to write a parser that parses a string like "Paris and Rome" into \large P\normalsize ARIS AND \large R\normalsize OME...?

This is, more or less, what I use now:

\documentclass[headings=optiontotoc,paper=a5,10pt]{scrbook}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage{microtype}
\usepackage{hyperref}
\usepackage{bookmark}

\linespread{1.05}

\renewcommand*{\raggedsection}{\centering}

% for centering part toc entry:
\makeatletter
\newcommand*{\specialparttocentryformat}[1]{%
    \large\bfseries\sffamily%
    \let\numberline@box\mbox%
    \def\autodot{: }%
    \centering%
    #1%
}
\RedeclareSectionCommand[tocnumwidth=0pt,tocindent=0pt,tocentryformat=\specialparttocentryformat,toclinefill={},tocpagenumberbox=\@gobble,tocpagenumberwidth=0pt,tocrightindent=0pt,tocraggedpagenumber]{part}
\makeatother

\newcommand*{\up}{\large}
\newcommand*{\down}{\normalsize}
\newcommand*{\muc}[1]{\MakeUppercase{#1}}

\newcommand*{\bookonetoc}{\up F\down IRST BOOK}
\newcommand*{\bookonetopictoc}{\up C\down APITALS IN EUROPE}
\newcommand*{\partonetoc}{\up F\down IRST THEME}
\newcommand*{\partonetopictoc}{\up B\down ERLIN AND \up R\down OME}

\newcommand*{\dlb}{\\\vspace{\baselineskip}}% double line break
\newcommand*{\tlb}{\\\vspace{2\baselineskip}}% triple line break
\newcommand*{\lbtoc}{\texorpdfstring{\hspace{50em}}{: }}% line break in toc
\newcommand*{\dlbtoc}{\texorpdfstring{\hspace{50em}\textcolor{white}{--}\hspace{50em}}{ -- }}% double line break in toc

\begin{document}

\tableofcontents

\part[%
    nonumber=true,%
    tocentry={\bookonetoc\lbtoc\bookonetopictoc\dlbtoc\partonetoc\lbtoc\partonetopictoc}%
]%
{\huge\muc{First book}\dlb\muc{Capitals in europe}\tlb\LARGE\muc{First theme}\dlb\muc{Berlin and Rome}}

\end{document}

So I would like to have flexibility regarding the font size. Furthermore, I prefer the bookmarks-entry to be all-caps.

BTW: \hspace{50em} of course is a hack. When I use \\ instead, the spacing between the lines is inconsistent. If someone has an idea on how to avoid this hack, I would of course be happy to hear it.

keth-tex
  • 466
  • 2
  • 10

2 Answers2

2

Assuming you're free to use LuaLaTeX, the following solution may be of interest to you. It consists of a LaTeX user macro called \badhack and a Lua background function called badhack. The former passes its argument to the latter to perform most of the work.

Note that the argument of \badhack can be a (LaTeX) macro.

enter image description here

% !TEX TS-program = lualatex
\documentclass{article}
\usepackage{luacode} % for \luaexec macro
\begin{luacode}
function badhack ( s )
  s = s:gsub ( "%u" , "{\\large %0}" ) -- enlarge uppercase letters
  s = string.upper ( s )
  tex.sprint ( ( s:gsub ( "\\LARGE", "\\large" ) ) )
end
\end{luacode}

\newcommand\badhack[1]{\directlua{badhack("#1")}}
\newcommand\PnR{Paris and Rome}

\begin{document}
\PnR

\textsc{\PnR}   % this is ok

\badhack{\PnR}  % and this is a bad hack!

\bfseries\sffamily
\PnR

\badhack{\PnR} % another bad hack
\end{document}
Mico
  • 506,678
  • Thanks for your answer. I'm not familiar with LuaTeX. I can compile your code. Though, with my own files, which are quite complex, I run into trouble. I think this is not a viable option for me. – keth-tex Jun 06 '20 at 18:40
2

This isn't the most robust or fault tolerant parser ever written but it works in at least two cases:

enter image description here

\documentclass{article}

\def\zz#1{\zzz#1 = \unskip}

\def\zzz#1#2 {%
\ifx=#1%
\else
\ifnum\lccode`#1=`#1%
\uppercase{#1#2}%
\else
{\Large#1}\uppercase{#2}%
\fi
\space
\expandafter
\zzz
\fi}

\begin{document}

[\zz{abc}]

[\zz{Paris and Rome}]


\end{document}
David Carlisle
  • 757,742
  • Thanks a lot. This is basically what I was looking for. Unfortunately there are still some issues. In fact I use this mainly for part toc entries and I use hyperref for links and bookmarks. I guess I should have been more specific from the beginning. Sorry for that. I now posted some code. One problem is the last spacing command which shows up in the bookmarks. Another one is that I would like the part bookmarks-entries to be all-caps. (I also noticed that the inter-word spacing is slightly increased with your solution. Since the effect is very subtle, I could live with that.) – keth-tex Jun 06 '20 at 20:16