% begriffHeck.sty - a LaTeX2e package for typesetting begriffsschrift

% Copyright (C) 2003 by Josh Parsons <josh@coombs.anu.edu.au>
% 
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
% 
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
% General Public License for more details.
% 
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111,
% USA.

% Changes made in October 2004 by Richard Heck <heck@fas.harvard.edu>
% Purpose of changes: To make the format of the formulae closer to how
% they are set in Frege's published works.
%
% Minor changes by Josh Parsons to fix problem with linespacing (May 2005)

%%% identification
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{begriff}

%%% initial code

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% thickness of lines
\newlength{\BGthickness}
\setlength{\BGthickness}{0.4pt}

% additional length after a quantifier, conditional, negation, or assertion
\newlength{\BGafterlen}
\setlength{\BGafterlen}{2pt}

% additional length before a quantifier, conditional, or negation
\newlength{\BGbeforelen}
\setlength{\BGbeforelen}{2pt}

% space inserted before a formula
\newlength{\BGspace}
\setlength{\BGspace}{3pt}

% total width of diagram
% Heck (10/2004): Due to changes below, this is the total width of the DIAGRAM
% and does not include the width of the terminal formulae. In previous versions,
% it did include them.
\newlength{\BGlinewidth}
\setlength{\BGlinewidth}{\linewidth}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%% options
%\DeclareOption{nothanks}{
%	\renewcommand{\mythanks}[1]{}
%	\let\@mythanks\relax
%}
\ProcessOptions

%%% package dependencies

%%% main code
\typeout{Begriffsschrift: 20 May 2005}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% variable-sized parenthesis
\newcommand{\BGbracket}[1]{%
\setbox0=\hbox{\ensuremath{#1}}%
\dimen0=\dp0%
\addtolength{\dimen0}{.5\baselineskip}%
\left(\vbox to \dp0 {\vskip.5\baselineskip\box0\vss}\right)%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% generate a terminal node with fill-line to the left
\newcommand{\BGterm}[1]{\unskip%
\setbox0=\hbox{%
\setlength{\BGlinewidth}{0pt}%
\vrule height \baselineskip depth 0pt width 0pt% strut
\vrule height \BGthickness width \BGafterlen depth 0pt%
\ensuremath{\hskip\BGspace #1}%
}%
% Heck (10/2004): Removed the following line, so that the terminal formulae will
% be left-aligned, as in Frege's published works.
%\addtolength{\BGlinewidth}{-\wd0}%
\vrule height \BGthickness width \BGlinewidth depth 0pt%
\box0%
\setlength{\BGlinewidth}{0pt}%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% box up some maths and subtract its width from linewidth
% Heck (10/2004): Because of the changes above, this should no longer be needed.
% It remains for compatibility with previous versions.
\newcommand{\BGstem}[1]{\unskip%
\setbox0=\hbox{%
\setlength{\BGlinewidth}{0pt}%
\ensuremath{\hskip\BGspace #1}%
}%
\addtolength{\BGlinewidth}{-\wd0}%
\box0%
\hskip\BGspace%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% generate a conditional \BGconditional{antecedent}{consequent}
\newcommand{\BGconditional}[2]{\unskip%
\addtolength{\BGlinewidth}{-\BGbeforelen}%
\setbox0=\hbox{%
\addtolength{\BGlinewidth}{-\BGafterlen}%
\vrule height \baselineskip depth 3pt width 0pt% strut
\vrule height \BGthickness width \BGafterlen depth 0pt%
\ensuremath{\hskip\BGspace #1}%
}%
\setbox1=\hbox{%
\addtolength{\BGlinewidth}{-\BGafterlen}%
\vrule height 0pt depth .3\baselineskip width 0pt% strut
\vrule height \BGthickness width \BGafterlen depth 0pt%
\ensuremath{\hskip\BGspace #2}%
}%
\dimen0=0pt%
\addtolength{\dimen0}{\dp1}%
\addtolength{\dimen0}{\ht0}%
\addtolength{\dimen0}{\lineskip}%
\hbox{%
\vrule width \BGbeforelen height \BGthickness depth 0pt%
\kern-\BGthickness%
\vrule width \BGthickness height \BGthickness depth \dimen0%
\vtop{\box1\box0}%
}%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% generate an assertion sign
\newcommand{\BGassert}[0]{%
\addtolength{\BGlinewidth}{-\BGafterlen}%
\addtolength{\BGlinewidth}{-\BGthickness}%
\vrule width \BGthickness height 5pt depth 5pt%
\vrule depth 0pt height \BGthickness width \BGafterlen%
\hskip \BGspace%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% generate a content stroke
\newcommand{\BGcontent}[0]{%
\addtolength{\BGlinewidth}{-\BGafterlen}%
\vrule depth 0pt height \BGthickness width \BGafterlen%
\hskip \BGspace%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% generate a negation
\newcommand{\BGnot}[0]{\unskip%
\addtolength{\BGlinewidth}{-\BGbeforelen}%
\addtolength{\BGlinewidth}{-\BGafterlen}%
\vrule width \BGbeforelen height \BGthickness depth 0pt%
\kern-\BGthickness%
\vrule width \BGthickness height \BGthickness depth 3pt%
\vrule depth 0pt height \BGthickness width \BGafterlen%
\hskip \BGspace%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% generate a universal quantifier
\newcommand{\BGquant}[1]{\unskip%
\addtolength{\BGlinewidth}{-\BGbeforelen}%
\addtolength{\BGlinewidth}{-8pt}%
\addtolength{\BGlinewidth}{-\BGafterlen}%
\hbox{%
\vrule width \BGbeforelen height \BGthickness depth 0pt%
\setlength{\unitlength}{1pt}%
\kern-\BGthickness%
\begin{picture}(8,0)(0,0)%
\linethickness{\BGthickness}%
\qbezier(0,0)(4,-4)(8,0)%
\end{picture}%
\kern-8pt%
% Heck (10/2004): Added "\mathfrak", since variables are always fraktur over quantifiers
\vbox{\hbox to 8pt {\hskip1pt\hskip\BGthickness\hss$_{\mathfrak{#1}}$\hss}\vskip1pt}%
\vrule width \BGafterlen height \BGthickness depth 0pt%
}%
\hskip\BGspace%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Heck (10/2004): Convenience functions
% Heck: What I'd like to do is add another (optional) argument to 
% \BGif, so that if it is p, the premise is treated as \BGterm;
% if it is c, the conculsion is; if it is d, both are. But this will
% do for now.
\newcommand{\BGif}[2]{\BGconditional{#1}{#2}}
% Treat premise as a terminal node
\newcommand{\BGifp}[2]{\BGconditional{\BGterm{#1}}{#2}}
% Treat conclusion as a terminal node
\newcommand{\BGifc}[2]{\BGconditional{#1}{\BGterm{#2}}}
% Treat both as terminal nodes
\newcommand{\BGifb}[2]{\BGconditional{\BGterm{#1}}{\BGterm{#2}}}
\newcommand{\BGneg}[0]{\BGnot}
\newcommand{\BGall}[1]{\BGquant{#1}}
