Search:   Help

Navigation

Groups

LyX documentation

Edit

Shared groups

Links

FilesWithSpecialChars

Categories: Uncategorized
<< | Page list | >>

On the use of "file names with special characters" with LaTeX

Angus Leeming
April 2005

The traditional response to the question, "How do I reference a file whose name contains spaces in my LaTeX file?" has always been, "You can't". However, modern versions of Web2C, the TeX engine used by most LaTeX distributions have some -- rather clunky -- support for file names containing a heap of unusual characters. So, if you're using a recent LaTeX distribution such as teTeX 3 or MikTeX 2.4, you'll be able to use \include, \input, \verbatim, \includegraphics and friends with such file names.

What file names can I use and what are the limitations?

foo"barfoo{barfoo}bar

We have found no way to enable any flavour of LaTeX to recognize file names containing { or } characters. The latex compiler can handle file names containing " characters, but there appears to be no way to automate the post-processing necessary to make the resulting .dvi file understandable to xdvi, yap or dvips. (Note that " isn't a legal file name character on Windows, so the point is moot.)

foo barfoo$bar

You'll be able to reference file names containing space or $ characters only if you are using teTeX 3 or MikTeX 2.4. However, whilst pdflatex will generate a perfect .pdf file, the latex compiler will produces a .dvi file that must be post-processed by the clean_dvi scripts below.

foo(barfoo)barfoo:bar

teTeX 3 and MikTeX 2.4 have no problems at all with file names containing (, ) or : characters. The latex and dvips that ship with Fedora Core 3 or with Debian unstable can handle these file names too, but they will crash xdvi (xdvik version 22.40v). Note that : is not a valid file name character on Windows.)

foo.barfoo%barfoo#barfoo~barfoo[bar
foo]barfoo&barfoo@barfoo'barfoo`bar
foo=barfoo!barfoo?barfoo^barfoo_bar

teTeX 3 and MikTeX 2.4 have no problems at all with file names containing ., %, #, ~, @, @, &, @, ', `, =, !, ?, ^ or _ characters. The latex, xdvi and dvips that ship with Fedora Core 3 or with Debian unstable are also happy. (Note that ? is not a valid file name character on Windows.)

Referencing these files in a LaTeX file

It is possible to reference files whose name contains these characters, but that doesn't mean it is easy. Many of the characters can be escaped with the TeX macro \string, but some require manipulation of the catcodes themselves. Georg Baum has written a comprehensive test file to investigate the use of these .eps files with \includegraphics:

a&ampersand.epsa"dquote.epsa(lparen.epsa)rparen.eps
a@at.epsa=equal.epsa'lquote.epsa`rquote.eps
a^circumflex.epsa!excl.epsa%percent.epsspace.eps
a:colon.epsa#hash.epsa?quest.epsa~tilde.eps
a$dollar.epsa{lbrace.epsa}rbrace.epsa_underscore.eps
a.dot.epsa[lbracket.epsa]rbracket.eps

You can grab archives of these .eps files as either a tar.gz file (850 Bytes) or as a zip archive (6.7 kBytes). Note, however, that a:colon.eps, a"dquote.eps and a?quest.eps are not valid file names on Windows.

Cleaning the .dvi file

The bad news is that, whilst the latex and pdflatex compilers can handle many of these files successfully, the utilities such as yap and dvips that are needed to view and to further process the .dvi file have not kept up. (Time of writing: April 2005.) Specifically, they are unable to handle quoted file names that appear in the .dvi file as, for example, ... PSfile=""a space".eps" .... Fortunately, it is possible to post-process the generated .dvi file so that this file is referenced as ... PSfile="a space.eps" ... (the extraneous quotes are removed). The various .dvi viewers and processors are perfectly happy with these cleaned .dvi files.

Two versions of the script to perform this cleaning are available:

In turn, these scripts require dv2dt and dt2dv from the DTL dviware package. I grabbed and compiled the C-sources without any problems, but if you need the executables, then just shout to the lyx-devel mailing list and we'll see what can be done to help you.

Usage is straightforward (using $ as the shell prompt):

 $ python clean_dvi.py infile.dvi outfile.dvi
 $ sh clean_dvi.sh infile.dvi outfile.dvi

The functionality of the two scripts is identical, so choose whichever one suits your system (or politics) best.

Using clean_dvi with LyX

LyX 1.3.6 will support the use of filenames containing spaces or the ~ character. If the paths to your external graphics files, etc, contain spaces then you'll need to use one of the clean_dvi scripts. I recommend that you place it in the scripts sub-directory of your User LyX directory:

  • $HOME/.lyx on *nix,
  • C:\Documents and Settings\<User>\Application Data\lyx on Windows

and then add four entries to your preferences file in this same User LyX directory, either by modifying the file directly or with the help of the Edit→Preferences dialog:

 \format "dvi2" "dvi" "DirtyDVI" ""
 \converter "latex" "dvi2" "latex $$i" ""
 \converter "dvi2" "dvi" "python $$s/scripts/clean_dvi.py $$i $$o" ""
 # Remove the existing latex->dvi converter
 \converter "latex" "dvi" "" ""

(Note that the $$i, $$o and $$s strings are placeholders used by LyX to identify the input file, the output file and the directory containing shared LyX resources, respectively.)

Uncategorized

Edit - History - Print - Recent Changes - All Recent Changes - Search
Page last modified on 2007-05-21 14:34 UTC