4

This is a follow-up question to the one about the capitalization of chapter names in the book class. Now I would like to make capital the names of book parts in the book class.

Part 1 --> PART 1

I use ShareLaTeX with XeLaTeX.

\documentclass{book}

\usepackage{fontspec}

\usepackage[english,greek]{babel}

\setmainfont
[
    UprightFont = *,
    BoldFont = *Bold,
    ItalicFont = *It,
    BoldItalicFont = *BoldIt,
    Extension = .otf,
    Ligatures = TeX,
    Mapping = tex-text
]{GFSArtemisia}

\setsansfont[Mapping = tex-text]{GFSArtemisia.otf}

\setmathfont{latinmodern-math.otf}

\setmathfont[range = \varnothing]{Asana-Math.otf}

\setmathfont[range = \int]{latinmodern-math.otf}

\begin{document}

\end{document}
2
  • 3
    So you haven't even tried using \renewcommand\partname{PART}? If this doesn't work, please provide more information regarding your setup. Some things (like packages or language settings) influence the availability or formatting of sectional units.
    – Werner
    Commented Mar 1, 2016 at 20:57
  • @Werner That was the second thing that I tried...The first was very shameful to admit. :P
    – Adam
    Commented Mar 1, 2016 at 20:59

2 Answers 2

3

This should work for some (but not all) languages.

\documentclass{book}

\let\oldpartname\partname

\renewcommand{\partname}{\MakeUppercase{\oldpartname}}


\begin{document}

\part{Foo}

\end{document}

Here's a babel based setup (for some arbitrary languages, say German and Spanish)

\MakeUppercase acts on a stored copy of \partname -- \let\oldpartname\partname generates this copy.

\documentclass{book}
\usepackage[ngerman,spanish]{babel}


\addto\captionsspanish{\let\oldpartname\partname
\renewcommand{\partname}{\MakeUppercase{\oldpartname}}}

\addto\captionsngerman{\let\oldpartname\partname
\renewcommand{\partname}{\MakeUppercase{\oldpartname}}}


\begin{document}
\tableofcontents
\otherlanguage{ngerman}
\part{Foo}

\selectlanguage{spanish}
\part{Foobar}

\end{document}
3
  • This too doesn't work. :/
    – Adam
    Commented Mar 1, 2016 at 21:01
  • @Adam: It would have helped if you would have provided your fontspec related stuff before!
    – user31729
    Commented Mar 1, 2016 at 21:05
  • 1
    Sorry! Now it works. Thank you very much. :)
    – Adam
    Commented Mar 1, 2016 at 21:07
3

It's quite simple:

\documentclass{book}

\usepackage{fontspec}

\usepackage[english,greek]{babel}

\setmainfont[
  Extension = .otf,
  UprightFont = *,
  BoldFont = *Bold,
  ItalicFont = *It,
  BoldItalicFont = *BoldIt,
]{GFSArtemisia}

\setsansfont{GFSArtemisia.otf}

\makeatletter
\addto\captionsenglish{%
  \protected@edef\partname{\MakeUppercase{\partname}}%
}
\addto\captionsgreek{%
  \protected@edef\partname{\MakeUppercase{\partname}}%
}
\makeatother

\begin{document}

\part{Τίτλος}

\selectlanguage{english}

\part{Title}

\end{document}

When \selectlanguage{<language>} or \begin{otherlanguage}{<language>} is scanned, LaTeX will process \captions<language> (for instance \captionsgreek). In this phase \partname is set to some language dependent string. With the trick

\protected@edef\partname{\MakeUppercase{\partname}}

we tell LaTeX that \partname is the uppercase version of the just defined string.

Note that \begin{document} executes \selectlanguage{greek} (because this is the last selected language), so everything comes out right.

enter image description here

enter image description here

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .