3

One thing I would really like to do (for the purposes of a thesis) is to embed equation references/tags inside images, so that I can reference the equations outside of the image.

To give you an idea, I would like to achieve something like the following:

enter image description here

However, I would like the equation numbers to be dynamic, that is, to change depending on the other equations in the document in which the graphic is embedded. I used GeoGebra to create this picture, but unfortunately I don't think this supports equation references (even though it is possible to export the picutre in TiKZ format, I think).

I have been told that it is much better practice for my thesis to create diagrams which summarise the equations being solved, but the downside of this is that the referencing is not necessarily straightforward. For example, I would like to be able to refer to the equations inside the graphic, rather than saying "Equation (1) from Figure XX".

Has anyone figured out a way to do this? If so, what strategy did you use?

7
  • You could could use minipages and place an image on the left had side and use latex to write the equations of the right hand side. Commented Dec 23, 2022 at 10:28
  • I understand - in the example shown above I gather this would be a sensible solution. But what about more generally (where the labels can be anywhere inside the graphic)?
    – OGBond
    Commented Dec 23, 2022 at 10:33
  • 1
    from Geogebra, it is possible to export to Tikz. The downside is that the generated code is quite static (doesn't use nodes as plotting variables). I can put references to equations inside the tikzpicture. they would update with your equations. Does this help?
    – anis
    Commented Dec 23, 2022 at 10:38
  • I don't know about GeoGebra but it is certainly possible to either use directly align or similar environments from amsmath in a node (though you will need to set a text width) or just use the equation counter directly. You will, of course, place \labels to later refer to them. Commented Dec 23, 2022 at 10:42
  • You can overprint an image using TikZ or package overpic and something like \refstepcounter{equation}(\theequation) to print the faked tag.
    – cabohah
    Commented Dec 23, 2022 at 10:43

2 Answers 2

3
  1. Export to tikz:

enter image description here

The resulting code is an absolute horror. But it does compile to what was displayed (there might be some edge cases).

\documentclass[10pt]{article}
\usepackage{pgf,tikz}
\usetikzlibrary{arrows}
\pagestyle{empty}
\begin{document}
\definecolor{zzttqq}{rgb}{0.6,0.2,0}
\definecolor{qqqqff}{rgb}{0,0,1}
\definecolor{cqcqcq}{rgb}{0.75,0.75,0.75}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
\draw [color=cqcqcq,dash pattern=on 1pt off 1pt, xstep=1.0cm,ystep=1.0cm] (0,-10) grid (10,0);
\draw[->,color=black] (0,0) -- (10,0);
\foreach \x in {,1,2,3,4,5,6,7,8,9}
\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) node[below] {\footnotesize $\x$};
\draw[->,color=black] (0,-10) -- (0,0);
\foreach \y in {-10,-9,-8,-7,-6,-5,-4,-3,-2,-1}
\draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt) node[left] {\footnotesize $\y$};
\draw[color=black] (0pt,-10pt) node[right] {\footnotesize $0$};
\clip(0,-10) rectangle (10,0);
\fill[line width=1.2pt,color=zzttqq,fill=zzttqq,fill opacity=0.1] (9.2,-2.18) -- (2.56,-2.12) -- (5.08,-5.16) -- cycle;
\draw [line width=1.2pt,color=zzttqq] (9.2,-2.18)-- (2.56,-2.12);
\draw [line width=1.2pt,color=zzttqq] (2.56,-2.12)-- (5.08,-5.16);
\draw [line width=1.2pt,color=zzttqq] (5.08,-5.16)-- (9.2,-2.18);
\begin{scriptsize}
\fill [color=qqqqff] (9.2,-2.18) circle (1.5pt);
\draw[color=qqqqff] (9.36,-1.92) node {$A$};
\fill [color=qqqqff] (2.56,-2.12) circle (1.5pt);
\draw[color=qqqqff] (2.72,-1.86) node {$B$};
\fill [color=qqqqff] (5.08,-5.16) circle (1.5pt);
\draw[color=qqqqff] (5.24,-4.9) node {$C$};
\draw[color=zzttqq] (7.4,-3.78) node {$b$};
\end{scriptsize}
\end{tikzpicture}
\end{document}
  1. add a node and the desired equation.
\documentclass[10pt]{article}
\usepackage{pgf,tikz}
\usetikzlibrary{arrows}
\pagestyle{empty}
\begin{document}
    
    \definecolor{zzttqq}{rgb}{0.6,0.2,0}
    \definecolor{qqqqff}{rgb}{0,0,1}
    \definecolor{cqcqcq}{rgb}{0.75,0.75,0.75}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
    \draw [color=cqcqcq,dash pattern=on 1pt off 1pt, xstep=1.0cm,ystep=1.0cm] (0,-10) grid (10,0);
    \draw[->,color=black] (0,0) -- (10,0);
    \foreach \x in {,1,2,3,4,5,6,7,8,9}
    \draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) node[below] {\footnotesize $\x$};
    \draw[->,color=black] (0,-10) -- (0,0);
    \foreach \y in {-10,-9,-8,-7,-6,-5,-4,-3,-2,-1}
    \draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt) node[left] {\footnotesize $\y$};
    \draw[color=black] (0pt,-10pt) node[right] {\footnotesize $0$};
    \clip(0,-10) rectangle (10,0);
    \fill[line width=1.2pt,color=zzttqq,fill=zzttqq,fill opacity=0.1] (9.2,-2.18) -- (2.56,-2.12) -- (5.08,-5.16) -- cycle;
    \draw [line width=1.2pt,color=zzttqq] (9.2,-2.18)-- (2.56,-2.12);
    \draw [line width=1.2pt,color=zzttqq] (2.56,-2.12)-- (5.08,-5.16);
    \draw [line width=1.2pt,color=zzttqq] (5.08,-5.16)-- (9.2,-2.18);
    \begin{scriptsize}
    \fill [color=qqqqff] (9.2,-2.18) circle (1.5pt);
    \draw[color=qqqqff] (9.36,-1.92) node {$A$};
    \fill [color=qqqqff] (2.56,-2.12) circle (1.5pt);
    \draw[color=qqqqff] (2.72,-1.86) node {$B$};
    \fill [color=qqqqff] (5.08,-5.16) circle (1.5pt);
    \draw[color=qqqqff] (5.24,-4.9) node {$C$};
    \draw[color=zzttqq] (7.4,-3.78) node {$b$};
    \end{scriptsize}
    
    % adding some reference to some equation
    \node at (8,-5){Applying equation \ref{eq-2}};
\end{tikzpicture}
    
    According to the right Pythagorean theorem:
\begin{equation}\label{eq-1}
    a^2 + b^2 = c^2
\end{equation}
    
According to the wrong Pythagorean theorem:
    \begin{equation}\label{eq-2}
    a + b = c
\end{equation}
\end{document}

Result:

result

EDIT:

Request: write the equation but don't display it, yet keep it referenced.

Answer: use the textpos package and wrap your equation in a textblock environment:

%\usepackage{textpos} <--- in the preambule
According to the wrong Pythagorean theorem:
\begin{textblock}{width}(X_offset, Y_offset)
\begin{equation}\label{eq-2}
    a + b = c
\end{equation}
\end{textblock}

You can use (X_offset, Y_offset) to "yeet" the equation out of the paper, for e.g. (10,10).

Result:

The equation can't be found in the pdf, but it is written in the LaTeX source.

enter image description here

10
  • Does this corresponds to what you wanted? @OGBond
    – anis
    Commented Dec 23, 2022 at 11:06
  • A better workflow should be to put directly placeholders inside GeoGebra via texts before the export to TikZ.
    – projetmbc
    Commented Dec 23, 2022 at 11:10
  • @anis Thank you so much - I will take a look and get back to you.
    – OGBond
    Commented Dec 23, 2022 at 11:13
  • it produces this \draw (9.22,-5.24) node[anchor=north west] {place holder text}; which isn't appealing to me tbh.
    – anis
    Commented Dec 23, 2022 at 11:14
  • @projetmbc I completely agree. However, I think GeoGebra would be reticent to adding this feature. I contacted them directly about LaTeX/TiKZ functionality and unfortunately it isn't currently being supported. I think this is probably because GeoGebra is primarily aimed at educators (who don't necessarily need to be able to use LaTeX) rather than academic mathematicians/scientists. That said, the code for GeoGebra is open-source, so somebody with more of a software development background could modify the code to include equation referencing - sadly I don't think I have time to do this...
    – OGBond
    Commented Dec 23, 2022 at 11:16
3

I am a bit confused about the other answer but going on

embed equation references/tags inside images, so that I can reference the equations outside of the image

Yes, this is possible but not that straight forward.

The numbered displaymath environments need a line width which is easily achieved in TikZ by setting a text width but you need to choose a sensible text width on your own. This will also place the equation number inside the node.

I've added a node with aligned in the example below where \tagoutside produces another column where the equation number is set left-aligned (as in your picture but not as with amsmath usually).

The \rlap and the measurements inside it make sure that the equation number is actually outside the node but this has the side effect that the equation numbers are also outside of the bounding box of the TikZ picture.

There probably is a more sophisticated solution with a tikzmark approach but for simple equations (and a simple rectangular node) this might be enough.

Code

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{shadows}
\makeatletter
\newcommand*\tagoutside[1]{
  &\kern-\alignsep@
    \rlap{% no math content → no mathrlap necessary
      \pgfmathsetlength\pgfutil@tempdima
        {\pgfkeysvalueof{/pgf/inner xsep}+(\pgfkeysvalueof{/pgf/outer xsep})}%
      \kern\pgfutil@tempdima
      \refstepcounter{equation}\label{#1}%
      \quad\tagform@\theequation
    }%
}
\makeatother

\begin{document}
Some formulas:
\begin{align}
    c^2 &= a^2 + b^2 \label{tri} \\
    E   &= mc^2      \label{albert}
\end{align}

Now a tikzpicture (inside a float):
\begin{figure}
\centering
\begin{tikzpicture}
\node[text width=3cm, draw, drop shadow, fill=white] {
  \vspace{-\topskip}
  \begin{align}
    c^2 &= a^2 + b^2 \label{tikz-tri} \\
    E   &= mc^2      \label{tikz-albert}
  \end{align}
};
\node[draw, drop shadow, fill=white] at (4,0) {$
  \begin{aligned}
    c^2 &= a^2 + b^2 \tagoutside{tikzed-tri} \\
    E   &= mc^2      \tagoutside{tikzed-albert}
  \end{aligned}$};
\end{tikzpicture}
\end{figure}

Now another set of formulas:
\begin{align}
    c^2 &= a^2 + b^2 \label{tri*} \\
    E   &= mc^2      \label{albert*}
\end{align}

Equations
\eqref{tri}        \eqref{albert}
\eqref{tikz-tri}   \eqref{tikz-albert}
\eqref{tikzed-tri} \eqref{tikzed-albert}
\eqref{tri*}       \eqref{albert*}
\end{document}

Output

enter image description here

1
  • I like this approach. I didn't know that align environment was allowed in tikz node
    – anis
    Commented Dec 23, 2022 at 12:04

You must log in to answer this question.

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