3

According to the help file:

    $ pdflatex --help
    Usage: pdftex [OPTION]... [TEXNAME[.tex]] [COMMANDS]
       or: pdftex [OPTION]... \FIRST-LINE
       or: pdftex [OPTION]... &FMT ARGS
      Run pdfTeX on TEXNAME, usually creating TEXNAME.pdf.
      Any remaining COMMANDS are processed as pdfTeX input, after TEXNAME is read.
      If the first line of TEXNAME is %&FMT, and FMT is an existing .fmt file,
      use it.  Else use `NAME.fmt', where NAME is the program invocation name,
      most commonly `pdftex'.

      Alternatively, if the first non-option argument begins with a backslash,
      interpret all non-option arguments as a line of pdfTeX input.

"if the first non-option argument begins with a backslash, interpret all non-option arguments as a line of pdfTex input."

Well I have a tex document that I know works. Since I am trying to print multiple tex documents to pdf I thought it would be better to store the document as a string in memory and then send the string directly to the executable instead of reading my template file repeatedly.

I tried via commandline just to test this:

pdftex \documentclass{book}   \usepackage{graphicx} \usepackage[absolute]{textpos}  \usepackage{fancyhdr} \pagestyle{fancy}  \usepackage{xcolor,colortbl} \definecolor{DarkGray}{rgb}{0.7,0.7,0.7} \definecolor{LightGray}{rgb}{0.93,0.93,0.93} \definecolor{LightCyan}{rgb}{0.88,1,1} \definecolor{White}{rgb}{.99,.99,.99}  \begin{document}  \pagenumbering{gobble} \begin{textblock}{150}(0,0.3)    \includegraphics[width=50mm]{images/logo.jpeg}  \end{textblock}  \begin{textblock}{150}(11,11.5)    \includegraphics[width=50mm]{images/watermark_uw.jpg}  \end{textblock}  \begin{textblock}{150}(3,2)     \mbox{\large{\textbf{NAME:}}} %NAME HERE \end{textblock}  \begin{textblock}{150}(6,2)   \mbox{\large{\textbf{Heather Steinmetz  }}} %NAME HERE \end{textblock}  {\renewcommand{\arraystretch}{2}% \begin{textblock}{400}(3,3.5)     \setlength\arrayrulewidth{1.0pt}    \begin{table}[h]    \begin{tabular}{c>{\hspace{3pc}}c>{\hspace{3pc}}c<{\hspace{20pt}}}      \rowcolor{DarkGray}         \hline          \textbf{\large{Time Slot}} & \textbf{\large{Meeting With}} & \textbf{\large{Location}} \\[5pt]  \hline          \rowcolor{LightGray}  1030 to 1100 & Alex Williams & DC2119 \\ \hline       \rowcolor{White}  1100 to 1130 & Unscheduled &  \\ \hline       \rowcolor{LightGray}  1130 to 1200 & Yasha Pushak & DC2119 \\ \hline        \rowcolor{White}  1300 to 1330 & Unscheduled &  \\ \hline               \rowcolor{White} & & \\     \end{tabular}   \end{table} \end{textblock}  \fancyhf{} % sets both header and footer to nothing \renewcommand{\headrulewidth}{0pt}  \rfoot{\mbox{519-988-4567 | uwaterloo.ca | 200 UNIVERSITY AVENUE WEST, WATERLOO, ON. CANADA N2L 3G1}}  \end{document}

However, I have not been able to get pdflatex to create a pdf with this method. It always errors out and says:

$ pdftex \documentclass{article} \begin{document} \end{document}
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
  • 1
    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
4

The shell interprets backslashes as part of its processing, before launching the program. You have to quote the argument:

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

It doesn't seem a good idea to have all the document in the command line, though.

|improve this answer|||||
  • I don't intend on using the command line. I'm using php to hold the string. I'll try again and let you know if this works... I thought I already tried using quotes >.< – Klik Mar 10 '15 at 20:47
  • In this case, I think this is not the best place for asking your question. – egreg Mar 10 '15 at 20:49
  • This does the trick thanks! I thought this was a better place to ask since my problem wasn't with the programming language, but rather using the pdflatex executable. – Klik Mar 10 '15 at 20:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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