【问题标题】:Makefile adding spaces to variablesMakefile向变量添加空格
【发布时间】:2015-04-16 23:50:47
【问题描述】:

我正在尝试使用 makefile 来在 LaTex 中编译我的故事。我正在尝试使用变量来完成我的故事的文件名。如果我简单地运行 make,它就可以工作。但是,我需要能够从 make 运行特定命令。

pdflatex "\\def\\isdraft{1} \\input{FMPGC.tex}"

我将如何从 PROJ + OBJS 创建一个变量,以便我可以做一些类似于我在下面尝试做的事情。如果我为 make draft 运行以下代码,它会失败并且似乎在 FMPGC 和 tex 之间添加了许多空格。

如何将两个变量与“。”结合起来这对之间的符号,所以我可以在下面的命令中编译我的故事。我也尝试过不转义 \ 符号,这似乎没有效果。

# This makefile compiles my story using LaTex
# Author:
#

# VARS - Variables to be changed for reuse of my script
PROJ = "FMPGC"          # The name of the project
OBJS = "tex"            # The extension for the content
AUXS = "aux"            # The aux extensions
CHAP = "chapters/"      # The chapters
FOO = $(PROJ) += "."
F002 = $(FOO) += $(OBJS)

# Configuration:
CC = pdflatex   # The compiler

# Rules
all:
    $(CC) $(PROJ).$(OBJS)
draft:
    $(CC) "\\def\\isdraft{1} \\input{$(FOO2)}"

当前的错误来自它没有向变量中输入任何内容 -

pdflatex     "\\def\\isdraft{1} \\input{}"

下面似乎是确切的问题。

<*> \def\isdraft{1} F
                     MPGC.tex

---------------- 更新了 Make 文件

# This makefile compiles my story using LaTex
# Author:
#

# VARS - Variables to be changed for reuse of my script

# The name of the project
PROJ:=FMPGC
# The extension for the content
OBJS:=tex
# The aux extensions
AUXS:=aux
# The chapters
CHAP:=chapters/

# Configuration:
# The compiler
CC=pdflatex

# Rules
all:
    $(CC) $(PROJ).$(OBJS);
draft:
    $(CC) "\def\isdraft{1} $(PROJ).$(OBJS)";

更新错误----

pdflatex "\def\isdraft{1} FMPGC.tex";
This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2014) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
LaTeX2e <2014/05/01>
Babel <3.9k> and hyphenation patterns for 21 languages loaded.

! LaTeX Error: Missing \begin{document}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

<*> \def\isdraft{1} F
                     MPGC.tex
? 
! Emergency stop.
 ...                                              

<*> \def\isdraft{1} F
                     MPGC.tex
!  ==> Fatal error occurred, no output PDF file produced!
Transcript written on texput.log.

【问题讨论】:

  • FOO = $(PROJ) += "."F002 = $(FOO) += $(OBJS) 行是怎么回事?你到底想在那里做什么?还有为什么第二行是F002 而不是FOO2? (您似乎在 draft 目标中使用了 $(FOO2)。)
  • 我删除了该部分。我试图将这两个变量结合起来,使其成为带有 .之间。请查看我的错误以及我在编辑中所做的更改。
  • 命令行看起来不错,只是错误似乎有奇怪的间距(这可能是 pdflatex 的事情)。 \def\isdraft{1} 和文件名应该是 pdflatex 的单个参数吗?
  • 我修好了。我会尽可能添加答案。万分感谢!这是我声明我的变量错误并且没有语法的组合。

标签: makefile latex pdflatex


【解决方案1】:

在 GNU make 手册的 The Two Flavors of Variables 部分,我们发现:

如果您将空格放在变量值的末尾,最好在行尾添加这样的注释以明确您的意图。相反,如果您不希望在变量值的末尾出现任何空白字符,则必须记住不要在行尾的一些空白之后随意添加注释,例如:

dir := /foo/bar    # directory to put the frobs in

这里变量 dir 的值是“/foo/bar”(有四个尾随空格),这可能不是本意。 (想象一下像“$(dir)/file”这样的定义!)

【讨论】:

  • 我删除了所有空格,但仍然无法正常工作。现在看来,在 F 和 var PROJ 的 MPGC 之间有一个空格,但显然不是这样。
  • 用编辑过的 makefile 更新帖子(附加它不要删除当前内容)和运行 make 的新错误输出。
  • 请看上面修改后的帖子。
【解决方案2】:

感谢@Etan Reisner,我在查看文档后能够修复它。

我的 make 文件现在看起来像这样 -

# This makefile compiles my story using LaTex
# Author:
#

# VARS - Variables to be changed for reuse of my script

# The name of the project
PROJ:=FMPGC
# The extension for the content
OBJS:=tex
# The aux extensions
AUXS:=aux
# The chapters
CHAP:=chapters/

# Configuration:
# The compiler
CC=pdflatex

# Rules
all:
    $(CC) $(PROJ).$(OBJS);
draft:
    $(CC) "\def\isdraft{1} \input{$(PROJ).$(OBJS)}";

我现在可以编译我的文档,它会添加我的变量以在 LaTex 中使用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-28
    • 2012-10-31
    • 2016-09-27
    • 2021-12-05
    • 1970-01-01
    • 2016-05-23
    • 1970-01-01
    • 2017-01-31
    相关资源
    最近更新 更多