Code: Select all
% File myDrawing.tex
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\usetikzlibrary{math} %needed tikz library
\tikzmath{\x1 = 1; \y1 =1; \x2 = \x1 + 1; \y2 =\y1 +3; }
% Using the variables for drawing
\begin{tikzpicture}
\draw[very thick, -stealth] (\x1, \y1)--(\x2, \y2);
\end{tikzpicture}
\end{document}
Code: Select all
\documentclass{article}
\begin{document}
Lorem ipsum, and this is a figure:
\begin{figure}
\input{myDrawing.tikz}
\caption{Caption to My drawing}
\end{figure}
\end{document}
But notice that this tikz picture has a call for a tikzlibrary (math) and also defines some coordinates.
What is the correct way to create a tikz file to be included in a document (article, book, beamer) that also has lines of code outside the tikzpicture environment?