-1

I am writing C code that writes a LaTeX file for me. I then attempt to compile the file using pdflatex in a non-interactive mode (as in I'm automating some process and don't want to wait for user input on fatal error). The LaTeX file is output at ./data/output_date.tex and I attempt to compile it using the command

system("./pdflatex --interaction=nonstopmode --output-directory=data ./data/output_date.tex");

However, I get the error message:

This is pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian)
entering extended mode
(./data/output_date.tex
LaTeX2e <2009/09/24>
Babel <v3.8l> and hyphenation patterns for english, usenglishmax, dumylang, noh
yphenation, loaded.
(/usr/share/texmf-texlive/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/share/texmf-texlive/tex/latex/base/size10.clo))
(/usr/share/texmf-texlive/tex/latex/pbox/pbox.sty
(/usr/share/texmf-texlive/tex/latex/tools/calc.sty)
(/usr/share/texmf-texlive/tex/latex/base/ifthen.sty))
(data/output_2013_date.aux))
! Emergency stop.
<*> ./data/output_date.tex

!  ==> Fatal error occurred, no output PDF file produced!
Transcript written on data/output_date.log.

I can't seem to decipher why exactly I'm getting an emergency stop, especially because when I run the same exact command from the terminal (from the same folder as the C executable), the LaTeX compiles fine to pdf.

Is there something special I have to do because I'm calling the compiler as a command from C code?

EDIT: Here is the text of the corresponding .log file. The only thing it seems to say is that "no legal \end found", which confuses me because I checked the source file to make sure my \begin and \end match up.

This is pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian) (format=pdflatex 2013.5.23)  15 JUL 2013 09:50
entering extended mode
 %&-line parsing enabled.
**./data/output_date.tex
(./data/output_date.tex
LaTeX2e <2009/09/24>
Babel <v3.8l> and hyphenation patterns for english, usenglishmax, dumylang, noh
yphenation, loaded.
(/usr/share/texmf-texlive/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/share/texmf-texlive/tex/latex/base/size10.clo
File: size10.clo 2007/10/19 v1.4h Standard LaTeX file (size option)
)
\c@part=\count79
\c@section=\count80
\c@subsection=\count81
\c@subsubsection=\count82
\c@paragraph=\count83
\c@subparagraph=\count84
\c@figure=\count85
\c@table=\count86
\abovecaptionskip=\skip41
\belowcaptionskip=\skip42
\bibindent=\dimen102
)
(/usr/share/texmf-texlive/tex/latex/pbox/pbox.sty
Package: pbox 2003/04/06 v1.0 Dynamic parboxes

(/usr/share/texmf-texlive/tex/latex/tools/calc.sty
Package: calc 2007/08/22 v4.3 Infix arithmetic (KKT,FJ)
\calc@Acount=\count87
\calc@Bcount=\count88
\calc@Adimen=\dimen103
\calc@Bdimen=\dimen104
\calc@Askip=\skip43
\calc@Bskip=\skip44
LaTeX Info: Redefining \setlength on input line 76.
LaTeX Info: Redefining \addtolength on input line 77.
\calc@Ccount=\count89
\calc@Cskip=\skip45
)
(/usr/share/texmf-texlive/tex/latex/base/ifthen.sty
Package: ifthen 2001/05/26 v1.1c Standard LaTeX ifthen package (DPC)
)
\pb@xlen=\skip46
)
(data/output_date.aux)
\openout1 = `output_date.aux'.

LaTeX Font Info:    Checking defaults for OML/cmm/m/it on input line 8.
LaTeX Font Info:    ... okay on input line 8.
LaTeX Font Info:    Checking defaults for T1/cmr/m/n on input line 8.
LaTeX Font Info:    ... okay on input line 8.
LaTeX Font Info:    Checking defaults for OT1/cmr/m/n on input line 8.
LaTeX Font Info:    ... okay on input line 8.
LaTeX Font Info:    Checking defaults for OMS/cmsy/m/n on input line 8.
LaTeX Font Info:    ... okay on input line 8.
LaTeX Font Info:    Checking defaults for OMX/cmex/m/n on input line 8.
LaTeX Font Info:    ... okay on input line 8.
LaTeX Font Info:    Checking defaults for U/cmr/m/n on input line 8.
LaTeX Font Info:    ... okay on input line 8.
LaTeX Font Info:    External font `cmex10' loaded for size
(Font)              <12> on input line 9.
LaTeX Font Info:    External font `cmex10' loaded for size
(Font)              <8> on input line 9.
LaTeX Font Info:    External font `cmex10' loaded for size
(Font)              <6> on input line 9.
LaTeX Font Info:    External font `cmex10' loaded for size
(Font)              <7> on input line 15.
LaTeX Font Info:    External font `cmex10' loaded for size
(Font)              <5> on input line 15.
)
! Emergency stop.
<*> ./data/output_date.tex

*** (job aborted, no legal \end found)


Here is how much of TeX's memory you used:
 375 strings out of 495061
 4422 string characters out of 1182621
 56939 words of memory out of 3000000
 3619 multiletter control sequences out of 15000+50000
 6675 words of font info for 24 fonts, out of 3000000 for 9000
 28 hyphenation exceptions out of 8191
 23i,14n,19p,304b,189s stack positions out of 5000i,500n,10000p,200000b,50000s
!  ==> Fatal error occurred, no output PDF file produced!
cjubb39
  • 454
  • 1
  • 5
  • 15
  • Not an expert but have you tried checking `data/output_date.log`? It obviously says it did put something into there. Maybe some hints on what went wrong. – luk32 Jul 15 '13 at 14:00
  • I did, but I couldn't really tell what the error was. I edited posted the text of the .log file above, but like I say there, the best I can find is an problem with \end, which is odd because my \begin and \end match up in the source. – cjubb39 Jul 15 '13 at 14:24
  • Since, you say that the exact same command works on command line, maybe you can strip down the tex file to a minimal offensive example where the shell command stills works while the embedded counter part breaks. Maybe then it would be possible (or easier) to analyze what's wrong with the tex document, or the environment. – luk32 Jul 15 '13 at 14:36
  • Duplicate of [Calling pdflatex inside C code](http://tex.stackexchange.com/q/124088); please delete this question and don't crosspost. – Martin Schröder Jul 15 '13 at 18:16
  • @MartinSchröder I understand that generally crossposting isn't ideal, but I feel like my question was relevant to both? It was an error with the C that manifested itself in the LaTex. Which one do you think it should be posted at if not both? (Please keep in mind I'm relatively new here) – cjubb39 Jul 15 '13 at 19:22
  • 1
    @ChaeJubb: From the OP's perspective (you), asking on multiple sites is ideal since you feel like you're maximizing your return on investment (for little/no extra effort). However, from the community's perspective this may seem like duplication of effort. One approach would be to post on SiteA and see if you get any response. If nothing happens in a week (say), then flag for migration or delete-and-repost to SiteB. If all else fails, mention it is cross-posted (with a link) so interested members can follow the discussion in parallel. This should only fit in extreme/boundary cases. – Werner Jul 15 '13 at 22:29
  • @Werner Thanks! Can you, by any chance, think of an example off-hand where you would say cross-posting is acceptable? – cjubb39 Jul 17 '13 at 01:56
  • @ChaeJubb: No, sorry. It really depends on the topic *and* the question itself. And even then, if the content straddles two sites/topics, you will most likely find someone on one of the sites that actually cover both the topics and can answer it on that site alone. This is purely speculative, as you can imagine. Best bet is to stick to one site at a time. – Werner Jul 17 '13 at 02:29

1 Answers1

1

Turns out I needed to close the file for writing (in the C code) before I attempt to compile it with the pdflatex command. I had inadvertently added it after the fclose command .

My guess is my ordering either hadn't flushed the buffer one last time (which would have included the \end{document}) before attempting to compile or the file being in use affected the pdflatex somehow.

cjubb39
  • 454
  • 1
  • 5
  • 15