Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I was toying a bit with the \@startsection command to change the layout of chapter / section headings. More specifically, I wanted my headers to be converted to uppercase.

I was following an example from the LaTeX compendium:

\documentclass{scrbook}
\makeatletter
\renewcommand\chapter{\@startsection
{chapter}{0}{0mm}
{-\baselineskip}
{0.5\baselineskip}
{\MakeUppercase}}
\makeatother
\usepackage{lipsum}
\begin{document}
\chapter{SomeChapter}
\lipsum[1]
\end{document}

This tossed an error message at me from the line \chapter{SomeChapter}:

Argument of \@gobble has an extra }.

After quite some trial & error, I found that using \uppercase instead of \MakeUppercase worked fine - but not for Umlauts.

What did I do wrong? Shouldn't \MakeUppercase work as well (and handle Umlauts correctly)?

share|improve this question
add comment

3 Answers

up vote 3 down vote accepted

Your redefinition works for the book class. With scrbook it doesn't, however I would make it differently any way.

  • There are KOMA-Script features which I would continue supporting, such as \sectfont, \raggedsection and \size@chapter. They are originally used for \chapter, similar with \section, not using them could break the expected behavior of KOMA-Script commands.

  • You could attach \MakeUppercase to \size@chapter. You could do it in different ways. Note, you have to use \makeatletter ... \makeatother around such a definition involving a command with @ in a name.

    • The quick and easy way, if you know your heading size, for example \Huge:

      \renewcommand*{\size@chapter}{\Huge\MakeUppercase}
      
    • The safe way, where you don't need to know your heading size, you just store and use it:

      \let\origsize\size@chapter
      \renewcommand*{\size@chapter}{\origsize\MakeUppercase}
      
    • A way using \expandafter to change the order of macro expansion, so you don't need an additional macro to backup the original size command, in just one line:

      \expandafter\def\expandafter\size@chapter\expandafter{\size@chapter\MakeUppercase}
      
    • The shortest way, using \g@addto@macro to attach code to another command:

      \g@addto@macro\size@chapter\MakeUppercase
      
  • I would not use headings completely in upper case. Instead, I recommend considering using small caps instead, which is easily done by

    \addtokomafont{chapter}{\scshape}
    

Not all fonts offer small caps in with bold sans serif font, which is common for KOMA-Script classes. kpfonts does, so \usepackage{kpfonts} would show this command works, or

\setkomafont{chapter}{\normalfont\huge\rmfamily\scshape}
share|improve this answer
    
Funny enough: Trying the \g@addto@macro approach above with chapter worked perfectly, but section gave me the very same troubles as mentioned in the question. However: It turns out that \uppercase, in this case, doesn't generate any errors and works correctly with Umlauts. :-D –  DevSolar Aug 8 '11 at 17:47
add comment

To format the headings with a KOMA-class you can use the commands setkomafont or addkomafont.

For more details have a look at the excelent documentation.

Here a solution which was created by Heiko Oberdieck:

\documentclass{scrartcl}
\usepackage{makerobust}
\makeatletter
\MakeRobustCommand\@hangfrom
\newcommand*{\SectionMakeUppercase}{%
\MakeRobustCommand\@svsec
\MakeUppercase
}
\makeatother
\setkomafont{section}{\SectionMakeUppercase}
\begin{document}
\section{Hello World}
\end{document}
share|improve this answer
    
Thanks for the hint at setkomafont and addkomafont. The Oberdieck example looks good... but strangely enough it doesn't work. If I replace \MakeUppercase in the example with e.g. \ttfamily, I get the expected result, but \MakeUppercase has no effect. (And using \uppercase there gives me a "missing { inserted" at the "Hello World" line...) I'm a bit confused here... –  DevSolar Aug 8 '11 at 8:41
add comment

You can also consider using a expandable version of \MakeUppercase. That's very safe in any arguments. And I hope this will be available in expl3 some day. See my previous question: Are there purely expandable variants of \MakeUppercase?

For example, using Joseph Wright's solution:

\documentclass{scrbook}

\usepackage{expl3}
\ExplSyntaxOn
\cs_new:Npn \tl_to_upper_case:n #1 {
  \exp_args:Nf \tl_to_upper_case_aux:n {#1}
}
\cs_new:Npn \tl_to_upper_case_aux:n #1 {
  \tl_to_upper_case_aux:w #1 ~ \q_no_value \q_stop
}
\cs_new:Npn \tl_to_upper_case_aux:w #1 ~ #2 \q_stop {
  \quark_if_no_value:nTF {#2}
    { 
      \tl_map_function:nN {#1} \tl_to_upper_case_aux:N 
      \tl_to_case_end:n { }
    }
    { \tl_to_upper_case_aux:w #1 { ~ } #2 \q_stop }
}
\cs_new:Npn \tl_to_upper_case_aux:N #1 {
  \prg_case_str:nnn {#1}
    {
      { a } { \tl_to_case_aux:nw { A } }
      { b } { \tl_to_case_aux:nw { B } }
      { c } { \tl_to_case_aux:nw { C } }
      { d } { \tl_to_case_aux:nw { D } }
      { e } { \tl_to_case_aux:nw { E } }
      { f } { \tl_to_case_aux:nw { F } }
      { g } { \tl_to_case_aux:nw { G } }
      { h } { \tl_to_case_aux:nw { H } }
      { i } { \tl_to_case_aux:nw { I } }
      { j } { \tl_to_case_aux:nw { J } }
      { k } { \tl_to_case_aux:nw { K } }
      { l } { \tl_to_case_aux:nw { L } }
      { m } { \tl_to_case_aux:nw { M } }
      { n } { \tl_to_case_aux:nw { N } }
      { o } { \tl_to_case_aux:nw { O } }
      { p } { \tl_to_case_aux:nw { P } }
      { q } { \tl_to_case_aux:nw { Q } }
      { r } { \tl_to_case_aux:nw { R } }
      { s } { \tl_to_case_aux:nw { S } }
      { t } { \tl_to_case_aux:nw { T } }
      { u } { \tl_to_case_aux:nw { U } }
      { v } { \tl_to_case_aux:nw { V } }
      { w } { \tl_to_case_aux:nw { W } }
      { x } { \tl_to_case_aux:nw { X } }
      { y } { \tl_to_case_aux:nw { Y } }
      { z } { \tl_to_case_aux:nw { Z } }
    }
    { \tl_to_case_aux:nw {#1 } }
}
\cs_new:Npn \tl_to_case_aux:nw #1#2 \tl_to_case_end:n #3 {
    #2 \tl_to_case_end:n { #3 #1 }
}
\char_make_math_shift:N \Q
\cs_new:Npn \tl_to_case_end:n #1 {
  \tl_to_case_strip_i:w #1 Q ~ Q
}
\cs_new:Npn \tl_to_case_strip_i:w #1 ~ Q {
  \tl_to_case_strip_ii:w #1 Q
}
\cs_new:Npn \tl_to_case_strip_ii:w #1 Q #2 {#1}
\char_make_letter:N \Q
\cs_set_eq:NN \MakeExpandableUppercase \tl_to_upper_case:n
\ExplSyntaxOff


\makeatletter
\renewcommand\chapter{\@startsection
{chapter}{0}{0mm}
{-\baselineskip}
{0.5\baselineskip}
{\MakeExpandableUppercase}}
\makeatother
\usepackage{lipsum}
\begin{document}
\chapter{SomeChapter}
\lipsum[1]
\end{document}
share|improve this answer
    
@@Leo Liu: this will not work if the title contains braced arguments. –  Bruno Le Floch Aug 8 '11 at 16:26
    
@Bruno: That may be what the OP want. And I know that there were several versions of expandable \MakeUppercase. –  Leo Liu Aug 8 '11 at 16:37
    
Yes, there were several versions, but I think that the reason we didn't put anything in (yet?) is that none of them was really robust. I learnt some more TeX tricks since that time, so I should be able to write a more robust version some time next week. –  Bruno Le Floch Aug 8 '11 at 16:48
    
we now have \tl_expandable_(upp|low)ercase:n. –  Bruno Le Floch Aug 13 '11 at 15:05
    
@Bruno: Good news. I checked l3kernel 2564 and find it. –  Leo Liu Aug 13 '11 at 16:19
add comment

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.