캡션을 위한 toc와 같은 전달 저장소

캡션을 위한 toc와 같은 전달 저장소

전문가 여러분, 나중에 사용할 수 있도록 표 캡션을 어떻게 작성합니까? 생각하다

\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파일이 이미 \newlabel언제 hyperref사용되는지(언제가 사용되지 않는지?) 캡션을 저장하고 있다고 생각합니다. 작성되었습니다 \newlabel. 더 이상 추측하는 대신 이것이 쉽고 좋은 sx 답변이 될 만큼 충분히 일반적인 문제이기를 바랍니다...

도움을 주셔서 감사합니다. /iaw

답변1

이것은 '더러운' 트릭입니다. 새 레이블에 대한 접두사를 사용하여 파일 \newlabel에 명시 적으로 쓰고 from을 사용하여 레이블 내용을 가져옵니다..auxstored::\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}

여기에 이미지 설명을 입력하세요

관련 정보