Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

hyperref, MakeUppercase and memoir

383 views
Skip to first unread message

Alan Munn

unread,
Apr 1, 2011, 12:11:09 PM4/1/11
to
Hi, I'm trying to get all chapter level headings set in uppercase
(including the LOT, LOF and any other Lists of that the user may have
defined) in my TOC in memoir. The following MWE shows the problem.

If I redefine \l@chapapp to use \MakeUppercase on its first argument, it
works, but not with hyperref. This is because hyperref adds a link
which can't be expanded by \MakeUppercase.

If I use \uppercase instead, then the links become black instead of red,
and I don't understand why.

I looked at Heiko's answer in this message:
<http://groups.google.com/group/comp.text.tex/browse_thread/thread/7a22e6
4e266329c3/fa53e73877dc8984?q=hyperref+MakeUppercase#fa53e73877dc8984>

But adding his suggested redefinition of \contentsline only seems to
make the table of contents entry in the TOC uppercase, not any of the
Lists-of, nor the chaptername.

Can someone help me sort out a better way to do this?

\documentclass{memoir}
\usepackage{hyperref}
\makeatletter
\renewcommand*{\cftchaptername}{Chapter\space}
\setlength{\cftchapternumwidth}{3em}
%\renewcommand*{\l@chapter}[2]{%
% \l@chapapp{\uppercase{#1}}{#2}{\cftchaptername}} % makes links black
%\renewcommand*{\l@chapter}[2]{%
% \l@chapapp{\MakeUppercase{#1}}{#2}{\cftchaptername}} % crashes
\makeatother
\begin{document}
\frontmatter
\tableofcontents
\listoffigures
\listoftables
\mainmatter
\chapter{A chapter}
\section{A section}
\begin{table}
\caption{A table}
\end{table}
\begin{figure}
\caption{A figure}
\end{figure}


\end{document}

Thanks

Alan

GL

unread,
Apr 1, 2011, 12:45:48 PM4/1/11
to
Le 01/04/2011 18:11, Alan Munn a écrit :
> Hi, I'm trying to get all chapter level headings set in uppercase
> (including the LOT, LOF and any other Lists of that the user may have
> defined) in my TOC in memoir. The following MWE shows the problem.
>
> If I redefine \l@chapapp to use \MakeUppercase on its first argument, it
> works, but not with hyperref. This is because hyperref adds a link
> which can't be expanded by \MakeUppercase.
>
> If I use \uppercase instead, then the links become black instead of red,
> and I don't understand why.
>
> I looked at Heiko's answer in this message:
> <http://groups.google.com/group/comp.text.tex/browse_thread/thread/7a22e6
> 4e266329c3/fa53e73877dc8984?q=hyperref+MakeUppercase#fa53e73877dc8984>
>
> But adding his suggested redefinition of \contentsline only seems to
> make the table of contents entry in the TOC uppercase, not any of the
> Lists-of, nor the chaptername.
>
> Can someone help me sort out a better way to do this?

Yes I think you do it bad.

Don't touch to macros which contains a @ inside for typesetting purpose.

\def\texorpdf #1#2{\texorpdfstring{#1{#2}}{#2}}

\chapter[\texorpdf\MakeUppercase{One}]{One}

And hyperref is happy: \texorpdfstring removes MakeUppercase.


Alan Munn

unread,
Apr 1, 2011, 1:17:31 PM4/1/11
to
In article <4d96013e$0$715$426a...@news.free.fr>,
GL <goua...@gmail.com> wrote:

> Le 01/04/2011 18:11, Alan Munn a écrit :
> > Hi, I'm trying to get all chapter level headings set in uppercase
> > (including the LOT, LOF and any other Lists of that the user may have
> > defined) in my TOC in memoir. The following MWE shows the problem.
> >
> > If I redefine \l@chapapp to use \MakeUppercase on its first argument, it
> > works, but not with hyperref. This is because hyperref adds a link
> > which can't be expanded by \MakeUppercase.
> >
> > If I use \uppercase instead, then the links become black instead of red,
> > and I don't understand why.
> >
> > I looked at Heiko's answer in this message:
> > <http://groups.google.com/group/comp.text.tex/browse_thread/thread/7a22e6
> > 4e266329c3/fa53e73877dc8984?q=hyperref+MakeUppercase#fa53e73877dc8984>
> >
> > But adding his suggested redefinition of \contentsline only seems to
> > make the table of contents entry in the TOC uppercase, not any of the
> > Lists-of, nor the chaptername.
> >
> > Can someone help me sort out a better way to do this?
>
> Yes I think you do it bad.
>
> Don't touch to macros which contains a @ inside for typesetting purpose.

This is inside a class file, so that general advice isn't so relevant
here.


>
> \def\texorpdf #1#2{\texorpdfstring{#1{#2}}{#2}}
>
> \chapter[\texorpdf\MakeUppercase{One}]{One}
>
> And hyperref is happy: \texorpdfstring removes MakeUppercase.

This doesn't solve the actual stated problem. The problem is not with
the formatting of the chapter titles, i.e the content of \chapter{} it's
with the formatting of the certain things that show up specifically in
the TOC.

Specifically:

List of Figures
List of Tables
List of ...

should be all uppercase

Also

Chapter 1 Title...

the Chapter should be all uppercase, not the title.

That's the effect of the line of code that causes hyperref to fail.

And this is part of a class file, so should be done in the class with no
user input required.

Thanks

Alan

GL

unread,
Apr 1, 2011, 1:36:24 PM4/1/11
to
Le 01/04/2011 19:17, Alan Munn a écrit :
> In article<4d96013e$0$715$426a...@news.free.fr>,
> GL<goua...@gmail.com> wrote:
>
>> Le 01/04/2011 18:11, Alan Munn a écrit :
>>> Hi, I'm trying to get all chapter level headings set in uppercase
>>> (including the LOT, LOF and any other Lists of that the user may have
>>> defined) in my TOC in memoir. The following MWE shows the problem.

> This doesn't solve the actual stated problem. The problem is not with


> the formatting of the chapter titles, i.e the content of \chapter{} it's
> with the formatting of the certain things that show up specifically in
> the TOC.

The "actual stated problem" is unclear to me.

"chapter level headings" : what does it mean ?

Chapter mark ?
Entry in the toc ?
Chapter title on the chapter page ?
Title of the "Table of Contents"/"List of Figures" formatted as chapters ?

What do you want to make upper case ?
Do you want the table of contents to appear in the table of contents ???
with the table of figures and of tables ???

Besides, if you want "black-colored" links in the table of contents,
the solution is:

First: \hypersetup{colorlink=true}% in the preamble
Second: {\hypersetup{linkcolor=.}\tableofcontents }

and xcolor.sty required.


Finally I dislike memoir because memoir fakes the packages.

What does \cftchaptername means ?????
it's *not* in the *tocloft* documentation
it means *nothing*

Why \cftchapternumwidth ???
in *tocloft* documentation it is \cftchapnumwidth ???

Why is there no \cfttoctitlefont ???
in *tocloft* documentation there is a \cfttoctitlefont !!!

then: \def\cfttoctitlefont{\MakeUppercase}

\tocsetup{
title/font=\MakeUppercase,
}

with interfaces.


>>>
>>> If I redefine \l@chapapp to use \MakeUppercase on its first argument, it
>>> works, but not with hyperref. This is because hyperref adds a link
>>> which can't be expanded by \MakeUppercase.
>>>
>>> If I use \uppercase instead, then the links become black instead of red,
>>> and I don't understand why.
>>>
>>> I looked at Heiko's answer in this message:
>>> <http://groups.google.com/group/comp.text.tex/browse_thread/thread/7a22e6
>>> 4e266329c3/fa53e73877dc8984?q=hyperref+MakeUppercase#fa53e73877dc8984>
>>>
>>> But adding his suggested redefinition of \contentsline only seems to
>>> make the table of contents entry in the TOC uppercase, not any of the
>>> Lists-of, nor the chaptername.
>>>
>>> Can someone help me sort out a better way to do this?
>>
>> Yes I think you do it bad.
>>
>> Don't touch to macros which contains a @ inside for typesetting purpose.
>
> This is inside a class file, so that general advice isn't so relevant
> here.
>>
>> \def\texorpdf #1#2{\texorpdfstring{#1{#2}}{#2}}
>>
>> \chapter[\texorpdf\MakeUppercase{One}]{One}
>>
>> And hyperref is happy: \texorpdfstring removes MakeUppercase.
>
>

Alan Munn

unread,
Apr 1, 2011, 1:46:43 PM4/1/11
to
In article <4d960d19$0$27520$426a...@news.free.fr>,
GL <goua...@gmail.com> wrote:

> Le 01/04/2011 19:17, Alan Munn a écrit :
> > In article<4d96013e$0$715$426a...@news.free.fr>,
> > GL<goua...@gmail.com> wrote:
> >
> >> Le 01/04/2011 18:11, Alan Munn a écrit :
> >>> Hi, I'm trying to get all chapter level headings set in uppercase
> >>> (including the LOT, LOF and any other Lists of that the user may have
> >>> defined) in my TOC in memoir. The following MWE shows the problem.
>
> > This doesn't solve the actual stated problem. The problem is not with
> > the formatting of the chapter titles, i.e the content of \chapter{} it's
> > with the formatting of the certain things that show up specifically in
> > the TOC.
>
> The "actual stated problem" is unclear to me.
>
> "chapter level headings" : what does it mean ?

I explained it further in my reply, (which you've bottom posted below)
and my code sample would also illustrate it.


> Chapter mark ?
> Entry in the toc ?
> Chapter title on the chapter page ?
> Title of the "Table of Contents"/"List of Figures" formatted as chapters ?
>
> What do you want to make upper case ?
> Do you want the table of contents to appear in the table of contents ???
> with the table of figures and of tables ???
>
>
>
> Besides, if you want "black-colored" links in the table of contents,
> the solution is:

Nowhere was this suggested that I wanted that. It's a side effect of
one of the possible solutions in my example though.

>
> First: \hypersetup{colorlink=true}% in the preamble
> Second: {\hypersetup{linkcolor=.}\tableofcontents }
>
> and xcolor.sty required.
>
>
> Finally I dislike memoir because memoir fakes the packages.

So with all due respect, don't answer questions about it. I'm not
interested in having a debate over the usefulness of memoir. I, and
many others like it for various reasons.

>
> What does \cftchaptername means ?????
> it's *not* in the *tocloft* documentation
> it means *nothing*
>
> Why \cftchapternumwidth ???
> in *tocloft* documentation it is \cftchapnumwidth ???
>
> Why is there no \cfttoctitlefont ???
> in *tocloft* documentation there is a \cfttoctitlefont !!!

Because this is memoir code and not tocloft code. Again, if you don't
know memoir, and you don't like memoir, then let others answer, please.

Thanks

Alan

GL

unread,
Apr 1, 2011, 1:57:45 PM4/1/11
to
Le 01/04/2011 18:11, Alan Munn a écrit :
Actually this is not good practice to put the table of contents in the
table of contents.

If you want to, it's always possible to add an \addcontentsline
statement in \cftmarktoc : this is its natural place.

Idem for \cftmarklof, \cftmarklot etc.

But it seems that memoir does not care of marks in the table of contents.

Is this good like that ?


%---------------------------------------------------------
\documentclass{memoir}
\usepackage[colorlinks]{hyperref}
\usepackage {xcolor,etoolbox}
\makeatletter

\renewcommand*{\cftchaptername}{Chapter\space}
\setlength{\cftchapternumwidth}{3em}

\def\texorpdf#1#2{\texorpdfstring{#1{#2}}{#2}}

\begin{document}
\frontmatter
{
\let\ADDCONTENTSLINE \addcontentsline \def\addcontentsline #1#2#3{}
\expandafter\def\expandafter\tocmark\expandafter{\tocmark\ADDCONTENTSLINE{toc}{chapter}{\protect\texorpdf\MakeUppercase{\contentsname}}}
\appto\lotmark{\ADDCONTENTSLINE{toc}{chapter}{\protect\texorpdf\MakeUppercase{\listtablename}}}
\appto\lofmark{\ADDCONTENTSLINE{toc}{chapter}{\protect\texorpdf\MakeUppercase{\listfigurename}}}
\hypersetup {linkcolor=.}
\loggingall
\tableofcontents

\listoffigures
\listoftables
}

\mainmatter

\chapter{A chapter}
\section{A section}
\begin{table}
\caption{A table}
\end{table}
\begin{figure}
\caption{A figure}
\end{figure}

% -----------------------------------------------------------------

zappathustra

unread,
Apr 1, 2011, 2:14:05 PM4/1/11
to
Le 01/04/2011 18:11, Alan Munn a écrit :
> Hi, I'm trying to get all chapter level headings set in uppercase
> (including the LOT, LOF and any other Lists of that the user may have
> defined) in my TOC in memoir. The following MWE shows the problem.
>
> If I redefine \l@chapapp to use \MakeUppercase on its first argument, it
> works, but not with hyperref. This is because hyperref adds a link
> which can't be expanded by \MakeUppercase.
>
> If I use \uppercase instead, then the links become black instead of red,
> and I don't understand why.
>
> I looked at Heiko's answer in this message:
> <http://groups.google.com/group/comp.text.tex/browse_thread/thread/7a22e6
> 4e266329c3/fa53e73877dc8984?q=hyperref+MakeUppercase#fa53e73877dc8984>
>
> But adding his suggested redefinition of \contentsline only seems to
> make the table of contents entry in the TOC uppercase, not any of the
> Lists-of, nor the chaptername.
>
> Can someone help me sort out a better way to do this?

This is just a hack, but if there is no other solution, the following
should provide a \fakeuppercase that should work reasonnably well:

%%%
\def\fakeuppercase#1{%
\FakeUppercase#1 endofentry % Intended space.
}
\def\FakeUppercase#1 {%
\unless\ifcsname #1@endofentry\endcsname
\FakeWord#1{endofentry} % Intended space.
\expandafter\FakeUppercase
\fi
}
\def\FakeWord#1{%
\unless\ifcsname #1@endofentry\endcsname
\ifcsname #1@uppercase\endcsname
\csname #1@uppercase\endcsname
\else
#1%
\fi
\expandafter\FakeWord
\fi
}

\csname endofentry@endofentry\endcsname
\expandafter\def\csname a@uppercase\endcsname{A}
\expandafter\def\csname b@uppercase\endcsname{B}
\expandafter\def\csname c@uppercase\endcsname{C}
% ... You get the picture? I let you write the other ones :)

%%%


Replace \uppercase with \fakeuppercase and, hopefully, it'll work.

Best,
Paul

Lars Madsen

unread,
Apr 4, 2011, 4:39:51 AM4/4/11
to

Seems we might need some refactoring in memoir

Something in the lines of:

\makeatletter

\renewcommand{\newlistof}[3]{%
\@namedef{ext@#2}{#2}
\@ifundefined{c@#2depth}{\newcounter{#2depth}}{}
\setcounter{#2depth}{1}
\@namedef{#2mark}{\markboth{#3}{#3}}
\@namedef{#1}{\@ifstar{\@nameuse{mem@#1}{01}}{\@nameuse{mem@#1}{00}}}
\@namedef{cft#2beforelisthook}{}%
\@namedef{cft#2afterlisthook}{}%
\@namedef{mem@#1}##1{%
\ensureonecol
\par
\begingroup
\@nameuse{@#2maketitle}
\if##1
\ifmem@em@starred@listof\else
\@nameuse{#1totoc}
\fi
\fi
\parskip\cftparskip
\@nameuse{cft#2beforelisthook}%
\@starttoc{#2}%
\@nameuse{cft#2afterlisthook}%
\endgroup
\restorefromonecol}
\@namedef{@#2maketitle}{%
\@nameuse{#2headstart}
{\parindent\z@
\parskip\z@
%%%% \parskip\cftparskip
\interlinepenalty\@M
\@nameuse{print#2nonum}%
\@nameuse{print#2title}{#3}%
\@nameuse{#2mark}%
\thispagestyle{chapter}%
\@nameuse{after#2title}
}
\@afterheading}
\@namedef{#2headstart}{\chapterheadstart}
\@namedef{after#2title}{\afterchaptertitle}
\@namedef{print#2nonum}{\printchapternonum}
\@namedef{print#2title}##1{\printchaptertitle{##1}}
\@namedef{#1totoc}{\phantomsection\addcontentsline{toc}{chapter}{#3}}
} % end \newlistof


\newlistof{tableofcontents}{toc}{\contentsname}
\newlistof{listoffigures}{lof}{\listfigurename}
\newlistof{listoftables}{lot}{\listtablename}

\renewcommand\tableofcontentstotoc{%
\phantomsection\addcontentsline{toc}{chapter}{CONTENTS}}


of course trying to combine this with hyperref and \MakeUppercase ends
in horror, but to me that seems to be hyperrefs problem, at least this
way one can gain access to it.

--

/daleif (remove RTFSIGNATURE from email address)

Memoir and mh bundle maintainer
LaTeX FAQ: http://www.tex.ac.uk/faq
LaTeX book: http://www.imf.au.dk/system/latex/bog/ (in Danish)
Remember to post minimal examples, see URL below
http://www.minimalbeispiel.de/mini-en.html

GL

unread,
Apr 4, 2011, 5:32:10 AM4/4/11
to

From the original post, it's possible to define a command
\MakeLinkUppercase designed for hyperref hyper-links:

\documentclass{memoir}
\usepackage{hyperref}
\makeatletter

\def\MakeLinkUppercase \hyper@linkstart #1#2#3\hyper@linkend
{\hyper@linkstart {#1}{#2}{\MakeUppercase{#3}}\hyper@linkend }


\renewcommand*{\cftchaptername}{Chapter\space}
\setlength{\cftchapternumwidth}{3em}

\pdfstringdefDisableCommands{\let\MakeUppercase \@firstofone }
\renewcommand*{\l@chapter}[2]{%
\l@chapapp{\MakeUppercase{#1}}{#2}{\cftchaptername}} % makes links black
\renewcommand*{\l@chapter}[2]{%
\l@chapapp{\MakeLinkUppercase #1}{#2}{\cftchaptername}} % crashes
\makeatother
\begin{document}
\frontmatter
{\loggingall


\tableofcontents
}
\listoffigures
\listoftables
\mainmatter
\chapter{A chapter}
\section{A section}
\begin{table}
\caption{A table}
\end{table}
\begin{figure}
\caption{A figure}
\end{figure}

Yours sincerely.

Lars Madsen

unread,
Apr 4, 2011, 5:41:49 AM4/4/11
to

interesting, but shouldn't hyperref provide this?

GL

unread,
Apr 4, 2011, 6:08:08 AM4/4/11
to
Le 04/04/2011 11:41, Lars Madsen a écrit :
> GL wrote:
>> Le 04/04/2011 10:39, Lars Madsen a écrit :
>>
>> \def\MakeLinkUppercase \hyper@linkstart #1#2#3\hyper@linkend
>> {\hyper@linkstart {#1}{#2}{\MakeUppercase{#3}}\hyper@linkend }
>>
>
> interesting, but shouldn't hyperref provide this?
>

Anyway I think the \contentsline of hyperref should be rewritten,
in order to execute \l@chapter on the title only, not on the
internal parameters of hyperref links:

\l@chapter {\hyperlink@start {link}{anchor}{title}\hyperlink@end}
{page number}

Should be something like:

\hyperlinkinTOC@start {link}{anchor}{\l@chapter {title}{number}} ...

But it's not easy to implement...

The other point, more important is that uppercase letters in the
toc should be possible without any \l@chapter and \l@chappapp
definition:

\cftbeforechaptitle = \MakeUppercase
or \cftchapfont = \MakeUppercase

should be possible, it this would be a correct interface.

This is like titlesec with the explicit option:
before = \MakeUppercase{#1}


Besides, I don't understand the implementation of \newlistof in
memoir: you need \phantomsection even with a non starred \section
because you set \addcontentsline at the beginning before the
\section command.

The natural and correct place for \addcontentsline is with
\sectionmark (or \tocmark in memoir, \cftmarktoc in tocloft).
Because: \sectionmark #1 -> \mark {#1}
and #1 is also the argument of \addcontentsline
(this is LaTeX... if one want to provide different
parameter for the toc and the header, it should be
thought further...)
And \sectionmark is executed just after the \section command.

I'm convinced that the order in which the commands are executed
is the most important thing in a programm. And this order must
be always the same for commands of same purpose:
print \tableofcontents title
is like \chapter or \section (same purpose)


Yours sincerely.

Lars Madsen

unread,
Apr 4, 2011, 6:26:01 AM4/4/11
to

huh, not understood

> The natural and correct place for \addcontentsline is with
> \sectionmark (or \tocmark in memoir, \cftmarktoc in tocloft).
> Because: \sectionmark #1 -> \mark {#1}
> and #1 is also the argument of \addcontentsline
> (this is LaTeX... if one want to provide different
> parameter for the toc and the header, it should be
> thought further...)
> And \sectionmark is executed just after the \section command.
>
> I'm convinced that the order in which the commands are executed
> is the most important thing in a programm. And this order must
> be always the same for commands of same purpose:
> print \tableofcontents title
> is like \chapter or \section (same purpose)
>
>
> Yours sincerely.

GL

unread,
Apr 4, 2011, 6:50:26 AM4/4/11
to
Le 04/04/2011 12:26, Lars Madsen a écrit :
> GL wrote:
>> Le 04/04/2011 11:41, Lars Madsen a écrit :
>>
>> Besides, I don't understand the implementation of \newlistof in
>> memoir: you need \phantomsection even with a non starred \section
>> because you set \addcontentsline at the beginning before the
>> \section command.
>>
>
> huh, not understood

Yes I was wrong ;-(

Back to your definition: it is correct relatively to what i said
about the order of the commands.

\@namedef{#1}{\@ifstar{\@nameuse{mem@#1}{YN}}{\@nameuse{mem@#1}{YY}}}

\@namedef{mem@#1}##1{%
\ensureonecol
\par

\begingroup % we are inside a group
\if ##1\else \@namedef{#1totoc}{}\fi
\@nameuse{@#2maketitle}
\if##1 |
\ifmem@em@starred@listof\else |-> this can be put inside
\@nameuse{#1totoc} | @#2maketitle


\fi |
\fi |
\parskip\cftparskip
\@nameuse{cft#2beforelisthook}%
\@starttoc{#2}%
\@nameuse{cft#2afterlisthook}%
\endgroup
\restorefromonecol}


\@namedef{@#2maketitle}{%
\@nameuse{#2headstart}
{\parindent\z@
\parskip\z@
%%%% \parskip\cftparskip
\interlinepenalty\@M
\@nameuse{print#2nonum}%
\@nameuse{print#2title}{#3}%

\@nameuse{#2mark}% |=> here \@nameuse{#1totoc}


\thispagestyle{chapter}%
\@nameuse{after#2title}
}
\@afterheading}


This would be just cleared like that, because \mem@toc is a
"general purpose command" which is not intended to be changed by
the user. If she doesn't want it, she does not use memoir.cls

While for \@tocmaketitle, it is recommended not to change it.
But it's not totally forbidden.

\@namedef{#2mark}{\markboth{#3}{#3}}% => and this is junky old TeX
% use eTeX \marks !


Yours sincerely.

Lars Madsen

unread,
Apr 4, 2011, 7:03:16 AM4/4/11
to

you are right in that, perhaps we will change it

> While for \@tocmaketitle, it is recommended not to change it.
> But it's not totally forbidden.
>
>
>
> \@namedef{#2mark}{\markboth{#3}{#3}}% => and this is junky old TeX
> % use eTeX \marks !
>

what's wrong with using \markboth? I've neveer even used \marks

GL

unread,
Apr 4, 2011, 7:32:00 AM4/4/11
to
Le 04/04/2011 13:03, Lars Madsen a écrit :
>> \@namedef{#2mark}{\markboth{#3}{#3}}% => and this is junky old TeX
>> % use eTeX \marks !
>>
>
> what's wrong with using \markboth? I've neveer even used \marks

\firstmark gives you the first \mark on the page, at \shipout time.
If you \markboth, it will be impossible to retrieve any further \mark.
While if you use independant \marks register, you can retrieve the
\firstmarks from the registers you want.


\documentclass [a4paper]{article}
\usepackage [T1]{fontenc}
\usepackage {fancyhdr}
\begin{document}

\fancyhead[L]{\leftmark}\fancyhead[R]{\rightmark}\pagestyle{fancy}

\section{One}

\subsection{Two}

shipout\clearpage

\def\sectionmark #1{\marks1{#1}}
\def\subsectionmark #1{\marks2{#1}}
\fancyhead [L]{\firstmarks1}\fancyhead[R]{\firstmarks2}\pagestyle{fancy}

\section{One}
\subsection{Two}

\end{document}\endinput

0 new messages