【问题标题】:Using pdflatex to compile LaTeX file within C code使用 pdflatex 在 C 代码中编译 LaTeX 文件
【发布时间】:2013-07-15 13:52:43
【问题描述】:

我正在编写为我编写 LaTeX 文件的 C 代码。然后我尝试在非交互模式下使用 pdflatex 编译文件(如我正在自动化某些过程并且不想等待用户输入致命错误)。 LaTeX 文件在./data/output_date.tex 输出,我尝试使用命令编译它

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

但是,我收到错误消息:

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.

我似乎无法理解为什么我会紧急停止,特别是因为当我从终端运行相同的命令时(来自与 C 可执行文件相同的文件夹),LaTeX 可以很好地编译为 pdf。

因为我将编译器作为 C 代码中的命令调用,所以我必须做一些特别的事情吗?

编辑:这是相应 .log 文件的文本。它似乎唯一说的是“找不到合法的 \end”,这让我感到困惑,因为我检查了源文件以确保我的 \begin 和 \end 匹配。

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!

【问题讨论】:

  • 不是专家,但你试过检查data/output_date.log吗?它显然说它确实在那里放了一些东西。也许对出了什么问题有一些提示。
  • 我做到了,但我无法真正说出错误是什么。我编辑发布了上面的 .log 文件的文本,但就像我在那里说的那样,我能找到的最好的是 \end 的问题,这很奇怪,因为我的 \begin 和 \end 在源代码中匹配。
  • 既然你说完全相同的命令在命令行上工作,也许你可以将 tex 文件剥离为一个最小的攻击性示例,其中 shell 命令仍然有效,而嵌入式计数器部分中断。也许这样就可以(或更容易)分析 tex 文档或环境有什么问题。
  • Calling pdflatex inside C code 的副本;请删除此问题,不要交叉发布。
  • @ChaeJubb:从 OP(您)的角度来看,在多个站点上询问是理想的,因为您觉得您正在最大化您的投资回报(只需很少/没有额外的努力)。但是,从社区的角度来看,这似乎是重复劳动。一种方法是在 SiteA 上发帖,看看您是否得到任何回应。如果一周内没有任何反应(例如),则标记为迁移或删除并重新发布到 SiteB。如果一切都失败了,请提及它是交叉发布的(带有链接),以便感兴趣的成员可以同时关注讨论。这应该只适用于极端/边界情况。

标签: c latex pdflatex


【解决方案1】:

在我尝试使用pdflatex 命令编译它之前,我需要关闭文件以进行写入(在 C 代码中)。我在fclose 命令之后无意中添加了它。

我的猜测是我的命令要么没有在尝试编译之前最后一次刷新缓冲区(这将包括 \end{document}),要么正在使用的文件以某种方式影响了 pdflatex。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-28
    • 2019-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多