8

I am preparing a document for my university and need to insert a list of used packages and their corresponding versions/dates in the appendix of the document.

One possibility is to just copy the output of \listfiles from the logs and format it by hand before actually handing in the final version of the document. But that feels error prone...

So is there a way to include such a list, table or whatever automagically?

12

The macros I propose just show the information for the document class and the packages, so only those with extension .cls or .sty, discarding the other files.

\documentclass{article}
\usepackage{xparse,l3regex,longtable,array}

\listfiles % initialize
\AtEndDocument{\printfilelist}

\ExplSyntaxOn
\NewDocumentCommand{\printfilelist}{}
 {
  \cleardoublepage
  \section*{Used ~ packages}
  \setlength{\LTleft}{0pt}
  \pagestyle{empty}
  \footnotesize
  \begin{longtable}{@{} >{\ttfamily}l >{\raggedright}p{.6\textwidth} @{}}
  \nobbz_print_filelist:
  \end{longtable}
 }

\tl_new:N \l_nobbz_filelist_body_tl

\cs_new_protected:Npn \nobbz_print_filelist:
 {
  \clist_map_inline:cn { @filelist }
   {
    \nobbz_print_fileinfo:n { ##1 }
   }
  \tl_use:N \l_nobbz_filelist_body_tl
 }

\cs_new_protected:Npn \nobbz_print_fileinfo:n #1
 {
  \regex_match:nnT { \.(sty|cls)\Z } { #1 }
   {
    \nobbz_print_pkginfo:n { #1 }
   }
 }

\cs_new_protected:Npn \nobbz_print_pkginfo:n #1
 {
  \tl_put_right:Nx \l_nobbz_filelist_body_tl
   {
    \exp_not:n { #1 }
    &
    \exp_not:v { ver@#1 }
    \exp_not:N \tabularnewline
   }
 }
\ExplSyntaxOff

\begin{document}

Some text

\end{document}

enter image description here

A variation for separating the file date from the information:

\documentclass{article}
\usepackage{xparse,l3regex,longtable,array,booktabs}

\listfiles % initialize
\AtEndDocument{\printfilelist}

\ExplSyntaxOn
\NewDocumentCommand{\printfilelist}{}
 {
  \cleardoublepage
  \section*{Used ~ packages}
  \setlength{\LTleft}{0pt}
  \footnotesize
  \begin{longtable}{@{} >{\ttfamily}l l >{\raggedright}p{.6\textwidth} @{}}
  \toprule
  \multicolumn{1}{@{}l}{\bfseries File~name} &
    \multicolumn{1}{c}{\bfseries Date} &
    \bfseries File~info
  \tabularnewline
  \midrule
  \endhead
  \bottomrule
  \endfoot
  \nobbz_print_filelist:
  \end{longtable}
 }

\tl_new:N \l_nobbz_filelist_body_tl
\tl_new:N \l_nobbz_fileinfo_tl

\cs_new_protected:Npn \nobbz_print_filelist:
 {
  \clist_map_inline:cn { @filelist }
   {
    \nobbz_print_fileinfo:n { ##1 }
   }
  \tl_use:N \l_nobbz_filelist_body_tl
 }

\cs_new_protected:Npn \nobbz_print_fileinfo:n #1
 {
  \regex_match:nnT { \.(sty|cls)\Z } { #1 }
   {
    \nobbz_print_pkginfo:n { #1 }
   }
 }

\cs_new_protected:Npn \nobbz_print_pkginfo:n #1
 {
  \tl_set_eq:Nc \l_nobbz_fileinfo_tl { ver@#1 }
  \tl_replace_once:Nnn \l_nobbz_fileinfo_tl { ~ } { & }
  \tl_put_right:Nx \l_nobbz_filelist_body_tl
   {
    \exp_not:n { #1 }
    &
    \exp_not:V \l_nobbz_fileinfo_tl
    \exp_not:N \tabularnewline
   }
 }
\ExplSyntaxOff

\begin{document}

Some text

\end{document}

enter image description here

2
  • This solution lists all dependencies. Is there a way to get only those that are explicitly included in the document's \usepackage statement? cc @touhami – Erwann Jun 14 '20 at 19:47
  • 1
    @Erwann Short answer: no. One might think to patch \usepackage. – egreg Jun 14 '20 at 20:33
2

Another solution

\documentclass{article}
%-- just for the example
\usepackage[a4paper]{geometry}
\usepackage{tikz}
\usepackage{lipsum}
%------------------------
\newlength\mtl
\makeatletter
\newcommand{\mtlistfiles}{%
\par\noindent
%%-- for measuring
\@for\@currname:=\@filelist\do{%
\setbox0=\hbox{\@currname}%
\ifdim\wd0>\mtl\relax\mtl=\wd0\fi}%
%%-- formating list
\@for\@currname:=\@filelist\do{%
\makebox[\mtl][l]{\@currname}
     \expandafter\ifx\csname ver@\@currname\endcsname\relax
     \else\@spaces\csname ver@\@currname\endcsname\fi
     \par\noindent}}
\makeatother
\listfiles
\begin{document}
bla bla
\mtlistfiles
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.