1

I'm using simpler-Wick package, and I would like to have up and down contractions in the same equation. In another questions @marmot gave me a solution for up and down contractions, but I would like to mix them.

Could anyone help me?

Thanks

  • 2
    I guess you will have much more success if you add a link and post what you have tried. –  Sep 21 '18 at 18:14

1 Answers1

2

Here is a simpleminded approach that allows you to mix positions and arrows. This goes now somewhat beyond minimal surgery but I think it is still controllable.

NOTE: In this version, there is no longer a below key. Instead, you will now be able to specify the positions using the positions key, which is a list of entries +1 (above) or -1 (below) that should be at least as long as the number of levels in the contraction. If this requirement is not met, there will be a warning, and the contraction will be drawn with the default values: above and without arrow.

I spent now some time in writing these modifications, but not much time in testing them. If you encounter a bug or a strange behavior, it would be really great if you could bring them to my attention.

Here is the code with examples:

\documentclass{article}
\usepackage{simpler-wick}
\usetikzlibrary{decorations.markings}
% from https://tex.stackexchange.com/a/39282/121799
\tikzset{W->-/.style={decoration={
  markings,
  mark=at position 0.5*\pgfdecoratedpathlength+2pt with
  {\draw[-latex] (-2pt,0pt) -- (1pt,0pt);}},postaction={decorate}},
  W-<-/.style={decoration={
  markings,
  mark=at position 0.5*\pgfdecoratedpathlength with
  {\draw[latex-] (-2pt,0pt) -- (1pt,0pt);}},postaction={decorate}}
  }
\pgfkeys{
  /simplerwick/.cd,
  arrows/.store in=\LstWickArrows,
  arrows/.initial={-,-,-,-,-,-,-,-,-}, % the # of contractions is bounded by 9
  arrows={-,-,-,-,-,-,-,-,-},
  positions/.store in=\LstWickPositions,
  positions={+1,+1,+1,+1,+1,+1,+1,+1,+1},
  positions/.initial={+1,+1,+1,+1,+1,+1,+1,+1,+1},
}

\makeatletter
\newcounter{Wick@up}
\newcounter{Wick@down}
\def\swick@end#1#2{
  \swick@setfalse@#1
  \tikzexternaldisable
  \begin{tikzpicture}[remember picture, baseline=(swick-close#1.base)]
    \node[use as bounding box, inner sep=0pt, outer sep=0pt] (swick-close#1) {$\displaystyle #2$};
  \end{tikzpicture}
  \tikz[remember picture, overlay]
{
\xdef\myW@style{\empty}
\foreach \W@X[count=\W@C] in \LstWickArrows
{\ifnum\W@C=#1
\xdef\myW@style{\W@X}
\fi}
\ifx\myW@style\empty
\PackageWarning{simpler-wick}{%
The list arrows has not enough entries!%
}{}
\xdef\myW@style{-}
\fi
\xdef\myW@pos{-77}
\foreach \W@X[count=\W@C] in \LstWickPositions
{\ifnum\W@C=#1
\xdef\myW@pos{\W@X}
\fi}
\ifnum\myW@pos=-77
\PackageWarning{simpler-wick}{%
The list positions has not enough entries!%
}{}
\xdef\myW@pos{+1}
\fi
\ifnum\myW@pos=-1
    \draw[\myW@style] ($(swick-open#1.south) + (0, -3pt)$) 
          -- ($(swick-open#1.base) + (0, -\swick@offset) + \theWick@down*(0, -\swick@sep)$) 
          -- ($(swick-close#1.base) + (0, -\swick@offset) + \theWick@down*(0, -\swick@sep)$) 
          -- ($(swick-close#1.south) + (0, -3pt)$);
\stepcounter{Wick@down}
\else
\stepcounter{Wick@up}
    \draw[\myW@style] ($(swick-open#1.north) + (0, 3pt)$) 
          -- ($(swick-open#1.base) + (0, \swick@offset) + \theWick@up*(0, \swick@sep)$) 
          -- ($(swick-close#1.base) + (0, \swick@offset) + \theWick@up*(0, \swick@sep)$) 
          -- ($(swick-close#1.north) + (0, 3pt)$);
\fi}
  \tikzexternalenable}
\def\wick@[#1]#2{\setcounter{Wick@up}{0}
\setcounter{Wick@down}{-1}
  \ifmmode
    \begingroup
    \pgfkeys{
        simplerwick,
        #1}
    % Define the variables and commands
    \swick@cond@reset
    \swick@count=0
    \def\swick@max{0}
    \def\c{\swick@smart}
    % Here is the text
    #2
    % Add a vbox equal to max height
    \dimen0=\swick@sep
    \multiply\dimen0 by \swick@max
    \advance\dimen0 by \swick@offset
    \vbox to \dimen0{}
    % Check that every has been closed
    \swick@cond@any{
      \PackageWarning{simpler-wick}{%
        I have reached the end of \protect\wick\space with some unclosed
        contractions%
      }{}
    }{}
    \endgroup
  \else
    \PackageWarning{simpler-wick}{%
      \protect\wich\space has been called outside a math environment, this will
      be ignore%
    }
  \fi
}

\makeatother
\begin{document}
\paragraph{Note}: The lists \verb|positions| and \verb|arrows| need to have at
least as many entries as levels are involved in the contraction.
\begin{enumerate}
\item You can specify single arrows like \texttt{W->-} or \texttt{W-<-}: $\displaystyle
  \wick[arrows={-,W->-,W-<-}]{
    \c1 a \c2 b \c3 c \c1 a d \c1 e
    \c1 e \c1 a \c2 b \c3 c \c1 a
  }
$
\item The default is not to draw arrows: $\displaystyle
  \wick{
    \c1 a \c2 b \c3 c \c1 a d \c1 e
    \c1 e \c1 a \c2 b \c3 c \c1 a
  }
$
\item You can selectatively have the contrations above or below: $\displaystyle
  \wick[positions={-1,1,-1}]{
    \c1 a \c2 b \c3 c \c1 a d \c1 e
    \c1 e \c1 a \c2 b \c3 c \c1 a
  }
$\bigskip
\item And you can combine this with arrows
equation: $\displaystyle
  \wick[arrows={-,W->-,W-<-},positions={-1,1,-1}]{
    \c1 a \c2 b \c3 c \c1 a d \c1 e
    \c1 e \c1 a \c2 b \c3 c \c1 a
  }$
\item Another example: $\displaystyle
  \wick[arrows={W->-,W-<-,-},positions={1,-1,1}]{
    \c1 a \c2 b \c3 c \c1 a d \c1 e
    \c1 e \c1 a \c2 b \c3 c \c1 a
  }$\bigskip
\item An example with a too short \verb|arrows| lists: $\displaystyle
  \wick[arrows={W->-,W-<-},positions={1,-1,1}]{
    \c1 a \c2 b \c3 c \c1 a d \c1 e
    \c1 e \c1 a \c2 b \c3 c \c1 a
  }$\bigskip  
\item An example with a too short \verb|positions| lists: $\displaystyle
  \wick[arrows={W->-,W-<-,-},positions={1,-1}]{
    \c1 a \c2 b \c3 c \c1 a d \c1 e
    \c1 e \c1 a \c2 b \c3 c \c1 a
  }$\bigskip  
\end{enumerate}
In all these examples, the appearance of \verb|\c3| implies that the lists have
to have at least 3 entries. In the last two examples, the lists are too short
and the elements have been replaced by their defaults and warnings were issued.
\end{document}

enter image description here

Finally, let me mention that if one of the contributors of simpler-wick feel that I am overdoing it here, I will be happy to remove this at any time. If they feel they want to merge some of this in their great package, please go ahead, I'd feel honored (and am not asking for credit or anything of that sort).