Subject: Re: bug#41089: 11.91; preview-latex gets confused by tikz calc syntax

From: Arash Esbati <[email-masked]>
Date: Tue, 05 May 2020 20:39:09 +0200

Hi Dylan,

Dylan Thurston <[email-masked]> writes:

> preview-latex appears to get confused by tikz calc syntax, which
> includes a dollar sign. Here is a minimal file:
> ------------------------------------------------------------
> \documentclass{article}
> \usepackage{tikz}
> \usetikzlibrary{calc}
>
> \begin{document}
>   \[
>   \begin{tikzpicture}[x=1.5cm]
>     \node (S1) at (0,1) {$S_1$};
>     \node (D1) at (1,1) {$D_1 \setminus V_1$};
>     \node (V1) at (2,1) {$V_1$};
>     \node at ($(S1.east)!0.5!(D1.west)$) {$\sqcup$};
>     \node at ($(D1.east)!0.5!(V1.west)$) {$\sqcup$};
>   \end{tikzpicture}
>   \]
> \end{document}
>
> %%% Local Variables:
> %%% mode: latex
> %%% TeX-master: t
> %%% End:
> ------------------------------------------------------------

Your example works for me if I give preview-latex 2 hints:

1)  Don't touch $ in order to keep tikz happy
2)  Tell preview-latex that it should render tikzpicture environment.

Then your document would look like this:

--8<---------------cut here---------------start------------->8---
\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{calc}

\usepackage[displaymath,floats,graphics,footnotes,
% textmath  %% Don't touch $ %%
]{preview}
\PreviewEnvironment[{[]}]{tikzpicture}

\begin{document}

Text
\[
  \begin{tikzpicture}[x=1.5cm]
    \node (S1) at (0,1) {$S_1$};
    \node (D1) at (1,1) {$D_1 \setminus V_1$};
    \node (V1) at (2,1) {$V_1$};
    \node at ($(S1.east)!0.5!(D1.west)$) {$\sqcup$};
    \node at ($(D1.east)!0.5!(V1.west)$) {$\sqcup$};
  \end{tikzpicture}
\]

Text
\begin{tikzpicture}[x=1.5cm]
  \node (S1) at (0,1) {$S_1$};
  \node (D1) at (1,1) {$D_1 \setminus V_1$};
  \node (V1) at (2,1) {$V_1$};
  \node at ($(S1.east)!0.5!(D1.west)$) {$\sqcup$};
  \node at ($(D1.east)!0.5!(V1.west)$) {$\sqcup$};
\end{tikzpicture}
Text

\end{document}
--8<---------------cut here---------------end--------------->8---

where preview-latex in Emacs looks like this:

Reg. the `textmath' option, this is the description from the manual:

    `textmath' will make all text math subject to previews.  Since math
      mode is used throughly inside of LaTeX even for other purposes,
      this works by redefining \(, \) and $ and the `math' environment
      (apparently some people use that).  Only occurences of these text
      math delimiters in later loaded packages and in the main document
      will thus be affected.

Best, Arash