2

I would like to use this solution by @egreg to type in fake small caps.

Since I have to use some specific font size for the capital/lower letters, I used some \fontsize{}{}\selectfont in the command definition.

Since I have to use the fake small caps in the chapter head, I redefined both \@makechapterhead and \@makeschapterhead from the book class as below and used \fakesc{#1}.

They worked when using \chapter{} and \chapter*{} but a problem appears when using \tableofcontents. I think because it uses \chapter*{}.

I agree that it is better to use a font with small caps support but unfortunately I have to use an specific one without it.

The first error when running xelatex mwe.tex is

(/usr/local/texlive/2018/texmf-dist/tex/latex/fontspec/fontspec.cfg)))
(./mwe.aux)
! Improper alphabetic constant.
<to be read again> 
                   \contentsname 
l.66 \tableofcontents

? 

MWE

\documentclass[a5paper]{book}
\usepackage{showframe}
\usepackage{fontspec}
\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\fakesc}{ o m }
 {
  \guido_fakesc:n { #2 }
  \IfNoValueTF{#1}
   {
    \tl_use:N \l__guido_temp_tl
   }
   {
    \cs_set_eq:NN #1 \l__guido_temp_tl
   }
 }
\cs_new_protected:Npn \guido_fakesc:n #1
 {
  \tl_set:Nn \l__guido_text_tl { #1 }
  \tl_replace_all:Nnn \l__guido_text_tl { ~ } { \q_space }
  \tl_set:Nn \l__guido_temp_tl { \group_begin:  }
  \tl_map_inline:Nn \l__guido_text_tl
   {
    \token_if_eq_meaning:NNTF ##1 \q_space
     {
      \tl_put_right:Nn \l__guido_temp_tl { ~ }
     }
     {
      \int_compare:nTF { \char_value_uccode:n { `##1 } = `##1 }
       {
        \tl_put_right:Nn \l__guido_temp_tl { {\fontsize{20}{22}\selectfont ##1} }
       }
       {
        \tl_put_right:Nn \l__guido_temp_tl { \tl_upper_case:n {\fontsize{14}{14}\selectfont ##1 } }
       }
     }
   }
  \tl_put_right:Nn \l__guido_temp_tl { \group_end: }
 }
\quark_new:N \q_space
\tl_new:N \l__guido_text_tl
\tl_new:N \l__guido_temp_tl
\ExplSyntaxOff

\makeatletter

\def\@makechapterhead#1{%
  \begin{center}
  \thechapter\par\vskip 5pt
  \fakesc{#1}
  \end{center}
  \vskip 4cm\interlinepenalty\@M
}

\def\@makeschapterhead#1{%
  \begin{center}
  \fakesc{#1} %% <---------- problem here
  \end{center}
  \vskip 4cm\interlinepenalty\@M
}

\makeatother

\begin{document}
\tableofcontents %% <-------- problem

\chapter*{Introduction}
foo

\chapter{title}
foo

\end{document}
  • well as @egreg writes in his answer "The argument to \fakesc must consist only of letters and spaces. No fancy characters or commands.", but in the tableofcontents the argument is \contentsname \@mkboth {\MakeUppercase \contentsname }{\MakeUppercase \contentsname}. – Ulrike Fischer Feb 6 at 16:22
  • @UlrikeFischer, so the solution could be replace \contentsname by a constant string and move the @mkboth outside! – Sigur Feb 6 at 16:25
  • @UlrikeFischer, yes. It worked. There is no chance to make use of translatable \contentsname but no problem for now. – Sigur Feb 6 at 16:28
  • And the same in the bibliography. – Sigur Feb 6 at 16:32

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.