(最终代码这里)
这是我在 扩展的图题和附带的“列表” 。
给出的解决方案有效,但我希望它能够让函数处理多个段落。因此,我将\addtocontents
和\contentsline
函数分别复制到\addefcline
和\efcline
,区别仅在于定义\long\def
而不是\def
,使它们能够处理多个段落。
结果,它工作正常,但在当前形式下,我必须使用\protect
我在 中创建的每个新行\extcaption{
。有没有办法自动保护所有新段落?
\documentclass[a4paper,10pt]{report}
\usepackage{fontspec}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{caption}
% Redefinition of \addcontentsline
\long\def\addefcline#1#2#3{%
\addtocontents{#1}{\protect\efcline{#2}{#3}{\thepage}}}
% Redefinition of \contentsline
\makeatletter
\long\def\efcline#1{\csname l@#1\endcsname}
\makeatother
% Extended figure caption
\newcommand{\extcaption}[1]{% Write to .efc file
\addefcline{efc}{extfig}{{\bfseries \protect\hyperlink{fig:\thefigure}{Figure \thefigure, page~\thepage:}} #1}}
\makeatletter
\newcommand{\printextcaptions}{\@starttoc{efc}}% Read .efc file
\newcommand{\l@extfig}[2]{\noindent #1 \vspace{\parskip} \par}% How each .efc entry is handled
\makeatother
\usepackage[linktoc=all]{hyperref}
\begin{document}
\chapter{A chapter}
\section{A section}
\lipsum[1]
\begin{figure}
\includegraphics{example-image-a.pdf}
\caption{Picture of a big A}
\extcaption{The reasons why A is magnificent
\protect\begin{itemize}
\protect\item "A" like Awesome
\protect\item "A" like Amazing
\protect\end{itemize}
}
\end{figure}
\begin{figure}
\includegraphics{example-image-b.pdf}
\caption{Picture of a big B}
\extcaption{The reasons why B is awful
\protect\begin{itemize}
\protect\item "B" like Bad
\protect\item "B" like Banana
\protect\end{itemize}
}
\end{figure}
\section{Extended figure captions}
\printextcaptions
\end{document}
答案1
您可以使用\unexpanded{\unexpanded{#1}}
:
\documentclass[a4paper,10pt]{report}
\usepackage{fontspec}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{caption}
% Redefinition of \addcontentsline
\long\def\addefcline#1#2#3{%
\addtocontents{#1}{\efcline{#2}{#3}{\thepage}}}
% Redefinition of \contentsline
\makeatletter
\long\def\efcline#1{\csname l@#1\endcsname}
\makeatother
% Extended figure caption
\newcommand{\extcaption}[1]{% Write to .efc file
\addefcline{efc}{extfig}{{%
\bfseries \protect\hyperlink{fig:\thefigure}{Figure \thefigure, page~\thepage:}} %
\unexpanded{\unexpanded{#1}}%
}%
}
\makeatletter
\newcommand{\printextcaptions}{\@starttoc{efc}}% Read .efc file
\newcommand{\l@extfig}[2]{\noindent #1 \vspace{\parskip} \par}% How each .efc entry is handled
\makeatother
\usepackage[linktoc=all]{hyperref}
\begin{document}
\chapter{A chapter}
\section{A section}
\lipsum[1]
\begin{figure}
\includegraphics{example-image-a.pdf}
\caption{Picture of a big A}\hypertarget{fig:\thefigure}{}
\extcaption{The reasons why A is magnificent
\begin{itemize}
\item "A" like Awesome
\item "A" like Amazing
\end{itemize}
}
\end{figure}
\begin{figure}
\includegraphics{example-image-b.pdf}
\caption{Picture of a big B}\hypertarget{fig:\thefigure}{}
\extcaption{The reasons why B is awful
\begin{itemize}
\item "B" like Bad
\item "B" like Banana
\end{itemize}
}
\end{figure}
\section{Extended figure captions}
\printextcaptions
\end{document}
我添加了几个目标以使链接能够正常工作。