1

I have the following latex document:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{angles}
\usetikzlibrary{calc}
\usetikzlibrary{quotes}
\begin{document}

\begin{tikzpicture}
\coordinate (o) at (0, 0);

\draw[thick, ->] (o) -- (3, 5.2) coordinate (b) node[left=2mm] {$b$};
\draw[thick, ->] (o) -- (7, 2) coordinate (a) node[right=1mm] {$a$};

\coordinate (p) at ($(0,0)!(b)!(a)$);
\draw[dashed] (p) -- (b);
\draw[thick, ->] (o) -- (p) node[below] {$p$};
\end{tikzpicture}

\end{document}

Running AUCTeX's preview-at-point in Emacs generates the following image:

generated picture with AUCTeX preview

The dashed line and the vector p are drawn incorrectly. Running lualatex example.tex the following pdf is created:

generated picture with lualatex

How can I generate a correct preview picture with AUCTeX preview?

Also: how can the font color be set to white for TikZ pictures?

Versions:

  • Emacs: 29.2
  • AUCTeX: 14.0.3

2 Answers 2

3

preview and tikz don't play well. I suggest you source out the tikzpicture into an external file, say standalone-test.tex and run pdflatex on it:

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{angles}
\usetikzlibrary{calc}
\usetikzlibrary{quotes}

\begin{document}

\begin{tikzpicture}
  \coordinate (o) at (0, 0);

  \draw[thick, ->] (o) -- (3, 5.2) coordinate (b) node[left=2mm] {$b$};
  \draw[thick, ->] (o) -- (7, 2) coordinate (a) node[right=1mm] {$a$};

  \coordinate (p) at ($(0,0)!(b)!(a)$);
  \draw[dashed] (p) -- (b);
  \draw[thick, ->] (o) -- (p) node[below] {$p$};
\end{tikzpicture}

\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:

and then include it back in your original file like this:

\documentclass{article}

\usepackage{graphicx}

\begin{document}

\noindent
\includegraphics[page=1]{standalone-test}

\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:

Running preview on the file above should look like this in Emacs: enter image description here

0

The preview package has an issue with TikZ calc syntax.

The TikZ picture is rendered correctly when I add this to the header:

\AtBeginEnvironment{tikzpicture}{\catcode`$=3 } % $

As mentioned here: https://lists.gnu.org/archive/html/bug-auctex/2020-05/msg00004.html

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .