
Quero criar uma lista como toc, lof, lot. Deve ser chamado de listofsongs ou similar. A questão é: existe algum pacote que me permita criar listas semelhantes ou tenho que fazer isso sozinho?
Existe uma lista de extensões de arquivo já usadas no LaTeX? ou seja, eu não deveria usar MyDocument.toc porque isso causaria conflitos com o índice.
No final, eu deveria ser capaz de escrever \listofsongs
como escrevo \tableofcontents
e deveria se comportar de maneira semelhante.
Responder1
Você provavelmente pode usar as macros LaTeX2e-kernel \@starttoc
e \addtocontents{<file-extension>}{<tokens>}
.
\addtocontents
escreverá (não expandido) no arquivo auxiliar algumas diretivas para gravação não expandida <tokens>
no arquivo, \jobname.<file-extension>
caso esse arquivo esteja aberto para entrada quando o arquivo auxiliar for processado no final da execução do LaTeX.
\@starttoc{<file-extension>}
fará o TeX ler/processar o arquivo \jobname.<file-extension>
caso esse arquivo exista e então destruir esse arquivo e então criá-lo novamente e abri-lo para entrada para que quando o arquivo aux for processado no final da execução do LaTeX, esse arquivo seja aberto para entrada.
Caso você queira fazer coisas mais sofisticadas, dê uma olhada na \addcontentsline
-macro do kernel do LaTeX2e.
Basicamente, \addcontentsline{<file-extension>}{<command name>}{<tokens>}
escreveremos no arquivo auxiliar algumas diretivas para gravação não expandida da sequência de token \contentsline{<command name>}{<tokens>}{<page number>}
no arquivo \jobname.<file-extension>
, caso esse arquivo esteja aberto para entrada quando o arquivo auxiliar for processado no final da execução do LaTeX. Depois de ter escrito \jobname.<file-extension>
durante o processamento do arquivo aux no final da execução do LaTeX, você encontrará essa diretiva
\contentsline{<command name>}{<tokens>}{<page number>}
nele. Assim, essa diretiva será executada quando - devido a \@starttoc
- o arquivo \jobname.<file-extension>
for lido/processado.
\contentsline{<command name>}{<tokens>}{<page number>}
por sua vez, chamará uma macro \l@<command name>
que processa dois argumentos, nomeadamente o <tokens>
-argumento e o <page number>
-argumento.
Quando este mecanismo é usado com o arquivo toc e os comandos de seccionamento, <command name>
será algo como section
ou subsection
produzindo a execução das macros \l@section
ou \l@subsection
mas você também pode definir suas próprias \l@..
-macros para suas próprias categorias de rubrificação.
O \addtocontents...
-mecanismo \@starttoc{<file-extension>}
, abaixo de outras coisas, define uma sequência de controle \tf@<file-extension>
. Portanto, para descobrir se esse mecanismo já alocou um \write
-handle para escrever um arquivo \jobname.<file-extension>
, você pode usar a \@ifundefined
-macro para verificar se a sequência de controle \tf@<file-extension>
já está definida.
Mas isso só funciona enquanto o pacote scrwfile não estiver em uso - a propósito: você pode estar interessado no pacote scrwfile caso pretenda criar muitas listas como toc, lof ou lot em seu documento. Mais informações sobre esse pacote podem ser encontradas no CTAN:https://www.ctan.org/pkg/scrwfile
O kernel do LaTeX2e é explicado e comentado no arquivo source2e.pdf que está disponível emhttps://www.ctan.org/pkg/source2e.
O \addtocontents
- \@starttoc
-mecanismo e a \addcontentsline
-macro que faz uso desse mecanismo são explicados na seção chamada Arquivo F ltsect.dtx → 59 Comandos de seccionamento → 59.3 Índice etc.
\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}
Responder2
Infelizmente não há MWE na questão. Então não sei o que você realmente quer fazer. Lendo seu perfil, acho que você está usando o scrbook
. Então aqui está uma sugestão que precisa de um KOMA-Script atualizado.
\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}
Aqui está outra versão usando classe padrão book
e pacote KOMA tocbasic
. Mas observe que não sei como você define seu \song
comando ou song
ambiente:
\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}