7

I need to load greek with babel to support Greek text, but I am also using titlecaps to capitalise certain heading text.

Unfortunately, it seems this combination is not compatible but I'm having trouble identifying the specific cause and figuring out a workaround.

\documentclass[greek,british]{article}
\usepackage{babel}
\usepackage{titlecaps}
\Addlcwords{of}

\begin{document}

    This is some text.

\end{document}

What is the best way to adapt this code so that it works properly?

In the example above, commenting out \Addlcwords{of} gets the code to compile. However, in my real example, this just results in a different error later in the code, and so on. So I'm pretty sure there is something systematic I'm doing wrong here. What is it?

cfr
  • 198,882
  • 1
    I will submit a revised package with egreg's recommendations, once I can fully understand the extent of the issues. I have already worked up the \roman fix, but I'm trying to understand his comment about unprotected end-of-lines. – Steven B. Segletes Jan 29 '15 at 01:56
  • @StevenB.Segletes That's wonderful! Thank you! I look forward to trying it out. – cfr Jan 29 '15 at 03:00
  • 1
    I just uploaded titlecaps V1.2 to ctan. It incorporates the bug fixes suggested by egreg. I also figured out how to handle \l and \aa which had eluded me earlier. It may take a day or two to propagate. – Steven B. Segletes Jan 30 '15 at 11:40
  • @StevenB.Segletes Brilliant! You should post that as an answer so that I can accept it. – cfr Jan 30 '15 at 12:25
  • egreg deserves all the credit. Please accept his answer. If you want, I can post an answer once the upgrade propagates, just to let readers know more easily that the fix is instituted in the package. – Steven B. Segletes Jan 30 '15 at 13:11

1 Answers1

5

It's the usual problem: the package uses \roman for representing a counter value in roman numerals, but the greek option to babel changes \roman into a non fully expandable command.

Unfortunately, \roman is used in almost all macros of titlecaps, so providing a patch means rewriting the package.

The workaround suggested by Manuel in comments may work, but it can break Greek text.

\documentclass{article}

\makeatletter
\let\latex@roman\@roman
\makeatother

\usepackage[greek,british]{babel}
\usepackage{titlecaps}

\makeatletter
\let\@roman\latex@roman
\makeatother

\Addlcwords{of}

\begin{document}

This is some text.

\end{document}

As a side note: the titlecaps package needs to be revised anyway, because several of its macros have unprotected end-of-lines in the definitions.

A series of patches to the commands of titlecaps that should give the right behavior seems to be as follows:

\documentclass{article}

\usepackage[greek,british]{babel}
\usepackage{titlecaps}
\usepackage{xpatch}

\makeatletter
\def\dopatch#1{\xpatchcmd{#1}{\roman}{\romannumeral\value}{}{}}
\dopatch\Addlcwords
\dopatch\add@lcword
\dopatch\seek@lcwords
\dopatch\seek@lcwords
\dopatch\seek@lcwords
\dopatch\seek@lcwords
\dopatch\titlecap
\dopatch\titlecap
\dopatch\titlecap
\dopatch\titlecap
\dopatch\titlecap
\dopatch\titlecap
\dopatch\title@string
\dopatch\title@string
\dopatch\title@string
\dopatch\parse@@@Block
\undef\dopatch
\makeatother

\Addlcwords{of}

\begin{document}

This is some text.

\end{document}

In this way all occurrences of \roman{<counter>} are changed into \romannumeral\value{<counter>} which is safe, because it expands to \romannumeral\c@<counter> and the search for a number ends there.

Update

With titlecaps version 1.2, released 2015/01/30, the issues have been solved and your original example will work unchanged.

egreg
  • 1,121,712
  • \let\originalroman\roman before babel and the other way after loading babel package? – Manuel Jan 28 '15 at 23:41
  • 1
    @Manuel This could be a solution provided \roman is never used for Greek text, which might be a safe assumption, but it depends on the nature of the document. – egreg Jan 28 '15 at 23:43
  • Thanks and thanks @Manuel. However, I'm not sure this is going to work in my case... Hmm... – cfr Jan 28 '15 at 23:53
  • Is there any alternative to titlecaps? I have a horrible feeling that I'm going to get into deep trouble with this solution. – cfr Jan 29 '15 at 00:09
  • 1
    @cfr I don't know what you're using it for. For me, capitalization is something to be left to the Germans. By the way, I found a copy of Jonathan Swift's A Modest Proposal, typeset with capitalized names in German style (which was used at Swift's time). But the font used is Times! It's really funny. – egreg Jan 29 '15 at 00:12
  • I used it in a timeline to automate the creation of nodes e.g. I tell it aristotle and it will create various things using aristotle while making it Aristotle when it gets typeset. (I don't like having to type capital letters.) But it isn't always a single name, of course. (See http://tex.stackexchange.com/questions/1319/showcase-of-beautiful-typography-done-in-tex-friends/215082#215082.) – cfr Jan 29 '15 at 01:13
  • Thank you [again] for this diagnosis. I will submit a revised version with the \roman -> \romannumeral\value correction. What do you mean by an unprotected end-of-line? – Steven B. Segletes Jan 29 '15 at 01:55
  • @StevenB.Segletes I'm referring to lines 205 and 209, where a line inside a definition is not protected with % and it should be. Also, after any assignment such as \catcode`~=13, leave a space or end-of-line. – egreg Jan 29 '15 at 09:36
  • @egreg. Oops on the missing %. I should have seen those. I was unaware of the rule regarding use of \catcode and a trailing space. Does that comment apply equally well to the two occurrences within \def\get@argsC#1? – Steven B. Segletes Jan 29 '15 at 12:52
  • 1
    @StevenB.Segletes Yes. While \catcode`~=12\fi does no real harm, because \fi is followed by \protected@edef that, in turn, starts with \let, it's better avoiding premature expansions and \catcode`~=12 \fi is the best method. The % after the final 13 will cause again premature expansion when \get@argsC is expanded and the \catcode assignment is performed. – egreg Jan 29 '15 at 12:56