I am currently trying to redefine some aspect of the footnote, footnotemark and footnotetext command to allow the use of these command in diverses situation (like in float) with things like hyperlink and backref. And it now work well in a large set of situation.
But, i am stuck at redefining a specific command. It seems like a problem of expansion in the command.
\documentclass[a4paper,12pt,oneside,final, DIV=12, listof=totoc, bibliography=totoc, toc=bibliography, open=right, chapterprefix=true]{scrbook}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{pdfpages}
\usepackage{xspace}
\usepackage[final]{hyperref}
\usepackage{footnotehyper}
\usepackage{footnotebackref}
\usepackage{tablefootnote}
\usepackage{bookmark}
\usepackage{perpage}
\MakePerPage{footnote}
%
% Lot of other package not usefull
%
%%%%%%%% redefinition of "footnote" to allow cool backref (work well) %%%%%%
\let\oldfootnote\footnote
%a new counter to create an unambiguous label-tag
\newcounter{myHyperFootnoteCounter}
\makeatletter
% branch between the footnote with/without opt. argument
\renewcommand{\footnote}{\@ifnextchar[\my@OptHyperFootnote\my@HyperFootnote}
%define an new footnote without optional argument
\newcommand{\my@HyperFootnote}[1]{%
\refstepcounter{myHyperFootnoteCounter}%
\def\myFootnoteTag{hfn:\themyHyperFootnoteCounter}%
\label{\myFootnoteTag}%
\oldfootnote{\hyperref[\myFootnoteTag]{$\uparrow$}~#1}%
}
%define an new footnote with optional argument
\newcommand{\my@OptHyperFootnote}[2][plop]{%
\refstepcounter{myHyperFootnoteCounter}%
\def\myFootnoteTag{hfn:\themyHyperFootnoteCounter}%
\label{\myFootnoteTag}%
% put the optional argument to the original `footnote`
\oldfootnote[#1]{\hyperref[\myFootnoteTag]{$\uparrow$}~#2}%
}
\makeatother
%%%%%%%%%%%%redefinition of myHyperFootnoteCounterMARK : work partially %%%%%%
\newcounter{myHyperFootnoteCounterMARK}
\let\oldfootnotetext\footnotetext
\let\oldfootnotemark\footnotemark
%
\makeatletter
\renewcommand{\footnotetext}{\@ifnextchar[\my@OptHyperFootnotetext\my@HyperFootnotetext}
%
\newcommand{\my@HyperFootnotetext}[1]{%
\def\myFootnoteTagtext{hfu:\themyHyperFootnoteCounterMARK}%
\oldfootnotetext{\hyperref[\myFootnoteTagtext]{$\uparrow$}~#1}
}
\newcommand{\my@OptHyperFootnotetext}[2][plop]{%
\def\myFootnoteTagtextARGU{hfoi:#1}%
\def\mysave{saved@Href@A}% In theory : saved@Href@#1
\let\Hy@footnote@currentHref\mysave
\oldfootnotetext{\hyperref[\myFootnoteTagtextARGU]{$\uparrow$}~#2}
}
%
\renewcommand{\footnotemark}{\@ifnextchar[\my@OptHyperFootnotemark\my@HyperFootnotemark}
%
\newcommand{\my@HyperFootnotemark}{%
\refstepcounter{myHyperFootnoteCounterMARK}%
\def\myFootnoteTagtext{hfu:\themyHyperFootnoteCounterMARK}%
\label{\myFootnoteTagtext}%
\oldfootnotemark%
}
\newcommand{\my@OptHyperFootnotemark}[1][plop]{%
\refstepcounter{myHyperFootnoteCounterMARK}
\def\myFootnoteTagtextargu{hfoi:#1}
\def\mysave{saved@Href@A}% In theory : saved@Href@#1
\label{\myFootnoteTagtextargu}%
\oldfootnotemark \global\let\mysave\Hy@footnote@currentHref%
}
%
\makeatother
The error is in the end of the command.
I use an Hyperref tricks by redefining manually \global\let\mysave\Hy@footnote@currentHref
after footnotemark and \let\Hy@footnote@currentHref\mysave
before footnotetext. It allow the use of footnotemark and footnotetext out of order by redefining on which footnotetext point footnotemark without using the [] variant that are not supported by hypperef.
The tricks work well in text, but i would like to generalise it. So i have redefined the [] variant of footnotemark and footnotetext to use the classic version of footnotemark and footnotetext (i have no use of the [] variant) but to use the optionnal argument as an anchor for hyperref, which allow me to define manually label of hyppereference with footnotemark and footnotetext.
The command work well if i write inside the command an ad-hoc argument to test it (like \global\let\saved@Href@AHy@footnote@currentHref
) (obviously, they don't point on a good target but it works) but when i tried to generalise that with :
\def\mysave{saved@Href@#1}%
\oldfootnotemark \global\let\mysave\Hy@footnote@currentHref%
it throw multiple error when i try to use the [] variant of footnotemark and footnotetext. (Undifined control sequence).
I have tested the replacement by a simple anchor like :
\def\mysave{saved@Href@A}%
\oldfootnotemark \global\let\mysave\Hy@footnote@currentHref%
And it doesn't work neither. So i guessed it was an axpansion priority problem and i tried the classical :
\def\mysave{saved@Href@A}%
\oldfootnotemark%
\expandafter\global\expandafter\let\mysave\Hy@footnote@currentHref%
But it surprinsigly doesn't work ... and throw multiple " missing control sequence inserted " . I have looked on several solution through the web that look like the one i have used so i don't understand why it doesn't work.
Any help will be appreciated ;)
\mysave
is just a bunch of characters, not a control sequence, so you can't\let
it to anything. Try\global\expandafter\let\csname\mysave\endcsname\Hy@footnote@currentHref
saved@Href@A
and (2)\saved@Href@A
are both a bunch of characters. However to TeX's eyes, the\
in front of example 2 makes it be one single (so-called) token, so for TeX example 1 is a group of 12 character tokens, while the second example is one single control sequence token, and that makes all the difference. The syntax of\let
is\let<token>=<token>
(the=
is optional), so you need two tokens, and your\mysave
contains several. Then\csname<characters>\endcsname
turns<characters>
into\<characters>
, which is what you need here.