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

From: Arash Esbati <[email-masked]>
Date: Fri, 08 Mar 2024 10:41:20 +0100

Dylan Thurston <[email-masked]> writes:

> On Mon, May 11, 2020 at 09:53:50PM +0200, Arash Esbati wrote:
>> 
>> Thanks for the link.  I think we should add something to the manual of
>> preview.sty about the problem and the solution.  WDYT, would it make
>> sense?
>
> That would be great!

I finally managed to add an entry to preview-faq.texi (commit
ff03bccb38).

--8<---------------cut here---------------start------------->8---
diff --git a/doc/preview-faq.texi b/doc/preview-faq.texi
index 95d70f05..38044af6 100644
--- a/doc/preview-faq.texi
+++ b/doc/preview-faq.texi
@@ -78,8 +78,8 @@ Emacs.
 It is known to work under the X Window System for Linux and for several
 flavors of Unix: we have reports for HP and Solaris.

-There are several development versions of Emacs around for native MacOS
-Carbon, and @previewlatex{} is working with them, too.
+There are several versions of Emacs around for macOS, and @previewlatex{}
+is working with them, too.

 With Windows, both native Emacs and Cygwin Emacs should work.  However, it
 is known that @url{https://miktex.org/,MiK@TeX{}} sometimes doesn't work
@@ -210,6 +210,35 @@ facilities of @file{preview.sty} to tell it how to resolve this, whether
 you want no previews, previews of whole slides or previews of inner
 material.

+@subsection Does @previewlatex{} work with the TikZ package?
+
+@previewlatex{} doesn't have support for the @code{tikzpicture}
+environment built-in.  It can be included manually by adding the lines:
+@example
+\usepackage[displaymath,sections,graphics,floats,textmath]@{preview@}
+\PreviewEnvironment[@{[]@}]@{tikzpicture@}
+@end example
+
+@noindent
+to the document preamble.
+
+Things get more complicated when the code inside the @code{tikzpicture}
+environment contains @code{$ $} for inserting inline math and
+@previewlatex{} is instructed to insert previews for it into the buffer.
+In this case, you can disable previews for inline math by changing the
+lines above to:
+@example
+\usepackage[displaymath,sections,graphics,floats
+  % textmath   %% Don't preview inline math
+]@{preview@}
+\PreviewEnvironment[@{[]@}]@{tikzpicture@}
+@end example
+
+Another solution is to source out the TikZ pictures into an external file
+which uses the @code{standalone} class, process them and insert them back
+into the main file as figures with the @code{\includegraphics} macro.  In
+this case, previewing of inline math will work as usual.
+
 @node Troubleshooting, Other formats, Customization, Frequently Asked Questions
 @section Troubleshooting
--8<---------------cut here---------------end--------------->8---

> If you wanted to get really fancy, you could even do it automatically,
> if given some appropriate option when the environment is loaded. (Or
> maybe even always? Does it make sense to reset the meaning of '$' in
> other circumstances?)

I refrained from doing something like that since I can't tell about
possible side effects.

I'm therefore closing this report.

Best, Arash