如何自動將所有腳註的內容放在一個文件中

如何自動將所有腳註的內容放在一個文件中

我寫了一篇論文,在腳註中包含參考書目,我想將它們組織在論文末尾的參考書目中(使用 Lyx)。

我可以複製每個腳註並將其貼到這樣的文件中,但這會花費很多時間。

您是否知道一種自動將每個腳註的內容放入一個文件中的方法,我可以組織該文件以將其呈現為我的參考書目?

非常感謝你的幫忙!

答案1

您可以重新定義內部命令\@footnotetext以將其內容寫入檔案。

這是一個簡單的解決方案,將腳註寫入文件file.ftn,其中文件file的名稱.tex作為參考書目:

\documentclass{article}

\newwrite\footaux
\immediate\openout\footaux\jobname.ftn
\immediate\write\footaux{\string\begin{thebibliography}{99}}
\AtEndDocument{
\immediate\write\footaux{\string\end{thebibliography}}
\closeout\footaux
}
\makeatletter
\let\@footnotetextorig\@footnotetext
\long\def\@footnotetext#1{\@footnotetextorig{#1}\immediate\write\footaux
{\string\bibitem:  #1}}
\makeatother
\begin{document}
This is the text\footnote{First footnote}.
\clearpage
This is the text\footnote{Second footnote}.
\end{document}

這是.ftn文件:

\begin{thebibliography}{99}
\bibitem: First footnote
\bibitem: Second footnote
\end{thebibliography}

答案2

解決方案思路

  1. 重新定義\footnote指令,以便將腳註文字儲存在參考書目格式的檔案中。
  2. 使用最後儲存的參考書目。

解決方案

\documentclass{article}

\usepackage{lipsum}

\usepackage{url}

\let\originalfootnote\footnote
\newwrite\footnotelist
\immediate\openout\footnotelist\jobname.bls
\immediate\write\footnotelist{\unexpanded{\begin{thebibliography}{99}}}
\def\savefootnote#1{\immediate\write\footnotelist{\unexpanded{\bibitem}{fn\thefootnote}\unexpanded{#1}}}
\def\footnote#1{%
  \originalfootnote{#1}%
  \savefootnote{#1}}

\AtEndDocument{\immediate\write\footnotelist{\unexpanded{\end{thebibliography}}}%
\immediate\closeout\footnotelist%
\IfFileExists{\jobname.bls}{\input{\jobname.bls}}{\relax}}

\begin{document}

\lipsum[1-10]

Put a footnote here.\footnote{\url{http://www.acm.org}}

\lipsum[11-20]

Put another footnote here.\footnote{\url{http://ieeexplore.ieee.org}}

\lipsum[21-30]

\end{document}

建立腳註列表文件

\begin {thebibliography}{99}
\bibitem {fn1}\url {http://www.acm.org}
\bibitem {fn2}\url {http://ieeexplore.ieee.org}
\end {thebibliography}

輸出

在此輸入影像描述

在此輸入影像描述

在此輸入影像描述

相關內容