% \title{Linear Logic symbols for Computer Modern}
% \author{Emmanuel Beffara}
% \date{April 20, 2010}
%
% \maketitle
%
% \section{Documentation}
%
% \subsection{Installation}
%
% The installation consists in copying the |.mf| files from the |mf|
% subdirectory somewhere in Metafont's search path and the |.sty| and |.fd|
% files from the |latex| subdirectory somewhere in \LaTeX's search path.
%
% Call |TEXMF| the base directory of your installation (on Unix this should be
% something like |/usr/share/texmf| or |~/texmf| for a single user
% installation). Then copy the directories as follows:
% \begin{itemize}
%   \item copy |mf| as |TEXMF/fonts/source/public/cmll|
%   \item copy |latex| as |TEXMF/tex/latex/cmll|
% \end{itemize}
% If you want to install the fonts in Type1 format:
% \begin{itemize}
%   \item copy |type1| as |TEXMF/fonts/type1/public/cmll|
%   \item copy |tfm| as |TEXMF/fonts/tfm/public/cmll|
%   \item copy |cmll.map| as |TEXMF/fonts/map/dvips/misc/cmll.map|
% \end{itemize}
% You may have to update \TeX's databases by running |texhash| or |mktexlsr|
% (this is for Kpathsea-based distributions like te\TeX) or a similar command.
% You may also have to register the map file for the Type1 fonts using
% |updmap|, depending on your installation.
% Linux users using Debian or Ubuntu can avoid all this by using the package
% at |http://iml.univ-mrs.fr/~beffara/soft/| (updated more often than TexLive).
%
% \subsection{Package loading}
%
% The package is loaded by simply saying |\usepackage{cmll}|. The variant of
% the font that should be used is chosen using the following package options:
% \begin{quote}
%   \begin{tabular}{>{\ttfamily}ll}
%     cm & Computer Modern serif \\
%     ss & Computer Modern sans serif \\
%     euler & AMS Euler \\
%     emu & emulation mode (see section~\ref{selection}) \\
%     auto & automatic selection among the above
%       (default, see section~\ref{selection})
%   \end{tabular}
% \end{quote}
%
% \subsection{Symbols}
%
% The \texttt{cmll} font defines a handful of symbols useful in linear logic
% that were not defined in other fonts and packages.
% \begin{symbols}{Unary operators:}
% \dosymbol\oc
% \dosymbol\wn
% \dosymbol\shpos
% \dosymbol\shneg
% \dosymbol\shift
% \end{symbols}
% \begin{symbols}{Binary operators:}
% \dosymbol\parr
% \dosymbol\invamp
% \dosymbol\with
% \end{symbols}
% \begin{symbols}{Large operators:}
% \dosymbol\bigparr
% \dosymbol\biginvamp
% \dosymbol\bigwith
% \end{symbols}
% \begin{symbols}{Binary relations:}
% \dosymbol\coh
% \dosymbol\scoh
% \dosymbol\incoh
% \dosymbol\sincoh
% \dosymbol\Perp
% \dosymbol\simperp
% \dosymbol\multimapinv
% \dosymbol\multimapboth
% \dosymbol\nmultimap
% \dosymbol\nmultimapinv
% \dosymbol\nmultimapboth
% \end{symbols}
% \begin{symbols}{Letter-like symbols:}
% \dosymbol\Bot
% \dosymbol\simbot
% \end{symbols}
% The symbols $\oc$, $\wn$ and $\with$ are actually characters from the
% standard Computer Modern fonts declared with a new math code to get proper
% spacing. See the following examples:
% \[\begin{tabular}{ll@{\hspace{4em}}ll}
%   \verb/A \& B/ & $A \& B$ & \verb/A \with B/ & $A \with B$ \\
%   \verb/A = !B/ & $A = !B$ & \verb/A = \oc B/ & $A = \oc B$ \\
%   \verb/A = ?B/ & $A = ?B$ & \verb/A = \wn B/ & $A = \wn B$
% \end{tabular}\]
% The names |\parr| and |\invamp| are synonyms, the names |\bigparr| and
% |\biginvamp| too. The macros |\biginvampemu| and |\bigwithemu| provide
% emulations for the |\biginvamp| and |\bigwith| symbols, built using the
% normal symbols at different sizes (using the |relsize| package). In
% emulation mode (i.e. with the package option |emu|) the names |\biginvamp|
% and |\bigwith| are synonyms for them.
%
% \subsection{Emulation and automatic selection}
% \label{selection}
%
% If you use a math font family other than Computer Modern or Euler, you may
% have an ampersand symbol that does not match the reversed ampersand from any
% variant of CMLL. In this case, the |cmll| package provides a ``poor man''
% version of the reversed ampersand and large ampersands, built using the
% standard |\&| symbol.
% Also provided are the ``big'' variants of |\with| and |\invamp| built using
% the normal version at a different size (using the |relsize| package).
% These versions can be used explicitly under the names |\invampemu|,
% |\bigwithemu| and |\biginvampemu|.
%
% In the emulation mode, that is when the package is loaded with the |emu|
% option, these variants are used instead of the symbols provided by the
% font.
% Moreover, in emulation mode, any symbol that already exists is preserved by
% |cmll|, otherwise all symbols are redefined.
% This is useful for instance with |txfonts|, which already provides |\invamp|
% and |\multimapboth|.
% Note that this feature works only if the package |cmll| is loaded
% \emph{after} loading any package that might define one of the symbols
% provided by CMLL.
%
% The automatic selection works as follows:
% \begin{itemize}
% \item if |euler| is loaded, use the Euler variant,
% \item if |txfonts| or |pxfonts| is loaded, use the emulation mode,
% \item if the default font is |cmss|, use the |ss| variant,
% \item otherwise use the |cm| variant.
% \end{itemize}
%
% \subsection{History}
%
% \begin{description}
% \item [2010-04-20]
%   New symbols: |\multimapinv|, |\nmultimap|, |\nmultimapinv|,
%   |\nmultimapboth|.
% \item [2009-01-23]
%   New symbols: |\multimapboth|, |\Perp|, |\Bot|, |\simperp|, |\simbot|.
%   Synonyms |\invamp| and |\biginvamp| added for compatibility.
%   New package option |emu|.
%   Various fixes and code improvements.
% \item [2006-02-22]
%   First public release.
% \end{description}
%
%
% \section{Files}
%
% \subsection{This document}
%
%    \begin{macrocode}
%<*driver>
\documentclass{ltxdoc}
\usepackage{array,cmll}
\newenvironment{symbols}[1]{%
  \par%
  \def\dosymbol##1{\leavevmode\hbox to .5\textwidth{%
    \kern.25\textwidth \hbox to 2em{\hss$##1$\hfil}%
    \texttt{\string##1}\hss}\penalty10}%
  \flushleft%
  #1\strut\\}{\endflushleft}
\begin{document}
\DocInput{cmll.dtx}
\end{document}
%</driver>
%    \end{macrocode}
%
% \subsection{Font definitions}
%
% The font definition file is deduced from the ones for Computer Modern. We
% provide an NFSS entry named \texttt{cmllr} in medium and bold extended
% versions.
%
%    \begin{macrocode}
%<*ucmllr>
\DeclareFontShape{U}{cmllr}{m}{n}{%
      <5><6><7><8><9>gen*cmllr%
      <10><10.95>cmllr10%
      <12><14.4>cmllr12%
      <17.28->cmllr17%
      }{}
\DeclareFontShape{U}{cmllr}{bx}{n}{%
      <5><6><7><8><9>gen*cmllbx%
      <10><10.95>cmllbx10%
      <12->cmllbx12%
      }{}
%</ucmllr>
%    \end{macrocode}
%
% The following is a definition for the sans-serif version, named
% \texttt{cmllss}.
%
%    \begin{macrocode}
%<*ucmllss>
\DeclareFontShape{U}{cmllss}{m}{n}{%
      <-8>cmllss8%
      <9>cmllss9%
      <10>cmllss10
      <12><14.4>cmllss12%
      <17.28->cmllss17%
      }{}
\DeclareFontShape{U}{cmllss}{bx}{n}{%
      <->cmllssbx10}{}
%</ucmllss>
%    \end{macrocode}
%
% The following is a definition for the Euler-style version, named
% \texttt{eull}.
%
%    \begin{macrocode}
%<*ueull>
\DeclareFontShape{U}{eull}{m}{n}{%
      <5><6><7><8><9>gen*eullr%
      <10->eullr10}{}
\DeclareFontShape{U}{eull}{bx}{n}{%
      <5><6><7><8><9>gen*eullbx%
      <10->eullbx10}{}
%</ueull>
%    \end{macrocode}
%
% \subsection{The package}
%
%    \begin{macrocode}
%<*package>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{cmll}[2010/04/20 Linear Logic symbols for Computer Modern]
%    \end{macrocode}
%
% With the package option |emu|, symbols already defined are used and
% |\invamp| (if undefined) is made by rotation using an ampersand. This
% requires the |graphicx| package.
%
%    \begin{macrocode}
\let\cmll@ifemu=\iffalse
\DeclareOption{emu}{\let\cmll@ifemu=\iftrue}
%    \end{macrocode}
%
% The font is declared as a symbol font named \texttt{llsymbols}, in normal
% and bold versions. We provide package options to switch between the
% standard, sans-serif and Euler-style variants.
%
%    \begin{macrocode}
\def\cmll@style{auto}
\DeclareOption*{\edef\cmll@style{\CurrentOption}}
\ProcessOptions\relax
%    \end{macrocode}
%
% The following code is used to detect which family should be used. Euler is
% detected if its package is loaded, emulation is activated for txfonts and
% pxfonts, sans-serif is detected by looking at the default font family name.
%    \begin{macrocode}
\RequirePackage{ifthen}
\def\cmll@use@auto{%
  \@ifpackageloaded{euler}{%
    \def\cmll@style{euler}}{%
  \@ifpackageloaded{txfonts}{%
    \let\cmll@ifemu=\iftrue%
    \def\cmll@style{cm}}{%
  \@ifpackageloaded{pxfonts}{%
    \let\cmll@ifemu=\iftrue%
    \def\cmll@style{cm}}{%
  \ifthenelse{\equal{\rmdefault}{cmss}}{%
    \def\cmll@style{ss}}{%
    \def\cmll@style{cm}}%
  }}}%
  \csname cmll@use@\cmll@style\endcsname}
%    \end{macrocode}
%
% The following macros are used to set up the font families and symbols from
% other fonts.
%    \begin{macrocode}
\def\cmll@use@cm{%
  \DeclareSymbolFont{llsymbols}{U}{cmllr}{m}{n}%
  \SetSymbolFont{llsymbols}{bold}{U}{cmllr}{bx}{n}%
  \DeclareMathSymbol{\with}{\mathbin}{operators}{`\&}%
  \DeclareMathSymbol{\oc}{\mathord}{operators}{`!}%
  \DeclareMathSymbol{\wn}{\mathord}{operators}{`?}}
%    \end{macrocode}
% Here is the sans-serif variant.
%    \begin{macrocode}
\def\cmll@use@ss{%
  \DeclareSymbolFont{llsymbols}{U}{cmllss}{m}{n}%
  \SetSymbolFont{llsymbols}{bold}{U}{cmllss}{bx}{n}%
  \DeclareMathSymbol{\with}{\mathbin}{operators}{`\&}%
  \DeclareMathSymbol{\oc}{\mathord}{operators}{`!}%
  \DeclareMathSymbol{\wn}{\mathord}{operators}{`?}}
%    \end{macrocode}
% And here is the Euler variant.
%    \begin{macrocode}
\def\cmll@use@euler{%
  \DeclareSymbolFont{llsymbols}{U}{eull}{m}{n}%
  \SetSymbolFont{llsymbols}{bold}{U}{eull}{bx}{n}%
  \DeclareMathSymbol{\with}{\mathbin}{EulerFraktur}{"26}%
  \DeclareMathSymbol{\oc}{\mathord}{EulerFraktur}{"21}%
  \DeclareMathSymbol{\wn}{\mathord}{EulerFraktur}{"3F}}
%    \end{macrocode}
% Finally we activate the proper variant.
%    \begin{macrocode}
\csname cmll@use@\cmll@style\endcsname
%    \end{macrocode}
%
% In some cases it is preferable to emulate the |\invamp| by rotating the
% ampersand symbol. Here is a robust definition of this rotation:
%    \begin{macrocode}
\newcommand\invampemu{%
  \mathbin{\mathchoice%
    {\rotatebox[origin=c]{180}{$\&$}}%
    {\rotatebox[origin=c]{180}{$\&$}}%
    {\rotatebox[origin=c]{180}{$\scriptstyle\&$}}%
    {\rotatebox[origin=c]{180}{$\scriptscriptstyle\&$}}%
  }}
%    \end{macrocode}
% We may also want to emulate the big versions of the ampersand. In this case
% we change ther text size appropriately for each style, using the |relsize|
% package. This version is reasonable at normal size and becomes approximative
% when math is composed in small or large sizes.
%    \begin{macrocode}
\newcommand\bigwithemu{%
  \mathop{\mathchoice%
    {\vcenter{\hbox{\relsize{+4}$\&$}}}%
    {\vcenter{\hbox{\relsize{+2}$\&$}}}%
    {\vcenter{\hbox{\relsize{+0.5}$\&$}}}%
    {\vcenter{\hbox{\relsize{-1}$\&$}}}%
  }}
%    \end{macrocode}
% For the large inversed ampersand, we call the |\invamp| macro, which is
% supposed to be defined (either as a proper character or as an emulation as
% above). When it is emulated, this makes two nested |\mathchoice|s, which is
% not very efficient.
%    \begin{macrocode}
\newcommand\biginvampemu{%
  \mathop{\mathchoice%
    {\vcenter{\hbox{\relsize{+4}$\invamp$}}}%
    {\vcenter{\hbox{\relsize{+2}$\invamp$}}}%
    {\vcenter{\hbox{\relsize{+0.5}$\invamp$}}}%
    {\vcenter{\hbox{\relsize{-1}$\invamp$}}}}}
%    \end{macrocode}
%
% The actual commands |\invamp|, |\bigwith| and |\biginvamp| can be defined in
% various ways depending on the setup.
%
%    \begin{macrocode}
\cmll@ifemu
  \@ifundefined{invamp}{%
    \RequirePackage{graphicx}%
    \let\invamp=\invampemu
  }{}%
  \RequirePackage{relsize}%
  \let\bigwith=\bigwithemu
  \let\biginvamp=\biginvampemu
%    \end{macrocode}
% Already existing symbols are preserved in emulation mode.
%    \begin{macrocode}
  \def\cmll@declare@symbol#1#2#3#4{%
    \@ifundefined{#1}{%
      \expandafter\DeclareMathSymbol%
      \expandafter{\csname#1\endcsname}{#2}{#3}{#4}}{}}
\else
  \def\cmll@declare@symbol#1#2#3#4{%
    \expandafter\DeclareMathSymbol%
    \expandafter{\csname#1\endcsname}{#2}{#3}{#4}}
\fi
%    \end{macrocode}
%
% The new symbol definitions are the same for all variants.
%    \begin{macrocode}
\cmll@declare@symbol{invamp}{\mathbin}{llsymbols}{0}
\let\parr=\invamp
\cmll@declare@symbol{shpos}{\mathord}{llsymbols}{1}
\cmll@declare@symbol{shneg}{\mathord}{llsymbols}{2}
\cmll@declare@symbol{shift}{\mathord}{llsymbols}{3}
\cmll@declare@symbol{coh}{\mathrel}{llsymbols}{4}
\cmll@declare@symbol{scoh}{\mathrel}{llsymbols}{5}
\cmll@declare@symbol{incoh}{\mathrel}{llsymbols}{6}
\cmll@declare@symbol{sincoh}{\mathrel}{llsymbols}{7}
\cmll@declare@symbol{bigwith}{\mathop}{llsymbols}{8}
\cmll@declare@symbol{biginvamp}{\mathop}{llsymbols}{10}
\let\bigparr=\biginvamp
\cmll@declare@symbol{multimapboth}{\mathrel}{llsymbols}{12}
\cmll@declare@symbol{Bot}{\mathord}{llsymbols}{13}
\cmll@declare@symbol{Perp}{\mathrel}{llsymbols}{13}
\cmll@declare@symbol{simbot}{\mathord}{llsymbols}{14}
\cmll@declare@symbol{simperp}{\mathrel}{llsymbols}{14}
\cmll@declare@symbol{multimapinv}{\mathrel}{llsymbols}{15}
\cmll@declare@symbol{nmultimap}{\mathrel}{llsymbols}{16}
\cmll@declare@symbol{nmultimapinv}{\mathrel}{llsymbols}{17}
\cmll@declare@symbol{nmultimapboth}{\mathrel}{llsymbols}{18}
%</package>
%    \end{macrocode}
%
% \Finale
