I'm writing a document where there are some equations which I'm commenting with hf-tikz package. It needs two LaTeX compilations in order to get the right coordinates and to draw everything in the right place. Looking at How to make a standalone document with one equation? I've been able to build a standalone file with my equation. But I don't know what's the best way to include it in a main document.

Besides, I wonder if it's even possible to keep fonts and sizes, so the inserted equation looks like the main document. Or is the standalone equation always included as an image?

Here is an example of one of my standalone equations:



 4x^2 + 12x + 9 & = \tikzmarkin{a1}(0.05,-0.2)(-0.05,0.4)(2x)^2 \tikzmarkend{a1} + 2\cdot \tikzmarkin{a2}(0.05,-0.2)(-0.05,0.4)(2x)\tikzmarkend{a2} \cdot \tikzmarkin{a3}(0.05,-0.2)(-0.05,0.4)3\tikzmarkend{a3} + \tikzmarkin{a4}(0.05,-0.2)(-0.05,0.4)3^2\tikzmarkend{a4} \\[6ex]
 & = (\,\, \tikzmarkin{a9}2x \tikzmarkend{a9}+ \tikzmarkin{a10} 3\tikzmarkend{a10} \,\,)^2

\begin{tikzpicture}[remember picture,overlay]% adjust the shift from "col" to move the position of the annotation
\coordinate (a5) at ($(a1)+(0.5,0.6)$);
\node[align=left,above] at (a5) {\large$a^2$};
\path[-stealth,red,draw] (a5) -- ($(a1)+(0.5,0)$);

\coordinate (a6) at ($(a2)+(0.4,0.6)$);
\node[align=left,above] at (a6) {\large$a$};
\path[-stealth,red,draw] (a6) -- ($(a2)+(0.4,0)$);

\coordinate (a7) at ($(a3)+(0.15,0.6)$);
\node[align=left,above] at (a7) {\large$b$};
\path[-stealth,red,draw] (a7) -- ($(a3)+(0.15,0)$);

\coordinate (a8) at ($(a4)+(0.2,0.6)$);
\node[align=left,above] at (a8) {\large$b^2$};
\path[-stealth,red,draw] (a8) -- ($(a4)+(0.2,0)$);

\coordinate (a11) at ($(a9)+(0.3,0.3)$);
\node[align=left,above] at (a11) {\large$a$};
\path[-stealth,red,draw] (a11) -- ($(a9)+(0.3,0)$);

\coordinate (a12) at ($(a10)+(0.2,0.3)$);
\node[align=left,above] at (a12) {\large$b$};
\path[-stealth,red,draw] (a12) -- ($(a10)+(0.2,0)$);


UPDATE TO CLARIFY I don't want the standalone file to be included as raw tex, since it's possible I reuse some of the coordinates names in other equations. The following doesn't work, as I'm not loading the required packages in the main preamble.

  • 1
    You can use \includestandalone – user11232 Nov 17 '14 at 9:43
  • Sorry but I don't really understand what you want. If you want the code from the file to use the settings from your main document, then it has to be read as 'raw tex' in order to be compiled with those settings, doesn't it? What is the middle ground you seek between reading the code and including an image? – cfr Nov 18 '14 at 1:05
  • @cfr I just want to know what people do when dealing with a lot (say 50-100) of equations, each one commented with some kind of overlay tikz code. If I use \input or similar to insert the raw text, I have to be careful to not repeat coordinate names, and always have to run LaTeX two times to ge the right result. On the other way, if I insert this equations as images...in order to keep font formatting from the main document, some kind of preamble should be shared, doesn't it? What is the best option to manage this? – Pablo B. Nov 18 '14 at 7:53

The standalone package allows for automated importing the preambles of the sub-files to the main document using the subpreambles option. However, if you have multiple sub-files with clashing preambles you will run into problems.

If you want to have a common preamble in the main document and all sub-files (or just all sub-files) then just place the common preamble code into a separate .tex file and \input this one in all files in the preamble.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.