I use a .tex file that I sync with Dropbox across two computers, - mac (running win 7) and a pc.

The problem is that the .tex file is large, and contains a lot of tex commands (even user-written ones) like:


Of course, this is the absolute path on my PC and the same file on my mac looks like:


Note how / are changed in \ and how the path is different.

My question is: how can I simply (and quickly) change all the paths when I move from my pc to my mac and vice versa? I use the latest winedt version to edit my latex file.

Many thanks for your help!

  • 4
    You must not use absolute paths. Use always relative paths. It is more simple and it is necessary for security reason too. – user56567 Jul 20 '14 at 10:49
  • 1
    \addbibresource{file.bib} (sorry, but I think that .bib is more appropriate for \addbibresource command) is the solution if latex/main/ is the working directory for both system. – user56567 Jul 20 '14 at 10:54
  • 1
    If you need to access a .tex file that is located in the main\other folder you have to write \input{main/other/file.tex} – user56567 Jul 20 '14 at 10:58
  • 1
    First: I don't know. Second: ../ go back in the folder. – user56567 Jul 20 '14 at 12:21
  • 1
    The paths are relative to the directory in which you are running pdflatex (or whichever). So if you run pdflatex main/my.file then the paths should be relative to the latex directory (i.e. to get to main/other/file you would simply put that). If you change into the main folder and run pdflatex my.file, then to get to the other folder you should put ../other/file. This messed me up so many times when I was using subfiles... :-) – darthbith Jul 20 '14 at 12:27

Perhaps use a system dependent preamble for this kind of information.

On the mac:

% systempreamble.tex 

On the pc:

% systempreamble.tex

% latex uses / for paths, even on a pc

In your document

% ...

(I haven't tested this since there's no easy MWE.) You should also consider the comments about absolute path names.

|improve this answer|||||
  • This is smart, thanks. But an even smarter way to go would be to run a shell like command pwd in latex to get the current working directory. Is that possible? – ℕʘʘḆḽḘ Jul 20 '14 at 13:05
  • 1
    I wouldn't use that strategy. If you want to try, the answer here may help: tex.stackexchange.com/questions/16790/… – Ethan Bolker Jul 20 '14 at 13:11
  • Thanks! May i ask you why you would not use that? The idea is just to run your tex file on whatever computer you want without messing manually with the code – ℕʘʘḆḽḘ Jul 20 '14 at 13:29
  • 1
    Using a shell script escape is more complex, so harder to write and more prone to error. It may solve this particular problem, but it's less flexible. It might be worth doing if you were writing TeX for many users to compile on many computers. In this case I'd go with the generally useful design principle that puts macros in a preamble. You will do that often as you move from Noobie status. Once you've written the (system dependent) preamble you don't have to "mess manually with the code" - you just run it. – Ethan Bolker Jul 20 '14 at 13:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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