armazenamento direto tipo toc para legendas

armazenamento direto tipo toc para legendas

Caros especialistas: como escrever as legendas das tabelas para uso posterior? Pensar

\documentclass{article}

\newcommand{\mycaption}[2]{\caption{#2}\label{#1}\savecaptioncontent{#1}{#2}}
\newcommand{\insertmytable}[1]{
  \begin{center}
   Insert Table~\ref{#1} here: '\contentcaption{#1}'
  \end{center}
}

\begin{document}

blah blah.  Table~\ref{tbl:first} tells me little.

\insertmytable{tbl:first}

above, it should have printed:

\begin{center}
   Insert Table~\ref{tbl:first} here: 'This is my first table'
\end{center}

\begin{table}
\mycaption{tbl:first}{This is my first table}
\end{table}

\end{document}

Quase certamente quero escrever no .auxarquivo, mas minhas tentativas amadoras estão presas no inferno da expansão. Na verdade, pode haver uma solução ainda mais fácil para este caso especial: acho que o .auxarquivo já salva legendas com um \newlabelquando hyperrefé usado (quando não é?), mas eu precisaria retirar a terceira expressão entre parênteses do aux- escrito \newlabel. Em vez de adivinhar mais, espero que este seja um problema comum o suficiente para ser fácil e se tornar uma boa resposta sexual...

ajuda apreciada. /iaw

Responder1

Este é um truque 'sujo': escreva \newlabelexplicitamente no .auxarquivo com um prefixo para um novo rótulo, diga stored::e use \nameref*from hyperrefpara obter o conteúdo do rótulo.

Os argumentos {}{}e {}podem estar vazios aqui, pois não são importantes para esta abordagem.

No entanto, a expansão será um problema. Se o próprio conteúdo da legenda contiver comandos bastante simples, \unexpanded{}deverá ser usado. Uma solução melhor depende dos requisitos precisos.

\documentclass{article}
\usepackage{caption}

\usepackage{hyperref}


\makeatletter
\newcommand{\savecaptioncontent}[2]{%
  \immediate\write\@auxout{%
    \string\newlabel{stored::#1}{{}{}{\unexpanded{#2}}{}}%
  }
}
\newcommand{\contentcaption}[1]{%
  \nameref*{stored::#1}%
}
\makeatother

\newcommand{\mycaption}[2]{\caption{#2}\label{#1}\savecaptioncontent{#1}{#2}}
\newcommand{\insertmytable}[1]{
  \begin{center}
   Insert Table~\ref{#1} here: '\contentcaption{#1}'
 \end{center}
}

\begin{document}

blah blah.  Table~\ref{tbl:first} tells me little.

But now:
\insertmytable{tbl:first}

above, it should have printed:

\begin{center}
   Insert Table~\ref{tbl:first} here: 'This is my first table'
\end{center}

\begin{table}
\mycaption{tbl:first}{This is my first table}
\end{table}

\end{document}

insira a descrição da imagem aqui

informação relacionada