Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

The emacs-variable preview-default-preamble contains the statement \PreviewEnvironment{tikzpicture} so tikz pictures are processed by preview, which usually works fine.

But preview in emacs fails if I use the calc library. Minimum example:

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

throws the following error in 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}

My emacs-version is

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

Any hints for solving this issue are appreciated.

share|improve this question
add comment

1 Answer

I just found the answer to my question here on stackexchange: resetting the $ to its original catcode seems to work (do not ask me why :-) ):

\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}

(I added the comment % $, so that font-locking will not be screwed in emacs)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.