这个问题源自于从 \includegraphics 生成图形编号和文件名列表。那里的答案提供了从 LaTeX 源生成图号和相关文件名的文本文件的基本代码。现在,我需要将此方法扩展到进一步的任务,即收集图源的文本文件。
在这本书中(几乎)全部图\caption{}
中包含了source{}
给出图形源的命令。它目前仅被定义为以文本形式打印有关图形源的信息,来源:斜体
\newcommand{\source}[1]{\emph{Source:} #1.}
有些图表需要许可,有些则不需要,但为了出版,出版商需要所有图表及其来源和许可状态的列表。
我希望至少从 LaTeX 源中提取此基础,通过修改\source{}
命令来将行写入来源列表(los
) 文件。
需要获得许可的图形的一个例子是:
\begin{figure}[htb]
\centering
\includegraphics[width=.6\textwidth]{\theChapter/fig/cholera-monmonier-gilbert}
\caption[\desc{Presentation graphic} Mark Monmonier's re-vision of the Gilbert version of Snow's map, as
a presentation graphic]{\desc{Presentation graphic} Mark Monmonier's re-vision of the Gilbert version of Snow's map, as
a presentation graphic. \source{Monmonier (1996), \emph{How to Lie with
Maps}, p. 158. Image: permission required, University of Chicago Press.}
}
如果这是书中的图 4.10,我希望重新定义的\source{}
命令将一行写入文件,los
例如:
4.10 Monmonier (1996), \emph{How to Lie with Maps}, p. 158. Image: permission required, University of Chicago Press.
换句话说:
通缉:一种修改方法\source{}
,以便它也能将行写入外部文件\jobname.los
,格式如下
fignum source
有人可以帮忙吗?
答案1
我从链接的答案中获取(这是我的答案)并添加了命令\source
,写入.los
并\addcontentsline
添加,\thefigure
以便清楚哪个图形和哪个来源属于一起。
\addcontentsline{los}{section}{\thefigure: #1}
将相关内容添加到.los
文件中,格式与section
常规的 类似ToC
。\@starttoc{los}
读取.los
文件并显示其内容。代码与 非常相似\tableofcontents
。
\documentclass{book}
\usepackage{xparse}
\usepackage{graphicx}
\usepackage{letltxmacro}
\DeclareRobustCommand{\source}[1]{\emph{Source:} \addcontentsline{los}{section}{\thefigure: #1}#1.}
\makeatletter
\newcommand{\listofsources}{%
\chapter*{List of Sources}
\@starttoc{los}
\clearpage
}
\makeatother
\LetLtxMacro\davidsincludegraphics\includegraphics
\makeatletter
\RenewDocumentCommand{\includegraphics}{sO{}mo}{%
\IfBooleanTF{#1}{%
\davidsincludegraphics*[#2]{#3}%
}{%
\davidsincludegraphics[#2]{#3}%
}%
\begingroup
% Trying to determine the extension
\def\loc@l@ext{}
\IfValueTF{#4}{%
\def\loc@l@ext{#4}%
}{%
\IfFileExists{#3}{%
}{%
\IfFileExists{#3.pdf}{%
\edef\loc@l@ext{.pdf}%
}{%
\IfFileExists{#3.jpg}{%
\edef\loc@l@ext{.jpg}%
}{%
\edef\loc@l@ext{.png}%
}%
}%
}%
}%
\advance\c@figure by \@ne
\addtocontents{lfn}{\thefigure\space #3\loc@l@ext}
\endgroup
}
\def\@starttocbutdonotshowit#1{%
\begingroup
\makeatletter
\if@filesw
\expandafter\newwrite\csname tf@#1\endcsname
\immediate\openout \csname tf@#1\endcsname \jobname.#1\relax
\fi
\@nobreakfalse
\endgroup}
\newcommand{\listoffigurenumbernames}{%
\@starttocbutdonotshowit{lfn}%
}
\begin{document}
\listoffigurenumbernames
\listofsources
\chapter{First}
\begin{figure}[htb]
\centering
\includegraphics[width=.49\textwidth]{galton-interp2}[.png]
\includegraphics[width=.49\textwidth]{galton-interp3}
\caption{A reconstruction of Galton's method for finding contours of
approximately equal frequency in the relationship between heights of parents
and their children. \source{Foo stuff}
}%
\label{fig:galton-interp2}
\end{figure}
\begin{figure}[htb]
\centering
\includegraphics[width=.49\textwidth]{galton-interp4}
\includegraphics[width=.49\textwidth]{galton-inter5}
\caption{A reconstruction of Galton's method for finding contours of
approximately equal frequency in the relationship between heights of parents
and their children.
\source{Monmonier (1996), \emph{How to Lie with
Maps}, p. 158. Image: permission required, University of Chicago Press.}
}%
\label{fig:galton-interp4}
\end{figure}
\chapter{Second}
\begin{figure}[htb]
\centering
\includegraphics[width=.49\textwidth]{galton-interp6}
\includegraphics[width=.49\textwidth]{galton-inter7}
\caption{A reconstruction of Galton's method for finding contours of
approximately equal frequency in the relationship between heights of parents
and their children.
}%
\label{fig:galton-interp5}
\end{figure}
\end{document}