- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 matplotlib
生成 pgf
文件。基于这些,我使用独立的 tex
文件,它只包含必要的设置和预先构建的 pgf
。在这种情况下,在我的绘图文件中使用自定义 tex-macros 进行描述时出现错误。
这里有一个例子 pgf
生成器:
import matplotlib as mpl
mpl.use("pgf")
mpl.rcParams.update({
"pgf.texsystem": "pdflatex",
"pgf.preamble": [
#r"\newcommand{\foo}{foo}",
r"\usepackage{import}",
r'\subimport{./}{foo.tex}'
]
})
import matplotlib.pyplot as plt
plt.figure(figsize=(4.5,2.5))
plt.plot(range(5))
plt.xlabel(r'\foo{}')
plt.savefig('foo.pgf')
可以在具有以下 foo.tex
文件的目录中使用:
\newcommand{\foo}{foo}
运行此命令会导致以下错误:
ValueError: Error processing '\foo{}'
LaTeX Output:
! Undefined control sequence.
<argument> ....000000}{12.000000}\selectfont \foo
{}
<*> ...ze{10.000000}{12.000000}\selectfont \foo{}}
! ==> Fatal error occurred, no output PDF file produced!
Transcript written on texput.log.
请注意,这是 matplotlib
产生的错误,不是 编译我的独立文件。另请注意,当 \foo
宏作为 pgf.preamble
的一部分提供时,错误就会消失(该行被注释掉)代替。我检查了这个变体生成的 pgf
,确实它使用了 \foo{}
。
我无法进一步缩小问题范围。这是我的具体问题:
matplotlib
会调用 pdflatex
?我正在生成 pgf
输出,因此 pdflatex
应该不是必需的。(供引用:我 strace
d 上面的脚本确实知道正在调用 pdflatex
。)matplotlib
尝试编译的临时文件?错误引用 texput.log
(当然)该文件之后不存在。最佳答案
tl;dr 包括 tex
-pgf.preamble
中的文件的 matplotlib
需要绝对路径。
为了以后,我推荐以下pdflatex
用于调试目的的“替换脚本”:
#!/usr/bin/env bash
MAIN=/usr/bin/pdflatex
cat /dev/stdin | tee /some/abs/path/to/dbg.tex | "${MAIN}" "${@}"
确保将其另存为 pdflatex
, 确保它是可执行的,确保 /usr/bin/pdflatex
是你的实际pdflatex
并确保首先在你的 PATH
中找到这个包装器(参见 which pdflatex
)。运行 python
时生成器,我们保留最终的 tex
在 dbg.tex
中输入.这就是 (2) 的答案。
考虑到输出,我们看到:
\documentclass{minimal}
\usepackage{import}
\subimport{./}{foo.tex}
\begin{document}
text $math \mu$
\typeout{pgf_backend_query_start}
\sbox0{\sffamily\fontsize{10.000000}{12.000000}\selectfont lp}
\typeout{\the\wd0,\the\ht0,\the\dp0}
\sbox0{\sffamily\fontsize{10.000000}{12.000000}\selectfont 0}
\typeout{\the\wd0,\the\ht0,\the\dp0}
\sbox0{\sffamily\fontsize{10.000000}{12.000000}\selectfont 1}
\typeout{\the\wd0,\the\ht0,\the\dp0}
\sbox0{\sffamily\fontsize{10.000000}{12.000000}\selectfont 2}
\typeout{\the\wd0,\the\ht0,\the\dp0}
\sbox0{\sffamily\fontsize{10.000000}{12.000000}\selectfont 3}
\typeout{\the\wd0,\the\ht0,\the\dp0}
\sbox0{\sffamily\fontsize{10.000000}{12.000000}\selectfont 4}
\typeout{\the\wd0,\the\ht0,\the\dp0}
\sbox0{\sffamily\fontsize{10.000000}{12.000000}\selectfont \foo{}}
\typeout{\the\wd0,\the\ht0,\the\dp0}
我不知道那应该有什么用。但我猜 matplotlib
正在尝试调整它尝试编译此“测试”文档的字体设置。那种(某种)答案 (1)。
现在得出结论(事后看来很明显): matplotlib
在临时目录中编译此示例文档。显然没有 foo.tex
在此目录中可用,因此 subimport
失败。从那时起很明显\foo
将不可用。
虽然不是最干净的解决方案,这可以通过包含 foo.tex
来解决通过绝对路径。使用 python 生成器最终回答 (3):
import matplotlib as mpl
import pathlib
mpl.use("pgf")
mpl.rcParams.update({
"pgf.texsystem": "pdflatex",
"pgf.preamble": [
r"\usepackage{import}",
f'\subimport{{{pathlib.Path.cwd().resolve()}/}}{{foo.tex}}']
})
import matplotlib.pyplot as plt
plt.figure(figsize=(4.5,2.5))
plt.plot(range(5))
plt.xlabel(r'\foo{}')
plt.savefig('foo.pgf')
(我使用 python3
和 pathlib
。对于 python2
我们宁愿回到os.getcwd .)
关于python - 描述中的 Matplotlib tex-macro,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52918660/
是否可以传递带有宏触发器的字符串作为宏参数?请参阅下面的示例代码: options mprint; %let string5='%abc%def%'; %macro test(string); dat
我意识到我的代码的某个部分由看起来相似的方法组组成(就像我有多个三重奏:一个辅助函数被另外两个为程序员准备的函数调用)。我正在尝试编写一个宏来为我定义这三个函数,这样我需要做的就是调用宏。但我的尝试导
这个问题在这里已经有了答案: What can you do with Lisp macros that you can't do with first-class functions? (8 个回答
在 haxe 宏中,对于每个表达式,我们可以以 http://api.haxe.org/haxe/macro/Position.html 的形式获取它的位置。 : { file:String,
如果我评价 (def ^:macro my-defn1 #'defn) 定义了一个名为“my-defn1”的宏,我可以像使用“defn”一样使用它。 但是,如果我改为求值 (if true (de
我想知道这段代码输出背后的原因。我想不出答案。 #define f(a,b) a##b #define g(a) #a #define h(a) g(a) void main() { print
我正在尝试编写一个宏,该宏扩展为具有解构的 let 形式。我的问题是我想拥有以 let 形式定义的符号列表,包括通过解构获得的符号列表。 用例 我试图排除这种行为,例如验证: (let [a (foo
这段代码: macro FL(message) return @sprintf("%s:%d | %s", @__FILE__, @__LINE__, message) # line 2 en
此宏的目的是创建一个宏,该宏为访问关联列表的某个键提供名称。 (defmacro generate-accessor (key-symbol prefix) (let ((mac-name
在mcpp.exe --help Options available with only -@std (default) option: -@compat Expand recursive ma
鉴于: (define-syntax (test stx) (syntax-case stx () [(_ body ...) (with-syntax ([body0 (pro
Doug Hoyte 在他对 Let Over Lambda 的介绍中将 symb 函数定义为使用宏进行元编程的基本实用程序: 在剪辑中: (defun mkstr (&rest args) (w
我的代码需要两种模式,debug 和 verbose。我在头文件中将它们定义为, #define verbose TRUE #define debug TRUE 到目前为止,在我的代码中,我一直在使用
Set-macro-character 有一个名为 non-terminating-p 的可选参数。好像是用来表示读完宏字符后是否要读另一个字符,但是reader algorithm似乎忽略了这个论点
我一直在搜索,但几乎找不到关于 LibreOffice Basic 的信息 我有点习惯在 excel 中编写宏,但这次需要做一个循环,直到我到达第一个空列并且它需要在 libreoffice 中。 在
我正在尝试编写一个调用某些函数的宏。这些函数只能由宏使用,因此我将它们放在包装宏的 letfn 中。伪代码: (letfn [(fn-a [] ...) (fn-b [] ...)
我发现对于任何在 clojure.tools.macro 中编写类似 defn 的宏的人来说,这将是一个很棒的工具。图书馆:name-with-attributes功能。文档字符串说: To be u
假设: (defmacro testing (&optional var) `(list 'this 'is ,@(when (consp var) `('a 'list)))
在 SBCL 中,我可以使用以下内容获取函数的文档字符串: (documentation #'mapcar t) 但是,我不明白如何获取宏的文档字符串。例如,给定宏: (defmacro with-l
想了解 undef 和将宏定义为 0 之间的区别。谢谢。 最佳答案 #define MACRO 0 定义预处理器标记 MACRO成为文字 0 #undef MACRO 删除预处理器标记 MACRO 的
我是一名优秀的程序员,十分优秀!