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.
\input{c:\string\Scripts\string\somescript}
might work.aux
or thetoc
file. You should set the jobname as--jobname=job1
(without the path) and the output-directory with the option--output-directory
.-interaction=nonstopmode -halt-on-error
from the compile options, and use David's suggestion of/
or egreg's suggestion of\string
, you may get a more useful error message and some lines of context, which you should edit into your question. Let us know when the problem is resolved.