TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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}
share|improve this question
2  
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 Mar 1 at 20:57
    
@Werner That was the second thing that I tried...The first was very shameful to admit. :P – Adam Mar 1 at 20:59
up vote 3 down vote accepted

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}
share|improve this answer
    
This too doesn't work. :/ – Adam Mar 1 at 21:01
    
@Adam: It would have helped if you would have provided your fontspec related stuff before! – Christian Hupfer Mar 1 at 21:05
1  
Sorry! Now it works. Thank you very much. :) – Adam Mar 1 at 21:07

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

share|improve this answer
    
+1 Thank you. Excellent answer. :) – Adam Mar 1 at 22:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.