
専門家の皆様:後で使用するために表のキャプションをどのように書き出せばいいのでしょうか?
\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}
ほぼ確実にファイルに書き込みたいのです.aux
が、私の素人の試みは拡張地獄に陥っています。実際、この特殊なケースにはさらに簡単な解決策があるかもしれません。ファイルは既に が使用されているとき.aux
にキャプションを保存していると思いますが (使用されていないときはいつですか?)、aux-written から 3 番目の括弧で囲まれた式を取り出す必要があります。さらに推測する代わりに、これが十分に一般的な問題であり、簡単で、優れた sx 回答になることを望みます...\newlabel
hyperref
\newlabel
助けていただければ幸いです。/iaw
答え1
これは「汚い」トリックです。新しいラベルのプレフィックスを付けてファイル\newlabel
に明示的に書き込み、 from を使用してラベルの内容を取得します。.aux
stored::
\nameref*
hyperref
および引数{}{}
は、{}
このアプローチでは重要ではないため、ここでは空にすることができます。
ただし、拡張が問題になります。キャプション コンテンツ自体に非常に単純なコマンドが含まれている場合は、\unexpanded{}
を使用する必要があります。より適切なソリューションは、正確な要件によって異なります。
\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}