CTAN Comprehensive TeX Archive Network

Directory macros/latex/contrib/filecontentsdef

Source:  filecontentsdef.dtx (v1.5 2019/09/29)
Author:  Jean-Francois Burnol
Info:    filecontents + macro + verbatim
License: LPPL 1.3c
Copyright (C) 2016-2019 Jean-Francois Burnol.
<jfbu at free dot fr>


This lightweight package provides an environment filecontentsdef which is like the filecontents environment of Scott Pakin's filecontents package but in addition to the file creation stores the (verbatim) contents into a macro given as an additional argument (either as a control sequence or as a name).

Displaying verbatim these contents is possible via \filecontentsprint, and executing them (if they represent code) via \filecontentsexec.

A variant environment filecontentsdefmacro stores the contents into a macro, but skips the save-to-a-file part.


v1.5 [2019/09/29]

  • \filecontentsexec does not forcefully reset \newlinechar to its default after execution.
  • \FCD@ as prefix for internal non public macros.
  • drop usage of the legacy mechanism which issued a warning in case of a form feed or horizontal tabulation character in the parsed contents.
  • make handling of the tabulation and form feed characters customizable.
  • treat especially the case when the \end{filecontents...} is not on a line of its own.
  • add filecontentsdefstarred (et al.) as alias for filecontentsdef* (et al.) for easying up encapsulation in wrapping environments.
  • breaking change: filecontentsdef and filecontentsdefmacro define a macro obeying the local scope. Use filecontentsgdef, resp. filecontentsgdefmacro for definitions with global scope.
  • make the name of the environment used by \filecontentsprint customizable (it defaults to verbatim) and allow to pass options to it; has been tested with fancyvrb and minted.
  • add \filecontentsprintviascan which allows to use verbatim-like environment such as listings which are incompatible with \filecontentsprint.

v1.4 [2019/04/20]

  • backport 2018/04/01 release change to filecontents environment (^^L and ^^I definitions).
  • add filecontentsdefmacro environment.
  • extend filecontentsdef and filecontentsdefmacro environments as well as \filecontentsprint and \filecontentsexec macros to accept indifferently either a control sequence or a name as argument.
  • refactor documentation, explain how to define wrapper environments.

v1.2 [2016/09/19]

Initial version.


This Work may be distributed and/or modified under the conditions of the Project Public License 1.3c. This version of this license is in


and the latest version of this license is in


and version 1.3 or later is part of all distributions of version 2005/12/01 or later.

The Author of this Work is:

  • Jean-Francois Burnol <jfbu at free dot fr>

This Work consists of the main source file filecontentsdef.dtx and its derived files filecontentsdef.sty, filecontentsdef.pdf, filecontentsdef.dvi, README.md, INSTALL.md, README, INSTALL.

Download the contents of this package in one zip archive (142.3k).

filecontentsdef – filecontents + macro + verbatim

The package provides two environments called filecontentsdef and filecontentshere. They are derived from the filecontents environment as provided by Scott Pakin's filecontents package. In addition to the file creation they either store the (verbatim) contents in a macro (filecontentsdef) or typeset them (verbatim) on the spot (filecontentshere).

The author developed the package to display code verbatim in documentation and the same time produce the corresponding files during the run in order to embed them in the PDF as file attachment annotations (by using Scott Pakin's package attachfile).

Version1.5 2019-09-29
LicensesThe Project Public License 1.3
Copyright2016–2019 Jean-François Burnol
MaintainerJean-François Burnol
Contained inTeX Live as filecontentsdef
MiKTeX as filecontentsdef
TopicsFile management
See alsofilecontents
Guest Book Sitemap Contact Contact Author