0

It's not graphs. It's a .tex file that I want to include. I used \input and it worked fine. But as I keep writing more and more, the file got bigger and bigger and I decided to use chapterbib to make the reference clearer. I used natbib and I found for chapterbib to work, I must use \include and not \input.

When I changed to \include, it wouldn't compile any more.

I can't write on file `"Literature review/M.aux"'.
\@include ...\immediate \openout \@partaux #1.aux 

\immediate \write \@partau...
l.67 \include{"Literature\space review/M"}

(Press Enter to retry, or Control-D to exit; default file extension is `.tex')
Please type another output file name
! Emergency stop.
\@include ...\immediate \openout \@partaux #1.aux 
\immediate \write \@partau...
l.67 \include{"Literature\space review/M"}

I found this but it doesn't work. How to make \include work with a quoted string path containing spaces?

I tried some combinations.

This works: \include{review\M} (supposing I have a file call "M.tex" in folder of "review" and the folder "review" is in the same folder of my base tex file)

This works: \include{"M\space 1"} (supposing I have a file call "M 1.tex" in the same folder of my base tex file)

But this doesn't work: \include{"Literature\space review/M"} (supposing I have a file call "M.tex" in folder of "Literature review" and the folder "Literature review" is in the same folder of my base tex file)

Someone asked if this works: \include{"Literature review/M"}. No. It gives no error, but the output will simply be review/M.

I found someone said to change TEXINPUTS in bash. I did not understand it at all. I'm using windows. I don't know how to change the path.

I found this did not work either. How to include graphics with spaces in their path?

How could I make it work? Thanks!

Update:

I replaced all the spaces with underlines and still it didn't work. Is it because my file is too deep? It is \include{{"Folder_A/B/C/D/M"}}. LaTeX still reported that it could not write the 'Folder_A/B/C/D/M.aux' file. So perhaps it was not the spaces that caused the issue in the first place.
Any idea?

fyang
  • 195
  • 2
    Why do you need spaces in your path names? My suggestion would be to use underscore _ for spaces, which should solve your problem. – Werner Nov 05 '15 at 01:40
  • That's just a simplified example. I have so many folders, and some of them contain a lot of words separated by spaces. I don't want to change them one by one. I would rather just replace all the \input with \include. – fyang Nov 05 '15 at 01:45
  • Change them one-by-one? Windows doesn't allow "multiple" (or "mass") renaming? – jon Nov 05 '15 at 02:05
  • I don't know how. – fyang Nov 05 '15 at 02:15
  • Seems like there are many possibilities; see this link for example. Or this search. – jon Nov 05 '15 at 02:19
  • @jon OK. Thanks! I keep your suggestion for back-up solution. I'll wait and see if there is any LaTex solution. – fyang Nov 05 '15 at 02:23
  • @jon: I've used the Bulk Rename Utility myself quite successfully. It's freeware. – Werner Nov 05 '15 at 02:46
  • Just some more info. If I type \include{{"Literature_review/M 1"}} first, it won't work. But If I type \include{{"Literature_review/M"}} first and then compile and then \include{{"Literature_review/M 1"}}, it will work. If I delete all the newly generated files, then when I type \include{{"Literature_review/M 1"}} and compile, it will fail again. I guess after a successful run of \include{{"Literature_review/M"}} the first time, LaTeX was brought into the relative path "\Literature_review" so that I when I ran \include{{"Literature_review/M 1"}} afterwards, it worked. – fyang Nov 05 '15 at 03:25
  • So, perhaps if any of you could help me on how to set the relative path for the \include command, then you may help me solve this problem as well. By the way, I'm now using the on-line editor ShareLaTeX. I don't know if they use Windows or Linux. I could 't change the files on their server either. So I need some code that I can type in the editor. – fyang Nov 05 '15 at 03:31
  • Have you tried \include{"Literature review"/M} or \include{{Literature review}/M} . Just a blind shot.. –  Nov 05 '15 at 04:38
  • @Harish Kumar: Didn't work. I even defined a new command for the path. In the error message, I found the path was correct. But LaTeX couldn't write the M.aux file, as long as there was some spaces in the path. I think perhaps this is due to something written in the \include command. I don't understand the language used in LaTeX. I can't do too much myself here I think. – fyang Nov 05 '15 at 04:52
  • @Werner -- I suspected some of those programs/methods were of use! Just not easy for me to test directly.... – jon Nov 05 '15 at 06:10
  • 6
    I'm rather certain that you already spent more time on getting spaces to work that it would have cost you to remove the spaces from the folder and files names ... Even if you find some way to handle the spaces: it can always break if you move to some other os. It is not worth the time. – Ulrike Fischer Nov 05 '15 at 09:13
  • @ Ulrike Fischer: Yeah. I want to finish my writing, and in the meanwhile, I also want to know the answer, or perhaps learn something new. – fyang Nov 05 '15 at 22:56
  • I replaced all the spaces with underlines and still it didn't work. Is it because my file is too deep? It is \include{{"Folder_A/B/C/D/M"}}. LaTeX still reported that it could not write the Folder_A/B/C/D/M.aux file. So perhaps it was not the spaces that caused the issue in the first place. Any idea? – fyang Nov 05 '15 at 23:24
  • I'll start a new topic. – fyang Nov 05 '15 at 23:28
  • 1
    \include{Folder_A/B/C/D/M}, I guess. Why do you need anything that deep in terms of directory structure? Seems very strange.... – cfr Nov 06 '15 at 00:23

2 Answers2

1

For the name ‘amo amas amat’, this works under TeX Live on GNU/Linux:

\documentclass{book}
\includeonly{
  "amo\space amas\space amat"
  }
\begin{document}
\include{"amo\space amas\space amat"}
\end{document}

and this works under MiKTeX on Windows:

\documentclass{book}
\includeonly{
  {"amo amas amat"}
  }
\begin{document}
\include{{"amo amas amat"}}
\end{document}

Reference: 24.2 \include & \includeonly

Sherry869
  • 194
1

There is no way to escape spaces and quotes. If you must, change \include's definition.

\def\include#1{%
   \relax
   \ifnum\@auxout=\@partaux
      \@latex@error{\string\include\space cannot be nested}\@eha
   \else
      \begingroup
         \escapechar\m@ne
         \xdef\@curr@file{%
            \expandafter\string\csname #1\endcsname
         }
      \endgroup
      \expandafter\@include\expandafter{\@curr@file} % trailing space
   \fi
}

Generally, never use quotes and redundant braces unless you know what you are doing. In \includeonly, a \space is welcomed for space escaping.

\includeonly{a\space b}

For \input, simply cover the path with braces. \input{a b}, \input "a b" are both ok.