
我想建立一個像 toc、lof、lot 這樣的清單。應該稱為 listofsongs 或類似的。問題是:是否有任何軟體包允許我創建類似的列表,還是我必須自己完成這一切?
LaTeX 中是否有已使用的檔案副檔名清單?即我不應該使用 MyDocument.toc,因為這會導致與目錄衝突。
最後,我應該能夠\listofsongs
像我寫的那樣寫\tableofcontents
,並且表現應該相似。
答案1
您可能可以使用 LaTeX2e-kernel-macros\@starttoc
和\addtocontents{<file-extension>}{<tokens>}
.
\addtocontents
將向 aux 檔案寫入(未展開)一些指令,以便在 LaTeX 運行結束時處理 aux 檔案時開啟該檔案以供輸入,以便未展開寫入<tokens>
該檔案。\jobname.<file-extension>
\@starttoc{<file-extension>}
如果該文件存在,將使 TeX 讀取/處理該文件\jobname.<file-extension>
,然後銷毀該文件,然後重新建立它並開啟它以進行輸入,以便在 LaTeX 運行結束時處理輔助文件時,該文件已開啟用於輸入。
如果您想做一些更奇特的事情,請查看\addcontentsline
LaTeX2e 核心的巨集。
基本上\addcontentsline{<file-extension>}{<command name>}{<tokens>}
將向 aux 檔案寫入一些指令,以便在 LaTeX 運行結束時處理 aux 檔案時開啟檔案以供輸入,以便將標記序列未展開地寫入\contentsline{<command name>}{<tokens>}{<page number>}
檔案中。在 LaTeX 運行結束時處理 aux 檔案期間
\jobname.<file-extension>
寫入後,您將在其中找到該指令。因此,當檔案被讀取/處理時,該指令將被執行。\jobname.<file-extension>
\contentsline{<command name>}{<tokens>}{<page number>}
\@starttoc
\jobname.<file-extension>
\contentsline{<command name>}{<tokens>}{<page number>}
依序呼叫一個\l@<command name>
處理兩個參數的宏,即<tokens>
-argument 和<page number>
-argument。
當此機制與 toc 檔案和分段命令一起使用時,<command name>
將類似於section
或subsection
產生巨集的執行\l@section
,或者\l@subsection
但您也可以\l@..
為自己的紅化類別定義自己的 - 巨集。
\addtocontents...
-機制\@starttoc{<file-extension>}
在其他事物之下定義了一個控制序列\tf@<file-extension>
。因此,為了找出機制是否已經指派了\write
用於寫入檔案的 -handle \jobname.<file-extension>
,您可以使用\@ifundefined
-macro 來檢查控制序列是否\tf@<file-extension>
已定義。
但這僅在 scrwfile-package 未使用時有效 - 順便說一下:如果您打算在文檔中創建許多列表,如 toc、lof 或 lot,您可能會對 scrwfile-package 感興趣。有關該軟體包的更多資訊可以在 CTAN 上找到:https://www.ctan.org/pkg/scrwfile
LaTeX2e 核心在檔案 source2e.pdf 中進行了解釋和註釋,該檔案位於https://www.ctan.org/pkg/source2e。-
機制和使用該機制的巨集在名為檔案 F ltsect.dtx → 59 切片指令 → 59.3 目錄等的部分中進行了解釋。\addtocontents
\@starttoc
\addcontentsline
\documentclass{article}
\usepackage{hyperref}
\usepackage{verbatim}
\makeatletter
\newcommand\l@songline[2]{%
\par Now we have data about another song:\\
Title of song: #1. Song is printed on page: #2.%
}%
\makeatother
\begin{document}
\LaTeX{} will now write directives to aux-file for writing the first
line into \jobname.weird. These directives will be carried out at
the end of the \LaTeX-run when the aux-file is read/processed in
case at that time the file \jobname.weird is open for writing to it.\\
\addtocontents{weird}{First line in file \jobname.weird.}%
\bigskip
This is what \jobname.weird looks like before calling \verb|\@starttoc|: \\
\verbatiminput{\jobname.weird}
\bigskip
This is how \verb|\l@songline| is defined:\\{%
\csname verbatim@font\endcsname\selectfont
\expandafter\meaning\csname l@songline\endcsname
}%
\bigskip
The file \jobname.weird is \csname @ifundefined\endcsname{tf@weird}{not}{already} allocated.
\bigskip
\LaTeX will now read/process \jobname.weird and then destroy that file
and create it anew and open it for writing. Thus at the end of the
\LaTeX-run, when the aux-file is read/processed, that file will be open
for writing to it:\bigskip
\csname @starttoc\endcsname{weird}%
\bigskip
The file \jobname.weird is \csname @ifundefined\endcsname{tf@weird}{not}{already} allocated.
\bigskip
\LaTeX{} will now write directives to aux-file for writing the second
line into \jobname.weird. These directives will be carried out at
the end of the \LaTeX-run when the aux-file is read/processed in
case at that time the file \jobname.weird is open for writing to it.\\
\addtocontents{weird}{Second line in file \jobname.weird.}%
\bigskip
Now two \verb|\addcontentsline|-entries for writing things to \jobname.weird
that need to be "rubrified" by means of applying the \verb|l@songgline|-macro.
\addcontentsline{weird}{songline}{Morning has broken}
\addcontentsline{weird}{songline}{Final Countdown}
\end{document}
答案2
不幸的是,問題中沒有 MWE。所以我不知道你真正想做什麼。閱讀您的個人資料,我猜您正在使用scrbook
.因此,這裡有一個需要更新的 KOMA 腳本的建議。
\documentclass[listof=totoc,ngerman]{scrbook}[2016/06/14]% needs at least KOMA-Scritp version 3.21
\usepackage{babel}
\DeclareNewTOC[
type=song,
tocentryindent=0pt,
tocentrynumwidth=2.3em,
tocentrystyle=tocline,
tocentrylinefill=\hfill,
tocentryentryformat=\sffamily,
tocentrypagenumberformat=\sffamily
]{los}
\newcaptionname{ngerman}{\listsongname}{Liederverzeichnis}
\DeclareNewSectionCommand[
style=chapter,
level=0,
beforeskip=-1sp,
innerskip=0pt,
afterskip=\baselineskip,
font=\usekomafont{section},
prefixfont=\usekomafont{chapter},
pagestyle=plain
]{song}
\renewcommand\songformat{}
\renewcommand\addsongtocentry[2]{\addxcontentsline{los}{song}{#2}}
\usepackage{hyperref}
\begin{document}
\tableofcontents
\addchap{Einleitung}
Text
\listofsongs
\song{Ein Liedtitel}
\end{document}
這是使用標準類別book
和 KOMA 套件的另一個版本tocbasic
。但請注意,我不知道你如何定義你的\song
命令或song
環境:
\documentclass[ngerman]{book}
\usepackage{babel}
\usepackage{tocbasic}[2016/06/14]% needs at least KOMA-Scritp version 3.21
\DeclareNewTOC[
type=song,
tocentryindent=0pt,
tocentrynumwidth=2.3em,
tocentrystyle=tocline,
tocentrylinefill=\hfill,
tocentryentryformat=\sffamily,
tocentrypagenumberformat=\sffamily
]{los}
\newcaptionname{ngerman}{\listsongname}{Liederverzeichnis}
\usepackage{lipsum}
\usepackage{hyperref}
\begin{document}
\listofsongs
\clearpage
\phantomsection\addxcontentsline{los}{song}{Ein Liedtitel im Verzeichnis}
\section*{Ein Liedtitel}
\lipsum
\clearpage
\phantomsection\addxcontentsline{los}{song}{Ein anderer Liedtitel im Verzeichnis}
\section*{Ein anderer Liedtitel}
\end{document}