2

If I to include a graphic I have to manually replace backslashes '\' with slashes '/', which isn't very convenient especially if the path is long. But Latex is all about convenience and automation, right?

So I wonder if the a macro/package that would take a Windows path and replace backslashes with slashes and return it, preferably could handle sdpaces in the path. Intended use for including graphics and listings like this

\includegraphics{"\windowspath{my path1\my path2\my image.png}"}
\lstinputlisting{"\windowspath{my path1\my path2\myscript.m}"}

I found something similar here but it seems to define the converted path as a new variable, rather then returning it.

  • 2
    It should be rather rare to ever need a full path, \includegraphics{"my image"} would be enough in most cases. The syntax you suggest would be very tricky as the space after \my is never tokenised it will have been absorbed while tex parsed the command \my so while you could detokenise the string and turn \to / you can not reliably tell if there should be a space after \my – David Carlisle Nov 07 '17 at 19:17
  • why do you have to "replace \ with / ? How did the original string get entered? I ask as it would be better to fix that process so the / version gets entered into the file. – David Carlisle Nov 07 '17 at 19:27
  • But Latex is all about convenience and automation, right?
  • I have good news and bad news...
  • – percusse Nov 07 '17 at 19:39
  • @percusse please tell them, I'm very curious! – Skillmon Nov 07 '17 at 19:42
  • I have good and bad news. The good: it is easily possible to write a macro which contains paths with \ in them and return the same path with / instead of \. The bad: it won't work in \input and I don't think it would in \includegraphics or similar. – Skillmon Nov 07 '17 at 19:44
  • @Skillmon you can probably do it expandably so it works in input and includegraphics, but spaces are an issue and I'm not sure why it would be needed. – David Carlisle Nov 07 '17 at 19:50
  • @DavidCarlisle I don't manage to make the macro expandable, atm, but spaces aren't an issue in it (while expandability certainly is). – Skillmon Nov 07 '17 at 19:58
  • Aren't TeX implementation on Windows accepting / as path delimiter instead of \? – egreg Dec 03 '17 at 14:55