emacs 中的 tikz 库 calc 和 auctex 预览失败

emacs 中的 tikz 库 calc 和 auctex 预览失败

emacs-variable preview-default-preamble 包含语句 \PreviewEnvironment{tikzpicture},因此 tikz 图片通过预览进行处理,通常可以正常工作。

但是如果我使用 calc 库,emacs 中的预览会失败。最小示例:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
  \draw ($(0,0) + (0,0)$) -- ($(1,1) + (1,1)$);
\end{tikzpicture}
\end{document}

在 emacs 中抛出以下错误

! Preview: Snippet 1 started.
<-><->

l.8 \begin{tikzpicture}

! Missing \endcsname inserted.
<to be read again> 
                   \pr@$ 
l.9 \draw ($(0,0)
                  + (0,0)$) -- ($(1,1) + (1,1)$);
! Missing number, treated as zero.
<to be read again> 
                   \pr@$ 
l.9 \draw ($(0,0)
                  + (0,0)$) -- ($(1,1) + (1,1)$);
! Illegal unit of measure (pt inserted).
<to be read again> 
                   \pr@$ 
l.9 \draw ($(0,0)
                  + (0,0)$) -- ($(1,1) + (1,1)$);

! Package PGF Math Error: Unknown operator `0' or `0@' (in '$(0').

See the PGF Math package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.9 \draw ($(0,0)
                  + (0,0)$) -- ($(1,1) + (1,1)$);
! Missing $ inserted.
<inserted text> 
                $
l.9 \draw ($(0,0)
                  + (0,0)$) -- ($(1,1) + (1,1)$);
! Missing \endcsname inserted.
<to be read again> 
                   \pr@$ 
l.9 \draw ($(0,0)
                  + (0,0)$) -- ($(1,1) + (1,1)$);
! Missing number, treated as zero.
<to be read again> 
                   \pr@$ 
l.9 \draw ($(0,0)
                  + (0,0)$) -- ($(1,1) + (1,1)$);
! Illegal unit of measure (pt inserted).
<to be read again> 
                   \pr@$ 
l.9 \draw ($(0,0)
                  + (0,0)$) -- ($(1,1) + (1,1)$);

! Package PGF Math Error: Unknown operator `0' or `0@' (in '$(0').

See the PGF Math package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.9 \draw ($(0,0)
                  + (0,0)$) -- ($(1,1) + (1,1)$);
! Missing $ inserted.
<inserted text> 
                $
l.9 \draw ($(0,0)
                  + (0,0)$) -- ($(1,1) + (1,1)$);

! Package tikz Error: Giving up on this path. Did you forget a semicolon?.

See the tikz package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.9 \draw ($(0,0) + (0,0)$
                          ) -- ($(1,1) + (1,1)$);
Preview: Tightpage -32891 -32891 32891 32891
! Preview: Snippet 1 ended.(26214+0x26214).
<-><->

l.10 \end{tikzpicture}

我的 emacs 版本是

GNU Emacs 24.3.1 (x86_64-apple-darwin13.0.0, Carbon Version 1.6.0 AppKit 1265)

任何关于解决该问题的提示都将受到赞赏。

答案1

我刚刚在 stackexchange 上找到了我的问题的答案:将 $ 重置为其原始 catcode 似乎有效(不要问我为什么:-)):

\documentclass{standalone}
\usepackage{tikz}
\usepackage{etoolbox}
\usetikzlibrary{calc}
\AtBeginEnvironment{tikzpicture}{\catcode`$=3 } % $
\begin{document}
\begin{tikzpicture}
\draw ($(0,0) + (0,0)$) -- ($(1,1) + (1,1)$);
\end{tikzpicture}
\end{document}

(我添加了注释 % $,这样 emacs 中的字体锁定就不会被破坏)

相关内容