%20definida%20em%20um%20comando%20chamado%20a%20partir%20de%20uma%20figura%20se%20comporta%20como%20foi%20definida%20automaticamente%20antes.png)
Recentemente, tentei generalizar um comando trabalhando com marca de rodapé e texto de nota de rodapé. Para isso, trabalho com uma chamada condicional que definiu um contador, que serve como teste das chamadas anteriores.
Encontrei algum problema com a estrutura do teste, mas foi resolvido em outra questão no stackexchange. Mas agora me deparo com um problema mais estranho. O teste condicional parece funcionar de forma diferente se os comandos forem chamados a partir da legenda de uma figura ou de um texto. E não vejo porquê.
O mais estranho é que ele se comporta de maneira diferente se for chamado a partir de uma figura clássica ou de uma figura usando ffimgbox.
Aqui está o código de teste para ilustrar o problema: (eu uso tux.png para o teste: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}
Em teoria, a chamada de myOptHyperFootnotemark antes de myOptHyperFootnotetext deveria levar à criação do contador "counter@Href:truc" e ao incremento do contador "lala" que serve aqui como teste para a chamada destas funções. 0 para lala = nunca chamou a criação do contador e outro número -> a criação foi chamada.
E funciona na parte de descomentar do código chamado de um texto. Obtemos "BB" no texto (que significa: "Estou no bloco de atribuição da função") e "AA1" na nota de rodapé (que significa: o contador com esse nome já foi atribuído, então estou no bloco não atribuído). Esse é o resultado desejado e é lógico, isso também prova que o teste funciona.
Mas se fizer o mesmo em uma figura, o resultado não é o mesmo (parte comentada do código para descomentar para teste). Numa figura clássica, obtemos “BA1” no texto e “AA1” na nota de rodapé. O que ambos significam: em outro momento o código para criar a variável foi chamado, mas não está aqui (mas onde?...).
O resultado é ainda mais estranho se você o chamar em um ambiente floatrow (que é meu objetivo), pois mostra BA0 e AA0 que significam "Nunca chamamos a função de atribuição, mas passamos no teste da existência do contador de qualquer maneira..."
Esta última variante é muito estranha para mim e não entendo bem como isso pode ser possível ...
Aceito qualquer ajuda ;)
Responder1
A resposta completa desta pergunta foi dada por @frougon nesta pergunta: Como fazer uma rotulagem condicional robusta que resista a múltiplas compilações e figuras?
É um pouco técnico, mas funciona (no balcão, na etiqueta ou qualquer outra coisa).
Por favor, reporte-se a esta página para ter a resposta completa;)