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 am trying to create a header that consist of chaptername and sectionname (chaptername:sectionname) both of them a hyperlink to chapter and section respectively. I am using Hungarian language so there are many accented word, and - as I gathered - hyperref do not support accented links and after all, section names can be the same in different chapters so I need to get some unique names. So I generate a unique ASCII section name (see \Section) and in \sectionmark I concatenated it with the name of the section and in \fancyhead I try to separate them again and using them in a \hyperlink command, but so far I failed. Here is the brief (not working) code example:

\documentclass[pdftex,a4paper,12pt,oneside]{book}%

\usepackage[latin2]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[magyar]{babel}
\usepackage{fancyhdr}
\usepackage{xstring}
\usepackage{hyperref}
\usepackage{bookmark}

\hypersetup{colorlinks,                               linkcolor=blue!80,filecolor=Orange,urlcolor=red!60,citecolor=magenta,
              linktoc=all,
            hypertexnames=false,
            unicode=true,
            bookmarksnumbered=false,
        pdfmenubar=true,%
          pdftoolbar=true
         }

\newcommand{\chapterlinkname}{}
\newcommand{\setchapterlinkname}[1]{\renewcommand{\chapterlinkname}{#1}}
\newcommand{\chapterlink}[1]{\setchapterlinkname{lnk:chap#1}\hypertarget{\chapterlinkname}{}}
\newcommand{\Chapter}[2]{\newpage\chapterlink{#2} \chapter{#1}}

\newcommand{\sectionlinkname}{}
\newcommand{\setsectionlinkname}[1]{\renewcommand{\sectionlinkname}{#1}}
\newcommand{\sectionlink}[1]{\setsectionlinkname{\chapterlinkname:sec#1}\hypertarget{\sectionlinkname}{}}
\newcommand{\Section}[2]{\sectionlink{#2}\section{#1}}

\newcommand{\seclink}{}
\newcommand{\secname}{}
\newcommand{\mystrsplit}[4]{
  \renewcommand{#3}{\StrBefore{#1}{#2}}
  \renewcommand{#4}{\StrBehind{#1}{#2}}
}  

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

\begin{document}

\pagestyle{fancy}
\fancyhf{} 
\renewcommand{\chaptermark}[1]{\markboth{##1}{}}
\renewcommand{\sectionmark}[1]{\markright{\sectionlinkname,##1}} 

\fancyhead[LO,RE]{\mystrsplit{\rightmark}{,}{\seclink}{\secname} \hyperlink{\chapterlinkname}{\bfseries\leftmark} : \hyperlink{\seclink}{\bfseries\secname}}  

\fancyhead[LE,RO]{\bfseries\thepage}
\renewcommand{\headrulewidth}{0.5pt}
\renewcommand{\footrulewidth}{0pt}
\addtolength{\headheight}{2.5pt} 
\fancypagestyle{plain}{\fancyhead{}\renewcommand{\headrulewidth}{0pt}} 

\Chapter{Állóképek}{Allokepek}

\Section{Tükörkép}{Tukorkep}

\newpage

\Section{Sírkőgyártó}{Sirkogyarto}

\end{document}

I am using MiKTeX 2.9 with TeXnicCenter.

share|improve this question
    
possible duplicate of Nested macros and hyperlink problem –  Marco Daniel Apr 15 '12 at 9:14
    
see at: (tex.stackexchange.com/questions/51770/…) –  pmks Apr 16 '12 at 7:18
add comment

1 Answer

up vote 10 down vote accepted

The following example first fixes a compatibility problem between hyperref and magyar. Both redefine \refstepcounter. Then \@currentHref is available that contains the name of the anchor used in hyperref's \refstepcounter. Then the titles of the chapters or sections do not need to be used as target or label name.

\documentclass[pdftex,a4paper,12pt,oneside]{book}%

\usepackage[latin2]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage{fancyhdr}

\usepackage[magyar]{babel}
% magyar.ldf redefines \refstepcounter in \extrasmagyar
% and overwrites hyperref's definition.
% The following hacks work around this by
% restoring hyperref's definition that will
% then call magyar.ldf's version.
\begingroup
  \extrasmagyar
  \global\let\MagyarRefstepcounter\refstepcounter
\endgroup
\let\refstepcounter\MagyarRefstepcounter
\usepackage{hyperref}
\let\HyperrefRefstepcounter\refstepcounter
\addto\extrasmagyar{%
  \let\refstepcounter\HyperrefRefstepcounter
}
\usepackage{bookmark}

\hypersetup{colorlinks,
            linkcolor=blue!80,filecolor=Orange,
            urlcolor=red!60,citecolor=magenta,
            linktoc=all,
            hypertexnames=false,
            unicode=true,
            bookmarksnumbered=false,
        pdfmenubar=true,%
          pdftoolbar=true
         }

\begin{document}

\pagestyle{fancy}
\fancyhf{} 

% \@currentHref contains the anchor name
\makeatletter
\renewcommand{\chaptermark}[1]{%
  \markboth{\protect\hyperlink\@currentHref}{\thechapter. #1}}{}%
}
\renewcommand{\sectionmark}[1]{%
  \markright{\protect\hyperlink{\@currentHref}{\thesection. #1}}%
}

\fancyhead[LO,RE]{{\bfseries\leftmark} : {\bfseries\rightmark}}  

\fancyhead[LE,RO]{\bfseries\thepage}
\renewcommand{\headrulewidth}{0.5pt}
\renewcommand{\footrulewidth}{0pt}
\addtolength{\headheight}{2.5pt} 
\fancypagestyle{plain}{\fancyhead{}\renewcommand{\headrulewidth}{0pt}} 

\chapter{Állóképek}

\section{Tükörkép}

\newpage

\section{Sírkogyártó}

\end{document}
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.