5

I am trying to include a command in a TeX file to a bibliography file that I am storing centrally.

However, when including the filepath, like

/Foldername with whitespace/ANOTHER folder name with whitespace/nowsinfldrname/bibo.bib

my Unix-based typesetting system complains. Is there a way to rectify that other than renaming my folders?

3
  • Which typesetting program are you using? The immediate fix is covered well by grgarside but having scripts that all properly escape strings is much harder. Especially if they are modular and pass file names on to other scripts, etc...
    – bmike
    Jan 19, 2015 at 15:01
  • Thanks @bmike It is texshop within the context of latex. The error output is coming from its console which makes whitespaces explicit as an issue. Now trying with the single quote marks.
    – Hirek
    Jan 19, 2015 at 21:53
  • It still doesn't work but perhaps I need to move this to tex.stackexchange instead.
    – Hirek
    Jan 19, 2015 at 22:03

4 Answers 4

9

In bash, there are two main ways to have spaces in path names:

  • Backslash escape the spaces

    /path/to/folder\ with\ spaces/
    
  • Wrap with quote marks

    "/path/to/folder with spaces and $variable/"
    
    '/path/to/folder with spaces and a literal $/'
    

    Double quote marks expand shell variables. Single quote marks do not.

3
  • 1
    You probably want to use single quotes to avoid interpolation of special characters like $. "/path/to/my/$money" is /path/to/my/ with the value of the $money shell variable on the end (which will probably be empty). '/path/to/my/$money' is /path/to/my/$money.
    – Schwern
    Jan 18, 2015 at 19:25
  • @Schwern Thanks—I specifically chose double quote marks for this reason as the original question was specifically about spaces and the folder name in OP's path may have been provided by a variable, but I understand that I totally presumed this and didn't make it clear in my answer.
    – grg
    Jan 18, 2015 at 19:30
  • @Schwern The backslashes actually did not work as I got another message from my tex console that whitespaces were detected. Neither did double quotes. I will try it with single quotes though.
    – Hirek
    Jan 19, 2015 at 1:30
2

Escape the spaces with a backslash:

This\ has\ spaces

1

As a last resort there are symbolic links.

the link is expanded at a lower level so the application level quoting is skipped.

ln -s '/Foldername with whitespace/ANOTHER folder name with whitespace/nowsinfldrname' /tmp/
1
  • This actually might be a decent workaround if the tool chain just isn't able to properly escape file names and/or handle arbitrary unicode file names and paths.
    – bmike
    Jan 19, 2015 at 15:02
0

The answer is very simple. It is not OS X's fault but BibTex. It is quite old and doesn't support whitespaces in file names or paths.

You must log in to answer this question.

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