図から呼び出されたコマンドで定義された条件変数(カウンター)は、以前に自動的に定義されたように動作します。

図から呼び出されたコマンドで定義された条件変数(カウンター)は、以前に自動的に定義されたように動作します。

最近、footnotemark と footnotetext を操作するコマンドを一般化しようとしています。そのために、以前の呼び出しのテストとして機能するカウンターを定義した条件付き呼び出しを使用しています。

テストの構造で問題が発生しましたが、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" の増分につながるはずです。これは、ここではこれらの関数の呼び出しのテストとして機能します。lala の 0 = カウンターの作成は呼び出されず、その他の数値 -> 作成が呼び出されました。

そして、テキストから呼び出されるコードのコメント解除部分で動作します。テキストでは「BB」(つまり、「関数の割り当てブロック内」)が、脚注では「AA1」(つまり、その名前のカウンターは既に割り当てられているため、未割り当てブロック内)が取得されます。これは、必要な結果であり、論理的であり、テストが機能していることも証明しています。

しかし、図で同じことを行うと、結果は同じではありません (テストのためにコメント解除するコードのコメント部分)。 典型的な図では、テキストに「BA1」、脚注に「AA1」が表示されます。 どちらも次のことを意味します。別の時点で変数を作成するコードが呼び出されましたが、ここにはありません (しかし、どこですか? ...)。

これを floatrow 環境で呼び出した場合 (これが私の目標です)、結果はさらに奇妙になります。BA0 と AA0 が表示されるためです。これは、「割り当て関数を呼び出したことはありませんが、とにかくカウンターの存在のテストに合格しました...」という意味です。

この最後のバリエーションは私にとって非常に奇妙であり、それがどのように可能なのか本当に理解できません...

どんな助けでも歓迎します ;)

答え1

この質問の完全な回答は、この質問で @frougon によって提供されています: 複数のコンパイルや図に耐える堅牢な条件付きラベル付けを作成するにはどうすればよいでしょうか?

少し技術的ですが、機能します(カウンターやラベルなど)。

完全な回答を得るには、このページに報告してください ;)

関連情報