Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

What's the best practice for naming LaTeX files?

I know R, Matlab, and Java all differ in their use of ., _, -, camel case, capitalization, etc. What do people generally use for naming LaTeX files? Is this easily portable across systems?

I remember having a HUGE problem interpreting a Matlab program of mine. Turned out that I had named the file in a way that Matlab couldn't handle. To avoid such issues in the future, I'd just like to start naming my LaTeX files using best practices.

share|improve this question
    
related: allowable filenames for source files –  Lover of Structure Jul 13 '13 at 12:15

4 Answers 4

up vote 24 down vote accepted

It depends a little if this files are only used by you are if you are planning to share them with other people, e.g. if you work with them on one document or the files are part of a LaTeX package.

But in general I would strongly recommend you to limit yourself to lowercase alphanumeric ASCII characters, i.e. a-z, 0-9 and -.

The reasons for that are:

  • Unicode or other non-ASCII characters can cause trouble when copied on a different file system with a different code page. I had the case that I couldn't even see files with German umlauts on a Windows share mounted by Linux. This is now much better, but still a risk. The normal TeX doesn't like non-ASCII character that much either.
  • Some file systems (FS) are case sensitive (e.g. under *nix FSs) others aren't (e.g. FAT, NTFS). If you keep you file names all lowercase you avoid collisions between files which can lead to loss of data when copied from a case sensitive to a case insensitive FS. Also you will run intro trouble on case sensitive systems when the actual filename has a different capitalization as on the hard drive. You might not realize that on e.g. Windows, but it will hit you then hard on a different FS.
  • Characters which are special in TeX will work as long they are valid at this position which excludes % and #. Others as & can cause trouble as well and there is no real reason to use them, so avoid them. Even _ which is commonly used and will work inside \input can cause trouble when the filename should be printed, so avoid it as well.
  • Spaces are "evil" in filename as well because some external tools will take them as file name separator. TeX should be fine with them, except when they used multiple times in a row. TeX will then combine them to one prior to the interpretation as a filename!
  • Dots will confuse the simple extension extraction algorithms used by LaTeX. See this question for an example.

I'm going through some effort in the svn-multi package to allow for arbitrary file names. This is done using verbatim mode which doesn't help for other input macros like \input, \include or \includegraphics.

share|improve this answer

It's recommended that you only use ascii letters and some punctuation; avoid spaces, accented/Unicode letters, and multiple periods in file names. Okay:

  • filename.tex
  • file-name.tex
  • FileName.tex

You may encounter possible issues with:

  • file name.tex
  • file.name.tex
  • fîlénåmè.tex

(I'd play it safe and avoid _, *, &, %, # and so on, but they will sometimes work just fine. It depends!)

share|improve this answer
8  
Of course, whether your filesystem differentiates between filename.tex and FileName.tex is another story! Don't have files named like this in the same directory if you ever want to move those files to a Mac. –  Will Robertson Feb 27 '11 at 4:00
    
Unless you happen to have a case sensitive HFS+ partition, something I've never done because who knows what horrible assumptions application writers make. –  TH. Feb 27 '11 at 6:03
8  
The basic rule is: never assume case sensitivity, and never assume case insensitivity. –  Philipp Feb 27 '11 at 12:20

This is not, strictly speaking, the answer you sought, but here is a tip that works for me. In all my projects, I follow the a very strict scheme:

  1. Main file is named 00.tex, which makes it show first in directory listing.
  2. This main file inputs a 000.tex with all the definitions, packages, etc.
  3. The abstract goes in a file named abstract.tex
  4. The introduction goes in a file named introduction.tex (I gave up comparability with 8.3 operating systems)
  5. The outline stays at 00.tex
  6. The final/conclusion/discussion section goes in a file named zz.tex
  7. All other sections are placed in files whose name is a single, lowercase, English word. (This makes it easy on not too smart spell checkers). If the section name is changed, the name of the file containing it does not change.

Now, the main file is so set that it show the document structure, and nothing else, e.g.,

\documentclass{article}
\input{000}
\author{U. K. Owen}
\title{Ten Little Darker Skin Human Beings}
\begin{document}
\maketitle
\begin{abstract}
  \input{abstract}
\end{abstract}

\section{Introduction}
\input{introduction}

\paragraph{Outline} The remainder of this manuscript is organized as follows.
 Section~\ref{Section:defs} makes some definitions. 
 The results are presented in Section~\ref{Section:results}.
 Section~\ref{final} concludes.

\section{Definitions}
\label{Section:defs}
\input{definitions}

\section{Results}
\label{Section:results}
\input{results}

\section{Conclusions, Discussion, and Further Research}
\label{Section:final}
\input{zz}

\end{document}

Following this scheme frees neurons who might be busy with file naming issues to deal with what is really important.

share|improve this answer

The rules outlined by Will are fine; here are a few technical additions:

  • All modern OSes and file systems can handle arbitrary Unicode characters in file names.
  • Operating systems are sometimes case-sensitive, sometimes not; but modern operating systems are always case-preserving. That means that if you ask for a file named A you may get a file named A or a, but if you create a new file named A, you'll never end up with a file named a.
  • Operating systems are sometimes normalization-preserving, sometimes not.
  • Most TeX engines can handle arbitrary input file names as long as a valid \jobname can be constructed from them; however, there is no formal definition, so it's best to stick to what is known to work if you want to preserve portability.
  • Names of second-level files (included by \input or \includegraphics, for example) with spaces or multiple often cause problems because the LaTeX kernel and packages assume there is no space and at most one dot in each file name. Packages such as grffile fix a few of the issues.
share|improve this answer
    
The second point should also have a "modern" in it, since I know quite some file systems (e.g. FAT 16) which are not case-preserving. And VFAT for example converts UPPERCASE names to Titlecase. (I'm not sure these file systems are in use anymore ... but there still may be USB sticks or such). –  Paŭlo Ebermann Feb 28 '11 at 0:12
    
@Paŭlo Ebermann: I'll add it, but I think no operating system since Windows 95 has been affected. "Modern" for me means Windows XP and above, OS X, a recent Linux, or similar. Case-insensitivity is generally a feature of the file system implementation in the operating system, not of the file system itself. –  Philipp Feb 28 '11 at 6:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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