1

I am trying to make some linear algebra notes which will be comprised of a main file loading subfiles for each chapter. All of my files have spaces in the file names, which has worked fine for most things. I am even able to compile and view the main file while having spaces in both subfiles and the main file names. However, it seems that having spaces in the main file name is causing problems with compiling and viewing the subfiles (I'm pretty sure it's to do with spaces in the name of the main file, because I have tried renaming the main file to one work and I was able to compile the subfiles).

So my problem is: I would like to be able to keep spaces in the main file name and still compile the subfiles separately.

For example, here is a subfile

%!TeX root = Introduction - Linear Algebra Notes
\documentclass[Main - Linear Algebra Notes.tex]{subfiles}
\begin{document}
BLAH BLAH BLAH
\end{document}

where the subfile name is "Introduction - Linear Algebra Notes" and the main file name is "Main - Linear Algebra Notes". The error that I get is

File `Main-LinearAlgebraNotes.tex' not found. \subimport{\filename@area}{\filename@base}

and as I said above I don't get this error if I rename the main file to something like just "main" (i.e. with one word).

PS: I use TeXstudio 2.12.14.

2
  • In general: try avoiding spaces in latex filenames and paths
    – DG'
    Apr 24, 2020 at 21:18
  • 1
    the code to handle global document options removes spaces. So better avoid file names with spaces if you want to use subfiles. Apr 24, 2020 at 21:45

1 Answer 1

2

It is best to avoid spaces in LaTeX filenames!

But there is, as often, a dirty workaround. Define the filename as a command:

\newcommand{\mainfile}{"Main - Linear Algebra Notes.tex"}
\documentclass[\mainfile]{subfiles}
\begin{document}
BLAH BLAH BLAH
\end{document}

But that you can do a thing does not mean, that you should do it. Please don't!

5
  • This worked! Thank you for your answer. I am wondering why you say "Please don't" in regards to this solution: it seems to me to work well, and I haven't had any other problems with spaces in file names before (it works fine with biblatex and everything else I've been doing). I am used to having spaces in my file names as I like them to be detailed.
    – Dave
    Apr 24, 2020 at 22:07
  • I am glad, that it works for you, but I suspect it will break sooner or later.
    – DG'
    Apr 24, 2020 at 22:09
  • Fair enough. There is much about latex that I'm still learning. If I notice any errors/problems as a result of this I'll post them here.
    – Dave
    Apr 24, 2020 at 22:15
  • 1
    @Dave There are other ways than using spaces, such as hyphens (my-file-name) or underscores (my_file_name) which will be much more robust with LaTeX. Spaces in file names seems to be one of the many infelicities from Microsoft. --- GOM Apr 25, 2020 at 17:41
  • How it is connected to Microsoft? As far as I know, ext was developed in 1992, before NTFS, and supported spaces in file names. I don't see anything "dirty" in the workaround.
    – facetus
    Nov 8, 2021 at 17:05

You must log in to answer this question.

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