Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

  1. Forward slashes work fine in Windows
  2. Escaping backslashes is achieved (if needed) by prepending each path part with \string:

    (for example: C:\string\dirname\string\filename.ext)

  3. -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.

  4. 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 file C:\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.

share|improve this question
    
Not sure, but \input{c:\string\Scripts\string\somescript} might work. –  egreg Dec 12 '12 at 13:36
1  
You should switch to the directory of the input file before calling pdflatex or pdflatex will have difficulty to find external files like the aux or the toc file. You should set the jobname as --jobname=job1 (without the path) and the output-directory with the option --output-directory. –  Ulrike Fischer Dec 12 '12 at 13:52
    
@Roman: If you take out the -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. –  cyberSingularity Dec 13 '12 at 10:31
    
OK I have discovered that forward slashes are indeed working in Windows, and there's a problem specific to the given path (probably permissions). With that, @egreg's solution is correct, preceding with \string indeed escaped the backslash. In addition, Ulrike Fischer was also correct that I should use --output-directory instead of providing a full path to -job-name. –  Roman Dec 13 '12 at 20:09
    
Just updated the question with the root of the problem and the solution. Thanks. –  Roman Dec 13 '12 at 20:46
add comment

1 Answer

up vote 4 down vote accepted

TeX (and most windows APIs are happy to use / as a file separator so you can use

\newcommand{\inputFileParam}{c:/Source/job1}\input{c:/Scripts/somescript.tex}
share|improve this answer
    
Doesn't seem to work for me. The error it gives is "! Emergency Stop" and then (*) with port of the "c:/Source/job1" path. –  Roman Dec 12 '12 at 13:56
    
hmm strange, although following Ulrike's advice in her comment is probably a better idea anyway –  David Carlisle Dec 12 '12 at 14:01
    
I seem to recall having this problem when I had Windows. I think I got around it by write "C:" instead of "c:". And, I used `\`, not /. –  A.Ellett Dec 12 '12 at 15:02
    
@DavidCarlisle you are correct, when I changed the path to another directory, forward slashes worked correctly. Therefore the slashes are not the problem, I am still investigating what is. I am marking yours as answer and will update once I discover the underlying problem. –  Roman Dec 13 '12 at 20:04
    
Just updated the question with the root of the problem and the solution. Thanks. –  Roman Dec 13 '12 at 20:45
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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