2

I want to define newcomands to minimize the following code:

 \documentclass{beamer}
 \usepackage{mathtools,tikz,lmodern, xparse}
\usetikzlibrary{shapes.geometric, arrows, matrix, positioning,  shapes.callouts,shadows,shapes,chains, shapes.misc}
\tikzset{>=stealth}

\usepackage{amsmath} %For align environement
\usepackage{color}% to define the next colors
\definecolor{airforceblue}{rgb}{0.36, 0.54, 0.66}
\definecolor{alizarin}{rgb}{0.82, 0.1, 0.26}
\definecolor{white}{rgb}{1.0, 1.0, 1.0}
\definecolor{blue(munsell)}{rgb}{0.0, 0.5, 0.69}

\begin{document}


 \begin{frame}{Quantum corrections to gauge interactions}
 \begin{align*} 
 F(\Phi)= \only<1>{\begin{tikzpicture}[remember picture, note/.style={rounded rectangle, fill=blue}]\node[rounded rectangle, draw, fill=blue!20](Alpha){$\alpha$}; 
 \end{tikzpicture}}\only<2->{\alpha} X
 +\only<2>{\begin{tikzpicture}[remember picture, note/.style={rounded rectangle, fill=blue}]\node[rounded rectangle, draw, fill=blue!20](gPhi){$g(\Phi)$};
 \end{tikzpicture}}\only<1,3->{g(\Phi)}
\end{align*}
 \begin{tikzpicture}[remember picture, 
 note/.style={rectangle        callout,rounded corners, fill=blue}]
\only<1>{\node [note=blue!50, opacity=.5, overlay,
callout absolute pointer={(Alpha.south)}] at (4,-0.3) {CommentI};}
\only<2>{\node [note=blue!50, opacity=.5, overlay,
callout absolute pointer={(gPhi.south)}] at (7,-0.3) {CommentII};}
 \end{tikzpicture}

\end{frame} 

\end{document}

I tried :

  \documentclass{beamer}
  \usepackage{mathtools,tikz,lmodern, xparse}
  \usetikzlibrary{shapes.geometric, arrows, matrix, positioning, shapes.callouts,shadows,shapes,chains, shapes.misc}
 \tikzset{>=stealth}

\usepackage{amsmath} %For align environement
\usepackage{color}% to define the next colors
\definecolor{airforceblue}{rgb}{0.36, 0.54, 0.66}
\definecolor{alizarin}{rgb}{0.82, 0.1, 0.26}
\definecolor{white}{rgb}{1.0, 1.0, 1.0}
\definecolor{blue(munsell)}{rgb}{0.0, 0.5, 0.69}

\NewDocumentCommand{\rect}{ m m m m m}{\begin{tikzpicture}[remember picture, note/.style={rounded rectangle,rounded corners}]
\node[rounded rectangle, draw, fill=#1!#2](#3){#4};\end{tikzpicture}}

\newcommand{\mycallout}[9]{\begin{tikzpicture}[remember picture, note/.style={rectangle callout,rounded corners}]
\node [note=#3!#4, opacity=.5, overlay,
callout absolute pointer={(#5)}] at (#7,#8) {#9};
\end{tikzpicture}}

\begin{document}


 \begin{frame}{Quantum corrections to gauge interactions}
 \begin{align*} 
 F(\Phi)= \only<1>{\rect{blue}{20}{Alpha}{$\alpha$}}\only<2->{\alpha} X
 +\only<2>{\rect{blue}{20}{gPhi}{$g(\Phi)$}}\only<1,3->{g(\Phi)}
\end{align*}

\only<1>{\mycallout{blue}{50}{Alpha.south}{4}{0.3} {CommentI}}
\only<2>{\mycallout{blue}{50}{gPhi.south}{7}{-0.3} {CommentII}} 
\end{frame}     
\end{document}

But it gives me the error File ended while scanning use of \frame.. Another problem, which I want to fix, is the shift of $\alpha$ and ${g(\Phi)}$ due to the tikz box.

Mohamed Vall
  • 1,166
  • You have so many inconsistencies in your MWE, that is to me impossible figured out, what you like to achieve. To point out for some possible source of errors: (i) in the last line in frame is missed }, (ii) I guess, that there (and in line before) is missed \mycallout, but I'm not sure, (iii) why you need 9 parameters for \mycallout but use then only 6? etc – Zarko Jan 11 '16 at 16:05
  • @Zarko thank you for your comment. You're right I missed \mycallout and a }... – Mohamed Vall Jan 11 '16 at 16:18
  • Even with with correct of this, your second example doesn't work, to figured out, why not, I need first to understand your first example :-( – Zarko Jan 11 '16 at 16:23
  • In the first example I labeled some elements of an equation by adding comments as callouts. In the second code I wanted to use newcommands in order to minimize the code. – Mohamed Vall Jan 11 '16 at 16:27

1 Answers1

3

I managed to some hove fix and optimize your first example, see, if after this you still need new-commands defined in your second example:

    \documentclass{beamer}
        \usepackage{mathtools,tikz,lmodern, xparse}
    \usetikzlibrary{%arrows, chains, matrix, 
                    positioning, 
                    %shadows,
                    shapes, shapes.callouts,
                    %shapes.geometric,
                    %shapes.misc
                    }

    \tikzset{>=stealth,
             note/.style={rectangle callout, 
                          callout absolute pointer={#1},
                          rounded corners, draw, fill=blue!20,
                          %, fill opacity=.5  %<-- is this necessary?
                          }
             }

    \usepackage{amsmath} %For align environement
    %\definecolor{airforceblue}{rgb}{0.36, 0.54, 0.66}
    %\definecolor{alizarin}{rgb}{0.82, 0.1, 0.26}
    %\definecolor{white}{rgb}{1.0, 1.0, 1.0}
    %\definecolor{blue(munsell)}{rgb}{0.0, 0.5, 0.69}

\newcommand{\rect}[2]{%
        \tikz[remember picture,baseline=-0.5ex]
        \node[name=#1,rounded corners, draw, fill=blue!20] {#2};}

    \begin{document}
    \begin{frame}{Quantum corrections to gauge interactions}
        \begin{align*}
 F(\Phi)=   \only<1>{\rect{Alpha}{$\alpha$}}
            \only<2->{\alpha} X +
            \only<2>{\rect{gPhi}{$g(\Phi)$};}
            \only<3->{g(\Phi)}
        \end{align*}

        \begin{tikzpicture}[remember picture,overlay,
                            node distance=7mm and 1mm]
    \only<1>{\node [note=(Alpha.south),
                    below left= of Alpha] 
                    {Comment I};}
    \only<2>{\node [note=(gPhi.south),
                    below right= of gPhi] 
                    {Comment II};}
        \end{tikzpicture}
    \end{frame}
    \end{document}

Edit (1): I add newcommand for typing rect in equations.

Edit (2): newcommand for typing mycall for comments of equation:

\newcommand{\mycallout}[4]{%
    \tikz[remember picture,overlay,
          node distance=7mm and 1mm]{%
          \node [note=(#1.#2),
                below #3= of #1]
                {#4};}     }

And use in your case it as follows:

\only<1>{\mycallout{Alpha}{south}{left}{Comment I}}
\only<2>{\mycallout{gPhi}{south}{right}{Comment II}}

As I see, it doesn't make code shorter very much.

Zarko
  • 296,517
  • Thank you for your answer. It works very well and solve the shift problem, but I have a long equation so it would be good if you can define a new command to minimize it – Mohamed Vall Jan 11 '16 at 17:14
  • In comparison to your first example is my proposition significantly more concise :-), anyway see upgrade with new command for \rect, for callout I need more time. – Zarko Jan 11 '16 at 17:21
  • Yes, you are right :). – Mohamed Vall Jan 11 '16 at 17:30
  • @MedVall, now my answer is complete. I also add definition for mycallout. They will positioned on right place after second run of MWE. – Zarko Jan 11 '16 at 18:10
  • can you prevent \tikzset{>=stealth, every node/ from changing all the nodes in the document?. It changed my background images, page numerotation ,,, ! – Mohamed Vall Jan 11 '16 at 21:10
  • Yes, I will edit my answer. See, if this change work for you. – Zarko Jan 11 '16 at 21:18
  • when you remove every node the \rect does not work anymore, I tried in a vain to fix that :( – Mohamed Vall Jan 11 '16 at 23:39
  • Sorry, I put every node content into wrong place in rectmacro. Now I correct it and the same time erase not used color definitions. – Zarko Jan 12 '16 at 02:40