Using external files


In my thesis, I have a number of citations of a single website and I don't like to have all of them in the literature (biblatex). First, I wrote a macro to format those citations uniformly:

% use: \lwn{article-no}{author}{title}{date}
\newcommand{\lwn}[4]{[LWN:#1]\footnote{#2: #3 (#4)

This allows to write:

In the merge window of Linux 3.12, several new features are
planned \lwn{565251}{Jonathan Corbet}{The 3.12 merge window opens}{September 5, 2013}...

This will put a [LWN:565251] in the text and creates a footnote with the name of the author, the title, date, and URL.

To create a listing of all such citations in the appendix, the benefit of creating a macro plays out: by just changing the macro, it is possible to automatically collect all citations.


With the \index{} macro, it is possible to create entries to the *.idx file. Those could be postprocessed with a script to generate a piece of LaTeX that can be included in the document. But the entries will still occur in the index (or the file must be postprocessed to remove them).

I used this in a Beamer presentation for a LaTeX tutorial to collect a list of all packages and all TeXdocs for the handout. For the Beamer slides, the index was not used otherwise.


You can use \package{tikz}, see also \texdoc{latex2e}.

In the Makefile was added:

grep 'package!' slides.idx | sed -e 's/\\indexentry{package!\(.*\)}{.*}/\1/' |sort|uniq > packages.txt
grep 'texdoc!' slides.idx | sed -e 's/\\indexentry{texdoc!\(.*\)}{.*}/\1/' |sort|uniq > texdoc.txt

Writing to files

Latex allows to open a new file and write (or read) to (from) that file.

\immediate\write\outputstream{foo 1}
\immediate\write\outputstream{foo 2}
\immediate\write\outputstream{\string\textbf{foo 3}}

(Source of that example: Juanjo (latex-community)).

My new macro for the \lwn citation is now:

% use: \lwn{article-no}{author}{title}{date}
\newcommand{\lwn}[4]{[LWN:#1]\footnote{#2: #3 (#4) \url{}}\immediate\write\outputstream{#1;#2;#3;#4}}

% Open file at the begin of the document

% Close the file at the end of document

The macros \AtBeginDocument and \AtEndDocument register those pieces (opening and closing the file) for the beginning and end of the document.

The file is lwncite.csv containing lines with article number, author, title, and date, separated by semicolon. In the Makefile, this is sorted and reformated:

sort lwncite.csv | awk -F';' '{print "[LWN:" $1 "] -- " $2 ". ``" $3 "''." $1 " (" $4 ")"}' > lwncite.txt

This will be changed from text format to LaTeX as soon as I integrate the file into my document.

Fix "No room for a new \write"

If the compilation breaks with the error message "No room for a new \write", the maximum number of 16 open files is exceeded. But help is simple: The Package morewrites can be loaded at the beginning of the document (before any other packages). It invades deeply into the guts of LaTeX, but it has helped me without further problems. Source