Beamer で方程式、矢印、コメントを外出先で表示

Beamer で方程式、矢印、コメントを外出先で表示

私は、tikZとbeamerを組み合わせて方程式を強調表示する方法が好きです(beamerarticleやarticleモードでもうまく機能します)。TeXの例この機能をよく使用しますが、コードを「外出先で」操作するのは難しいと思います。コード内で簡単に呼び出せるnewcommand(?) (方程式とコメント) を作成したいと思います。\EqNComments

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

ここに画像の説明を入力してください

こちらは 3x3 要素で非常にうまく機能する MWE です。

  1. newcommandパラメータの9の制限に悩まされています
  2. \foreachコードを最適化するために入力するのが難しい
  3. この問題を処理するにはもっと賢い方法があるはずだ...

    \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}
    

答え1

これはそのようなことを行います。tikzmarkライブラリを使用しますが、これはスペースを破壊せず、モードを検出できるため、より優れたツールです。任意の量を注釈で付けることができます。

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

これらを環境に配置するとAnnotatedEquation、実行しているのと同様にリストによって注釈が付けられます。ノードは、定義されている範囲でスタイルなどを使用しますCol1Col2オプションの引数を使用して、いくつかのキーを追加できます。

\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}

ここに画像の説明を入力してください

で動作するバージョンはこちらです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}

付録: これはより複雑だがより一般的なバージョンで、矢印を調整することができます。これはspecial arrowキーを使用して行うことができます。たとえば、

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

矢印が注釈テキストの北から出て、90 度の角度で出るよう指示します。デフォルトは東のアンカーと 0 度です。これは分数の分子を扱うときに特に役立ちます。

\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}

ここに画像の説明を入力してください

さらなる改善は可能ですが、実際にこれを使用しているユーザーからの意見が必要です。

関連情報