
我最近嘗試概括一個使用腳註標記和腳註文字的命令。為此,我使用定義了計數器的條件調用,該計數器用作對先前調用的測試。
我在測試結構上遇到了一些問題,但它在 stackexchange 上的另一個問題中得到了解決。但現在我遇到了一個更奇怪的問題。如果從圖形標題或文字呼叫命令,條件測試的運作方式似乎有所不同。我不明白為什麼。
更奇怪的是,如果從經典圖形或使用 ffimgbox 的圖形呼叫它,它的行為會有所不同。
這裡是說明問題的測試程式碼:(我使用 tux.png 進行測試:https://upload.wikimedia.org/wikipedia/commons/a/af/Tux.png)
%%%%%%%%%%% LOT OF PACKAGES AND DEFINITIONS %%%%%%%%%%
\documentclass[a4paper,12pt,oneside,final, DIV=12, listof=totoc, bibliography=totoc, toc=bibliography, open=right, chapterprefix=true]{scrbook}
\usepackage[greek,english,french]{babel}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[final]{hyperref}
\usepackage{footnotehyper}
\usepackage{footnotebackref}
\usepackage{tablefootnote}
\usepackage{graphicx}
\graphicspath{ {images/} }
\usepackage[format=plain, font=small, labelfont=bf, textfont=it]{caption}
\usepackage{floatrow}
\usepackage{perpage}
\MakePerPage{footnote}
\usepackage[float=false]{scrhack}
%%%%%%%%%%% LOT OF PACKAGES AND DEFINITIONS END %%%%%%%%%%
%%%%%%%%%%% BEGENNING OF THE WORK ON FOOTNOTES %%%%%%%%%%
%%% Counter for making unique ID for the footnotemark and footnotetext without [] %%%%%%
\newcounter{myHyperFootnoteCounterMARK}
%%%%% Counter for testing in which branch of testing we go %%%%%%
\newcounter{lalala}
%
\makeatletter
%%%%% define an new footnote with optional argument : the IF never reach the undefined case, the counter "lala" is never incrememented and "BA" is only shown in the text : i have tested diverses formulation \@ifundefined \ifcsname etc etc... %%%%%
\newcommand{\myOptHyperFootnotetext}[2][plop]{
\def\myFootnoteTagtextARGU{hfoi:#1}
\def\mysavee{saved@Href@#1}
%
\ifcsname c@counter@Href:#1\endcsname
% CASE DEFINED
AA\thelalala
%
\expandafter\let\expandafter\Hy@footnote@currentHref\csname\mysavee\endcsname%
\footnotetext{\hyperref[\myFootnoteTagtextARGU]{$\uparrow$}~#2}%
%
\else
% CASE UNDEFINED
AB\stepcounter{lalala}
%
\expandafter\let\expandafter\Hy@footnote@currentHref\csname\mysavee\endcsname
\footnotetext{\hyperref[\myFootnoteTagtextARGU]{$\uparrow$}~#2}
%definition of the counter if it is undifined
\newcounter{counter@Href:#1}
%
\fi
}
\newcommand{\myOptHyperFootnotemark}[1][plop]{%
\def\myFootnoteTagtextargu{hfoi:#1}%
\def\mysave{saved@Href:#1}%
%
\ifcsname c@counter@Href:#1\endcsname
% CASE DEFINED
BA\thelalala
%
\label{\myFootnoteTagtextargu}
\footnotemark \global\expandafter\let\csname\mysave\endcsname\Hy@footnote@currentHref%
\else
% CASE UNDEFINED
BB\stepcounter{lalala}
\label{\myFootnoteTagtextargu}
\footnotemark \global\expandafter\let\csname\mysave\endcsname\Hy@footnote@currentHref%
%definition of the counter if it is undifined
\newcounter{counter@Href:#1}
%
\fi
}
%
\makeatother
%%%%%%% some package %%%%%%%
\KOMAoptions{DIV=last}
%%%%%% begin %%%%%%%
\begin{document}
%%%%%% TEST %%%%%%
\chapter{TEST}
\section{Introduction}
Texttest
%%%%%%%% uncomment this to test the code when it works outisde the figure %%%%%%%%
%\myOptHyperFootnotemark[truc]
%%%%%%%% Uncomment to test the code in a classic figure %%%%%%%%
%\begin{figure}[h]
%\centering
%\includegraphics{Tux.png}
%\caption{A caption \myOptHyperFootnotemark[truc]}
%\label{Tux}
%\end{figure}
%%%%%%%% The code calling from the caption inside a floatrow %%%%%%%%
\begin{figure}[ht]
\centering
{
\begin{floatrow}[1]
\ffigbox[\FBwidth]{\caption[blaa]{\label{Tino} BLAAAAA \myOptHyperFootnotemark[truc]}}%
{\includegraphics{Tux.png}}.
\end{floatrow}
}
\end{figure}
EEEEEEEEEEEEEEEEE
EEEEEEEEEEEEEEEEE
\myOptHyperFootnotetext[truc]{A footnote}%
\end{document}
理論上,在 myOptHyperFootnotetext 之前調用 myOptHyperFootnotemark 應該會導致創建計數器“counter@Href:truc”並增加計數器“lala”,此處用作對這些函數調用的測試。 0 表示 lala = 從未呼叫過計數器的創建,而其他數字 -> 呼叫了創建。
它適用於從文字呼叫的程式碼的取消註解部分。我們在文本中獲得“BB”(這意味著:“我在函數的賦值塊中”)和腳註中的“AA1”(這意味著:具有該名稱的計數器已經被分配,所以我在未分配的塊)。這是我們想要的結果,也是合乎邏輯的,這也證明了測試是有效的。
但是如果你在圖中做同樣的事情,結果是不一樣的(註解掉部分程式碼以取消註解以進行測試)。在經典圖中,我們在文本中獲得“BA1”,在腳註中獲得“AA1”。這兩者都意味著:在另一點調用了創建變數的程式碼,但它不在這裡(但在哪裡?...)。
如果你在floatrow 環境中呼叫它(這是我的目標),結果會更奇怪,因為它顯示BA0 和AA0,這意味著「我們從未呼叫過賦值函數,但我們無論如何都通過了計數器是否存在的測試......”
最後一個變體對我來說非常奇怪,我真的不明白它怎麼可能...
我需要任何幫助;)