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 would like my sections (and potentially subsections) to be in "sentencecase" no matter how I type them. I am happy with the way the \MakeSentenceCase macro from the biblatex package converts text with arbitrary capitalization into sentencecase. I am having difficulty integrating this into the \section macro.

My first attempt was to redefine \section to be

\renewcommand{\section}{\@startsection{section}{1}{\z@}{-3.5ex \@plus -1ex \@minus -.2ex}{2.3ex \@plus.2ex}{\normalfont\Large\bfseries\MakeSentenceCase}}

but this fails because the first token (or something like that) to \MakeSentenceCase is not the first token of the text of my section heading, but rather related to the numbering and indenting. The following method works

\documentclass{article}

\usepackage{etoolbox}
\usepackage[backend=biber]{biblatex}

\makeatletter
\let\sectionOrig\section
\renewcommand{\section}{\@ifstar{\@sectionStar}{\@sectionNoStar}}%
\newcommand{\@sectionNoStar}[2][\relax]{\ifdefstring{\relax}{#1}{%
  \sectionOrig{\MakeSentenceCase{#2}}%
}{%
  \sectionOrig[#1]{\MakeSentenceCase{#2}}%
}}
\newcommand{\@sectionStar}[1]{\sectionOrig*{\MakeSentenceCase{#1}}}%
\makeatother

\begin{document}
\section{sections SHOULD BE IN {SENTENCECASE}}
\end{document}

by completely redefining the \section command. I have tried to take care of the starred and unstarred forms and optional arguments, but I am worried that this approach is going to cause problems someplace else.

I guess I have 3 questions. First, is it reasonable to expect LaTeX to automatically handle the capitalization of sections. Second, is my approach reasonable. Third, is there a better approach (or an already existing package).

share|improve this question
    
Sorry, but it's not reasonable to expect LaTeX knows English (or any other language). –  egreg Jun 21 '13 at 16:49
    
@egreg "to expect LaTeX to know the English (or any other) language" ? ;-) [I am not sure ;-) -- will presumably soon delete this comment for fear of bringing shame on me... ] –  jfbu Jun 21 '13 at 19:52
1  
@jfbu In this case, "expect LaTeX knows" is short for "expect that LaTeX knows". The word "that" can often be dropped. Your version is correct too. –  John Wickerson Jun 22 '13 at 7:36
    
@JohnWickerson sigh of relief... thanks! –  jfbu Jun 22 '13 at 8:10
1  
@jfbu (shame shame shame—learn Italian ;)) Also, I don't see this as unreasonable as it is asked—but I would counter-ask (?) if this is what you really want; if any acronyms appear in your sections, they may be downcased (depending on how \MakeSentenceCase handles groups). –  Sean Allred Jul 28 '13 at 20:57
show 1 more comment

1 Answer 1

up vote 10 down vote accepted
+50

This is easy using the titlesec package. With the explicit option (p. 8, sec. 3.7), we can use an (I think) arbitrary transformation on the sectioning title stored as #1. With this knowledge, the rest becomes a piece of cake:

\documentclass[twocolumn]{article} % two-column used to get everything onto one page
\usepackage{biblatex}

\usepackage[explicit]{titlesec} % note the `explicit` option

\titleformat{\section} % The normal, unstarred version
    {\Large\bfseries}{}{2ex}
    {\thesection. \MakeSentenceCase{#1}}

\titleformat{name=\section,numberless} % The starred version; note the `numberless` key
    {\Large\bfseries}{}{2ex}
    {\MakeSentenceCase{#1}}

\usepackage{mwe}
\begin{document}
\section{I am a Section}
\lipsum[1]
\section{I am An Other section}
\lipsum[2]
\section*{I am an UnNumBeReD section with {ACRO}-nyms}
\lipsum[3]
\section{I am a Section}
\lipsum[4]
\section{I am An Other section}
\lipsum[5]
\section{More {ACR}-o-{NYM}s!}
\end{document}

enter image description here

(Note that this solution can be easily applied to the other sectioning commands by just replacing \section and \thesection appropriately.)


As for your other questions:

  • as long as you are not expecting LaTeX to achieve/follow fancy casing rules (such as title-casing) for arbitrary languages, then you are fine. TeX knows the relationships between all of the letters (uppercase/lowercase) and can swap between them where necessary. So-called 'dumb' control of casing (e.g. capitalize first letter, lowercase the rest) is completely reasonable.
  • Your approach is reasonable if it works well, but it is usually better to build upon an existing package (e.g. titlesec) for more functionality. (For example, if you had written your own \MakeSentenceCase, that may have been a bit too much work—a lot of code means a lot of room for small errors.)
share|improve this answer
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.