
Estimados expertos: ¿cómo se escriben los títulos de las tablas para utilizarlos más adelante? 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}
Es casi seguro que quiero escribir en el .aux
archivo, pero mis intentos de aficionado se estancan en el infierno de la expansión. De hecho, puede haber una solución aún más sencilla para este caso especial: creo que el .aux
archivo ya guarda títulos con un \newlabel
cuándo hyperref
se usa (¿cuándo no?), pero necesitaría seleccionar la tercera expresión entre paréntesis del archivo auxiliar. escrito \newlabel
. En lugar de seguir adivinando, espero que este sea un problema lo suficientemente común como para que sea fácil y se convierta en una buena respuesta sexual...
Se agradece la ayuda. /iaw
Respuesta1
Este es un truco "sucio": escriba \newlabel
explícitamente en el .aux
archivo con un prefijo para una nueva etiqueta, diga stored::
y use \nameref*
from hyperref
para obtener el contenido de la etiqueta.
Los argumentos {}{}
y {}
pueden estar vacíos aquí, ya que no son importantes para este enfoque.
Sin embargo, la expansión será un problema. Si el contenido del título contiene comandos que son bastante simples, \unexpanded{}
se debe utilizar. Una mejor solución depende de los 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}