Skip to content

Commit

Permalink
Cleanup and minor edits.
Browse files Browse the repository at this point in the history
Mostly just documenting functions and fixing a few missing words in the
documentation.

Signed-off-by: JP-Ellis <[email protected]>
  • Loading branch information
JP-Ellis committed Dec 11, 2015
1 parent 4455401 commit 76bdf2a
Show file tree
Hide file tree
Showing 3 changed files with 184 additions and 110 deletions.
Binary file modified simpler-wick.pdf
Binary file not shown.
39 changes: 34 additions & 5 deletions simpler-wick.sty
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,19 @@
\RequirePackage{tikz}
\RequirePackage{pgfopts}
\usetikzlibrary{calc}
\usetikzlibrary{external}

\pgfkeys{
simplerwick/.is family,
simplerwick,
/simplerwick/.is family,
/simplerwick,
sep/.store in=\swick@sep,
sep=3pt,
offset/.store in=\swick@offset,
offset=1em}

\ProcessPgfOptions{/simplerwick}

% Works just like \@ifnextchar[, except for digits [1-9]
\def\swick@ifnextdigit#1#2{
\@ifnextchar 1{#1}{
\@ifnextchar 2{#1}{
Expand All @@ -47,8 +49,10 @@
\@ifnextchar 8{#1}{
\@ifnextchar 9{#1}{#2}}}}}}}}}}

% A count to keep track of how many contraction are currently open.
\countdef\swick@count=0

% Convert the digit to its representation as a word
\def\swick@translate#1{%
\ifcase#1\or
one\or
Expand All @@ -62,6 +66,7 @@
nine\fi
}

% Keeping track of which contraction is open or closed.
\newif\ifswick@if@one@
\newif\ifswick@if@two@
\newif\ifswick@if@three@
Expand All @@ -72,15 +77,24 @@
\newif\ifswick@if@eight@
\newif\ifswick@if@nine@

% Shortcut to the ith 'if' variable
\def\swick@settrue@#1{
\csname swick@if@\swick@translate{#1}@true\endcsname}
\def\swick@setfalse@#1{
\csname swick@if@\swick@translate{#1}@false\endcsname}

% Returns true or false based on whether the ith. Use as:
%
% \if\swick@cond@4
% <if true>
% \else
% <if false
% \fi
\def\swick@cond@#1{
TT\fi
\csname ifswick@if@\swick@translate{#1}@\endcsname}

% Check if *any* of the ifs is true.
\def\swick@cond@any#1#2{
\if\swick@cond@1{#1}\else
\if\swick@cond@2{#1}\else
Expand All @@ -94,6 +108,7 @@
{#2}
\fi\fi\fi\fi\fi\fi\fi\fi\fi}

% Set all ifs back to false.
\def\swick@cond@reset{
\swick@setfalse@1
\swick@setfalse@2
Expand All @@ -106,8 +121,13 @@
\swick@setfalse@9
}

% Do nothing
\def\swick@ignore#1{}

% Delegate to the appropriate subfunction based on the next char:
% - 0: do nothing
% - [1-9]: Open the given contraction
% - anything else: Open contraction 1
\def\swick@smart{
\@ifnextchar0{
\swick@ignore
Expand All @@ -118,14 +138,17 @@
\swick@smart@1
}}}

% Open or close the given contraction.
\def\swick@smart@#1#2{
\if\swick@cond@#1
\swick@end#1{#2}
\else
\swick@begin#1{#2}
\fi}

% Open a contraction
\def\swick@begin#1#2{
% swick@max keeps track of the tallest contraction yet.
\ifnum\swick@max<#1
\def\swick@max{#1}
\fi
Expand All @@ -143,13 +166,14 @@
\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]
\tikz[remember picture, overlay]
\draw ($(swick-open#1.north) + (0, 3pt)$)
-- ($(swick-open#1.base) + (0, \swick@offset) + #1*(0, \swick@sep)$)
-- ($(swick-close#1.base) + (0, \swick@offset) + #1*(0, \swick@sep)$)
-- ($(swick-close#1.north) + (0, 3pt)$);
\tikzexternalenable}

% Start the \wick environment, checking optional arguments if needed.
\def\wick{
\@ifnextchar[{
\wick@
Expand Down Expand Up @@ -177,12 +201,17 @@
\vbox to \dimen0{}
% Check that every has been closed
\swick@cond@any{
\PackageWarning{simpler-wick}{%
\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
}

Expand Down
Loading

0 comments on commit 76bdf2a

Please sign in to comment.