1

I redefine the default macros for real and imaginary part according to

\let\Re\relax
\DeclareMathOperator{\Re}{Re}
\let\Im\relax
\DeclareMathOperator{\Im}{Im}

Besides the main document, I'd also like these changes to be applied to a bunch of external TikZ images which I include with the standalone package's \includestandalone. standalone is loaded with the options

\usepackage[subpreambles=true,mode=buildnew]{standalone}

On p. 23 of the package documentation, it says

group=true|false This option is set the ‘true’ by default and controlled whether or not a group is added around the content of standalone files. Normally (‘true’) the document environment of the sub-files is turned into an environment which does nothing, besides adding the usual group. If set to ‘false’ this environment made transparent, so that no group is added. Any definition inside the document body of sub-files will still be accessible after the \input macro. Note that this does not effects the \includestandalone macro which always will add a group.

How can I prevent \includestandalone from adding a group so that my custom \Re and \Im macros are passed on to my TikZ images?

Update

In response to Martin Scharrer's comment, I added an MWE. Note the redefinition of \Re and \Im as well as the macro \poles that appears inside the standalone file and replaces part of the TikZ image for this particular use of the file.

Main file

\documentclass{scrartcl}

\usepackage[subpreambles=true,mode=buildnew]{standalone}
\usepackage{mathtools}

\DeclareMathOperator{\Tr}{Tr}
\let\Re\relax
\DeclareMathOperator{\Re}{Re}
\let\Im\relax

\begin{document}

\ifdefined\poles\renewcommand{\poles}{
    \node (poles) at (3,1.5) {poles of $\smash{\frac{1}{-p_0^2 + x^2}}$};
    \draw[fill]
    (2,3) coordinate [circle,fill,inner sep=1pt,label=right:$p_1$] (p1)
    (-2,-3) coordinate [circle,fill,inner sep=1pt,label=below:$p_2$] (p2);
    \begin{scope}[on background layer]
        \draw[ultra thin,gray]
        (poles) -- (p1)
        (poles) -- (p2);
    \end{scope}
}\else\fi

\begin{figure}[htbp!]
    \centering
    \includestandalone{"Contour 1"}
    \caption{Counterclockwise path $C$ enclosing the imaginary frequency axis but excluding poles of $\frac{1}{-p_0^2 + x^2}$}
    \label{fig:contour 1}
\end{figure}

\end{document}

Standalone file (named "Contour 1.tex")

\documentclass[svgnames]{standalone}

\usepackage{tikz}
\usetikzlibrary{backgrounds,decorations.markings,positioning}

\providecommand{\poles}{
    \node (poles) at (3,1.5) {poles of $h(p_0)$};
    \draw[fill]
    (2.5,3) coordinate [circle,fill,inner sep=1pt,label=right:$p_1$] (p1)
    (2,-2) coordinate [circle,fill,inner sep=1pt,label=below:$p_2$] (p2)
    (-3,2) coordinate [circle,fill,inner sep=1pt,label=above:$p_3$] (p3)
    (-2.5,-2.5) coordinate [circle,fill,inner sep=1pt,label=above:$p_4$] (p4);
    \begin{scope}[on background layer]
        \draw[ultra thin,gray]
        (poles) -- (p1)
        (poles) -- (p2)
        (poles.west) -- (p3)
        (poles) -- (p4);
    \end{scope}
}

\begin{document}
\begin{tikzpicture}[thick]

    \def\xr{4}\def\yr{4}

    % Axes
    \draw [->] (-\xr-1,0) -- (\xr+1,0) node [above left]  {$\Re(p_0)$};
    \draw [->] (0,-\yr-0.7) -- (0,\yr+0.7) coordinate [below left = 0.3 and 0.1] (y-axis);
    \node (y-label) at ([xshift=-50]y-axis) {$\Im(p_0)$};
    \draw[ultra thin,gray] (y-axis) -- (y-label);

    % Matsubara frequencies
    \foreach \n in {-\yr,...,-1,1,2,...,\yr}{%
        \draw[fill] (0,\n) circle (1pt) node [right] {$i \omega_{_{\n}}$};}
    \draw[fill] (0,0) circle (1pt) node [above right] {0};

    % Contour line
    \draw[DarkBlue,decoration={markings,mark=between positions 0 and 1 step 0.28 with \arrow{>}},postaction={decorate}] (1,-\yr) -- (1,\yr) node [below right] {$C$} arc (0:180:1) (-1,\yr) -- (-1,-\yr) arc (180:360:1);

    % Poles
    \poles

\end{tikzpicture}
\end{document}
  • You make the redefinitions in the main file and want them to be still valid in the included files? If so, then the group does not changes the definition back, it just avoids that local changes INSIDE the included files are kept there. Maybe post a full, compilable MWE. – Martin Scharrer Sep 7 '17 at 10:09
  • @MartinScharrer Perhaps I misunderstood the documentation there. Please see my updated question for an MWE. – Casimir Sep 7 '17 at 10:53
  • @MartinScharrer A solution would still be very useful to me. The interesting thing is when I use \input instead of \includestandalone, the macros are passed along from the main to the external file. Any ideas why \includestandalone behaves differently and what I might do to change its behavior? – Casimir Oct 26 '17 at 12:58
  • The reason is that with mode=buildnew the subfile is compiled by its own and the resulting PDF is added as an image to the main file. Therefor no macros are passed from the main file. See my recent answer on a related question. – Martin Scharrer Nov 29 '17 at 19:02
  • Related question: tex.stackexchange.com/q/254863/2975 – Martin Scharrer Nov 29 '17 at 19:16
1

Well, \includestandalone is modeled after \includegraphics: Its either builds the given subfile (e.g. with package option mode=buildnew) with a second, internally LaTeX call and then includes the resulting PDF as an image using \includegraphics OR it includes the LaTeX code from the given file while assuming that code draws a diagram or other block content. The later is actually ALSO done using \includegraphics not \input (!) because standalone loads my other package gincltex which adds a .tex driver for \includegraphics. That 'driver' simple adds the TeX content as a box and - inside a group. This way all \includegraphics options like width or scale etc. can directly be applied on subfiles!

As I cannot remove the boxing or grouping in order to stay compatible with the intended feature set there is nothing I can do. Note that with mode=buildnew the code of the subfile is compiled separately anyway, so the main file never sees the code there!

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.