# Conflict between appendix, bookmark, hyperref and magyar babel due to utf8 chars

I tried to use babel with the magyar language along with the package appendix and hyperref. There is an issue with the warnings of magyar babel and a I also had a similar problem to that one when one loads the dutch language for babel. My approach was to mix the the solutions in mweA.tex:

\UseRawInputEncoding % [2]
\documentclass{book}
\usepackage{hyperref} % either I have it or not
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\def\magyarOptions{defaults=hu-min} % [2]
\usepackage[magyar]{babel}

\usepackage[titletoc]{appendix}
\usepackage{bookmark} % [1]

\begin{document}

\tableofcontents

\begin{appendices}
\chapter{test appendix}
\end{appendices}
\end{document}


or in mweB.tex:

\documentclass{book}
\usepackage{hyperref} % either I have it or not
\usepackage[T1]{fontenc}

\def\magyarOptions{defaults=hu-min,suggestions=no} % [2]
\usepackage[magyar]{babel}

\usepackage[titletoc]{appendix}
\usepackage{bookmark} % [1]

\begin{document}

\tableofcontents

\begin{appendices}
\chapter{test appendix}
\end{appendices}
\end{document}


(References in the code: [1] [2].) But in both cases I got the following error:

! Undefined control sequence.
\GenericError  ...
#4  \errhelp \@err@     ...
l.1 ...mberline {A}test appendix}{3}{függelék.a.A}


What is going wrong here? How could I use the package appendix with magyar babel?

I figured out that without \usepackage{hyperref} I got the same errors, but if I remove \usepackage{bookmark}, the problems disappear. But I'd like to use the \usepackage{hyperref} package.

The problematic bit seems to be

\contentsline {chapter}{f\"uggel\'ek \numberline {A}test appendix}{3}{függelék.1.A}


that is produced in the .aux and .toc file when the example is run.

In particular the fact that the last argument of \contentsline, the link destination label, contains non-ASCII characters really seems to bother pdfTeX, where non-ASCII characters in label should be avoided (see Non-ASCII character in label and Non-English identifiers in \label / \ref ("Missing \endcsname inserted")). (The MWEs both work fine with LuaLaTeX. Interestingly XeLaTeX seems to hang on something as well, which I did not expect ...)

You can instruct appendix not to use the translated string függelék as a label, but to stick with the safe appendix as defined in \Hy@appendixstring instead.

With

\UseRawInputEncoding
\documentclass{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\def\magyarOptions{defaults=hu-min}
\usepackage[magyar]{babel}
\usepackage[titletoc]{appendix}
\usepackage{hyperref}
\usepackage{bookmark}

\makeatletter
\renewcommand{\@resets@pp}{\par
\@ppsavesec
\stepcounter{@pps}
\setcounter{section}{0}%
\if@chapter@pp
\setcounter{chapter}{0}%
\renewcommand\@chapapp{\appendixname}%
\renewcommand\thechapter{\@Alph\c@chapter}%
\else
\setcounter{subsection}{0}%
\renewcommand\thesection{\@Alph\c@section}%
\fi
\if@pphyper
\if@chapter@pp
\renewcommand{\theHchapter}{\theH@pps.\Alph{chapter}}%
\else
\renewcommand{\theHsection}{\theH@pps.\Alph{section}}%
\fi
\xdef\Hy@chapapp{\Hy@appendixstring}% <- changed appendixname to \Hy@appendixstring
\fi
\restoreapp
}
\renewcommand{\@resets@ppsub}{\par
\stepcounter{@pps}
\if@chapter@pp
\setcounter{section}{0}
\renewcommand{\thesection}{\setthesection}
\else
\setcounter{subsection}{0}
\renewcommand{\thesubsection}{\setthesubsection}
\fi
\if@pphyper
\if@chapter@pp
\renewcommand{\theHsection}{\theH@pps.\setthesection}%
\else
\renewcommand{\theHsubsection}{\theH@pps.\setthesubsection}%
\fi
\xdef\Hy@chapapp{\Hy@appendixstring}% <- changed appendixname to \Hy@appendixstring
\fi
}
\makeatother

\begin{document}

\tableofcontents

\begin{appendices}
\chapter{test appendix}
\end{appendices}
\end{document}


the example should compile. The \xdef\Hy@chapapp{\Hy@appendixstring} instead of appendix.sty's \def\Hy@chapapp{\appendixname} is directly taken from hyperref.sty's definition of \appendix. This is exactly what was the cause of the issue in Conflict between babel, hyperref and appendix package as well, but the workaround mentioned there did not help here - we really had to address the root of the issue directly. See also Apéndices (Appendix spanish accent), How to make appendix and hyperref packages work together with cyrillic (non ASCII) characters?, Hyperref, Bookmark and Appendix packages: Getting labels inside Appendices to work.

You should probably delete your temporary files and recompile from scratch to avoid remnants of the old code in the auxiliary files messing things up.

You may also want to consider writing to the maintainer of appendix.sty about this issue. At least to me it seems like a good idea to use the safe string \Hy@appendixstring here instead of the potentially dangerous \appendixname.

Note that I changed the loading order in your preamble a bit. hyperref should usually be the last package you load (there are a few documented exceptions like cleveref and some matters of taste, like the order together with bookmark: Which package should I load first: hyperref or bookmark?): It was loaded very (too?) early in your example.