# Why am I getting an error when trying to send a tex string to pdflatex executable?

According to the help file:

This is pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian)
entering extended mode
! I can't find file documentclass{article}'.
<*> documentclass{article}
begin{document} end{document}


What am I doing wrong?

EDIT

To summarize the steps that I did to solve the problem: (Thanks to egreg's answer and Warren's comment)

1. Send the string to pdflatex, not pdftex like it says in the helpfile.

2. Put quotes around the string. Use single quotes and not double quotes since single quotes take the string as is (without processing special characters).

3. Remove the line breaks. I did this with a string replace in PHP.

4. Remove the comments--denote by '%' signs.

On top of the answer that egreg gave, I also removed all linebreaks in the string that I sent to pdflatex.

• You would need to run this through pdflatex (not pdftex). But you'll run into problems if you pass everything through the command line, as comment chars without line breaks might not be interpreted as expected. – Werner Mar 10 '15 at 20:09
• Thanks for the tip. I thought they were both the same. I was trying with /usr/bin/pdflatex before, but I noticed with the '--help' argument it showed the usage as pdftex. – Klik Mar 10 '15 at 20:53
• Just to clarify about which executable to call: pdftex is set up to process input in the "Plain TeX" format, while pdflatex is set up for "LaTeX" format. \documentclass etc. are LaTeX macros; they are not defined in Plain TeX, so pdftex doesn't understand them. – musarithmia Mar 12 '15 at 13:52

pdflatex "\documentclass{book}\begin{document}Hello world\end{document}"
`