Issue resolved, please see end of question for details
I am passing a file path as a parameter to a tex script, run by pdflatex on Windows.
Here's an example of a command:
pdflatex -interaction=nonstopmode -halt-on-error -job-name=c:/target/job1 "\newcommand{\inputFileParam}{c:/Source/job1}\input{c:/Scripts/somescript.tex}"
Note that the paths are delimited using forward slashes. This is not recognized by Windows. Therefore on Windows I need to use backslashes. However, I cannot find a way to escape those backslashes that belong to the path correctly.
Unless correctly escaped, pdflatex treats the sequences which start with a backslash as commands, and fails with undefined command error.
To summarize, How do I escape the path backslashes in:
\newcommand{\inputFileParam}{c:\Source\job1}\input{c:\Scripts\somescript.tex}
EDIT – Solution
The answers below helped separate multiple issues with the above command.
-
Forward slashes work fine in Windows
-
Escaping backslashes is achieved (if needed) by prepending each path part with
\string
:(for example:
C:\string\dirname\string\filename.ext
) -
-job-name
should not contain a full path.-output-directory
should be used in conjunction with-job-name
to specify the path, otherwise an error is issued. -
The "file not found" error was in fact due to another issue. As you see,
C:\Source\job1
was provided without extension. Such a file, without extension, indeed exists in the specified directory. However, it seems that pdflatex assumes a PDF extension if none is provided. Therefore when I added the fileC:\Source\job1.pdf
the command worked flawlessly.It should be noted that the error string both on console and in log referred to "c:\Source\job1" without extension.
Best Answer
TeX (and most windows APIs are happy to use
/
as a file separator so you can use