1

I am trying to write a .bat file for my Windows machine that removes page numbers and converts the pdf to a png file with pdfcrop and pdftoppm. The conversion part is not an issue; running latex from the .bat file is what I'm having trouble with. For example if I make a file mycmd.bat containing

pdflatex '\AtBeginDocument{\pagestyle{empty}}\input{%1}'

and run mycmd bbb on the file bbb.tex

\documentclass{article}
\begin{document}
some text
\end{document}

then in the terminal I get

C:\Users\<user>\Downloads> mycmd bbb

C:\Users&lt;user>\Downloads>pdflatex '\AtBeginDocument{\pagestyle{empty}}\input{bbb}' pdflatex: security risk: running with elevated privileges This is pdfTeX, Version 3.141592653-2.6-1.40.25 (MiKTeX 23.5) (preloaded format=pdflatex.fmt) restricted \write18 enabled. entering extended mode ! I can't find file `''. <to be read again> \protect <*> '\AtBeginDocument {\pagestyle{empty}}\input{bbb}' (Press Enter to retry, or Control-C to exit) Please type another input file name:

But if I run the command pdflatex '\AtBeginDocument{\pagestyle{empty}}\input{bbb}' directly in the terminal then it works fine.

My only guess is that latex has an issue with the percent in %1 from the .bat file. If this is the issue, how can I fix it? If not, what is going wrong?

mbert
  • 4,171
  • I think you need to put the %1 in quote marks of some form, like "%1" in your .bat file. If not then hopefully someone knows the answer, might be a good question for superuser if you don't get an answer over here – JamesT May 19 '23 at 23:28
  • @JamesT I had tried quotes but no luck. Should've put that in the question – mbert May 19 '23 at 23:35
  • 1
    You need double quotes. Single quotes are not special in Windows Batch (in fact Windows Batch file is very complicated) ■ edit actually maybe not, but the behavior of command-line versus in batch file is also different so not sure – user202729 May 19 '23 at 23:49
  • @user202729 Ah yes that works, thanks! Feel free to post as an answer – mbert May 19 '23 at 23:52
  • you can post one yourself. – user202729 May 19 '23 at 23:52

1 Answers1

1

As @user202729 mentioned in the comments, you need to use double quotes around the entire argument of pdflatex:

pdflatex "\AtBeginDocument{\pagestyle{empty}}\input{%1}"

Probably Windows-specific.

mbert
  • 4,171