ho-tex / oberdiek

Updating the oberdiek bundle
Other
16 stars 6 forks source link

conflict with documentclass boek and \part, because of MakeUppercase #58

Closed db-inf closed 11 months ago

db-inf commented 5 years ago

I use the documentclass boek, a dutch equivalent largely compatible with the standard class book, but with some style modifications. One of them is that it prints a \part title in uppercase. That conflicts with the redefinition of the \MakeUppercase command in hyperref.sty.

Compiling this minimal example (in TexLive 2016, which has the latest hyperref version as per the hyperref README.md) :

\documentclass[dutch]{boek}
\usepackage{babel}
\usepackage{hyperref}
\begin{document}
    \part{My part title}
    tekst
\end{document}

gives this error in the log

! Undefined control sequence.
\MakeUppercase ...ppercaseUnsupportedInPdfStrings 

l.5     \part{My part title}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

The conflict is clearly, and seemingly intentionally, caused by this definition in hyperref.sty :

    \def\MakeUppercase{\MakeUppercaseUnsupportedInPdfStrings}%
    \def\MakeLowercase{\MakeLowercaseUnsupportedInPdfStrings}%

with, as far as I can see, \MakeUppercaseUnsupportedInPdfStrings being an undefined command.

I can work around this conflict by giving \MakeUppercaseUnsupportedInPdfStrings a proper definition, such as equating it to the basic \uppercase command

\def\MakeUppercaseUnsupportedInPdfStrings{\uppercase}

or to a small caps command

\def\MakeUppercaseUnsupportedInPdfStrings{\scshape}

or their equivalents forms with \newcommand.

Maybe I could even define \MakeUppercaseUnsupportedInPdfStrings to the original definition of \MakeUppercase. But then the question arrises: why does the hyperref package need to invalidate that command by replacing it with \MakeUppercaseUnsupportedInPdfStrings? What will go wrong with my workarounds?

The ChangeLog.txt has only 2 mildly relevant entries :

2009-04-04  6.78q  Heiko Oberdiek
    * 6.78q
* Better error message for \MakeUppercase and \MakeLowercase

and

2000-05-08  6.70g  Heiko Oberdiek
    * 6.70g
    * \autoref names: To solve the uppercase problem,
first the names \...autorefname are used in \autoref.

so this may date to before 1997.

Is the reason for \MakeUppercaseUnsupportedInPdfStrings still known?

u-fischer commented 5 years ago

The problem is not that the class prints the part name with \MakeUppercase (actually it uses \uppercase here) but that it uses it also for the tableofcontents (and so it ends also in the bookmarks):

  \addcontentsline{toc}{part}{\toc@case{#1}}%

(toc@case is defined as \MakeUppercase).

None of your definitions will work around the problem. Setting \MakeUppercaseUnsupportedInPdfStrings to \MakeUppercase will gives errors, \uppercase will compile but will be removed by hyperref (" Token not allowed in a PDF string "), and similar with \scshape.

Imho the only sensible definition is

 \let\MakeUppercaseUnsupportedInPdfStrings\@firstofone

(I have no idea why it is not the default ...).

db-inf commented 5 years ago

You are right: both my workarounds compile and render fine with \tableofcontents and only 1 \part, but indeed, 2 and more \part make the conflict appear again. I had not noticed that yet, because I am still working on the first part of my little book.

Your suggestion however may not have the right syntax, and it is beyond me to puzzle out how it should be. Copied like you wrote it, either before or after \usepackage{hyperref}, it gives this as first error :

! LaTeX Error: Missing \begin{document}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.4 \let\MakeUppercaseUnsupportedInPdfStrings\@f
                                                 irstofone

and then adds 2 errors per \part after the first one :

! LaTeX Error: Something's wrong--perhaps a missing \item.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.3 ...em}\MakeUppercase {My 2nd part title}}{9}{part.2}

Try typing  <return>  to proceed.
If that doesn't work, type  X <return>  to quit.

But thanks for giving attention to this case.

u-fischer commented 5 years ago

You need \makeatletter before the line (as \@firstofone contains a @).

db-inf commented 5 years ago

Thank you. I updated my minimal not-working example to

\documentclass[dutch]{boek}
\usepackage{babel}
\usepackage{hyperref}
\makeatletter
\let\MakeUppercaseUnsupportedInPdfStrings\@firstofone
\makeatother
\begin{document}
    \tableofcontents    
\part{My 1st part title}
    tekst
\part{My 2nd part title}
    tekst
\part{My 3rd part title}
    tekst
\end{document}

This still compiles with errors, but one of early passes of, I think, latexpdf does produce a pdf that at first sight looks OK: part titles in capitals, and table of contents hyperlinked to them. It still makes no difference wether the replacement of \MakeUppercaseUnsupportedInPdfStrings is before or after \usepackage{hyperref}. mwe.log

The errors in the log are

 (output/mwe.toc

! LaTeX Error: Something's wrong--perhaps a missing \item.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.3 ...keUppercase {My 2nd part title}}{7}{part.2}
[mwe.log](https://github.com/ho-tex/oberdiek/files/2848191/mwe.log)

However, maybe this thread starts to belongs on something like Stack Exchange, instead of here on the developer's github.

u-fischer commented 5 years ago

That's not a hyperref problem and not related to the definition. The class is faulty, it doesn't like if two \part entries follow directly after another in the toc. Add a chapter:

\documentclass[dutch]{boek}
\usepackage{babel}
\begin{document}
    \tableofcontents    
\part{My 1st part title}
%\chapter{blub} %without this error
    tekst
\part{My 2nd part title}
\end{document} 
db-inf commented 5 years ago

Thanks, that works.

Conclusion This issue could be closed, if it would be acceptable for the rest of the package hyperref to include these 2 definitions in hyperref.sty :

\makeatletter
\let\MakeUppercaseUnsupportedInPdfStrings\@firstofone
\let\MakeLowercaseUnsupportedInPdfStrings\@firstofone
\makeatother
pablgonz commented 4 years ago

@davidcarlisle I vote to move this issue to hyperref repository.

ilateef commented 3 years ago

Thank you for clearly identifying this problem and giving a solution. I have been struggling with this for a while in Ph.D. thesis.

u-fischer commented 11 months ago

This should be in the hyperref repository. But beside this the problem has been resolved in a current LaTeX and the original document no longer errors.