I suggest to enhance the code formatting with an optional argument for a filename.



Nice workaround suggested in comments to use 3 #:


  • 5
    The code formatting is provided by the stackexchange team for all stackexchange sites and we mods do not have direct access to it. You could use ### test.tex to create an headline 3rd order for the filename. Nov 7, 2012 at 14:18
  • 3
    See Markdown help for all the ins-and-outs on markdown available on the Stack Exchange network. Specifically for headers, see Headers. Click on 'show more' (and possibly 'expand all') to see more.
    – Werner Mod
    Nov 7, 2012 at 17:13

1 Answer 1


In most cases, the specific name of a file doesn't matter, but even if it does, there's no need for a heading outside of the code. If the file name does matter, there usually are several files involved with one main file accessing the other(s) (e.g. a .bib file). In those cases, I'd recommend using a filecontents environment in order to enable user to create everything with one file. If you complement that with the \jobname macro, which carries the current file's name, you enable users here to have maximal influence on the names of files while still being able to refer to files. Example:



    author = {Anthony Apple},
    title = {Title}}
    author = {Barbara Banana and Chris Coconut},
    title = {Title}}
    author = {Donna Date and Eric Eggplant and Fred Fig},
    title = {Title}}



You can also do things like \begin{filecontents}{\jobname-hello-world.tex}. Here is some more information about the filecontents environment and the filecontents package (which might be handy in some cases), quoted from the filecontents documentation:

The environment filecontents is intended for passing the contents of packages, options, or other files along with a document in a single file. It has one argument, which is the name of the file to create. If that file already exists (maybe only in the current directory if the OS supports a notion of a current directory' ordefault directory') then nothing happens (except for an information message) and the body of the environment is bypassed. Otherwise, the body of the environment is written verbatim to the file name given as the first argument, together with some comments about how it was produced. The environment is allowed only before \documentclass to ensure that all packages or options necessary for this particular run are present when needed. The begin and end tags should each be on a line by itself. There is also a star-form; this does not write extra comments into the file.

(The comment about filecontents being valid only before \documentclass is, in fact, untrue. filecontents is allowed anywhere in the document's preamble.)

The filecontents package provides a hacked-up version of the filecontents and filecontents* environments that lifts the two restrictions stated above, namely that existing files are never overwritten and that filecontents must be used before the \documentclass declaration (really, the \begin{document}). filecontents is therefore a more convenient way to write external files from within a LaTeX document than is provided by default by the LaTeX2ε kernel.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .