2

I'm trying to put a TikZ picture inside an equation, and then turn that into a standalone image using the "standalone" class. Representative but meaningless MWE below:

% This compiles but gives me an entire page
%\documentclass{article}
%\usepackage{tikz}

% This is what I want to do. \documentclass[tikz]{standalone}

\begin{document} \begin{equation} \begin{tikzpicture}[baseline=(current bounding box.center)] \draw (1,0) -- (0,0) -- (0,1); \end{tikzpicture} \enspace = \enspace \exp(5) \end{equation} \end{document}

However, this gives me a lot of errors related to missing $s or \endgroups in maths mode, e.g. Missing $ inserted. \end{tikzpicture}.

Can anyone help me fix these errors? This compiles perfectly fine in an article (I'm trying to extract a standalone image from an existing document I've written). Worst case I'll just screenshot my document but I'd like the vector graphics!

Jared
  • 23
  • 1
    Don't use equation in standalone. Use tikzpicture directly. Do you really need the equation number? – Sigur Jan 23 '23 at 16:51
  • It's not about the equation number, the figure I'm making is basically "tikz picture = maths = tikz picture". I was actually going to use equation* in the final version but forgot to do that in the MWE. – Jared Jan 23 '23 at 17:03
  • Do you actually need TikZ for this? There is for example \lefthalfcup from the MnSymbol package which produces such a symbol – samcarter_is_at_topanswers.xyz Jan 23 '23 at 17:16
  • You can also put the equation inside a minipage. I doubt varwidth will do anything to help; as equations fill the entire width. – John Kormylo Jan 23 '23 at 17:17
  • @samcarter_is_at_topanswers.xyz the two TikZ diagrams are much more complicated than this MWE. – Jared Jan 23 '23 at 17:29

1 Answers1

3

Variant with equation

Adaptations

Result

enter image description here

Code

\documentclass[preview]{standalone}
\usepackage{tikz}

\begin{document} \begin{equation} \begin{tikzpicture}[baseline=(current bounding box.center)] \draw (1,0) -- (0,0) -- (0,1); \end{tikzpicture} \enspace = \enspace \exp(5) \end{equation} \end{document}

Variant without equation

Result

enter image description here

Code

\documentclass{standalone}
\usepackage{tikz}

\begin{document} (\displaystyle \begin{tikzpicture}[baseline=(current bounding box.center)] \draw (1,0) -- (0,0) -- (0,1); \end{tikzpicture} \enspace = \enspace \exp(5) ) \end{document}

dexteritas
  • 9,161