Ecuaciones, flechas y comentarios sobre la marcha en Beamer

Ecuaciones, flechas y comentarios sobre la marcha en Beamer

Me gusta la forma en que tikZ combinado con beamer puede resaltar ecuaciones (funciona bien con el modo artículo y artículo de beamer también) como enEjemplo de texto Utilizo esta función a menudo, pero creo que el código es difícil de manipular "sobre la marcha". Me gustaría crear una newcommand(?) \EqNComments(Ecuación y comentarios) que pueda llamar fácilmente en mi código.

    \EqNComments
    {$\Delta$}{=}{Le point Delta}
    {$\mathcal{N}(d_1)$}{+}{Hedge ratio}
    {$K.e^{-rt}.\mathcal{N}(d_2)$}{}{Strike actualised}

ingrese la descripción de la imagen aquí

Aquí está MWE que funciona muy bien con elementos de 3x3.

  1. Estoy atascado con la limitación de 9 en newcommandlos parámetros.
  2. Tengo problemas para ingresar un \foreachpara optimizar mi código
  3. Debe haber una forma más inteligente de procesar este asunto...

    \documentclass{beamer}
    %\documentclass[11pt,twoside]{article}
    %\usepackage[envcountsect]{beamerarticle}
    \usetheme{Warsaw}
    \usepackage{amsmath}
    \usepackage{amssymb}
    \usepackage{tikz}
    \usetikzlibrary{arrows,shapes}
    
    \tikzset{
        Col1/.style= {fill=blue!20,anchor=base,rounded corners=2pt},
        Col2/.style= {Col1, fill=red!20},
        Col3/.style= {Col1, fill=green!20},
    }
    
    \newcommand{\EqNComments}[9]
    {
    
    \tikzstyle{every picture}+=[remember picture]
    \tikzstyle{na} = [baseline=-.5ex]
    
    \begin{frame}
        \begin{equation}
                        \tikz[baseline] {\node[Col1] (d1) {#1};}  #2
                        \tikz[baseline] {\node[Col2] (d2) {#4};}  #5
                        \tikz[baseline] {\node[Col3] (d3) {#7};}  #8                    
    %                   \tikz[baseline] {\node[Col3] (d4) {#10};} #11                    
        \end{equation}
    
        \begin{itemize}
            \item #3 
            \tikz[na] \node[coordinate] (s1) {};
            \item #6 
            \tikz[na] \node[coordinate] (s2) {};        
            \item #9  
            \tikz[na] \node[coordinate] (s3) {};
    %       \item #12  
    %       \tikz[na] \node[coordinate] (s4) {};        
        \end{itemize}
    
        \begin{tikzpicture}[overlay]
            \path[->] (s1) edge [bend left]     (d1);
            \path[->] (s2) edge [bend right]    (d2);
            \path[->] (s3) edge [out=0, in=-90] (d3);
    %       \path[->] (s4) edge [out=0, in=-90] (d4);       
        \end{tikzpicture}
    \end{frame}
    } 
    
    \begin{document}
    
    \EqNComments
    {$\Delta$}{=}{Le point Delta}
    {$\mathcal{N}(d_1)$}{+}{Hedge ratio}
    {$K.e^{-rt}.\mathcal{N}(d_2)$}{-}{Strike actualised}
    %{dividendes}{.}{Not working here if I try to extend the command to 12 arguments}
    
    \end{document}
    

Respuesta1

Esto hace algo por el estilo. Utiliza la tikzmarkbiblioteca, que es una mejor herramienta porque, entre otras cosas, no destruye el espaciado y detecta el modo en el que estamos. Cualquier cantidad se puede anotar con

\tmn{<quantity>}{<annotation>}

Siempre que los coloque en un AnnotatedEquationentorno, la lista los anotará de manera similar a lo que está haciendo. Los nodos utilizarán los estilos Col1, Col2etc. en la medida en que estén definidos. Puede utilizar el argumento opcional para agregar algunas claves.

\documentclass{beamer} 
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\newcounter{mytn}
\makeatletter
\newcommand{\tmn}[3][]{\stepcounter{mytn}%
\tikzmarknode[Col\the\numexpr\value{mytn}-\mytn@start\relax/.try,inner xsep=2pt,%
minimum height=1.6em,#1]{mytn-\number\value{mytn}}{#2}%
\expandafter\gdef\csname tmn@annot@\number\value{mytn}\endcsname{#3}}
\newenvironment{AnnotatedEquation}{\edef\mytn@start{\number\value{mytn}}%
\begin{equation}}{\end{equation}%
\edef\mytn@end{\number\value{mytn}}%
\ifnum\mytn@end>\mytn@start
\begin{itemize}
 \foreach \X in {\the\numexpr\mytn@start+1,...,\mytn@end} 
 {\item \tikzmarknode{mytn-annot-\X}{\csname tmn@annot@\X\endcsname}%
 \begin{tikzpicture}[overlay,remember picture]
  \draw[-stealth] (mytn-annot-\X.east) to[out=0,in=-90] (mytn-\X.south);
 \end{tikzpicture}} 
\end{itemize}
\fi}
\makeatother
\tikzset{ Col1/.style= {fill=blue!20,anchor=base,rounded corners=2pt}, 
Col2/.style= {Col1, fill=red!20}, 
Col3/.style= {Col1, fill=green!20}, }
\begin{document}
\begin{frame}[t]
\frametitle{Some annotated equation}
\begin{AnnotatedEquation}
 \tmn{\Delta}{Le point Delta}= \tmn{\mathcal{N}(d_1)}{Hedge ratio}-
 \tmn{K\cdot \mathrm{e}^{-r\,t}\cdot\mathcal{N}(d_2)}{Strike actualised} 
\end{AnnotatedEquation}
\end{frame}
\begin{frame}[t]
\frametitle{Another annotated equation}
\begin{AnnotatedEquation}
 \tmn{\Delta}{Le point Delta}= \tmn{\mathcal{N}(d_1)}{Hedge ratio}-
 \tmn{K\cdot \mathrm{e}^{-r\,t}\cdot\mathcal{N}(d_2)}{Strike actualised} 
 +\tmn{\xi}{a Weyl spinor}
 +\tmn{\eta}{another Weyl spinor}
\end{AnnotatedEquation}
\end{frame}
\end{document}

ingrese la descripción de la imagen aquí

Aquí hay una versión que funciona con external.

\documentclass{beamer} 
\usepackage{tikz}
\usetikzlibrary{tikzmark,external}
\newcounter{mytn}
\makeatletter
\newcommand{\tmn}[3][]{\stepcounter{mytn}%
\tikzmarknode[Col\the\numexpr\value{mytn}-\mytn@start\relax/.try,inner xsep=2pt,%
minimum height=1.6em,#1]{mytn-\number\value{mytn}}{#2}%
\expandafter\gdef\csname tmn@annot@\number\value{mytn}\endcsname{#3}}
\newenvironment{AnnotatedEquation}{\edef\mytn@start{\number\value{mytn}}%
\tikzexternaldisable
\begin{equation}}{\end{equation}%
\edef\mytn@end{\number\value{mytn}}%
\ifnum\mytn@end>\mytn@start
\begin{itemize}
 \foreach \X in {\the\numexpr\mytn@start+1,...,\mytn@end} 
 {\item \tikzmarknode{mytn-annot-\X}{\csname tmn@annot@\X\endcsname}%
 \begin{tikzpicture}[overlay,remember picture]
  \draw[-stealth] (mytn-annot-\X.east) to[out=0,in=-90] (mytn-\X.south);
 \end{tikzpicture}} 
\end{itemize}
\fi\tikzexternalenable}
\makeatother
\tikzset{ Col1/.style= {fill=blue!20,anchor=base,rounded corners=2pt}, 
Col2/.style= {Col1, fill=red!20}, 
Col3/.style= {Col1, fill=green!20}, }
\begin{document}
\begin{frame}[t]
\frametitle{Some annotated equation}
\begin{AnnotatedEquation}
 \tmn{\Delta}{Le point Delta}= \tmn{\mathcal{N}(d_1)}{Hedge ratio}-
 \tmn{K\cdot \mathrm{e}^{-r\,t}\cdot\mathcal{N}(d_2)}{Strike actualised} 
\end{AnnotatedEquation}
\end{frame}
\begin{frame}[t]
\frametitle{Another annotated equation}
\begin{AnnotatedEquation}
 \tmn{\Delta}{Le point Delta}= \tmn{\mathcal{N}(d_1)}{Hedge ratio}-
 \tmn{K\cdot \mathrm{e}^{-r\,t}\cdot\mathcal{N}(d_2)}{Strike actualised} 
 +\tmn{\xi}{a Weyl spinor}
 +\tmn{\eta}{another Weyl spinor}
\end{AnnotatedEquation}
\end{frame}
\end{document}

APÉNDICE: Aquí hay una versión más complicada pero también más general que permite ajustar las flechas. Esto se puede hacer usando la special arrowclave. Por ejemplo,

\tmn[special arrow={out=90,annotations/out anchor=north}]{\Delta}{Le point Delta}= \tmn{\mathcal{N}(d_1)}{Hedge ratio}

Indica a la flecha que salga desde el norte del texto de la anotación y que salga en un ángulo de 90 grados. Los valores predeterminados son el ancla este y 0 grados. Esto es particularmente útil cuando se trata de numeradores de fracciones.

\documentclass{beamer} 
\usepackage{tikz}
\usetikzlibrary{tikzmark,external}
\newcounter{mytn}
\makeatletter
\newcommand{\tmn}[3][]{\stepcounter{mytn}%
\tikzmarknode[annotations/Col\the\numexpr\value{mytn}-\mytn@start\relax/.try,inner xsep=2pt,%
minimum height=1.6em,#1]{mytn-\number\value{mytn}}{#2}%
\expandafter\gdef\csname tmn@annot@\number\value{mytn}\endcsname{#3}}
\tikzset{special arrow/.code={%
\expandafter\xdef\csname tmn@arrow@style@\number\value{mytn}\endcsname{#1}}}
\newenvironment{AnnotatedEquation}{\edef\mytn@start{\number\value{mytn}}%
\tikzexternaldisable
\begin{equation}}{\end{equation}%
\edef\mytn@end{\number\value{mytn}}%
\ifnum\mytn@end>\mytn@start
\begin{itemize}
 \foreach \X in {\the\numexpr\mytn@start+1,...,\mytn@end} 
 {\item \tikzmarknode{mytn-annot-\X}{\csname tmn@annot@\X\endcsname}%
 \begin{tikzpicture}[overlay,remember picture]
  \ifcsname tmn@arrow@style@\X\noexpand\endcsname
   \draw[-stealth,out=0,in=-90,
    style/.expanded=\csname tmn@arrow@style@\X\noexpand\endcsname] 
    (mytn-annot-\X.\pgfkeysvalueof{/tikz/annotations/out anchor}) 
    to (mytn-\X.\pgfkeysvalueof{/tikz/annotations/in anchor});
  \else
   \draw[-stealth,out=0,in=-90] (mytn-annot-\X.\pgfkeysvalueof{/tikz/annotations/out anchor})
    to (mytn-\X.\pgfkeysvalueof{/tikz/annotations/in anchor});
  \fi
 \end{tikzpicture}} 
\end{itemize}
\fi\tikzexternalenable}
\makeatother
\tikzset{annotations/.cd, 
Col1/.style= {fill=blue!20,anchor=base,rounded corners=2pt}, 
Col2/.style= {annotations/Col1, fill=red!20}, 
Col3/.style= {annotations/Col1, fill=green!20}, 
in anchor/.initial=south,out anchor/.initial=east}
\begin{document}
\begin{frame}[t]
\frametitle{Some annotated equation}
\begin{AnnotatedEquation}
 \tmn{\Delta}{Le point Delta}= \tmn{\mathcal{N}(d_1)}{Hedge ratio}-
 \tmn{K\cdot \mathrm{e}^{-r\,t}\cdot\mathcal{N}(d_2)}{Strike actualised} 
\end{AnnotatedEquation}
\end{frame}
\begin{frame}[t]
\frametitle{Another annotated equation}
\begin{AnnotatedEquation}
 \tmn[special arrow={out=90,annotations/out anchor=north}]{\Delta}{Le point Delta}= \tmn{\mathcal{N}(d_1)}{Hedge ratio}-
 \tmn{K\cdot \mathrm{e}^{-r\,t}\cdot\mathcal{N}(d_2)}{Strike actualised} 
 +\frac{\tmn[special arrow={in=-160,annotations/in anchor=west}]{\xi}{a Weyl spinor}}{\tmn{\eta}{another Weyl spinor}}
\end{AnnotatedEquation}
\end{frame}
\end{document}

ingrese la descripción de la imagen aquí

Es posible realizar más mejoras, pero requieren la participación de los usuarios que realmente lo utilizan.

información relacionada